Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified sources/net.sf.j2s.core/dist/dropins/net.sf.j2s.core.jar
Binary file not shown.
Binary file modified sources/net.sf.j2s.core/dist/net.sf.j2s.core_3.1.1.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
import org.eclipse.jdt.core.dom.WhileStatement;
import org.eclipse.jdt.core.dom.WildcardType;

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

public boolean visit(EnhancedForStatement node) {
String varName = getQualifiedSimpleName(node.getParameter().getName());
writeReplaceV("for (var V, $V = ", "V", varName);
SimpleName name = node.getParameter().getName();
String varName = getQualifiedSimpleName(name);
buffer.append("for (var ");
acceptVariableFinal(name, 1);
writeReplaceV(", $V = ", "V", varName);
Expression exp = node.getExpression();
ITypeBinding typeBinding = exp.resolveTypeBinding();
if (typeBinding.isArray()) {
Expand Down Expand Up @@ -672,8 +677,6 @@ public boolean visit(MethodDeclaration node) {
buffer.append("alert('native method must be replaced! " + key + "');\r\n");
log("native: " + key);
}
// didn't we just find out that there was nothing to do?
// addNativeJavadoc(node.getJavadoc(), null);
buffer.append("}\r\n");
// clearVariables(getVariableList('n'));
// blockLevel--;
Expand All @@ -689,16 +692,33 @@ public boolean visit(MethodDeclaration node) {
public void endVisit(MethodDeclaration node) {
if (NativeDoc.checkj2sIgnore(node))
return;
removeVariableFinals(node);
super.endVisit(node);
}

private void acceptVariableFinal(SimpleName name, int offset) {
IBinding binding = name.resolveBinding();
if (binding != null) {
String identifier = name.getIdentifier();
int level = blockLevel + offset;
VariableAdapter.FinalVariable f = new VariableAdapter.FinalVariable(level, identifier,
methodDeclareNameStack.size() == 0 ? null : methodDeclareNameStack.peek());
addVariable(f, identifier, binding);
//buffer.append("/*blockLevel " + blockLevel + " level " + level + "*/");
}
name.accept(this);
}

private void removeVariableFinals(MethodDeclaration node) {
IMethodBinding mBinding = node.resolveBinding();
if (mBinding != null)
methodDeclareNameStack.pop();
@SuppressWarnings("unchecked")
List<SingleVariableDeclaration> parameters = node.parameters();
String methodSig = (mBinding == null ? null : mBinding.getKey());
List<VariableAdapter.FinalVariable> finalVars = getVariableList('f');
List<VariableAdapter.FinalVariable> visitedVars = getVariableList('v');
List<VariableAdapter.FinalVariable> normalVars = getVariableList('n');
@SuppressWarnings("unchecked")
List<SingleVariableDeclaration> parameters = node.parameters();
IMethodBinding resolveBinding = node.resolveBinding();
String methodSig = (resolveBinding == null ? null : resolveBinding.getKey());
for (int i = parameters.size() - 1; i >= 0; i--) {
SingleVariableDeclaration varDecl = parameters.get(i);
SimpleName name = varDecl.getName();
Expand All @@ -708,13 +728,26 @@ public void endVisit(MethodDeclaration node) {
VariableAdapter.FinalVariable f = new VariableAdapter.FinalVariable(blockLevel + 1, identifier, methodSig);
f.toVariableName = identifier;
normalVars.remove(f);
//buffer.append("/*remNorm " + f.variableName + "/to/" + f.toVariableName + "*/");
if (Modifier.isFinal(binding.getModifiers())) {
finalVars.remove(f);
//buffer.append("/*remFinal " + f.variableName + "/to/" + f.toVariableName + "*/");
}
visitedVars.remove(f);
//buffer.append("/*remVis " + f.variableName + "/to/" + f.toVariableName + "*/");
}
}
}

private void clearVariables(char nf) {
List<VariableAdapter.FinalVariable> vars = getVariableList(nf);
for (int i = vars.size(); --i >= 0;) {
VariableAdapter.FinalVariable var = vars.get(i);
if (var.blockLevel >= blockLevel) {
vars.remove(i);
//buffer.append("/*remVar " + nf + " " + var.toVariableName + " */");
}
}
super.endVisit(node);
}

public boolean visit(MethodInvocation node) {
Expand Down Expand Up @@ -817,21 +850,12 @@ public void endVisit(ReturnStatement node) {
super.endVisit(node);
}

/**
* method parameters or catch variables
*/
public boolean visit(SingleVariableDeclaration node) {
SimpleName name = node.getName();
IBinding binding = name.resolveBinding();
if (binding != null) {
String identifier = name.getIdentifier();
VariableAdapter.FinalVariable f = null;
if (methodDeclareNameStack.size() == 0) {
f = new VariableAdapter.FinalVariable(blockLevel + 1, identifier, null);
} else {
String methodSig = methodDeclareNameStack.peek();
f = new VariableAdapter.FinalVariable(blockLevel + 1, identifier, methodSig);
}
addVariable(f, identifier, binding);
}
name.accept(this);
acceptVariableFinal(name, 1);
return false;
}

Expand Down Expand Up @@ -886,7 +910,11 @@ public boolean visit(SwitchCase node) {
}

public boolean visit(SynchronizedStatement node) {
// not implemented in JS, as there is only one thread
// we wrap this with a simple if() statement,
// checking that it is not null
buffer.append("if(!(");
node.getExpression().accept(this);
buffer.append("){throw new NullPointerException()}else");
node.getBody().accept(this);
return false;
}
Expand Down Expand Up @@ -1743,15 +1771,6 @@ private void addSuperConstructor(SuperConstructorInvocation node, IMethodBinding
addCallInit();
}

private void clearVariables(List<VariableAdapter.FinalVariable> vars) {
for (int i = vars.size(); --i >= 0;) {
VariableAdapter.FinalVariable var = vars.get(i);
if (var.blockLevel >= blockLevel) {
vars.remove(i);
}
}
}

private String getAnonymousName(ITypeBinding binding) {
String binaryName = null, bindingKey;
if ((binding.isAnonymous() || binding.isLocal()) && (binaryName = binding.getBinaryName()) == null
Expand Down Expand Up @@ -2826,12 +2845,13 @@ private String simpleNameInVarBinding(SimpleName node, char ch, IVariableBinding
if (currentBlockForVisit != -1) {
List<VariableAdapter.FinalVariable> finalVars = getVariableList('f');
List<VariableAdapter.FinalVariable> visitedVars = getVariableList('v');
int size = finalVars.size();
for (int i = 0; i < size; i++) {
String vname = varBinding.getName();
for (int i = 0, size = finalVars.size(); i < size; i++) {
VariableAdapter.FinalVariable vv = finalVars.get(size - i - 1);
if (vv.variableName.equals(varBinding.getName()) && vv.blockLevel <= currentBlockForVisit) {
if (vv.blockLevel <= currentBlockForVisit && vv.variableName.equals(vname)) {
if (!visitedVars.contains(vv)) {
visitedVars.add(vv);
//buffer.append("/* current " + currentBlockForVisit + " vlevel " + vv.blockLevel + " " + vv.variableName + "*/");
}
fieldVar = vv.toVariableName;
}
Expand Down Expand Up @@ -2954,11 +2974,7 @@ public boolean visit(VariableDeclarationFragment node) {
IBinding binding = name.resolveBinding();
if (binding == null)
return false;
String identifier = name.getIdentifier();
VariableAdapter.FinalVariable f = new VariableAdapter.FinalVariable(blockLevel, identifier,
methodDeclareNameStack.size() == 0 ? null : (String) methodDeclareNameStack.peek());
addVariable(f, identifier, binding);
name.accept(this);
acceptVariableFinal(name, 0);
Expression right = node.getInitializer();
ITypeBinding rightBinding = (right == null ? null : right.resolveTypeBinding());
if (rightBinding == null)
Expand Down Expand Up @@ -3608,8 +3624,11 @@ private void addVariable(VariableAdapter.FinalVariable f, String identifier, IBi
List<VariableAdapter.FinalVariable> normalVars = getVariableList('n');
f.toVariableName = identifier;
normalVars.add(f);
if (Modifier.isFinal(binding.getModifiers()))
//buffer.append("/*addVar n " + identifier + " */");
if (Modifier.isFinal(binding.getModifiers())) {
finalVars.add(f);
//buffer.append("/*addVar f " + identifier + " */");
}
}

/**
Expand Down Expand Up @@ -4109,6 +4128,10 @@ private String getMethodNameOrArrayForDeclaration(MethodDeclaration node, IMetho
boolean isConstructor, boolean addUnqualified) {
SimpleName nodeName = node.getName();
String methodName = (isConstructor ? "c$" : NameMapper.getJ2SName(nodeName));
if (methodName.equals("subSequence$I$I")) {
// for StringBuffer and StringBuilder to be like String
return "['subSequence','subSequence$I$I']";
}
String qname = getJ2SQualifiedName(methodName, null, mBinding, null, false);
ITypeBinding methodClass = mBinding.getDeclaringClass();
List<String> names = null;
Expand Down
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
2 changes: 2 additions & 0 deletions sources/net.sf.j2s.java.core/src/J2SVERSION.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
J2S._version = "3.1.2_2018.06.22
// first attempt to add JDeskTopPane
32 changes: 18 additions & 14 deletions sources/net.sf.j2s.java.core/src/java/awt/Component.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
import java.util.Map;
import java.util.Vector;

import javax.swing.JInternalFrame;

import sun.awt.AppContext;
import sun.awt.SunToolkit;
import swingjs.JSToolkit;
Expand Down Expand Up @@ -174,7 +176,7 @@ public abstract class Component
*
* @see #getParent
*/
transient Container parent;
protected transient Container parent;

/**
* The <code>AppContext</code> of the component. Applets/Plugin may change
Expand Down Expand Up @@ -208,15 +210,15 @@ public AppContext getAppContext() {
* @serial
* @see #getSize
*/
int width;
protected int width;

/**
* The height of the component.
*
* @serial
* @see #getSize
*/
int height;
protected int height;

/**
* The foreground color for this component. <code>foreground</code> can be
Expand Down Expand Up @@ -262,7 +264,7 @@ public AppContext getAppContext() {
* @see #getCursor
* @see #setCursor
*/
Cursor cursor;
protected Cursor cursor;

/**
* The locale for the component.
Expand All @@ -271,7 +273,7 @@ public AppContext getAppContext() {
* @see #getLocale
* @see #setLocale
*/
Locale locale;
protected Locale locale;

/**
* True when the object is visible. An object that is not visible is not
Expand Down Expand Up @@ -450,8 +452,8 @@ static class AWTTreeLock {
* @serial
* @see #dispatchEvent
*/
boolean newEventsOnly = false;
transient ComponentListener componentListener;
protected boolean newEventsOnly = false;
protected transient ComponentListener componentListener;
transient FocusListener focusListener;
transient HierarchyListener hierarchyListener;
transient HierarchyBoundsListener hierarchyBoundsListener;
Expand All @@ -461,7 +463,7 @@ static class AWTTreeLock {
transient MouseWheelListener mouseWheelListener;
transient InputMethodListener inputMethodListener;

transient RuntimeException windowClosingException = null;
protected transient RuntimeException windowClosingException = null;

/** Internal, constants for serialization */
final static String actionListenerK = "actionL";
Expand Down Expand Up @@ -495,7 +497,7 @@ static class AWTTreeLock {
* @see #enableInputMethods
* @see AWTEvent
*/
long eventMask = AWTEvent.INPUT_METHODS_ENABLED_MASK;
protected long eventMask = AWTEvent.INPUT_METHODS_ENABLED_MASK;

/**
* Static properties for incremental drawing.
Expand Down Expand Up @@ -581,7 +583,7 @@ private Object getChangeSupportLock() {
// return acc;
// }
//
boolean isPacked = false;
protected boolean isPacked = false;

/**
* Pseudoparameter for direct Geometry API (setLocation, setBounds setSize
Expand Down Expand Up @@ -1134,7 +1136,7 @@ public boolean isVisible() {
return isVisible_NoClientCode();
}

final boolean isVisible_NoClientCode() {
protected final boolean isVisible_NoClientCode() {
return visible;
}

Expand Down Expand Up @@ -2117,7 +2119,7 @@ public void reshape(int x, int y, int width, int height) {
// windows here as it is done from peer or native code when
// the window is really resized or moved, otherwise some
// events may be sent twice
if (this instanceof Window) {
if (this instanceof Window && !(this instanceof JInternalFrame)) {
needNotify = false;
}
// }
Expand Down Expand Up @@ -2744,7 +2746,7 @@ protected void invalidateComp() {
/**
* Invalidates the component unless it is already invalid.
*/
final void invalidateIfValid() {
protected final void invalidateIfValid() {
if (isValid()) {
invalidate();
}
Expand Down Expand Up @@ -2859,6 +2861,8 @@ public void setCursor(Cursor cursor) {
* Updates the cursor. May not be invoked from the native message pump.
*/
final void updateCursorImmediately() {
// this is the key method that updates a JComponent if there is
// no layout manager -- for example, for a JDesktop.
JSToolkit.setCursor(cursor);
// TODO
// if (peer instanceof LightweightPeer) {
Expand All @@ -2871,7 +2875,7 @@ final void updateCursorImmediately() {
// cPeer.updateCursorImmediately();
// }
// } else if (peer != null) {
// peer.updateCursorImmediately();
peer.updateCursorImmediately();
// }
}

Expand Down
Loading