Skip to content

Commit c697d68

Browse files
committed
More v. 5.0.1 adjustments
dist/SwingJS-site.zip and dist_to_jsomo/jmol-j2s-site.zip upgraded transpiler simplifiying j2s/common visitors for 4.2 touch-screen fix for j2sComboBox.
1 parent 92b5957 commit c697d68

File tree

131 files changed

+4055
-1175
lines changed

Some content is hidden

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

131 files changed

+4055
-1175
lines changed

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

Lines changed: 0 additions & 19 deletions
This file was deleted.

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

Lines changed: 0 additions & 6 deletions
This file was deleted.

sources/net.sf.j2s.core/dist/site-resources/README.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.
425 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20231113192628
1+
20231115195339
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-
20231113192628
1+
20231115195339

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static File checkJ2SDir(String dir) {
146146

147147
/**
148148
* Entry point from compilation participant when Java build is complete and it is our turn.
149-
*
149+
* e
150150
* @param project
151151
* @param files
152152
* @return
@@ -500,11 +500,32 @@ protected String fixPackageName(String name) {
500500
if (packageFixes == null)
501501
return name;
502502
for (int i = 0; i < packageFixes.length; i++) {
503-
name = name.replaceAll(packageFixes[i++], packageFixes[i]);
503+
name = rep(name, packageFixes[i++], packageFixes[i]);
504504
}
505505
return name;
506506
}
507507

508508

509+
/**
510+
* Does a clean ITERATIVE replace of strFrom in str with strTo.
511+
* Thus, rep("Testttt", "tt","t") becomes "Test".
512+
*
513+
* @param str
514+
* @param strFrom
515+
* @param strTo
516+
* @return replaced string
517+
*/
518+
protected static String rep(String str, String strFrom, String strTo) {
519+
if (str == null || strFrom.length() == 0 || str.indexOf(strFrom) < 0)
520+
return str;
521+
boolean isOnce = (strTo.indexOf(strFrom) >= 0);
522+
do {
523+
str = str.replace(strFrom, strTo);
524+
} while (!isOnce && str.indexOf(strFrom) >= 0);
525+
return str;
526+
}
527+
528+
529+
509530

510531
}

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

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
import j2s.CorePlugin;
1414
import j2s.core.Java2ScriptCompiler;
15-
import j2s.jmol.common.ASTScriptVisitor;
16-
import j2s.jmol.common.DependencyASTVisitor;
15+
import j2s.jmol.common.Java2ScriptScriptVisitor;
16+
import j2s.jmol.common.Java2ScriptDependencyVisitor;
1717

1818
public class Java2ScriptLegacyCompiler extends Java2ScriptCompiler {
1919

@@ -25,6 +25,15 @@ public class Java2ScriptLegacyCompiler extends Java2ScriptCompiler {
2525

2626
private int nResources;
2727

28+
private static String[] myStringFixes = { //
29+
"cla$$", "c$" //
30+
,"innerThis", "i$" //
31+
,"finalVars", "v$" //
32+
,".callbacks", ".b$" //
33+
,".$finals", ".f$" //
34+
,"Class.forName", "Clazz._4Name"//
35+
};
36+
2837
public Java2ScriptLegacyCompiler(File f) {
2938
super(false, f);
3039
}
@@ -33,18 +42,13 @@ public Java2ScriptLegacyCompiler(File f) {
3342
public boolean initializeProject(IJavaProject project, boolean isCleanBuild) {
3443
if (!super.initializeProject(project, isCleanBuild, AST.JLS4)) {
3544
return false;
36-
}
37-
45+
}
3846
String s = getProperty(J2S_STRING_FIXES, null);
39-
if (s != null) {
40-
stringFixes = s.split(",");
41-
fixRegex(stringFixes);
42-
System.out.println(stringFixes.length + " string fixes");
43-
}
47+
stringFixes = getFixes(s, myStringFixes);
48+
System.out.println(stringFixes.length + " string fixes");
4449
s = getProperty(J2S_PACKAGE_FIXES, null);
4550
if (s != null) {
46-
packageFixes = s.split(",");
47-
fixRegex(packageFixes);
51+
packageFixes = getFixes(s, null);
4852
System.out.println(packageFixes.length + " package fixes");
4953
}
5054
nResources = 0;
@@ -53,10 +57,22 @@ public boolean initializeProject(IJavaProject project, boolean isCleanBuild) {
5357
return true;
5458
}
5559

56-
private void fixRegex(String[] a) {
60+
@SuppressWarnings("null")
61+
private String[] getFixes(String s, String[] myFixes) {
62+
String[] a = (s == null || s.length() == 0 ? new String[0] : rep(s, "\\,", "\1").split(","));
63+
int pt = (myFixes == null ? 0 : myFixes.length);
64+
if (pt == 0 && a.length == 0)
65+
return null;
66+
String[] b = new String[pt + a.length];
67+
for (int i = 0; i < pt; i++) {
68+
b[i] = myFixes[i]; // no escaped commas here
69+
System.out.print((i%2) == 0 ? b[i] : " -> " + b[i] + "\n");
70+
}
5771
for (int i = 0; i < a.length; i++) {
58-
a[i] = a[i].replaceAll("\\.", "\\\\.");
72+
System.out.print((i%2) == 0 ? a[i] : " -> " + a[i] + "\n");
73+
b[pt++] = a[i].replace('\1', ',');
5974
}
75+
return b;
6076
}
6177

6278
public void startBuild(boolean isClean) {
@@ -78,7 +94,7 @@ public boolean compileToJavaScript(IFile javaSource, String trailer) {
7894
astParser.setResolveBindings(true);
7995
astParser.setSource(createdUnit);
8096
CompilationUnit root = (CompilationUnit) astParser.createAST(null);
81-
DependencyASTVisitor dvisitor = new DependencyASTVisitor();
97+
Java2ScriptDependencyVisitor dvisitor = new Java2ScriptDependencyVisitor(this);
8298
boolean errorOccurs = false;
8399
try {
84100
root.accept(dvisitor);
@@ -95,22 +111,18 @@ public boolean compileToJavaScript(IFile javaSource, String trailer) {
95111
String packageName = dvisitor.getPackageName();
96112
if (packageName != null) {
97113
File folder = new File(outputPath, packageName.replace('.', File.separatorChar));
98-
outputPath = folder.getAbsolutePath();
99-
File jsFile = new File(outputPath, elementName + ".js"); //$NON-NLS-1$
114+
File jsFile = new File(folder, elementName + ".js"); //$NON-NLS-1$
100115
if (jsFile.exists()) {
101116
jsFile.delete();
102117
}
103118
}
104119
return false;
105120
}
106121

107-
ASTScriptVisitor visitor = new ASTScriptVisitor();
122+
Java2ScriptScriptVisitor visitor = new Java2ScriptScriptVisitor();
108123
isDebugging = "debug".equals(props.getProperty("j2s.compiler.mode"));
109124
visitor.setDebugging(isDebugging);
110125
dvisitor.setDebugging(isDebugging);
111-
// boolean toCompress = "release".equals(props.getProperty("j2s.compiler.mode"));
112-
// ((ASTVariableVisitor) visitor.getAdaptable(ASTVariableVisitor.class)).setToCompileVariableName(toCompress);
113-
// dvisitor.setToCompileVariableName(false);
114126
errorOccurs = false;
115127
try {
116128
root.accept(visitor);
@@ -122,25 +134,20 @@ public boolean compileToJavaScript(IFile javaSource, String trailer) {
122134
outputJavaScript(visitor, dvisitor, root, outputPath, trailer, sourceLocation);
123135
return true;
124136
}
125-
String folderPath = outputPath;
126137
String elementName = root.getJavaElement().getElementName();
127-
// if (elementName.endsWith(".class") || elementName.endsWith(".java")) {
128-
// //$NON-NLS-1$//$NON-NLS-2$
129138
elementName = elementName.substring(0, elementName.lastIndexOf('.'));
130-
// } /* maybe ended with other customized extension
131139
String packageName = visitor.getPackageName();
132140
if (packageName != null) {
133-
File folder = new File(folderPath, packageName.replace('.', File.separatorChar));
134-
folderPath = folder.getAbsolutePath();
135-
File jsFile = new File(folderPath, elementName + ".js"); //$NON-NLS-1$
141+
File folder = new File(outputPath, packageName.replace('.', File.separatorChar));
142+
File jsFile = new File(folder.getAbsolutePath(), elementName + ".js"); //$NON-NLS-1$
136143
if (jsFile.exists()) {
137144
jsFile.delete();
138145
}
139146
}
140147
return false;
141148
}
142149

143-
private void outputJavaScript(ASTScriptVisitor visitor, DependencyASTVisitor dvisitor, CompilationUnit fRoot,
150+
private void outputJavaScript(Java2ScriptScriptVisitor visitor, Java2ScriptDependencyVisitor dvisitor, CompilationUnit fRoot,
144151
String outputPath, String trailer, String sourceLocation) {
145152
String js = finalFixes(dvisitor.getDependencyScript(visitor.getBuffer()));
146153
String elementName = fRoot.getJavaElement().getElementName();
@@ -168,14 +175,8 @@ private void outputJavaScript(ASTScriptVisitor visitor, DependencyASTVisitor dvi
168175
}
169176

170177
private String finalFixes(String js) {
171-
js = js.replaceAll("cla\\$\\$", "c\\$").replaceAll("innerThis", "i\\$").replaceAll("finalVars", "v\\$")
172-
.replaceAll("\\.callbacks", "\\.b\\$").replaceAll("\\.\\$finals", "\\.f\\$")
173-
// BH 2023.11.10 added
174-
.replaceAll("Class\\.forName", "Clazz\\._4Name");
175-
if (stringFixes != null) {
176-
for (int i = 0; i < stringFixes.length; i++) {
177-
js = js.replaceAll(stringFixes[i++], stringFixes[i]);
178-
}
178+
for (int i = 0; i < stringFixes.length; i++) {
179+
js = rep(js, stringFixes[i++], stringFixes[i]);
179180
}
180181
return js;
181182
}

0 commit comments

Comments
 (0)