Skip to content

Commit c6c042b

Browse files
authored
Merge pull request #228 from BobHanson/master
major refactoring of legacy only
2 parents 1096819 + c80cb72 commit c6c042b

File tree

142 files changed

+10523
-11559
lines changed

Some content is hidden

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

142 files changed

+10523
-11559
lines changed

sources/net.sf.j2s.core/build.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ source.. = src/
22
output.. = bin/
33
bin.includes = META-INF/,\
44
.,\
5-
plugin.xml,\
6-
schema/
5+
plugin.xml
6+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Looking for the transpiler? It's in the dist/swingjs folder.
2+
-36.7 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20231115195339
1+
20231128000108
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20231115195339
1+
20231128000108

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ public class CorePlugin extends Plugin {
2626
* the actual "x.y.z" version is specified in plugin.xml.
2727
*
2828
*/
29-
public static String VERSION = "5.0.1-v1";
29+
public static String VERSION = "5.0.1-v2";
3030

3131
// if you change the x.x.x number, be sure to also indicate that in
3232
// j2sApplet.js and also (Bob only) update.bat, update-clean.bat
3333

34+
// BH 2023.11.27 -- 5.0.1-v2 final refactoring and creatiton of J2SUtil
35+
// BH 2023.11.21 -- 5.0.1-v2 adds Java8 syntaxes for try and switch; removes dependency for instanceOf and exception checking
3436
// BH 2023.11.09 -- 5.0.1-v1 merges Jmol legacy (.j2sjmol) with Java8//11 (.j2s)
3537
// BH 2023.03.29 -- 3.3.1-v7 fixes outer static method call from within lambda expression.
3638
// BH 2023.02.09 -- 3.3.1.v6 fixes j2s.excluded.paths needing /src/xxxx

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

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.eclipse.jdt.core.dom.ASTParser;
2424

2525
import j2s.CorePlugin;
26-
import j2s.jmol.Java2ScriptLegacyCompiler;
26+
import j2s.jmol.J2SLegacyCompiler;
2727
import j2s.swingjs.Java2ScriptSwingJSCompiler;
2828

2929
/**
@@ -84,10 +84,13 @@ public abstract class Java2ScriptCompiler {
8484

8585
abstract public boolean compileToJavaScript(IFile javaSource, String trailer);
8686

87-
abstract protected String getDefaultJ2SFile();
88-
8987
abstract public void finalizeProject();
9088

89+
/*
90+
* To save a default file with comments specific to this transpiler.
91+
*/
92+
abstract protected String getDefaultJ2SFileContents();
93+
9194
/**
9295
* The name of the J2S options file, aka as the "Dot-j2s" file. Please do not
9396
* change this value.
@@ -99,7 +102,6 @@ public abstract class Java2ScriptCompiler {
99102
protected Properties props;
100103

101104
protected String projectFolder;
102-
// protected String outputPath;
103105
protected String siteFolder;
104106
protected String j2sPath;
105107
protected String excludedPaths;
@@ -114,6 +116,9 @@ public abstract class Java2ScriptCompiler {
114116

115117
protected IJavaProject project;
116118

119+
protected int nResources;
120+
121+
117122
/**
118123
* This will activate @j2sDebug blocks, at least in SwingJS
119124
*/
@@ -158,7 +163,7 @@ public static Java2ScriptCompiler newCompiler(IJavaProject project, BuildContext
158163
File f = getJ2SConfigName(project, files[0]);
159164
return ( f == null ? null
160165
: J2S_CONFIG_JMOL.equals(j2stype = f.getName()) ?
161-
new Java2ScriptLegacyCompiler(f)
166+
new J2SLegacyCompiler(f)
162167
: J2S_CONFIG_SWINGJS.equals(j2stype) ?
163168
new Java2ScriptSwingJSCompiler(f) : null);
164169
}
@@ -271,10 +276,10 @@ protected boolean initializeProject(IJavaProject project, boolean isCleanBuild,
271276
return false;
272277
}
273278
if (getFileContents(activeJ2SFile).trim().length() == 0) {
274-
writeToFile(activeJ2SFile, getDefaultJ2SFile());
279+
writeToFile(activeJ2SFile, getDefaultJ2SFileContents());
275280
}
276281
int jslLevel = javaLanguageLevel;
277-
if (jslLevel == 8) {
282+
if (isSwingJS) {
278283
// SwingJS allows 8 or 11
279284
try {
280285
String ver = getProperty(J2S_COMPILER_JAVA_VERSION, "" + jslLevel);
@@ -345,14 +350,17 @@ boolean excludeFile(IFile javaSource) {
345350
return excludeFile(javaSource.getFullPath().toString());
346351
}
347352

348-
private boolean excludeFile(String filePath) {
353+
public boolean excludeFile(String filePath) {
349354
if (lstExcludedPaths != null) {
355+
if (filePath == null)
356+
return true;
350357
if (filePath.indexOf('\\') >= 0)
351358
filePath = filePath.replace('\\', '/');
352-
for (int i = lstExcludedPaths.size(); --i >= 0;)
359+
for (int i = lstExcludedPaths.size(); --i >= 0;) {
353360
if (filePath.indexOf(lstExcludedPaths.get(i)) >= 0) {
354361
return true;
355362
}
363+
}
356364
}
357365
return false;
358366
}
@@ -475,25 +483,24 @@ private int copyNonclassFiles(File dir, File target, int n) {
475483
return n;
476484
}
477485

478-
protected int checkCopiedResources(String packageName, String sourceLocation, String outputDir) {
486+
protected void copyAllResources(String packageName, String sourceLocation) {
479487
int pt = packageName.indexOf(".");
480488
if (pt >= 0)
481489
packageName = packageName.substring(0, pt);
482490
if (copiedResourcePackages.contains(packageName))
483-
return 0;
491+
return;
484492
copiedResourcePackages.add(packageName);
485493
pt = sourceLocation.lastIndexOf("/" + packageName + "/");
486494
if (pt <= 0) {
487495
// also don't allow "" root directory
488496
if (!"_".equals(packageName))
489497
System.out.println(
490498
"J2S ignoring bad sourceLocation for package \"" + packageName + "\": " + sourceLocation);
491-
return 0;
499+
return;
492500
}
493-
String sourceDir = sourceLocation.substring(0, pt);
494-
File src = new File(sourceDir, packageName);
495-
File dest = new File(outputDir, packageName);
496-
return copySiteResources(src, dest);
501+
File src = new File(sourceLocation.substring(0, pt), packageName);
502+
File dest = new File(j2sPath, packageName);
503+
nResources += copySiteResources(src, dest);
497504
}
498505

499506
protected String fixPackageName(String name) {

0 commit comments

Comments
 (0)