Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
218aacb
java.util.concurrent.ConcurrentMap
BobHanson Jun 18, 2018
b6546df
a2s.TextArea missing setCaretPosition()
BobHanson Jun 18, 2018
b5a4eb0
mixup of Float.MIN_VALUE and Float.MAX_VALUE
BobHanson Jun 18, 2018
269f2d2
adding Locale.UK as EN_US
BobHanson Jun 19, 2018
c51b806
// BH 6/19/2018 8:49:57 AM fix for checkDeclared
BobHanson Jun 19, 2018
cc8761a
Java7 java.util.Objects added; Arrays adapted
BobHanson Jun 19, 2018
21707d8
moving SwingJS-site.zip to /dist
BobHanson Jun 19, 2018
1673c46
moving SwingJS-site.zip to /dist; new site.zip
BobHanson Jun 19, 2018
df6f2ae
fix for Enum.valueOf(String) missing
BobHanson Jun 19, 2018
4570af7
fix for char File.separator missing
BobHanson Jun 19, 2018
b6e8ef6
new transpiler and runtime
BobHanson Jun 19, 2018
81942c7
new transpiler
BobHanson Jun 19, 2018
ba50f7e
adds .j2s param j2s.class.replacements
BobHanson Jun 19, 2018
4d4f870
.j2s j2s.class.replacements
BobHanson Jun 20, 2018
b9e3520
j2sClazz adds e.printStackTrace(PrintStream)
BobHanson Jun 20, 2018
7fb09c1
roughing in of JDesktopPane, JInternalFrame, DesktopManager
BobHanson Jun 20, 2018
edacf79
roughing in of JDesktopPane, JInternalFrame, DesktopManager
BobHanson Jun 20, 2018
6ab398e
adding java.util.concurrent.locks
BobHanson Jun 20, 2018
81dd881
new SwingJS-zip
BobHanson Jun 20, 2018
032bbe3
missing files
BobHanson Jun 20, 2018
e50a0b3
various upgrades for JalviewJS
BobHanson Jun 20, 2018
67f5742
new SwingJS-site.zip
BobHanson Jun 20, 2018
1567e4a
fixes menubar JS error trying to close
BobHanson Jun 20, 2018
9e97566
fixes missing Internal frame event classes
BobHanson Jun 20, 2018
dbabbfd
temporary JSProgressBarUI
BobHanson Jun 20, 2018
846adc0
for (int var: ....) becoming for (var var
BobHanson Jun 20, 2018
a72bb05
new zip
BobHanson Jun 20, 2018
cf340a4
JToolTip (still issues with HTML)
BobHanson Jun 21, 2018
8975a82
JToolTip fixed; now heavyweight
BobHanson Jun 21, 2018
98e8b22
transpiler and runtime fixes
BobHanson Jun 21, 2018
abe06ab
J2S._version = "3.1.2_2018.06.22
BobHanson Jun 22, 2018
01ff1e6
Adds JSInternalFrame as JFrame
BobHanson Jun 22, 2018
2871395
SwingJS-site.zip for JSInternalFrame extends JFrame
BobHanson Jun 22, 2018
59b7293
dispense with JSInternalFrame
BobHanson Jun 22, 2018
354999f
dispense with JSInternalFrame
BobHanson Jun 22, 2018
2d99ba4
Adds JInternalFrame/JDesktop
BobHanson Jun 23, 2018
2b68895
Adds JInternalFrame/JDesktop
BobHanson Jun 23, 2018
d18c927
// BH 6/23/2018 -- synchronized(a = new Object()) {...}
BobHanson Jun 23, 2018
d294a62
temp save
BobHanson Jun 23, 2018
edf4ea7
JInternalFrame HTML L&F, but not implemented
BobHanson Jun 24, 2018
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,10 @@
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)
// BH 3/27/2018 -- fix for anonymous inner classes of inner classes not having this.this$0
// BH 1/5/2018 -- @j2sKeep removed; refactored into one class
Expand Down Expand Up @@ -337,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 @@ -494,8 +498,10 @@ public boolean visit(EmptyStatement node) {

public boolean visit(EnhancedForStatement node) {
SimpleName name = node.getParameter().getName();
String varName = name.getIdentifier();
writeReplaceV("for (var V, $V = ", "V", varName);
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 @@ -671,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 @@ -688,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 @@ -707,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 @@ -816,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 @@ -885,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 @@ -1450,7 +1479,9 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
buffer.append(trailingBuffer.getAssertString());
addDefaultConstructor();
buffer.append("var $vals=[];\r\n");
buffer.append("Clazz.newMeth(C$, 'values', function() { return $vals }, 1);\r\n");
// implicit Enum methods added as trailer
buffer.append("Clazz.newMeth(C$, 'values', function() { return $vals }, 1);\r\n");
buffer.append("Clazz.newMeth(C$, '$valueOf$S', function(name) { for (var val in $vals){ if ($vals[val].$name == name) return $vals[val]} return null }, 1);\r\n");
} else {
buffer.append(trailingBuffer); // also writes the assert string
if (isAnonymous) {
Expand Down Expand Up @@ -1740,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 @@ -2823,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 @@ -2951,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 @@ -3605,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 @@ -4106,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 Expand Up @@ -4359,9 +4385,10 @@ private static String j2sGetParamCode(ITypeBinding binding, boolean addAAA, bool
name = "S";
break;
default:
if (prefix != null)
if (prefix == null)
name = checkClassReplacement(name);
else
name = (asGenericObject ? "O" : prefix + name); // "O";//

name = name.replace("java.lang.", "").replace('.', '_');
break;
}
Expand Down Expand Up @@ -4653,6 +4680,54 @@ public void setDebugging(boolean isDebugging) {
}



private static Map<String, String> htClassReplacements;
private static List<String> lstPackageReplacements;

public static void setClassReplacements(String keyValues) {
// j2s.class.replacements=org.apache.log4j.*:jalview.jslogger.;
htClassReplacements = null;
if (keyValues == null)
return;
htClassReplacements = new Hashtable<String, String>();
lstPackageReplacements = new ArrayList<String>();
String[] pairs = keyValues.split(";");
for (int i = pairs.length; --i >= 0;) {
pairs[i] = pairs[i].trim();
if (pairs[i].length() == 0)
continue;
String[] kv = pairs[i].split("->");
htClassReplacements.put(kv[0], kv[1]);
if (kv[0].endsWith("."))
lstPackageReplacements.add(kv[0]);
System.err.println("class replacement " + kv[0] + " --> " + kv[1]);
}
}


private static String checkClassReplacement(String className) {
if (htClassReplacements != null) {
String rep = htClassReplacements.get(className);
if (rep == null && lstPackageReplacements != null) {
for (int i = lstPackageReplacements.size(); --i >= 0;) {
rep = lstPackageReplacements.get(i);
if (className.startsWith(rep)) {
rep = htClassReplacements.get(rep) + className.substring(rep.length());
break;
}
if (i == 0)
rep = null;
}

}
if (rep != null) {
System.out.println(className + " -> " + rep);
return rep;
}
}
return className;
}

/**
* tracks file byte pointers for @j2sNative, @j2sIgnore
*/
Expand Down Expand Up @@ -4714,7 +4789,7 @@ private String getNestedClazzLoads(String className, boolean doCache) {
// loop through packages and outer Class
while (i < parts.length && (i == 1 || !Character.isUpperCase(parts[i - 1].charAt(0))))
s += "." + parts[i++];
s = "'" + s + "'";
s = "'" + checkClassReplacement(s) + "'";
// int nlast = parts.length;
if (i < parts.length) {
s = "[" + s;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void process(ICompilationUnit sourceUnit, IContainer binaryFolder) {
Java2ScriptVisitor.setNoQualifiedNamePackages(getProperty("j2s.compiler.nonqualified.classes"));
boolean isDebugging = "debug".equals(getProperty("j2s.compiler.mode"));
visitor.setDebugging(isDebugging);
Java2ScriptVisitor.setClassReplacements(getProperty("j2s.class.replacements"));
String j2sPath = siteFolder + "/swingjs/j2s";
try {

Expand Down
Binary file removed sources/net.sf.j2s.java.core/SwingJS-site.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions sources/net.sf.j2s.java.core/build_core_applet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@

<echo>TODO: Could delete demo html files? </echo>

<echo>creating SwingJS-site.zip </echo>
<zip destfile="SwingJS-site.zip" basedir="site" />
<echo>creating dist/SwingJS-site.zip </echo>
<zip destfile="dist/SwingJS-site.zip" basedir="site" />

</target>

Expand Down
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
4 changes: 4 additions & 0 deletions sources/net.sf.j2s.java.core/src/a2s/TextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public TextArea(String text, int rows, int cols) {
setViewportView(ta = new JTextArea(text, rows, cols));
awtDefaults();
}

public void setCaretPosition(int pos) {
ta.setCaretPosition(pos);
}

void awtDefaults() {
// setAutoscrolls(true);
Expand Down
Loading