Skip to content

Commit 3110fa2

Browse files
committed
java2script 5.0.1 Integrated Legacy and SwingJS transpilers
non-SwingJS "Legacy" Jmol was using the java2script 4.2 transpiler which was only operable using Eclipse Juno (4.2, 2013). This new branch integrates that into the SwingJS transpiler, allowing both to be used (and fixed!!) in current Eclipse versions. The difference is detected by using .j2sjmol for legacy and .j2s for SwingJS.
1 parent 4367fc5 commit 3110fa2

38 files changed

+7542
-579
lines changed

sources/net.sf.j2s.core/README.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
The net.sf.j2s.core Eclipse project creates the Java2Script transpiler for SwingJS.
1+
The net.sf.j2s.core Eclipse project creates the Java2Script transpiler for
2+
SwingJS as well as a "legacy" transpiler for legacy Jmol.
23

34
See the dist/dropins folder for the latest distribution and installation notes.
45

-267 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20231111183955
1+
20231112114539
Binary file not shown.
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-
20231111183955
1+
20231112114539

sources/net.sf.j2s.core/doc/howItWorks.md

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ support for boxing and unboxing numbers -- int i = Integer.valueOf(3) is not pro
1010
into just the number 3. I got around this in those early days by just going through all
1111
(and I mean ALL) of the Jmol code, making sure there were no implicit boxing or unboxing.
1212

13+
The primary issue with this transpiler is that it does not "qualify" method names.
14+
Thus, BufferedWriter.write(char) and BufferedWriter.write(int) both run through the
15+
same method in JavaScript, and (a very complex and time-expensive) algorithm then
16+
sorts out based on the JavaScript parameter type what is the MOST LIKELY intended
17+
method target. I did a huge amount of refactoring in Jmol to ensure that it almost
18+
never calls overloaded methods like this.
1319

14-
**java2script/SwingJS**
15-
16-
The full java2script/SwingJS operation involves two parts: Creating the JavaScript from the abstract syntax tree (java2script), and running that within the browser (SwingJS). Both are discussed below.
17-
18-
The code for these two parts are well-separated:
19-
20-
net.sf.j2s.core java2script transpiler
21-
net.sf.j2s.java.core SwingJS runtime
20+
And various other issues. IT SHOULD NOT BE USED FOR ANY OTHER PURPOSE.
2221

22+
This transpiler is enabled using .j2sjmol configuration file.
2323

2424
**java2script transpiler**
2525

@@ -54,22 +54,56 @@ etc.
5454
write(b)
5555
write(b, 2, 3)
5656

57-
will both point to the same function. A major task of the java2script transpiler is to sort this out before it becomes an issue at runtime. It does this by creating signature-specific function names in JavaScript, such as write$B and write$B$I$I.]
57+
will both point to the same function. A major task of the java2script SwingJS transpiler is to sort this out before it becomes an issue at runtime. It does this by creating signature-specific function names in JavaScript, such as write$B and write$B$I$I.]
58+
59+
60+
**java2script/SwingJS**
61+
62+
The full java2script/SwingJS operation involves two parts: Creating the JavaScript from the abstract syntax tree (java2script), and running that within the browser (SwingJS). Both are discussed below.
63+
64+
The code for these two parts are well-separated:
65+
66+
net.sf.j2s.core java2script transpiler
67+
net.sf.j2s.java.core SwingJS runtime
5868

5969

6070
**Creating a New Transpiler**
6171

62-
The transpiler is created in Eclipse by checking out the net.sf.j2s.core project from GitHub as a standard Java project and adjusting the code as necessary. When it is desired to create the transpiler (net.sf.j2s.core.jar):
72+
The transpiler is created in Eclipse by checking out the net.sf.j2s.core project from GitHub as a standard Java project and adjusting the code as necessary. The
73+
parts that make this happen include:
74+
75+
META-INF/MANIFEST.MF
76+
build.properties
77+
plugin.xml
78+
79+
80+
[note:
81+
-bootclasspath not supported at compliance level 9 and above
82+
83+
was fixed by adding
84+
85+
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
86+
87+
to MANIFEST.MF
88+
89+
thank you https://bugs.eclipse.org/bugs/show_bug.cgi?id=525280
90+
91+
]
92+
93+
94+
When it is desired to create the transpiler (net.sf.j2s.core.jar):
6395

6496
1) Use File...Export...Deployable plug-ins and fragments
6597
(if you do not see this option, check that you are using Eclipse
6698
Enterprise)
67-
2) Choose net.sf.j2s.core (Version 3.2.4), check the directory,
99+
2) Choose net.sf.j2s.core (Version x.x.x), check the directory,
68100
and press finish.
69101
3) Copy this file to the drop-ins directory, restart Eclipse,
70102
and test.
71103
4) Copy this file to the project dist/swingjs folder and also
72-
to the swingjs/ver/3.2.4 folder (or appropriate).
104+
to the swingjs/ver/x.x.x folder (or appropriate).
105+
106+
73107

74108
I do this with a DOS batch file, which also adds a timestamp.
75109

sources/net.sf.j2s.core/src/j2s/core/Java2ScriptCompiler.java

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import java.util.Properties;
1616

1717
import org.eclipse.core.resources.IFile;
18-
import org.eclipse.core.resources.IProject;
1918
import org.eclipse.core.runtime.IPath;
2019
import org.eclipse.jdt.core.IClasspathEntry;
2120
import org.eclipse.jdt.core.IJavaProject;
@@ -43,12 +42,13 @@ public abstract class Java2ScriptCompiler {
4342
private final static String J2S_COMPILER_STATUS = "j2s.compiler.status";
4443
private final static String J2S_COMPILER_STATUS_ENABLE = "enable";
4544
private final static String J2S_COMPILER_STATUS_ENABLED = "enabled";
45+
private final static String J2S_COMPILER_STATUS_DEFAULT = "enabled";
4646

4747
private final static String J2S_COMPILER_JAVA_VERSION = "j2s.compiler.java.version";
4848

49-
private final static String J2S_OUTPUT_PATH = "j2s.output.path";
50-
private final static String J2S_OUTPUT_PATH_DEFAULT = "bin";
51-
49+
// private final static String J2S_OUTPUT_PATH = "j2s.output.path";
50+
// private final static String J2S_OUTPUT_PATH_DEFAULT = "bin";
51+
//
5252
protected static final String J2S_SITE_DIRECTORY = "j2s.site.directory";
5353
protected static final String J2S_SITE_DIRECTORY_DEFAULT = "site";
5454

@@ -99,7 +99,7 @@ public abstract class Java2ScriptCompiler {
9999
protected Properties props;
100100

101101
protected String projectFolder;
102-
protected String outputPath;
102+
// protected String outputPath;
103103
protected String siteFolder;
104104
protected String j2sPath;
105105
protected String excludedPaths;
@@ -138,7 +138,6 @@ public boolean doBreakOnError() {
138138

139139

140140
static File checkJ2SDir(String dir) {
141-
System.out.println("Checking for .j2s or .j2sjmol in " + dir);
142141
File f;
143142
return ((f = new File(dir, J2S_CONFIG_JMOL)).exists() ? f
144143
: (f = new File(dir, J2S_CONFIG_SWINGJS)).exists() ? f
@@ -297,27 +296,23 @@ protected boolean initializeProject(IJavaProject project, boolean isCleanBuild,
297296

298297
breakOnError = !"false".equalsIgnoreCase(getProperty(J2S_BREAK_ON_ERROR, J2S_BREAK_ON_ERROR_DEFAULT));
299298

300-
// includes @j2sDebug blocks
301-
isDebugging = J2S_COMPILER_MODE_DEBUG
302-
.equalsIgnoreCase(getProperty(J2S_COMPILER_MODE, J2S_COMPILER_MODE_DEFAULT));
303-
304299
siteFolder = getProperty(J2S_SITE_DIRECTORY, J2S_SITE_DIRECTORY_DEFAULT);
305300
siteFolder = projectFolder + "/" + siteFolder;
306301

307-
outputPath = getProperty(J2S_OUTPUT_PATH, null);
308-
if (outputPath == null) {
309-
outputPath = J2S_OUTPUT_PATH_DEFAULT; // bin
310-
try {
311-
IPath loc = project.getOutputLocation();
312-
outputPath = loc.toString().substring(loc.toString().lastIndexOf('/') + 1);
313-
} catch (JavaModelException e1) {
314-
// TODO Auto-generated catch block
315-
e1.printStackTrace();
316-
}
317-
}
318-
302+
// outputPath = getProperty(J2S_OUTPUT_PATH, null);
303+
// if (outputPath == null) {
304+
// outputPath = J2S_OUTPUT_PATH_DEFAULT; // bin
305+
// try {
306+
// IPath loc = project.getOutputLocation();
307+
// outputPath = loc.toString().substring(loc.toString().lastIndexOf('/') + 1);
308+
// } catch (JavaModelException e1) {
309+
// // TODO Auto-generated catch block
310+
// e1.printStackTrace();
311+
// }
312+
// }
313+
//
319314
if (isDebugging) {
320-
System.out.println("J2S siteFolder=" + siteFolder + " outputPath=" + outputPath);
315+
System.out.println("J2S siteFolder=" + siteFolder);// + " outputPath=" + outputPath);
321316
}
322317
excludedPaths = getProperty(J2S_EXCLUDED_PATHS, J2S_EXCLUDED_PATHS_DEFAULT);
323318
lstExcludedPaths = null;
@@ -341,7 +336,7 @@ protected boolean initializeProject(IJavaProject project, boolean isCleanBuild,
341336
}
342337

343338
private boolean isEnabled() {
344-
String status = getProperty(J2S_COMPILER_STATUS, J2S_COMPILER_STATUS_ENABLED);
339+
String status = getProperty(J2S_COMPILER_STATUS, J2S_COMPILER_STATUS_DEFAULT);
345340
return (J2S_COMPILER_STATUS_ENABLE.equalsIgnoreCase(status)
346341
|| J2S_COMPILER_STATUS_ENABLED.equalsIgnoreCase(status));
347342
}

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import j2s.CorePlugin;
1414
import j2s.core.Java2ScriptCompiler;
1515
import j2s.jmol.common.ASTScriptVisitor;
16-
import j2s.jmol.common.ASTVariableVisitor;
1716
import j2s.jmol.common.DependencyASTVisitor;
1817

1918
public class Java2ScriptLegacyCompiler extends Java2ScriptCompiler {
@@ -106,15 +105,13 @@ public boolean compileToJavaScript(IFile javaSource, String trailer) {
106105
}
107106

108107
ASTScriptVisitor visitor = new ASTScriptVisitor();
109-
boolean objectStaticFields = "enable".equals(props.getProperty("j2s.compiler.static.quirks"));
110-
visitor.setSupportsObjectStaticFields(objectStaticFields);
111-
isDebugging = "debug".equals(props.getProperty("j2s.compiler.mode"))
112-
|| "debug".equals(props.getProperty("j2s.compiler.status"));
113-
visitor.setDebugging(isDebugging);
108+
109+
System.out.println("J2SL109 " + visitor.supportsObjectStaticFields);
110+
111+
112+
isDebugging = "debug".equals(props.getProperty("j2s.compiler.mode"));
113+
visitor.setDebugging(isDebugging);
114114
dvisitor.setDebugging(isDebugging);
115-
boolean toCompress = "release".equals(props.getProperty("j2s.compiler.mode"));
116-
((ASTVariableVisitor) visitor.getAdaptable(ASTVariableVisitor.class)).setToCompileVariableName(toCompress);
117-
dvisitor.setToCompileVariableName(toCompress);
118115
errorOccurs = false;
119116
try {
120117
root.accept(visitor);
@@ -246,8 +243,8 @@ private String finalFixes(String js) {
246243
@Override
247244
protected String getDefaultJ2SFile() {
248245
return "#j2sjmol default configuration file created by j2s.core plugin " + CorePlugin.VERSION + " " + new Date()
249-
+ "\n\n" + "#enable the Java2Script transpiler -- comment out to disable\n"
250-
+ "# default is \"enabled\".\n" + "j2s.compiler.status=enable\n\n"
246+
+ "\n\n" + "#enable the Java2Script transpiler -- set to \"disabled\" to disable\n"
247+
+ "# default is \"enabled\".\n" + "j2s.compiler.status=enabled\n\n"
251248
+ "# destination directory for all JavaScript\n" + "j2s.site.directory=site\n\n"
252249
+ "# uncomment j2s.* lines to process:\n\n"
253250
+ "# a semicolon-separated list of package-level file paths to be excluded "

0 commit comments

Comments
 (0)