Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions sources/net.sf.j2s.core/dist/libjs/README.txt

This file was deleted.

6 changes: 0 additions & 6 deletions sources/net.sf.j2s.core/dist/resources/README.txt

This file was deleted.

6 changes: 0 additions & 6 deletions sources/net.sf.j2s.core/dist/site-resources/README.txt

This file was deleted.

Binary file modified sources/net.sf.j2s.core/dist/swingjs/j2s.core.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20231113160352
20231115195339
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/SwingJS-site.zip
Binary file not shown.
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/j2s.core.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20231113160352
20231115195339
25 changes: 23 additions & 2 deletions sources/net.sf.j2s.core/src/j2s/core/Java2ScriptCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static File checkJ2SDir(String dir) {

/**
* Entry point from compilation participant when Java build is complete and it is our turn.
*
* e
* @param project
* @param files
* @return
Expand Down Expand Up @@ -500,11 +500,32 @@ protected String fixPackageName(String name) {
if (packageFixes == null)
return name;
for (int i = 0; i < packageFixes.length; i++) {
name = name.replaceAll(packageFixes[i++], packageFixes[i]);
name = rep(name, packageFixes[i++], packageFixes[i]);
}
return name;
}


/**
* Does a clean ITERATIVE replace of strFrom in str with strTo.
* Thus, rep("Testttt", "tt","t") becomes "Test".
*
* @param str
* @param strFrom
* @param strTo
* @return replaced string
*/
protected static String rep(String str, String strFrom, String strTo) {
if (str == null || strFrom.length() == 0 || str.indexOf(strFrom) < 0)
return str;
boolean isOnce = (strTo.indexOf(strFrom) >= 0);
do {
str = str.replace(strFrom, strTo);
} while (!isOnce && str.indexOf(strFrom) >= 0);
return str;
}




}
73 changes: 37 additions & 36 deletions sources/net.sf.j2s.core/src/j2s/jmol/Java2ScriptLegacyCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

import j2s.CorePlugin;
import j2s.core.Java2ScriptCompiler;
import j2s.jmol.common.ASTScriptVisitor;
import j2s.jmol.common.DependencyASTVisitor;
import j2s.jmol.common.Java2ScriptScriptVisitor;
import j2s.jmol.common.Java2ScriptDependencyVisitor;

public class Java2ScriptLegacyCompiler extends Java2ScriptCompiler {

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

private int nResources;

private static String[] myStringFixes = { //
"cla$$", "c$" //
,"innerThis", "i$" //
,"finalVars", "v$" //
,".callbacks", ".b$" //
,".$finals", ".f$" //
,"Class.forName", "Clazz._4Name"//
};

public Java2ScriptLegacyCompiler(File f) {
super(false, f);
}
Expand All @@ -33,18 +42,13 @@ public Java2ScriptLegacyCompiler(File f) {
public boolean initializeProject(IJavaProject project, boolean isCleanBuild) {
if (!super.initializeProject(project, isCleanBuild, AST.JLS4)) {
return false;
}

}
String s = getProperty(J2S_STRING_FIXES, null);
if (s != null) {
stringFixes = s.split(",");
fixRegex(stringFixes);
System.out.println(stringFixes.length + " string fixes");
}
stringFixes = getFixes(s, myStringFixes);
System.out.println(stringFixes.length + " string fixes");
s = getProperty(J2S_PACKAGE_FIXES, null);
if (s != null) {
packageFixes = s.split(",");
fixRegex(packageFixes);
packageFixes = getFixes(s, null);
System.out.println(packageFixes.length + " package fixes");
}
nResources = 0;
Expand All @@ -53,10 +57,22 @@ public boolean initializeProject(IJavaProject project, boolean isCleanBuild) {
return true;
}

private void fixRegex(String[] a) {
@SuppressWarnings("null")
private String[] getFixes(String s, String[] myFixes) {
String[] a = (s == null || s.length() == 0 ? new String[0] : rep(s, "\\,", "\1").split(","));
int pt = (myFixes == null ? 0 : myFixes.length);
if (pt == 0 && a.length == 0)
return null;
String[] b = new String[pt + a.length];
for (int i = 0; i < pt; i++) {
b[i] = myFixes[i]; // no escaped commas here
System.out.print((i%2) == 0 ? b[i] : " -> " + b[i] + "\n");
}
for (int i = 0; i < a.length; i++) {
a[i] = a[i].replaceAll("\\.", "\\\\.");
System.out.print((i%2) == 0 ? a[i] : " -> " + a[i] + "\n");
b[pt++] = a[i].replace('\1', ',');
}
return b;
}

public void startBuild(boolean isClean) {
Expand All @@ -78,7 +94,7 @@ public boolean compileToJavaScript(IFile javaSource, String trailer) {
astParser.setResolveBindings(true);
astParser.setSource(createdUnit);
CompilationUnit root = (CompilationUnit) astParser.createAST(null);
DependencyASTVisitor dvisitor = new DependencyASTVisitor();
Java2ScriptDependencyVisitor dvisitor = new Java2ScriptDependencyVisitor(this);
boolean errorOccurs = false;
try {
root.accept(dvisitor);
Expand All @@ -95,22 +111,18 @@ public boolean compileToJavaScript(IFile javaSource, String trailer) {
String packageName = dvisitor.getPackageName();
if (packageName != null) {
File folder = new File(outputPath, packageName.replace('.', File.separatorChar));
outputPath = folder.getAbsolutePath();
File jsFile = new File(outputPath, elementName + ".js"); //$NON-NLS-1$
File jsFile = new File(folder, elementName + ".js"); //$NON-NLS-1$
if (jsFile.exists()) {
jsFile.delete();
}
}
return false;
}

ASTScriptVisitor visitor = new ASTScriptVisitor();
Java2ScriptScriptVisitor visitor = new Java2ScriptScriptVisitor();
isDebugging = "debug".equals(props.getProperty("j2s.compiler.mode"));
visitor.setDebugging(isDebugging);
dvisitor.setDebugging(isDebugging);
// boolean toCompress = "release".equals(props.getProperty("j2s.compiler.mode"));
// ((ASTVariableVisitor) visitor.getAdaptable(ASTVariableVisitor.class)).setToCompileVariableName(toCompress);
// dvisitor.setToCompileVariableName(false);
errorOccurs = false;
try {
root.accept(visitor);
Expand All @@ -122,25 +134,20 @@ public boolean compileToJavaScript(IFile javaSource, String trailer) {
outputJavaScript(visitor, dvisitor, root, outputPath, trailer, sourceLocation);
return true;
}
String folderPath = outputPath;
String elementName = root.getJavaElement().getElementName();
// if (elementName.endsWith(".class") || elementName.endsWith(".java")) {
// //$NON-NLS-1$//$NON-NLS-2$
elementName = elementName.substring(0, elementName.lastIndexOf('.'));
// } /* maybe ended with other customized extension
String packageName = visitor.getPackageName();
if (packageName != null) {
File folder = new File(folderPath, packageName.replace('.', File.separatorChar));
folderPath = folder.getAbsolutePath();
File jsFile = new File(folderPath, elementName + ".js"); //$NON-NLS-1$
File folder = new File(outputPath, packageName.replace('.', File.separatorChar));
File jsFile = new File(folder.getAbsolutePath(), elementName + ".js"); //$NON-NLS-1$
if (jsFile.exists()) {
jsFile.delete();
}
}
return false;
}

private void outputJavaScript(ASTScriptVisitor visitor, DependencyASTVisitor dvisitor, CompilationUnit fRoot,
private void outputJavaScript(Java2ScriptScriptVisitor visitor, Java2ScriptDependencyVisitor dvisitor, CompilationUnit fRoot,
String outputPath, String trailer, String sourceLocation) {
String js = finalFixes(dvisitor.getDependencyScript(visitor.getBuffer()));
String elementName = fRoot.getJavaElement().getElementName();
Expand Down Expand Up @@ -168,14 +175,8 @@ private void outputJavaScript(ASTScriptVisitor visitor, DependencyASTVisitor dvi
}

private String finalFixes(String js) {
js = js.replaceAll("cla\\$\\$", "c\\$").replaceAll("innerThis", "i\\$").replaceAll("finalVars", "v\\$")
.replaceAll("\\.callbacks", "\\.b\\$").replaceAll("\\.\\$finals", "\\.f\\$")
// BH 2023.11.10 added
.replaceAll("Class\\.forName", "Clazz\\._4Name");
if (stringFixes != null) {
for (int i = 0; i < stringFixes.length; i++) {
js = js.replaceAll(stringFixes[i++], stringFixes[i]);
}
for (int i = 0; i < stringFixes.length; i++) {
js = rep(js, stringFixes[i++], stringFixes[i]);
}
return js;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public class ASTEmptyVisitor extends ASTVisitor {

/**
* Buffer that keep all compiled *.js.
* @see ASTScriptVisitor#laterBuffer
* @see Java2ScriptScriptVisitor#laterBuffer
*/
protected StringBuffer buffer = new StringBuffer();

Expand All @@ -117,7 +117,7 @@ public StringBuffer getBuffer() {

/**
* Buffer may be set to other buffer.
* @see ASTScriptVisitor#visit(TypeDeclaration)
* @see Java2ScriptScriptVisitor#visit(TypeDeclaration)
* @param buffer
*/
public void setBuffer(StringBuffer buffer) {
Expand Down
24 changes: 12 additions & 12 deletions sources/net.sf.j2s.core/src/j2s/jmol/common/ASTJ2SDocVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,18 @@ boolean visitNativeJavadoc(Javadoc javadoc, Block node, boolean superVisit) {
}
}
}
boolean toCompileVariableName = false;//((ASTVariableVisitor) getAdaptable(ASTVariableVisitor.class)).isToCompileVariableName();

if (!toCompileVariableName) {
for (Iterator iter = tags.iterator(); iter.hasNext();) {
TagElement tagEl = (TagElement) iter.next();
if ("@j2sNativeSrc".equals(tagEl.getTagName())) {
if (superVisit) super.visit(node);
visitJavadocJ2SSource(tagEl);
return false;
}
}
}
// boolean toCompileVariableName = false;//((ASTVariableVisitor) getAdaptable(ASTVariableVisitor.class)).isToCompileVariableName();
//
// if (!toCompileVariableName) {
// for (Iterator iter = tags.iterator(); iter.hasNext();) {
// TagElement tagEl = (TagElement) iter.next();
// if ("@j2sNativeSrc".equals(tagEl.getTagName())) {
// if (superVisit) super.visit(node);
// visitJavadocJ2SSource(tagEl);
// return false;
// }
// }
// }
for (Iterator iter = tags.iterator(); iter.hasNext();) {
TagElement tagEl = (TagElement) iter.next();
if ("@j2sNative".equals(tagEl.getTagName())) {
Expand Down
87 changes: 44 additions & 43 deletions sources/net.sf.j2s.core/src/j2s/jmol/common/ASTTypeVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,51 +125,52 @@ public String shortenQualifiedName(String name) {
name = Bindings.removeBrackets(name);
int index = name.indexOf("java.lang.");
char ch = 0;
if (index == 0
&& (name.indexOf('.', index + 10) == -1 || ((ch = name
.charAt(index + 10)) >= 'A' && ch <= 'Z'))) {
if (!name.startsWith("java.lang.ref")
&& !name.startsWith("java.lang.annotaion")
&& !name.startsWith("java.lang.instrument")
&& !name.startsWith("java.lang.management")) {
if (index == 0
&& (name.indexOf('.', 10) == -1 || ((ch = name
.charAt(10)) >= 'A' && ch <= 'Z'))) {
// java.lang.String or java.lang.String.Xxx but not java.lang.xxx....
// if (!name.startsWith("java.lang.ref") // as in "reflection"
// && !name.startsWith("java.lang.annotaion") // spelled wrong?
// && !name.startsWith("java.lang.instrument")
// && !name.startsWith("java.lang.management")) {
name = name.substring(10);
}
}
String swt = "org.eclipse.swt.SWT";
index = name.indexOf(swt);
if (index != -1) {
String after = name.substring(swt.length());
if (after.length() == 0 || after.startsWith(".")) {
name = "$WT" + after;
}
} else {
String os = "org.eclipse.swt.internal.browser.OS";
index = name.indexOf(os);
if (index != -1) {
String after = name.substring(os.length());
if (after.length() == 0 || after.startsWith(".")) {
name = "O$" + after;
}
}
}
String xhtml = "org.eclipse.swt.internal.xhtml.";
index = name.indexOf(xhtml);
if (index != -1) {
String after = name.substring(xhtml.length());
name = after;
}
xhtml = "net.sf.j2s.html.";
index = name.indexOf(xhtml);
if (index != -1) {
String after = name.substring(xhtml.length());
name = after;
}
swt = "org.eclipse.swt";
index = name.indexOf(swt);
if (index != -1) {
String after = name.substring(swt.length());
name = "$wt" + after;
// }
}
// String swt = "org.eclipse.swt.SWT";
// index = name.indexOf(swt);
// if (index != -1) {
// String after = name.substring(swt.length());
// if (after.length() == 0 || after.startsWith(".")) {
// name = "$WT" + after;
// }
// } else {
// String os = "org.eclipse.swt.internal.browser.OS";
// index = name.indexOf(os);
// if (index != -1) {
// String after = name.substring(os.length());
// if (after.length() == 0 || after.startsWith(".")) {
// name = "O$" + after;
// }
// }
// }
// String xhtml = "org.eclipse.swt.internal.xhtml.";
// index = name.indexOf(xhtml);
// if (index != -1) {
// String after = name.substring(xhtml.length());
// name = after;
// }
// xhtml = "net.sf.j2s.html.";
// index = name.indexOf(xhtml);
// if (index != -1) {
// String after = name.substring(xhtml.length());
// name = after;
// }
// swt = "org.eclipse.swt";
// index = name.indexOf(swt);
// if (index != -1) {
// String after = name.substring(swt.length());
// name = "$wt" + after;
// }
return name;
}

Expand Down
Loading