Skip to content

Commit 12c8d95

Browse files
authored
Merge pull request #100 from BobHanson/hanson1
Hanson1 - minor issues
2 parents fe2375c + 016b3d6 commit 12c8d95

File tree

21 files changed

+233
-41
lines changed

21 files changed

+233
-41
lines changed
164 Bytes
Binary file not shown.

sources/net.sf.j2s.core/dist/swingjs/_j2sclasslist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ javajs/util/JSThread.js
172172
javajs/util/Lst.js
173173
javajs/util/PT.js
174174
javajs/util/SB.js
175+
javax/net/ssl/HttpsUrlConnection.js
175176
javax/swing/AbstractAction.js
176177
javax/swing/AbstractButton.js
177178
javax/swing/AbstractListModel.js
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190516132838
1+
20190606154615
164 Bytes
Binary file not shown.

sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/_j2sclasslist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ javajs/util/JSThread.js
172172
javajs/util/Lst.js
173173
javajs/util/PT.js
174174
javajs/util/SB.js
175+
javax/net/ssl/HttpsUrlConnection.js
175176
javax/swing/AbstractAction.js
176177
javax/swing/AbstractButton.js
177178
javax/swing/AbstractListModel.js
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190516132838
1+
20190606154615
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Java2Script: How It Works
2+
3+
4+
A compiler converts code in one computer language to another. Typically this is from a higher-level language to a lower-level "machine code" language. In the case of the Java compiler, this is from written Java code (*.java) to "Java byte code" (*.class). In the case of of java2script, this is from Java to JavaScript. There are two basic requirements of a compiler: reading and writing. The reading process involves converting the written Java code to an <i>abstract syntax tree</i> [https://en.wikipedia.org/wiki/Abstract_syntax_tree]. The writing process involves scanning that tree, creating one or more output files from the original input file.
5+
6+
java2script is technically a "CompilationParticipant". [https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjdt%2Fcore%2Fcompiler%2FCompilationParticipant.html] It gets a notification that a certain set of files has been changed by the user or otherwise need compiling, just after the Java compiler has completed its work, it gets that same file list. It creates an instance of the Eclipse abstract syntax tree parser, org.eclipse.jdt.core.dom.ASTParser and initializes it with just a few statements (these from net.sf.j2s.core.Java2ScriptCompiler.java):
7+
8+
astParser.setSource(createdUnit);
9+
astParser.setResolveBindings(true);
10+
CompilationUnit root = (CompilationUnit) astParser.createAST(null);
11+
12+
13+
Its primarily work is via a subclass of "ASTVisitor" [https://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.jdt.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fjdt%2Fcore%2Fdom%2FASTVisitor.html]
14+
15+
Java2ScriptVisitor visitor = new Java2ScriptVisitor().setProject(project, testing);
16+
root.accept(visitor);
17+
18+
19+
So this is pretty straightforward. All the output that is ultimately saved in *.js files is created in that last call to ASTVisitor.accept(ASTVisitor). This call initiates a full scan of the abstract syntax tree in the form of calls to a series of heavily overloaded visit(...) methods, such as:
20+
21+
22+
public boolean visit(DoStatement node)
23+
public boolean visit(SingleVariableDeclaration node)
24+
25+
26+
etc.
27+
28+
If ever there is a need to fix something that the java2script compiler is doing wrong or to adapt to new Java syntax, as for Java 11, look in net.sf.j2s.core.Java2ScriptVisitor. There is great documentation on all of these org.eclipse.jdt.core.dom.ASTNode subclasses.
29+
30+
Bob Hanson 2019.06.07.
31+
32+
33+

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,10 @@ private String getProperty(String key) {
349349
return val;
350350
}
351351

352-
private void outputJavaScript(Java2ScriptVisitor visitor,
353-
// DependencyASTVisitor dvisitor, CompilationUnit fRoot,
354-
String j2sPath) {
352+
private void outputJavaScript(Java2ScriptVisitor visitor, String j2sPath) {
355353

356354
// fragments[0] is package]
357-
List<String> elements = visitor.getElementList();// dvisitor.getDependencyScript(visitor.getBuffer());
355+
List<String> elements = visitor.getElementList();
358356

359357
// BH all compression is deprecated --- use Google Closure Compiler
360358

@@ -376,10 +374,6 @@ private void createJSFile(String j2sPath, String packageName, String elementName
376374
throw new RuntimeException("Failed to create folder " + j2sPath); //$NON-NLS-1$
377375
}
378376
}
379-
// InnerHotspotServer.addCompiledItem(packageName + "." +
380-
// elementName);
381-
} else {
382-
// InnerHotspotServer.addCompiledItem(elementName);
383377
}
384378
writeToFile(new File(j2sPath, elementName + ".js"), js);
385379
}

sources/net.sf.j2s.java.core/_j2sclasslist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ javajs/util/JSThread.js
172172
javajs/util/Lst.js
173173
javajs/util/PT.js
174174
javajs/util/SB.js
175+
javax/net/ssl/HttpsUrlConnection.js
175176
javax/swing/AbstractAction.js
176177
javax/swing/AbstractButton.js
177178
javax/swing/AbstractListModel.js
111 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)