Skip to content

Commit 181fcdd

Browse files
authored
Merge pull request #26 from BobHanson/yadav1
Yadav1
2 parents cdb45c4 + edf4ea7 commit 181fcdd

113 files changed

Lines changed: 28449 additions & 1081 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
164 Bytes
Binary file not shown.
164 Bytes
Binary file not shown.

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/Java2ScriptVisitor.java

Lines changed: 66 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@
122122
import org.eclipse.jdt.core.dom.WhileStatement;
123123
import org.eclipse.jdt.core.dom.WildcardType;
124124

125+
// BH 6/23/2018 -- synchronized(a = new Object()) {...} ---> if(!(a = new Object()) {throw new NullPointerException()}else{...}
126+
// BH 6/21/2018 -- CharSequence.subSequence() should be defined both subSequence$I$I and subSequence
125127
// BH 6/20/2018 -- fixes for (int var : new int[] {3,4,5}) becoming for var var
126128
// BH 6/19/2018 -- adds .j2s j2s.class.replacements=org.apache.log4j.->jalview.javascript.log4j.;
127129
// BH 5/15/2018 -- fix for a[pt++] |= 3 incrementing pt twice and disregarding a[][] (see test/Test_Or.java)
@@ -339,8 +341,8 @@ public void endVisit(Block node) {
339341
// look for trailing j2sNative block just before the end of a block
340342
getJ2sJavadoc(node, false);
341343
buffer.append("}");
342-
clearVariables(getVariableList('f'));
343-
clearVariables(getVariableList('n'));
344+
clearVariables('f');
345+
clearVariables('n');
344346
blockLevel--;
345347
super.endVisit(node);
346348
}
@@ -495,8 +497,11 @@ public boolean visit(EmptyStatement node) {
495497
}
496498

497499
public boolean visit(EnhancedForStatement node) {
498-
String varName = getQualifiedSimpleName(node.getParameter().getName());
499-
writeReplaceV("for (var V, $V = ", "V", varName);
500+
SimpleName name = node.getParameter().getName();
501+
String varName = getQualifiedSimpleName(name);
502+
buffer.append("for (var ");
503+
acceptVariableFinal(name, 1);
504+
writeReplaceV(", $V = ", "V", varName);
500505
Expression exp = node.getExpression();
501506
ITypeBinding typeBinding = exp.resolveTypeBinding();
502507
if (typeBinding.isArray()) {
@@ -672,8 +677,6 @@ public boolean visit(MethodDeclaration node) {
672677
buffer.append("alert('native method must be replaced! " + key + "');\r\n");
673678
log("native: " + key);
674679
}
675-
// didn't we just find out that there was nothing to do?
676-
// addNativeJavadoc(node.getJavadoc(), null);
677680
buffer.append("}\r\n");
678681
// clearVariables(getVariableList('n'));
679682
// blockLevel--;
@@ -689,16 +692,33 @@ public boolean visit(MethodDeclaration node) {
689692
public void endVisit(MethodDeclaration node) {
690693
if (NativeDoc.checkj2sIgnore(node))
691694
return;
695+
removeVariableFinals(node);
696+
super.endVisit(node);
697+
}
698+
699+
private void acceptVariableFinal(SimpleName name, int offset) {
700+
IBinding binding = name.resolveBinding();
701+
if (binding != null) {
702+
String identifier = name.getIdentifier();
703+
int level = blockLevel + offset;
704+
VariableAdapter.FinalVariable f = new VariableAdapter.FinalVariable(level, identifier,
705+
methodDeclareNameStack.size() == 0 ? null : methodDeclareNameStack.peek());
706+
addVariable(f, identifier, binding);
707+
//buffer.append("/*blockLevel " + blockLevel + " level " + level + "*/");
708+
}
709+
name.accept(this);
710+
}
711+
712+
private void removeVariableFinals(MethodDeclaration node) {
692713
IMethodBinding mBinding = node.resolveBinding();
693714
if (mBinding != null)
694715
methodDeclareNameStack.pop();
716+
@SuppressWarnings("unchecked")
717+
List<SingleVariableDeclaration> parameters = node.parameters();
718+
String methodSig = (mBinding == null ? null : mBinding.getKey());
695719
List<VariableAdapter.FinalVariable> finalVars = getVariableList('f');
696720
List<VariableAdapter.FinalVariable> visitedVars = getVariableList('v');
697721
List<VariableAdapter.FinalVariable> normalVars = getVariableList('n');
698-
@SuppressWarnings("unchecked")
699-
List<SingleVariableDeclaration> parameters = node.parameters();
700-
IMethodBinding resolveBinding = node.resolveBinding();
701-
String methodSig = (resolveBinding == null ? null : resolveBinding.getKey());
702722
for (int i = parameters.size() - 1; i >= 0; i--) {
703723
SingleVariableDeclaration varDecl = parameters.get(i);
704724
SimpleName name = varDecl.getName();
@@ -708,13 +728,26 @@ public void endVisit(MethodDeclaration node) {
708728
VariableAdapter.FinalVariable f = new VariableAdapter.FinalVariable(blockLevel + 1, identifier, methodSig);
709729
f.toVariableName = identifier;
710730
normalVars.remove(f);
731+
//buffer.append("/*remNorm " + f.variableName + "/to/" + f.toVariableName + "*/");
711732
if (Modifier.isFinal(binding.getModifiers())) {
712733
finalVars.remove(f);
734+
//buffer.append("/*remFinal " + f.variableName + "/to/" + f.toVariableName + "*/");
713735
}
714736
visitedVars.remove(f);
737+
//buffer.append("/*remVis " + f.variableName + "/to/" + f.toVariableName + "*/");
738+
}
739+
}
740+
}
741+
742+
private void clearVariables(char nf) {
743+
List<VariableAdapter.FinalVariable> vars = getVariableList(nf);
744+
for (int i = vars.size(); --i >= 0;) {
745+
VariableAdapter.FinalVariable var = vars.get(i);
746+
if (var.blockLevel >= blockLevel) {
747+
vars.remove(i);
748+
//buffer.append("/*remVar " + nf + " " + var.toVariableName + " */");
715749
}
716750
}
717-
super.endVisit(node);
718751
}
719752

720753
public boolean visit(MethodInvocation node) {
@@ -817,21 +850,12 @@ public void endVisit(ReturnStatement node) {
817850
super.endVisit(node);
818851
}
819852

853+
/**
854+
* method parameters or catch variables
855+
*/
820856
public boolean visit(SingleVariableDeclaration node) {
821857
SimpleName name = node.getName();
822-
IBinding binding = name.resolveBinding();
823-
if (binding != null) {
824-
String identifier = name.getIdentifier();
825-
VariableAdapter.FinalVariable f = null;
826-
if (methodDeclareNameStack.size() == 0) {
827-
f = new VariableAdapter.FinalVariable(blockLevel + 1, identifier, null);
828-
} else {
829-
String methodSig = methodDeclareNameStack.peek();
830-
f = new VariableAdapter.FinalVariable(blockLevel + 1, identifier, methodSig);
831-
}
832-
addVariable(f, identifier, binding);
833-
}
834-
name.accept(this);
858+
acceptVariableFinal(name, 1);
835859
return false;
836860
}
837861

@@ -886,7 +910,11 @@ public boolean visit(SwitchCase node) {
886910
}
887911

888912
public boolean visit(SynchronizedStatement node) {
889-
// not implemented in JS, as there is only one thread
913+
// we wrap this with a simple if() statement,
914+
// checking that it is not null
915+
buffer.append("if(!(");
916+
node.getExpression().accept(this);
917+
buffer.append("){throw new NullPointerException()}else");
890918
node.getBody().accept(this);
891919
return false;
892920
}
@@ -1743,15 +1771,6 @@ private void addSuperConstructor(SuperConstructorInvocation node, IMethodBinding
17431771
addCallInit();
17441772
}
17451773

1746-
private void clearVariables(List<VariableAdapter.FinalVariable> vars) {
1747-
for (int i = vars.size(); --i >= 0;) {
1748-
VariableAdapter.FinalVariable var = vars.get(i);
1749-
if (var.blockLevel >= blockLevel) {
1750-
vars.remove(i);
1751-
}
1752-
}
1753-
}
1754-
17551774
private String getAnonymousName(ITypeBinding binding) {
17561775
String binaryName = null, bindingKey;
17571776
if ((binding.isAnonymous() || binding.isLocal()) && (binaryName = binding.getBinaryName()) == null
@@ -2826,12 +2845,13 @@ private String simpleNameInVarBinding(SimpleName node, char ch, IVariableBinding
28262845
if (currentBlockForVisit != -1) {
28272846
List<VariableAdapter.FinalVariable> finalVars = getVariableList('f');
28282847
List<VariableAdapter.FinalVariable> visitedVars = getVariableList('v');
2829-
int size = finalVars.size();
2830-
for (int i = 0; i < size; i++) {
2848+
String vname = varBinding.getName();
2849+
for (int i = 0, size = finalVars.size(); i < size; i++) {
28312850
VariableAdapter.FinalVariable vv = finalVars.get(size - i - 1);
2832-
if (vv.variableName.equals(varBinding.getName()) && vv.blockLevel <= currentBlockForVisit) {
2851+
if (vv.blockLevel <= currentBlockForVisit && vv.variableName.equals(vname)) {
28332852
if (!visitedVars.contains(vv)) {
28342853
visitedVars.add(vv);
2854+
//buffer.append("/* current " + currentBlockForVisit + " vlevel " + vv.blockLevel + " " + vv.variableName + "*/");
28352855
}
28362856
fieldVar = vv.toVariableName;
28372857
}
@@ -2954,11 +2974,7 @@ public boolean visit(VariableDeclarationFragment node) {
29542974
IBinding binding = name.resolveBinding();
29552975
if (binding == null)
29562976
return false;
2957-
String identifier = name.getIdentifier();
2958-
VariableAdapter.FinalVariable f = new VariableAdapter.FinalVariable(blockLevel, identifier,
2959-
methodDeclareNameStack.size() == 0 ? null : (String) methodDeclareNameStack.peek());
2960-
addVariable(f, identifier, binding);
2961-
name.accept(this);
2977+
acceptVariableFinal(name, 0);
29622978
Expression right = node.getInitializer();
29632979
ITypeBinding rightBinding = (right == null ? null : right.resolveTypeBinding());
29642980
if (rightBinding == null)
@@ -3608,8 +3624,11 @@ private void addVariable(VariableAdapter.FinalVariable f, String identifier, IBi
36083624
List<VariableAdapter.FinalVariable> normalVars = getVariableList('n');
36093625
f.toVariableName = identifier;
36103626
normalVars.add(f);
3611-
if (Modifier.isFinal(binding.getModifiers()))
3627+
//buffer.append("/*addVar n " + identifier + " */");
3628+
if (Modifier.isFinal(binding.getModifiers())) {
36123629
finalVars.add(f);
3630+
//buffer.append("/*addVar f " + identifier + " */");
3631+
}
36133632
}
36143633

36153634
/**
@@ -4109,6 +4128,10 @@ private String getMethodNameOrArrayForDeclaration(MethodDeclaration node, IMetho
41094128
boolean isConstructor, boolean addUnqualified) {
41104129
SimpleName nodeName = node.getName();
41114130
String methodName = (isConstructor ? "c$" : NameMapper.getJ2SName(nodeName));
4131+
if (methodName.equals("subSequence$I$I")) {
4132+
// for StringBuffer and StringBuilder to be like String
4133+
return "['subSequence','subSequence$I$I']";
4134+
}
41124135
String qname = getJ2SQualifiedName(methodName, null, mBinding, null, false);
41134136
ITypeBinding methodClass = mBinding.getDeclaringClass();
41144137
List<String> names = null;
75.7 KB
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
J2S._version = "3.1.2_2018.06.22
2+
// first attempt to add JDeskTopPane

sources/net.sf.j2s.java.core/src/java/awt/Component.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
import java.util.Map;
6666
import java.util.Vector;
6767

68+
import javax.swing.JInternalFrame;
69+
6870
import sun.awt.AppContext;
6971
import sun.awt.SunToolkit;
7072
import swingjs.JSToolkit;
@@ -174,7 +176,7 @@ public abstract class Component
174176
*
175177
* @see #getParent
176178
*/
177-
transient Container parent;
179+
protected transient Container parent;
178180

179181
/**
180182
* The <code>AppContext</code> of the component. Applets/Plugin may change
@@ -208,15 +210,15 @@ public AppContext getAppContext() {
208210
* @serial
209211
* @see #getSize
210212
*/
211-
int width;
213+
protected int width;
212214

213215
/**
214216
* The height of the component.
215217
*
216218
* @serial
217219
* @see #getSize
218220
*/
219-
int height;
221+
protected int height;
220222

221223
/**
222224
* The foreground color for this component. <code>foreground</code> can be
@@ -262,7 +264,7 @@ public AppContext getAppContext() {
262264
* @see #getCursor
263265
* @see #setCursor
264266
*/
265-
Cursor cursor;
267+
protected Cursor cursor;
266268

267269
/**
268270
* The locale for the component.
@@ -271,7 +273,7 @@ public AppContext getAppContext() {
271273
* @see #getLocale
272274
* @see #setLocale
273275
*/
274-
Locale locale;
276+
protected Locale locale;
275277

276278
/**
277279
* True when the object is visible. An object that is not visible is not
@@ -450,8 +452,8 @@ static class AWTTreeLock {
450452
* @serial
451453
* @see #dispatchEvent
452454
*/
453-
boolean newEventsOnly = false;
454-
transient ComponentListener componentListener;
455+
protected boolean newEventsOnly = false;
456+
protected transient ComponentListener componentListener;
455457
transient FocusListener focusListener;
456458
transient HierarchyListener hierarchyListener;
457459
transient HierarchyBoundsListener hierarchyBoundsListener;
@@ -461,7 +463,7 @@ static class AWTTreeLock {
461463
transient MouseWheelListener mouseWheelListener;
462464
transient InputMethodListener inputMethodListener;
463465

464-
transient RuntimeException windowClosingException = null;
466+
protected transient RuntimeException windowClosingException = null;
465467

466468
/** Internal, constants for serialization */
467469
final static String actionListenerK = "actionL";
@@ -495,7 +497,7 @@ static class AWTTreeLock {
495497
* @see #enableInputMethods
496498
* @see AWTEvent
497499
*/
498-
long eventMask = AWTEvent.INPUT_METHODS_ENABLED_MASK;
500+
protected long eventMask = AWTEvent.INPUT_METHODS_ENABLED_MASK;
499501

500502
/**
501503
* Static properties for incremental drawing.
@@ -581,7 +583,7 @@ private Object getChangeSupportLock() {
581583
// return acc;
582584
// }
583585
//
584-
boolean isPacked = false;
586+
protected boolean isPacked = false;
585587

586588
/**
587589
* Pseudoparameter for direct Geometry API (setLocation, setBounds setSize
@@ -1134,7 +1136,7 @@ public boolean isVisible() {
11341136
return isVisible_NoClientCode();
11351137
}
11361138

1137-
final boolean isVisible_NoClientCode() {
1139+
protected final boolean isVisible_NoClientCode() {
11381140
return visible;
11391141
}
11401142

@@ -2117,7 +2119,7 @@ public void reshape(int x, int y, int width, int height) {
21172119
// windows here as it is done from peer or native code when
21182120
// the window is really resized or moved, otherwise some
21192121
// events may be sent twice
2120-
if (this instanceof Window) {
2122+
if (this instanceof Window && !(this instanceof JInternalFrame)) {
21212123
needNotify = false;
21222124
}
21232125
// }
@@ -2744,7 +2746,7 @@ protected void invalidateComp() {
27442746
/**
27452747
* Invalidates the component unless it is already invalid.
27462748
*/
2747-
final void invalidateIfValid() {
2749+
protected final void invalidateIfValid() {
27482750
if (isValid()) {
27492751
invalidate();
27502752
}
@@ -2859,6 +2861,8 @@ public void setCursor(Cursor cursor) {
28592861
* Updates the cursor. May not be invoked from the native message pump.
28602862
*/
28612863
final void updateCursorImmediately() {
2864+
// this is the key method that updates a JComponent if there is
2865+
// no layout manager -- for example, for a JDesktop.
28622866
JSToolkit.setCursor(cursor);
28632867
// TODO
28642868
// if (peer instanceof LightweightPeer) {
@@ -2871,7 +2875,7 @@ final void updateCursorImmediately() {
28712875
// cPeer.updateCursorImmediately();
28722876
// }
28732877
// } else if (peer != null) {
2874-
// peer.updateCursorImmediately();
2878+
peer.updateCursorImmediately();
28752879
// }
28762880
}
28772881

0 commit comments

Comments
 (0)