Skip to content

Commit 44c6921

Browse files
committed
java2script dual-mode transpiler 5.0.1 for SwingJS and legacy Jmol
Hooray! Working for Jmol. We can abandon the need to use Eclipse Luna to run the old java2script 4.2 transpiler that was so quirky. Now the transpiler for Jmol creates code directly in the site/ folder, just like the SwingJS transpiler, and changes in "legacy" Jmol can be checked in JavaScript directly using the ?j2sdebugcode directive on the url line.
1 parent 6fe508c commit 44c6921

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+236
-9435
lines changed
-415 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20231112114539
1+
20231113043956
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20231112114539
1+
20231113043956

sources/net.sf.j2s.core/src/j2s/jmol/Java2ScriptLegacyCompiler.java

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ public boolean compileToJavaScript(IFile javaSource, String trailer) {
108108
isDebugging = "debug".equals(props.getProperty("j2s.compiler.mode"));
109109
visitor.setDebugging(isDebugging);
110110
dvisitor.setDebugging(isDebugging);
111-
dvisitor.setToCompileVariableName(false); // no compression
111+
// boolean toCompress = "release".equals(props.getProperty("j2s.compiler.mode"));
112+
// ((ASTVariableVisitor) visitor.getAdaptable(ASTVariableVisitor.class)).setToCompileVariableName(toCompress);
113+
// dvisitor.setToCompileVariableName(false);
112114
errorOccurs = false;
113115
try {
114116
root.accept(visitor);
@@ -142,10 +144,7 @@ private void outputJavaScript(ASTScriptVisitor visitor, DependencyASTVisitor dvi
142144
String outputPath, String trailer, String sourceLocation) {
143145
String js = finalFixes(dvisitor.getDependencyScript(visitor.getBuffer()));
144146
String elementName = fRoot.getJavaElement().getElementName();
145-
// if (elementName.endsWith(".class") || elementName.endsWith(".java")) {
146-
// //$NON-NLS-1$//$NON-NLS-2$
147147
elementName = elementName.substring(0, elementName.lastIndexOf('.'));
148-
// } /* maybe ended with other customized extension
149148
String packageName = visitor.getPackageName();
150149
if (packageName != null) {
151150
String dir = packageName.replace('.', '/');
@@ -161,69 +160,13 @@ private void outputJavaScript(ASTScriptVisitor visitor, DependencyASTVisitor dvi
161160
}
162161
elementName = fixPackageName(elementName);
163162
File jsFile = new File(outputPath, elementName + ".js"); // $NON-NLS-1
164-
writeToFile(jsFile, js + ";//" + trailer);
163+
writeToFile(jsFile, js + ";//" + trailer + "\r\n");
165164

166165
if (packageName != null) {
167166
nResources += checkCopiedResources(packageName, sourceLocation, j2sPath);
168167
}
169-
170-
// this was for class files with multiple non-private additional classes.
171-
// specifically StateManager.Connections, ActionManager.Gesture, and Int2IntHash.Int2IntHashEntry
172-
// these should have been private to those classes.
173-
// String[] classNameSet = dvisitor.getClassNames();
174-
// if (classNameSet.length > 1) {
175-
// addPackageJS(packageName, elementName, classNameSet, outputPath);
176-
// }
177168
}
178169

179-
// private void addPackageJS(String packageName, String elementName, String[] classNameSet, String outputPath) {
180-
// StringBuffer buffer = new StringBuffer();
181-
// String key = "ClazzLoader.jarClasspath (path + \"" + elementName + ".js\", [";
182-
// buffer.append(key + "\r\n");
183-
// DependencyASTVisitor.joinArrayClasses(buffer, classNameSet, null, ",\r\n");
184-
//
185-
// buffer.append("]);\r\n");
186-
// String s = props.getProperty("package.js");
187-
// if (s == null || s.length() == 0) {
188-
// s = "package.js";
189-
// }
190-
// File f = new File(outputPath, s);
191-
// String source = null;
192-
// if (f.exists()) {
193-
// source = FileUtil.readSource(f);
194-
// int index = source.indexOf(key);
195-
// boolean updated = false;
196-
// if (index != -1) {
197-
// int index2 = source.indexOf("]);", index + key.length());
198-
// if (index2 != -1) {
199-
// source = source.substring(0, index) + buffer.toString() + source.substring(index2 + 5);
200-
// updated = true;
201-
// }
202-
// }
203-
// if (!updated) {
204-
// source += buffer.toString();
205-
// }
206-
// }
207-
// if (source == null) {
208-
// String pkgName = null;
209-
// if (packageName == null || packageName.length() == 0) {
210-
// pkgName = "package";
211-
// } else {
212-
// pkgName = packageName + ".package";
213-
// }
214-
// source = "var path = ClazzLoader.getClasspathFor (\"" + pkgName + "\");\r\n"
215-
// + "path = path.substring (0, path.lastIndexOf (\"package.js\"));\r\n";
216-
// source += buffer.toString();
217-
// }
218-
// try {
219-
// FileOutputStream fos = new FileOutputStream(f);
220-
// fos.write(source.getBytes());
221-
// fos.close();
222-
// } catch (IOException e) {
223-
// e.printStackTrace();
224-
// }
225-
// }
226-
227170
private String finalFixes(String js) {
228171
js = js.replaceAll("cla\\$\\$", "c\\$").replaceAll("innerThis", "i\\$").replaceAll("finalVars", "v\\$")
229172
.replaceAll("\\.callbacks", "\\.b\\$").replaceAll("\\.\\$finals", "\\.f\\$")

sources/net.sf.j2s.core/src/j2s/jmol/common/ASTJ2SDocVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ boolean visitNativeJavadoc(Javadoc javadoc, Block node, boolean superVisit) {
153153
}
154154
}
155155
}
156-
boolean toCompileVariableName = ((ASTVariableVisitor) getAdaptable(ASTVariableVisitor.class)).isToCompileVariableName();
156+
boolean toCompileVariableName = false;//((ASTVariableVisitor) getAdaptable(ASTVariableVisitor.class)).isToCompileVariableName();
157157

158158
if (!toCompileVariableName) {
159159
for (Iterator iter = tags.iterator(); iter.hasNext();) {

sources/net.sf.j2s.core/src/j2s/jmol/common/ASTScriptVisitor.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ public boolean visit(AnonymousClassDeclaration node) {
240240
buffer.append(shortClassName);
241241
buffer.append("$ = function () {\r\n");
242242

243-
buffer.append("Clazz.pu$h(self.c$);\r\n");
244-
buffer.append("cla$$ = ");
243+
buffer.append("/*if*/;(function(){\r\n//Clazz.pu$h(self.c$);\r\n");
244+
buffer.append("var cla$$ = ");
245245
//buffer.append("Clazz.decorateAsType (");
246246
buffer.append("Clazz.decorateAsClass (");
247247
// buffer.append(JavaLangUtil.ripJavaLang(fullClassName));
@@ -427,7 +427,7 @@ public boolean visit(AnonymousClassDeclaration node) {
427427
}
428428
}
429429

430-
buffer.append("cla$$ = Clazz.p0p ();\r\n");
430+
buffer.append("/*eoif*/})();\r\n//cla$$ = Clazz.p0p ();\r\n");
431431

432432
typeVisitor.setClassName(oldClassName);
433433

@@ -1187,12 +1187,12 @@ public boolean visit(EnumDeclaration node) {
11871187
node.accept(visitor);
11881188
if ((node.getModifiers() & Modifier.STATIC) != 0) {
11891189
String str = visitor.getBuffer().toString();
1190-
if (!str.startsWith("cla$$")) {
1190+
if (!str.startsWith("var cla$$")) {
11911191
laterBuffer.append(str);
11921192
} else {
1193-
laterBuffer.append("Clazz.pu$h(self.c$);\r\n");
1194-
laterBuffer.append(str);
1195-
laterBuffer.append("cla$$ = Clazz.p0p ();\r\n");
1193+
laterBuffer.append("/*if*/;(function(){\r\n//Clazz.pu$h(self.c$);\r\n");
1194+
laterBuffer.append(str);
1195+
laterBuffer.append("/*eoif*/})();\r\n//cla$$ = Clazz.p0p ();\r\n");
11961196
}
11971197
} else {
11981198
/*
@@ -1219,9 +1219,9 @@ public boolean visit(EnumDeclaration node) {
12191219
// methodBuffer.append("$" + binding.getName());
12201220
// }
12211221
// methodBuffer.append("$ = function () {\r\n");
1222-
methodBuffer.append("Clazz.pu$h(self.c$);\r\n");
1222+
methodBuffer.append("/*if*/;(function(){\r\n//Clazz.pu$h(self.c$);\r\n");
12231223
methodBuffer.append(visitor.getBuffer().toString());
1224-
methodBuffer.append("cla$$ = Clazz.p0p ();\r\n");
1224+
methodBuffer.append("/*eoif*/})();\r\n//cla$$ = Clazz.p0p ();\r\n");
12251225
// methodBuffer.append("};\r\n");
12261226
//
12271227
// String pkgName = visitor.getPackageName();
@@ -1242,7 +1242,7 @@ public boolean visit(EnumDeclaration node) {
12421242
}
12431243
return false;
12441244
}
1245-
buffer.append("cla$$ = ");
1245+
buffer.append("var cla$$ = ");
12461246

12471247
buffer.append("Clazz.decorateAsClass (");
12481248

@@ -2047,7 +2047,7 @@ private boolean checkJ2STags(MethodDeclaration node, boolean needScope) {
20472047
read = readSources(node, "@j2sDebug", prefix, suffix, false);
20482048
}
20492049
if (!read) {
2050-
boolean toCompileVariableName = ((ASTVariableVisitor) getAdaptable(ASTVariableVisitor.class)).isToCompileVariableName();
2050+
boolean toCompileVariableName = false;//((ASTVariableVisitor) getAdaptable(ASTVariableVisitor.class)).isToCompileVariableName();
20512051
if (!toCompileVariableName) {
20522052
read = readSources(node, "@j2sNativeSrc", prefix, suffix, false);
20532053
}
@@ -2703,7 +2703,7 @@ public void endVisit(TypeDeclaration node) {
27032703
}
27042704
}
27052705
if (needReturn) {
2706-
buffer.append("cla$$ = ");
2706+
buffer.append("var cla$$ = ");
27072707
}
27082708
buffer.append("Clazz.declareInterface (");
27092709
int lastIndexOf = fullClassName.lastIndexOf('.');
@@ -3369,12 +3369,12 @@ public boolean visit(TypeDeclaration node) {
33693369
|| (node.getParent() instanceof TypeDeclaration
33703370
&& ((TypeDeclaration) node.getParent()).isInterface())) {
33713371
String str = visitor.getBuffer().toString();
3372-
if (!str.startsWith("cla$$")) {
3372+
if (!str.startsWith("var cla$$")) {
33733373
laterBuffer.append(str);
33743374
} else {
3375-
laterBuffer.append("Clazz.pu$h(self.c$);\r\n");
3375+
laterBuffer.append("/*if*/;(function(){\r\n//Clazz.pu$h(self.c$);\r\n");
33763376
laterBuffer.append(str);
3377-
laterBuffer.append("cla$$ = Clazz.p0p ();\r\n");
3377+
laterBuffer.append("/*eoif*/})();\r\n//cla$$ = Clazz.p0p ();\r\n");
33783378
}
33793379
} else {
33803380
/*
@@ -3418,9 +3418,9 @@ public static void main(String[] args) {
34183418
targetClassName = targetClassName.replace('.', '$');
34193419
methodBuffer.append(targetClassName);
34203420
methodBuffer.append("$ = function () {\r\n");
3421-
methodBuffer.append("Clazz.pu$h(self.c$);\r\n");
3421+
methodBuffer.append("/*if*/;(function(){\r\n//Clazz.pu$h(self.c$);\r\n");
34223422
methodBuffer.append(visitor.getBuffer().toString());
3423-
methodBuffer.append("cla$$ = Clazz.p0p ();\r\n");
3423+
methodBuffer.append("/*eoif*/})();\r\n//cla$$ = Clazz.p0p ();\r\n");
34243424
methodBuffer.append("};\r\n");
34253425

34263426
String pkgName = visitor.getPackageName();
@@ -3442,7 +3442,7 @@ public static void main(String[] args) {
34423442
return false;
34433443
}
34443444
readSources(node, "@j2sPrefix", "", " ", true);
3445-
buffer.append("cla$$ = ");
3445+
buffer.append("var cla$$ = ");
34463446

34473447
buffer.append("Clazz.decorateAsClass (");
34483448

sources/net.sf.j2s.core/src/j2s/jmol/common/ASTVariableVisitor.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,16 @@ public class ASTVariableVisitor extends AbstractPluginVisitor {
5252
/**
5353
* Whether to compile variable names into minimized names or not
5454
*/
55-
protected boolean toCompileVariableName = true;
56-
57-
public boolean isToCompileVariableName() {
58-
return toCompileVariableName;
59-
}
60-
61-
public void setToCompileVariableName(boolean toCompileVariableName) {
62-
this.toCompileVariableName = toCompileVariableName;
63-
}
55+
protected boolean toCompileVariableName = false;
6456

57+
// public boolean isToCompileVariableName() {
58+
// return toCompileVariableName;
59+
// }
60+
//
61+
// public void setToCompileVariableName(boolean toCompileVariableName) {
62+
// this.toCompileVariableName = toCompileVariableName;
63+
// }
64+
//
6565
protected String getVariableName(String name) {
6666
for (int i = normalVars.size() - 1; i >= 0; i--) {
6767
ASTFinalVariable var = (ASTFinalVariable) normalVars.get(i);

sources/net.sf.j2s.core/src/j2s/jmol/common/DependencyASTVisitor.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,14 +1042,14 @@ public void setDebugging(boolean isDebugging) {
10421042
this.isDebugging = isDebugging;
10431043
}
10441044

1045-
public boolean isToCompileVariableName() {
1046-
return toCompileVariableName;
1047-
}
1048-
1049-
public void setToCompileVariableName(boolean toCompileVariableName) {
1050-
this.toCompileVariableName = toCompileVariableName;
1051-
}
1052-
1045+
// public boolean isToCompileVariableName() {
1046+
// return toCompileVariableName;
1047+
// }
1048+
//
1049+
// public void setToCompileVariableName(boolean toCompileVariableName) {
1050+
// this.toCompileVariableName = toCompileVariableName;
1051+
// }
1052+
//
10531053
public boolean visit(MethodDeclaration node) {
10541054
IMethodBinding mBinding = node.resolveBinding();
10551055
if (Bindings.isMethodInvoking(mBinding, "net.sf.j2s.ajax.SimplePipeRunnable", "deal")) {

0 commit comments

Comments
 (0)