Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdf0959d

Browse files
authored
Merge pull request#229 from BobHanson/master
monolithic update from BobHanson/master
2 parentsc6c042b +b84c33d commitdf0959d

File tree

74 files changed

+9465
-7731
lines changed

Some content is hidden

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

74 files changed

+9465
-7731
lines changed

‎README.md‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,31 @@ within Eclipse, with immediate JavaScript testing and debugging in a browser bas
1919
in Java. Using the java2script/SwingJS Eclipse plug-in, both Java .class files and their equivalent .js files are created simultaneously.
2020

2121

22-
java2script/SwingJS includes an Eclipse plug-in (technically a "drop-in"), net.sf.j2s.core.zip
22+
java2script/SwingJS includes an Eclipse plug-in (technically a "drop-in"), net.sf.j2s.cor
23+
24+
e.zip
2325
(seehttps://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/swingjs),
2426
along with a JavaScript version of the Java Virtual Machine (SwingJS,https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.java.core/SwingJS-site.zip)
2527
to allow the rapid and
2628
automated production of browser-ready JavaScript versions of Java applications and applets.
2729

2830

31+
#Working Examples
32+
33+
Examples of SwingJS applied to allow single-source Java+JavaScript development include:
34+
35+
Jmol-SwingJShttps://github.com/BobHanson/Jmol-SwingJS
36+
37+
JalView-JShttps://www.jalview.org/jalview-js
38+
39+
MathePrismahttps://www.matheprisma.de/ (over 600 applets)
40+
41+
Open Source Physics (OSP)https://github.com/OpenSourcePhysics/osp/tree/swingJS
42+
43+
TrackerJShttps://physlets.org/tracker/trackerJS
44+
45+
46+
2947
#QuickStart
3048

3149
Seehttps://github.com/BobHanson/java2script/tree/master/sources/net.sf.j2s.core/dist and the README file in that directory.
-119 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20231128000108
1+
20240114215407
2.72 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20231128000108
1+
20240114215407

‎sources/net.sf.j2s.core/src/j2s/jmol/J2SASTVisitor.java‎

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,12 @@ public boolean visit(PackageDeclaration node) {
8484

8585
publicbooleanvisit(Blocknode) {
8686
blockLevel++;
87-
if (buffer !=null) {
88-
buffer.append("{\r\n");
89-
}
9087
ASTNodeparent =node.getParent();
9188
if (parentinstanceofMethodDeclaration) {
9289
MethodDeclarationmethod = (MethodDeclaration)parent;
9390
Javadocjavadoc =method.getJavadoc();
94-
/*
95-
* if comment contains "@j2sNative", then output the given native JavaScript
96-
* codes directly.
97-
*/
91+
// if comment contains "@j2sNative", then output the given native JavaScript
92+
// codes directly.
9893
if (!processJ2STags(javadoc,node,true)) {
9994
returnfalse;
10095
}
@@ -118,10 +113,10 @@ public boolean visit(Block node) {
118113
superclass =superclass.getSuperclass();
119114
}
120115
if (containsSuperPrivateMethod) {
121-
buffer.append("var $private = Clazz.checkPrivateMethod (arguments);\r\n");
122-
buffer.append("if ($private != null) {\r\n");
123-
buffer.append("return $private.apply (this, arguments);\r\n");
124-
buffer.append("}\r\n");
116+
buffer.append("var $private = Clazz.checkPrivateMethod (arguments);\n");
117+
buffer.append("if ($private != null) {\n");
118+
buffer.append("return $private.apply (this, arguments);\n");
119+
buffer.append("}\n");
125120
}
126121
}
127122
}
@@ -244,8 +239,24 @@ protected boolean processJ2STags(Javadoc javadoc, Block node, boolean superVisit
244239
if ("@j2sNative".equals(tagEl.getTagName())) {
245240
if (superVisit)
246241
super.visit(node);
247-
if (buffer !=null)
248-
writeJavaScript(tagEl);
242+
if (buffer !=null) {
243+
List<?>fragments =tagEl.fragments();
244+
booleanisFirstLine =true;
245+
StringBufferbuf =newStringBuffer();
246+
for (Iterator<?>iterator =fragments.iterator();iterator
247+
.hasNext();) {
248+
TextElementcommentEl = (TextElement)iterator.next();
249+
Stringtext =commentEl.getText().trim();
250+
if (isFirstLine) {
251+
if (text.length() ==0) {
252+
continue;
253+
}
254+
}
255+
buf.append(text);
256+
buf.append("\n");
257+
}
258+
buffer.append(fixCommentBlock(buf.toString()));
259+
}
249260
returnfalse;
250261
}
251262
}
@@ -254,25 +265,6 @@ protected boolean processJ2STags(Javadoc javadoc, Block node, boolean superVisit
254265
returntrue;
255266
}
256267

257-
privatevoidwriteJavaScript(TagElementtagEl) {
258-
List<?>fragments =tagEl.fragments();
259-
booleanisFirstLine =true;
260-
StringBufferbuf =newStringBuffer();
261-
for (Iterator<?>iterator =fragments.iterator();iterator
262-
.hasNext();) {
263-
TextElementcommentEl = (TextElement)iterator.next();
264-
Stringtext =commentEl.getText().trim();
265-
if (isFirstLine) {
266-
if (text.length() ==0) {
267-
continue;
268-
}
269-
}
270-
buf.append(text);
271-
buf.append("\r\n");
272-
}
273-
buffer.append(fixCommentBlock(buf.toString()));
274-
}
275-
276268
privateStringfixCommentBlock(Stringtext) {
277269
if (text ==null ||text.length() ==0) {
278270
returntext;
@@ -284,16 +276,19 @@ private String fixCommentBlock(String text) {
284276

285277
/**
286278
* Write JavaScript source from @j2sNative and @J2SIgnore
279+
*
280+
* @return true if JavaScript was written
287281
*/
288-
protectedbooleanwriteJ2SSources(BodyDeclarationnode,StringtagName,Stringprefix,Stringsuffix,booleanboth) {
289-
booleanexisted =false;
282+
protectedbooleanwriteJ2STags(BodyDeclarationnode,booleanneedScope) {
283+
Stringprefix = (needScope ?"{\n" :"");
284+
Stringsuffix = (needScope ?"\n}" :"");
290285
Javadocjavadoc =node.getJavadoc();
291286
if (javadoc !=null) {
292287
List<?>tags =javadoc.tags();
293288
if (tags.size() !=0) {
294289
for (Iterator<?>iter =tags.iterator();iter.hasNext();) {
295290
TagElementtagEl = (TagElement)iter.next();
296-
if (tagName.equals(tagEl.getTagName())) {
291+
if ("@j2sNative".equals(tagEl.getTagName())) {
297292
List<?>fragments =tagEl.fragments();
298293
StringBufferbuf =newStringBuffer();
299294
booleanisFirstLine =true;
@@ -306,19 +301,16 @@ protected boolean writeJ2SSources(BodyDeclaration node, String tagName, String p
306301
}
307302
}
308303
buf.append(text);
309-
buf.append("\r\n");
304+
buf.append("\n");
310305
}
311306
Stringsources =buf.toString().trim();
312307
sources =sources.replaceAll("(\\/)-\\*|\\*-(\\/)","$1*$2").replaceAll("<@>","@");
313308
buffer.append(prefix +sources +suffix);
314-
existed =true;
309+
returntrue;
315310
}
316311
}
317312
}
318313
}
319-
if (existed && !both) {
320-
returnexisted;
321-
}
322314
List<?>modifiers =node.modifiers();
323315
for (Iterator<?>iter =modifiers.iterator();iter.hasNext();) {
324316
Objectobj =iter.next();
@@ -327,9 +319,7 @@ protected boolean writeJ2SSources(BodyDeclaration node, String tagName, String p
327319
StringqName =annotation.getTypeName().getFullyQualifiedName();
328320
intindex =qName.indexOf("J2S");
329321
if (index != -1) {
330-
StringannName =qName.substring(index);
331-
annName =annName.replaceFirst("J2S","@j2s");
332-
if (annName.startsWith(tagName)) {
322+
if (qName.substring(index).startsWith("J2SNative")) {
333323
StringBufferbuf =newStringBuffer();
334324
IAnnotationBindingannotationBinding =annotation.resolveAnnotationBinding();
335325
if (annotationBinding !=null) {
@@ -342,23 +332,23 @@ protected boolean writeJ2SSources(BodyDeclaration node, String tagName, String p
342332
Object[]lines = (Object[])value;
343333
for (intj =0;j <lines.length;j++) {
344334
buf.append(lines[j]);
345-
buf.append("\r\n");
335+
buf.append("\n");
346336
}
347337
}elseif (valueinstanceofString) {
348338
buf.append(value);
349-
buf.append("\r\n");
339+
buf.append("\n");
350340
}
351341
}
352342
}
353343
}
354344
}
355345
buffer.append(prefix +buf.toString().trim() +suffix);
356-
existed =true;
346+
returntrue;
357347
}
358348
}
359349
}
360350
}
361-
returnexisted;
351+
returnfalse;
362352
}
363353

364354
}

‎sources/net.sf.j2s.core/src/j2s/jmol/J2SDependencyVisitor.java‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,8 @@ public boolean visit(TypeDeclaration node) {
330330
allClassBindings.add(resolveBinding);
331331
}
332332
readJ2sImportTags(node);
333-
334333
processImports(node);
335334
processJ2SRequireImport(node);
336-
//visitForOptionals(node);
337335
returnsuper.visit(node);
338336
}
339337

@@ -345,7 +343,6 @@ public boolean visit(EnumDeclaration node) {
345343
allClassBindings.add(resolveBinding);
346344
}
347345
readJ2sImportTags(node);
348-
349346
imports.add("java.lang.Enum");
350347
processImports(node);
351348
processJ2SRequireImport(node);
@@ -508,8 +505,8 @@ public boolean visit(MethodInvocation node) {
508505

509506
publicbooleanvisit(Initializernode) {
510507
if (J2SUtil.getJ2STag(node,"@j2sIgnore") !=null) {
511-
returnfalse;
512-
}
508+
returnfalse;
509+
}
513510
returnsuper.visit(node);
514511
}
515512

@@ -842,7 +839,6 @@ private void processImports(AbstractTypeDeclaration node) {
842839
if (mustAddDependency(qualifiedName,node,false)) {
843840
imports.add(qn);
844841
}
845-
//musts.add(superBinding.getQualifiedName());
846842
}
847843
}
848844
List<?>superInterfaces =null;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp