Thanks to visit codestin.com
Credit goes to github.com

Skip to content

major refactoring of legacy only #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Nov 28, 2023
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
4 changes: 2 additions & 2 deletions sources/net.sf.j2s.core/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml,\
schema/
plugin.xml

2 changes: 2 additions & 0 deletions sources/net.sf.j2s.core/dist/jmol/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Looking for the transpiler? It's in the dist/swingjs folder.

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 @@
20231115195339
20231128000108
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 @@
20231115195339
20231128000108
4 changes: 3 additions & 1 deletion sources/net.sf.j2s.core/src/j2s/CorePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ public class CorePlugin extends Plugin {
* the actual "x.y.z" version is specified in plugin.xml.
*
*/
public static String VERSION = "5.0.1-v1";
public static String VERSION = "5.0.1-v2";

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

// BH 2023.11.27 -- 5.0.1-v2 final refactoring and creatiton of J2SUtil
// BH 2023.11.21 -- 5.0.1-v2 adds Java8 syntaxes for try and switch; removes dependency for instanceOf and exception checking
// BH 2023.11.09 -- 5.0.1-v1 merges Jmol legacy (.j2sjmol) with Java8//11 (.j2s)
// BH 2023.03.29 -- 3.3.1-v7 fixes outer static method call from within lambda expression.
// BH 2023.02.09 -- 3.3.1.v6 fixes j2s.excluded.paths needing /src/xxxx
Expand Down
39 changes: 23 additions & 16 deletions sources/net.sf.j2s.core/src/j2s/core/Java2ScriptCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.eclipse.jdt.core.dom.ASTParser;

import j2s.CorePlugin;
import j2s.jmol.Java2ScriptLegacyCompiler;
import j2s.jmol.J2SLegacyCompiler;
import j2s.swingjs.Java2ScriptSwingJSCompiler;

/**
Expand Down Expand Up @@ -84,10 +84,13 @@ public abstract class Java2ScriptCompiler {

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

abstract protected String getDefaultJ2SFile();

abstract public void finalizeProject();

/*
* To save a default file with comments specific to this transpiler.
*/
abstract protected String getDefaultJ2SFileContents();

/**
* The name of the J2S options file, aka as the "Dot-j2s" file. Please do not
* change this value.
Expand All @@ -99,7 +102,6 @@ public abstract class Java2ScriptCompiler {
protected Properties props;

protected String projectFolder;
// protected String outputPath;
protected String siteFolder;
protected String j2sPath;
protected String excludedPaths;
Expand All @@ -114,6 +116,9 @@ public abstract class Java2ScriptCompiler {

protected IJavaProject project;

protected int nResources;


/**
* This will activate @j2sDebug blocks, at least in SwingJS
*/
Expand Down Expand Up @@ -158,7 +163,7 @@ public static Java2ScriptCompiler newCompiler(IJavaProject project, BuildContext
File f = getJ2SConfigName(project, files[0]);
return ( f == null ? null
: J2S_CONFIG_JMOL.equals(j2stype = f.getName()) ?
new Java2ScriptLegacyCompiler(f)
new J2SLegacyCompiler(f)
: J2S_CONFIG_SWINGJS.equals(j2stype) ?
new Java2ScriptSwingJSCompiler(f) : null);
}
Expand Down Expand Up @@ -271,10 +276,10 @@ protected boolean initializeProject(IJavaProject project, boolean isCleanBuild,
return false;
}
if (getFileContents(activeJ2SFile).trim().length() == 0) {
writeToFile(activeJ2SFile, getDefaultJ2SFile());
writeToFile(activeJ2SFile, getDefaultJ2SFileContents());
}
int jslLevel = javaLanguageLevel;
if (jslLevel == 8) {
if (isSwingJS) {
// SwingJS allows 8 or 11
try {
String ver = getProperty(J2S_COMPILER_JAVA_VERSION, "" + jslLevel);
Expand Down Expand Up @@ -345,14 +350,17 @@ boolean excludeFile(IFile javaSource) {
return excludeFile(javaSource.getFullPath().toString());
}

private boolean excludeFile(String filePath) {
public boolean excludeFile(String filePath) {
if (lstExcludedPaths != null) {
if (filePath == null)
return true;
if (filePath.indexOf('\\') >= 0)
filePath = filePath.replace('\\', '/');
for (int i = lstExcludedPaths.size(); --i >= 0;)
for (int i = lstExcludedPaths.size(); --i >= 0;) {
if (filePath.indexOf(lstExcludedPaths.get(i)) >= 0) {
return true;
}
}
}
return false;
}
Expand Down Expand Up @@ -475,25 +483,24 @@ private int copyNonclassFiles(File dir, File target, int n) {
return n;
}

protected int checkCopiedResources(String packageName, String sourceLocation, String outputDir) {
protected void copyAllResources(String packageName, String sourceLocation) {
int pt = packageName.indexOf(".");
if (pt >= 0)
packageName = packageName.substring(0, pt);
if (copiedResourcePackages.contains(packageName))
return 0;
return;
copiedResourcePackages.add(packageName);
pt = sourceLocation.lastIndexOf("/" + packageName + "/");
if (pt <= 0) {
// also don't allow "" root directory
if (!"_".equals(packageName))
System.out.println(
"J2S ignoring bad sourceLocation for package \"" + packageName + "\": " + sourceLocation);
return 0;
return;
}
String sourceDir = sourceLocation.substring(0, pt);
File src = new File(sourceDir, packageName);
File dest = new File(outputDir, packageName);
return copySiteResources(src, dest);
File src = new File(sourceLocation.substring(0, pt), packageName);
File dest = new File(j2sPath, packageName);
nResources += copySiteResources(src, dest);
}

protected String fixPackageName(String name) {
Expand Down
Loading