Skip to content

Commit d3604f8

Browse files
authored
Merge pull request #131 from BobHanson/master
several updates, including flagging Thread.sleep with alert
2 parents f3ee80a + 769c80a commit d3604f8

File tree

77 files changed

+10288
-456
lines changed

Some content is hidden

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

77 files changed

+10288
-456
lines changed

sources/net.sf.j2s.core/dist/build-site.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
<for param="file.zip">
5656
<path>
57-
<fileset dir="${libjs.dir}" includes="*.zip"/>
57+
<fileset dir="${libjs.dir}" includes="*.zip" erroronmissingdir="false" />
5858
</path>
5959
<sequential>
6060
<unzip src="@{file.zip}" dest="${site.dir}" overwrite="true"/>
@@ -73,14 +73,14 @@
7373

7474
<echo> Copying ${resource.dir} files into ${j2s.dir} </echo>
7575
<copy todir="${j2s.dir}">
76-
<fileset dir="${resource.dir}">
76+
<fileset dir="${resource.dir}" erroronmissingdir="false" >
7777
<include name="**"/>
7878
</fileset>
7979
</copy>
8080

8181
<echo> Copying ${site-resource.dir} files into ${site.dir} </echo>
8282
<copy todir="${site.dir}">
83-
<fileset dir="${site-resource.dir}">
83+
<fileset dir="${site-resource.dir}" erroronmissingdir="false" >
8484
<include name="**"/>
8585
</fileset>
8686
</copy>
60 KB
Binary file not shown.
332 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20191008173421
1+
20191020181703
Binary file not shown.
332 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20191008173421
1+
20191020181703

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

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,45 @@ class Java2ScriptCompiler {
5050
private Map<String, String> htMethodsCalled;
5151
private List<String> lstMethodsDeclared;
5252

53+
private final static String J2S_COMPILER_STATUS = "j2s.compiler.status";
54+
private final static String J2S_COMPILER_STATUS_ENABLE = "enable";
55+
private final static String J2S_COMPILER_STATUS_ENABLED = "enabled";
56+
57+
private static final String J2S_SITE_DIRECTORY = "j2s.site.directory";
58+
59+
/**
60+
* log file name for methods declared
61+
*/
62+
private static final String J2S_LOG_METHODS_DECLARED = "j2s.log.methods.declared";
63+
64+
/**
65+
* log file name for methods called
66+
*/
67+
private static final String J2S_LOG_METHODS_CALLED = "j2s.log.methods.called";
68+
69+
private static final String J2S_LOG_ALL_CALLS = "j2s.log.all.calls";
70+
71+
private static final String J2S_LOG_ALL_CALLS_TRUE = "true";
72+
73+
private static final String J2S_EXCLUDED_PATHS = "j2s.excluded.paths";
74+
75+
private static final String J2S_TESTING = "j2s.testing";
76+
77+
private static final String J2S_TESTING_TRUE = "true";
78+
79+
private static final String J2S_COMPILER_NONQUALIFIED_PACKAGES = "j2s.compiler.nonqualified.packages";
80+
81+
private static final String J2S_COMPILER_NONQUALIFIED_CLASSES = "j2s.compiler.nonqualified.classes";
82+
83+
private static final String J2S_COMPILER_MODE = "j2s.compiler.mode";
84+
85+
private static final String J2S_COMPILER_MODE_DEBUG = "debug";
86+
87+
private static final String J2S_CLASS_REPLACEMENTS = "j2s.class.replacements";
88+
89+
private static final String J2S_TEMPLATE_HTML = "j2s.template.html";
90+
91+
5392
private Properties props;
5493
private String htmlTemplate = null;
5594

@@ -132,8 +171,8 @@ boolean initializeProject(IJavaProject project, boolean isCompilationParticipant
132171
try {
133172
File j2sFile = new File(projectFolder, J2S_OPTIONS_FILE_NAME);
134173
props.load(new FileInputStream(j2sFile));
135-
String status = getProperty("j2s.compiler.status");
136-
if (!"enable".equals(status) && !"enabled".equals(status)) {
174+
String status = getProperty(J2S_COMPILER_STATUS);
175+
if (!J2S_COMPILER_STATUS_ENABLE.equalsIgnoreCase(status) && !J2S_COMPILER_STATUS_ENABLED.equalsIgnoreCase(status)) {
137176
if (getFileContents(j2sFile).trim().length() == 0) {
138177
writeToFile(j2sFile, getDefaultJ2SFile());
139178
} else {
@@ -148,7 +187,7 @@ boolean initializeProject(IJavaProject project, boolean isCompilationParticipant
148187
}
149188

150189
File file;
151-
siteFolder = getProperty("j2s.site.directory");
190+
siteFolder = getProperty(J2S_SITE_DIRECTORY);
152191
if (siteFolder == null)
153192
siteFolder = "site";
154193
siteFolder = projectFolder + "/" + siteFolder;
@@ -159,7 +198,7 @@ boolean initializeProject(IJavaProject project, boolean isCompilationParticipant
159198
// method declarations and invocations are only logged
160199
// when the designated files are deleted prior to building
161200

162-
logDeclared = (isCompilationParticipant && !isCleanBuild ? null : getProperty("j2s.log.methods.declared"));
201+
logDeclared = (isCompilationParticipant && !isCleanBuild ? null : getProperty(J2S_LOG_METHODS_DECLARED));
163202
if (logDeclared != null) {
164203
if (!(file = new File(projectFolder, logDeclared)).exists()) {
165204
lstMethodsDeclared = new ArrayList<String>();
@@ -169,17 +208,17 @@ boolean initializeProject(IJavaProject project, boolean isCompilationParticipant
169208
}
170209
logAllCalls = false;
171210

172-
logCalled = (isCompilationParticipant && !isCleanBuild ? null : getProperty("j2s.log.methods.called"));
211+
logCalled = (isCompilationParticipant && !isCleanBuild ? null : getProperty(J2S_LOG_METHODS_CALLED));
173212
if (logCalled != null) {
174213
if (!(file = new File(projectFolder, logCalled)).exists()) {
175214
htMethodsCalled = new Hashtable<String, String>();
176215
System.err.println("logging methods called to " + file);
177216
}
178217
logCalled = projectFolder + "/" + logCalled;
179-
logAllCalls = "true".equals(getProperty("j2s.log.all.calls"));
218+
logAllCalls = J2S_LOG_ALL_CALLS_TRUE.equalsIgnoreCase(getProperty(J2S_LOG_ALL_CALLS));
180219
}
181220

182-
excludedPaths = getProperty("j2s.excluded.paths");
221+
excludedPaths = getProperty(J2S_EXCLUDED_PATHS);
183222

184223
lstExcludedPaths = null;
185224

@@ -193,21 +232,21 @@ boolean initializeProject(IJavaProject project, boolean isCompilationParticipant
193232
lstExcludedPaths = null;
194233
}
195234

196-
testing = "true".equals(getProperty("j2s.testing"));
235+
testing = J2S_TESTING_TRUE.equalsIgnoreCase(getProperty(J2S_TESTING));
197236

198-
String prop = getProperty("j2s.compiler.nonqualified.packages");
237+
String prop = getProperty(J2S_COMPILER_NONQUALIFIED_PACKAGES);
199238
// older version of the name
200-
String nonqualifiedPackages = getProperty("j2s.compiler.nonqualified.classes");
239+
String nonqualifiedPackages = getProperty(J2S_COMPILER_NONQUALIFIED_CLASSES);
201240
nonqualifiedPackages = (prop == null ? "" : prop)
202241
+ (nonqualifiedPackages == null ? "" : (prop == null ? "" : ";") + nonqualifiedPackages);
203242
if (nonqualifiedPackages.length() == 0)
204243
nonqualifiedPackages = null;
205244
// includes @j2sDebug blocks
206-
isDebugging = "debug".equals(getProperty("j2s.compiler.mode"));
245+
isDebugging = J2S_COMPILER_MODE_DEBUG.equalsIgnoreCase(getProperty(J2S_COMPILER_MODE));
207246

208-
String classReplacements = getProperty("j2s.class.replacements");
247+
String classReplacements = getProperty(J2S_CLASS_REPLACEMENTS);
209248

210-
String htmlTemplateFile = getProperty("j2s.template.html");
249+
String htmlTemplateFile = getProperty(J2S_TEMPLATE_HTML);
211250
if (htmlTemplateFile == null)
212251
htmlTemplateFile = "template.html";
213252

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
import org.eclipse.jdt.core.dom.WhileStatement;
135135
import org.eclipse.jdt.core.dom.WildcardType;
136136

137+
// BH 2019.10.18 fix for "P$.licationShutdownHooks"
137138
// BH 2019.09.07 adds optimization for lambda methods that do not have finals
138139
// BH 2019.08.29 fix for boxing of binary representation 0b01... (Google Closure Compiler bug)
139140
// BH 2019.05.13 fix for Math.getExponent, ulp, nextDown, nextUp, nextAfter needing qualification
@@ -1713,8 +1714,11 @@ private void addClassOrInterface(ASTNode node, ITypeBinding binding, List<?> bod
17131714
this$0Name0 = this$0Name;
17141715
this$0Name = null;
17151716
finalShortClassName = getFinalJ2SClassName(
1716-
(isLambda ? getMyJavaClassNameLambda(true) : getJavaClassNameQualified(binding)), FINAL_P)
1717-
.substring(3);
1717+
(isLambda ? getMyJavaClassNameLambda(true) : getJavaClassNameQualified(binding)), FINAL_P);
1718+
if (finalShortClassName.startsWith("P$.")) {
1719+
// java.lang.x will return x, not P$.x
1720+
finalShortClassName = finalShortClassName.substring(3);
1721+
}
17181722
setClassAndBinding(finalShortClassName, binding);
17191723
if (isLambda)
17201724
buffer.append("(");
@@ -4391,8 +4395,9 @@ private String getMyJavaClassNameLambda(boolean andIncrement) {
43914395

43924396
static String stripJavaLang(String name) {
43934397
// shorten java.lang.XXX.YYY but not java.lang.xxx.YYY
4394-
return (!name.startsWith("java.lang.") || name.equals("java.lang.Object")
4398+
String s = (!name.startsWith("java.lang.") || name.equals("java.lang.Object")
43954399
|| name.length() > 10 && !Character.isUpperCase(name.charAt(10)) ? name : name.substring(10));
4400+
return s;
43964401
}
43974402

43984403
/**
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
BH 2018.08.12
4+
5+
- requires tools/ant-contrib.jar
6+
7+
- creates the site/ directory if it does not exist
8+
- unzip libjs/*.zip into site/swingjs/j2s
9+
- unzips swingjs/SwingJS-site.zip into site/
10+
- copies non-java resources from resources/ into site/swingjs/j2s
11+
12+
-->
13+
14+
<project name="swingjs-project" default="tosite" basedir="."
15+
xmlns:if="ant:if"
16+
xmlns:unless="ant:unless">
17+
18+
<target name="tosite">
19+
20+
<!-- input directories -->
21+
22+
<!-- location of ant-contrib.jar -->
23+
<property name="tools.dir" value = "tools" />
24+
25+
<!-- SwingjS_site zip file (could be varied if versioning is needed)
26+
<property name="swingjs.zip" value="swingjs/SwingJS-site.zip" />
27+
-->
28+
29+
<!-- location of third-party jar contents as precompiled zipped .js files to copy to site/ -->
30+
<property name="libjs.dir" value="libjs" />
31+
32+
<!-- non-Java resources to copy to site/swingjs/j2s -->
33+
<property name="resource.dir" value="resources" />
34+
35+
<!-- non-Java resources to copy to site/ -->
36+
<property name="site-resource.dir" value="site-resources" />
37+
38+
<!-- output directories -->
39+
40+
<property name="site.dir" value="site" />
41+
<property name="j2s.dir" value="${site.dir}/swingjs/j2s" />
42+
43+
<!-- <for ...> construct needs ant-contrib.jar -->
44+
<taskdef resource="net/sf/antcontrib/antlib.xml">
45+
<classpath>
46+
<pathelement location="${tools.dir}/ant-contrib.jar" />
47+
</classpath>
48+
</taskdef>
49+
50+
<!-- unzip all libjs zip files into site
51+
52+
all zip files placed in libjs will be processed
53+
54+
-->
55+
56+
<for param="file.zip">
57+
<path>
58+
<fileset dir="${libjs.dir}" erroronmissingdir="false" includes="*.zip"/>
59+
</path>
60+
<sequential>
61+
<unzip src="@{file.zip}" dest="${site.dir}" overwrite="true"/>
62+
</sequential>
63+
</for>
64+
65+
<!-- unzip SwingJS-site.zip
66+
67+
not in net.sf.j2s
68+
69+
<unzip src="${swingjs.zip}" dest="${site.dir}/" overwrite="true"/>
70+
-->
71+
72+
73+
<!-- transfer resources -->
74+
75+
<echo> Copying ${resource.dir} files into ${j2s.dir} </echo>
76+
<copy todir="${j2s.dir}">
77+
<fileset dir="${resource.dir}" erroronmissingdir="false" >
78+
<include name="**"/>
79+
</fileset>
80+
</copy>
81+
82+
<echo> Copying ${site-resource.dir} files into ${site.dir} </echo>
83+
<copy todir="${site.dir}">
84+
<fileset dir="${site-resource.dir}" erroronmissingdir="false" >
85+
<include name="**"/>
86+
</fileset>
87+
</copy>
88+
89+
90+
</target>
91+
92+
93+
</project>

0 commit comments

Comments
 (0)