Skip to content

Commit bd0944d

Browse files
authored
Merge pull request #177 from BobHanson/master
transpiler lambda expressions; various minor SwingJS issues
2 parents e0864c9 + f63071c commit bd0944d

56 files changed

Lines changed: 1225 additions & 508 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
1.37 KB
Binary file not shown.
159 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200728062204
1+
20200807063741
1.37 KB
Binary file not shown.
159 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200728062204
1+
20200807063741

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class CorePlugin extends Plugin {
3131
// j2sApplet.js and also (Bob only) update.bat, update-clean.bat
3232

3333

34+
// BH 2020.08.03 -- 3.2.9-v1p fix for boxing boolean should be Boolean.valueOf$, not new Boolean
35+
// BH 2020.08.01 -- 3.2.9-v1o fix for lambda expressions too static
36+
// BH 2020.07.08 -- 3.2.9-v1n fix for try with resources and adds option varOrLet
3437
// BH 2020.07.04 -- 3.2.9.v1m fix for X.super.y() in anonymous class
3538
// BH 2020.06.22 -- 3.2.9.v1k fix for varargs not proper qualified arrays
3639
// BH 2020.06.17 -- 3.2.9-v1j fix for functional interface this::privateMethod

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

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@
135135

136136
// TODO: superclass inheritance for JAXB XmlAccessorType
137137

138+
//BH 2020.08.03 -- 3.2.9-v1p fix for boxing boolean should be Boolean.valueOf$, not new Boolean
139+
//BH 2020.08.01 -- 3.2.9-v1o fix for lambda expressions too static
138140
//BH 2020.07.08 -- 3.2.9-v1n fix for try with resources and adds option varOrLet
139141
//BH 2020.07.04 -- 3.2.9-v1m fix for X.super.y() in anonymous class
140142
//BH 2020.06.22 -- 3.2.9-v1k fix for varargs not proper qualified arrays
@@ -654,6 +656,8 @@ int getPrimitiveDefaultType(Code code) {
654656
*/
655657
private boolean[] package_haveStaticArgsReversal = new boolean[] {false};
656658

659+
private int b$count;
660+
657661
private void addApplication() {
658662
if (apps == null)
659663
apps = new ArrayList<String>();
@@ -1054,6 +1058,8 @@ private String processLocalInstance(ASTNode node, ASTNode anonymousClassDeclarat
10541058
// instantiation, so we need to cache the final string "{m:m,b:b,...}" at
10551059
// creation time and recover it here.
10561060

1061+
int b$count0 = b$count;
1062+
10571063
// String finals;
10581064
boolean isStatic = true;
10591065
if (localType != REALLY_LOCAL_CLASS) {
@@ -1092,7 +1098,9 @@ private String processLocalInstance(ASTNode node, ASTNode anonymousClassDeclarat
10921098

10931099
String key = binding.getKey();
10941100
Set<IVariableBinding> set = package_htClassKeyToVisitedFinalVars.get(key);
1095-
return (set == null || set.isEmpty() ? anonName : null);
1101+
boolean canBeReused = (set == null || set.isEmpty()
1102+
&& b$count == b$count0);
1103+
return (canBeReused ? anonName : null);
10961104
}
10971105

10981106
/**
@@ -4804,6 +4812,7 @@ private String getClassNameAndDot(ASTNode node, ITypeBinding declaringClass, boo
48044812
* @return "this" + .qualifier
48054813
*/
48064814
private String getSyntheticReference(String className) {
4815+
b$count++;
48074816
return "this" + (className.equals("java.lang.Object") || className.equals("Object") ? ""
48084817
//: className.equals(this$0Name) ? ".this$0"
48094818
: ".b$['" + getFinalJ2SClassName(className, FINAL_RAW) + "']");
@@ -4827,10 +4836,17 @@ private boolean appendBoxingNode(ASTNode element, boolean toCharCode) {
48274836
ITypeBinding typeBinding = exp.resolveTypeBinding();
48284837
if (typeBinding.isPrimitive()) {
48294838
String name = typeBinding.getName();
4830-
name = (name.equals("char") ? "Character"
4831-
: name.equals("int") ? "Integer"
4832-
: Character.toUpperCase(name.charAt(0)) + name.substring(1));
4833-
buffer.append("new " + name + "(");
4839+
String t = getJSTypeCode(name);
4840+
switch (name) {
4841+
case "char":
4842+
name = "Character";break;
4843+
case "int":
4844+
name = "Integer";break;
4845+
default:
4846+
name = Character.toUpperCase(name.charAt(0)) + name.substring(1);
4847+
break;
4848+
}
4849+
buffer.append(name + ".valueOf$" + t + "(");
48344850
element.accept(this);
48354851
buffer.append(")");
48364852
return true;
@@ -5673,48 +5689,40 @@ private String j2sGetParamCode(ITypeBinding binding) {
56735689
// as well.
56745690
// NOTE: These are the same as standard Java Spec, with the exception of
56755691
// Short, which is "H" instead of "S"
5692+
name = getJSTypeCode(name);
5693+
if (arrays != null) {
5694+
arrays = arrays.replaceAll("\\[\\]", "A");
5695+
name += arrays;
5696+
}
5697+
return name;
5698+
}
56765699

5677-
switch (name) {
5700+
private String getJSTypeCode(String className) {
5701+
switch (className) {
56785702
case "boolean":
5679-
name = "Z";
5680-
break;
5703+
return "Z";
56815704
case "byte":
5682-
name = "B";
5683-
break;
5705+
return "B";
56845706
case "char":
5685-
name = "C";
5686-
break;
5707+
return "C";
56875708
case "double":
5688-
name = "D";
5689-
break;
5709+
return "D";
56905710
case "float":
5691-
name = "F";
5692-
break;
5711+
return "F";
56935712
case "int":
5694-
name = "I";
5695-
break;
5713+
return "I";
56965714
case "long":
5697-
name = "J";
5698-
break;
5715+
return "J";
56995716
case "short":
5700-
name = "H"; // differs from Java Spec so we can use S for String
5701-
break;
5717+
return "H"; // differs from Java Spec so we can use S for String
57025718
case "java.lang.Object":
57035719
case "Object":
5704-
name = "O";
5705-
break;
5720+
return "O";
57065721
case "java.lang.String":
5707-
name = "S";
5708-
break;
5722+
return "S";
57095723
default:
5710-
name = stripJavaLang(NameMapper.checkClassReplacement(name)).replace('.', '_');
5711-
break;
5724+
return stripJavaLang(NameMapper.checkClassReplacement(className)).replace('.', '_');
57125725
}
5713-
if (arrays != null) {
5714-
arrays = arrays.replaceAll("\\[\\]", "A");
5715-
name += arrays;
5716-
}
5717-
return name;
57185726
}
57195727

57205728
/**
1.37 KB
Binary file not shown.

sources/net.sf.j2s.java.core/src/java/io/File.java

Lines changed: 85 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,9 @@ public boolean canWrite() {
769769
}
770770

771771
/**
772+
*
773+
* SwingJS note: All directories are considered to exist.
774+
*
772775
* Tests whether the file or directory denoted by this abstract pathname
773776
* exists.
774777
*
@@ -785,6 +788,9 @@ public boolean exists() {
785788
}
786789

787790
/**
791+
* SwingJS note: The only way we can check if something is a directory is if
792+
* its path is the same as its prefix length. That is, if it ends with "/".
793+
*
788794
* Tests whether the file denoted by this abstract pathname is a
789795
* directory.
790796
*
@@ -1085,85 +1091,85 @@ public File[] listFiles() {
10851091
}
10861092
return fs;
10871093
}
1088-
//
1089-
// /**
1090-
// * Returns an array of abstract pathnames denoting the files and
1091-
// * directories in the directory denoted by this abstract pathname that
1092-
// * satisfy the specified filter. The behavior of this method is the same
1093-
// * as that of the {@link #listFiles()} method, except that the pathnames in
1094-
// * the returned array must satisfy the filter. If the given {@code filter}
1095-
// * is {@code null} then all pathnames are accepted. Otherwise, a pathname
1096-
// * satisfies the filter if and only if the value {@code true} results when
1097-
// * the {@link FilenameFilter#accept
1098-
// * FilenameFilter.accept(File,&nbsp;String)} method of the filter is
1099-
// * invoked on this abstract pathname and the name of a file or directory in
1100-
// * the directory that it denotes.
1101-
// *
1102-
// * @param filter
1103-
// * A filename filter
1104-
// *
1105-
// * @return An array of abstract pathnames denoting the files and
1106-
// * directories in the directory denoted by this abstract pathname.
1107-
// * The array will be empty if the directory is empty. Returns
1108-
// * {@code null} if this abstract pathname does not denote a
1109-
// * directory, or if an I/O error occurs.
1110-
// *
1111-
// * @throws SecurityException
1112-
// * If a security manager exists and its {@link
1113-
// * SecurityManager#checkRead(String)} method denies read access to
1114-
// * the directory
1115-
// *
1116-
// * @since 1.2
1117-
// */
1118-
// public File[] listFiles(FilenameFilter filter) {
1119-
// String ss[] = list();
1120-
// if (ss == null) return null;
1121-
// ArrayList<File> files = new ArrayList<File>();
1122-
// for (String s : ss)
1123-
// if ((filter == null) || filter.accept(this, s))
1124-
// files.add(new File(s, this));
1125-
// return files.toArray(new File[files.size()]);
1126-
// }
1127-
//
1128-
// /**
1129-
// * Returns an array of abstract pathnames denoting the files and
1130-
// * directories in the directory denoted by this abstract pathname that
1131-
// * satisfy the specified filter. The behavior of this method is the same
1132-
// * as that of the {@link #listFiles()} method, except that the pathnames in
1133-
// * the returned array must satisfy the filter. If the given {@code filter}
1134-
// * is {@code null} then all pathnames are accepted. Otherwise, a pathname
1135-
// * satisfies the filter if and only if the value {@code true} results when
1136-
// * the {@link FileFilter#accept FileFilter.accept(File)} method of the
1137-
// * filter is invoked on the pathname.
1138-
// *
1139-
// * @param filter
1140-
// * A file filter
1141-
// *
1142-
// * @return An array of abstract pathnames denoting the files and
1143-
// * directories in the directory denoted by this abstract pathname.
1144-
// * The array will be empty if the directory is empty. Returns
1145-
// * {@code null} if this abstract pathname does not denote a
1146-
// * directory, or if an I/O error occurs.
1147-
// *
1148-
// * @throws SecurityException
1149-
// * If a security manager exists and its {@link
1150-
// * SecurityManager#checkRead(String)} method denies read access to
1151-
// * the directory
1152-
// *
1153-
// * @since 1.2
1154-
// */
1155-
// public File[] listFiles(FileFilter filter) {
1156-
// String ss[] = list();
1157-
// if (ss == null) return null;
1158-
// ArrayList<File> files = new ArrayList<File>();
1159-
// for (String s : ss) {
1160-
// File f = new File(s, this);
1161-
// if ((filter == null) || filter.accept(f))
1162-
// files.add(f);
1163-
// }
1164-
// return files.toArray(new File[files.size()]);
1165-
// }
1166-
//
1094+
1095+
/**
1096+
* Returns an array of abstract pathnames denoting the files and
1097+
* directories in the directory denoted by this abstract pathname that
1098+
* satisfy the specified filter. The behavior of this method is the same
1099+
* as that of the {@link #listFiles()} method, except that the pathnames in
1100+
* the returned array must satisfy the filter. If the given {@code filter}
1101+
* is {@code null} then all pathnames are accepted. Otherwise, a pathname
1102+
* satisfies the filter if and only if the value {@code true} results when
1103+
* the {@link FilenameFilter#accept
1104+
* FilenameFilter.accept(File,&nbsp;String)} method of the filter is
1105+
* invoked on this abstract pathname and the name of a file or directory in
1106+
* the directory that it denotes.
1107+
*
1108+
* @param filter
1109+
* A filename filter
1110+
*
1111+
* @return An array of abstract pathnames denoting the files and
1112+
* directories in the directory denoted by this abstract pathname.
1113+
* The array will be empty if the directory is empty. Returns
1114+
* {@code null} if this abstract pathname does not denote a
1115+
* directory, or if an I/O error occurs.
1116+
*
1117+
* @throws SecurityException
1118+
* If a security manager exists and its {@link
1119+
* SecurityManager#checkRead(String)} method denies read access to
1120+
* the directory
1121+
*
1122+
* @since 1.2
1123+
*/
1124+
public File[] listFiles(FilenameFilter filter) {
1125+
String ss[] = list();
1126+
if (ss == null) return null;
1127+
ArrayList<File> files = new ArrayList<File>();
1128+
for (String s : ss)
1129+
if ((filter == null) || filter.accept(this, s))
1130+
files.add(new File(s, this));
1131+
return files.toArray(new File[files.size()]);
1132+
}
1133+
1134+
/**
1135+
* Returns an array of abstract pathnames denoting the files and
1136+
* directories in the directory denoted by this abstract pathname that
1137+
* satisfy the specified filter. The behavior of this method is the same
1138+
* as that of the {@link #listFiles()} method, except that the pathnames in
1139+
* the returned array must satisfy the filter. If the given {@code filter}
1140+
* is {@code null} then all pathnames are accepted. Otherwise, a pathname
1141+
* satisfies the filter if and only if the value {@code true} results when
1142+
* the {@link FileFilter#accept FileFilter.accept(File)} method of the
1143+
* filter is invoked on the pathname.
1144+
*
1145+
* @param filter
1146+
* A file filter
1147+
*
1148+
* @return An array of abstract pathnames denoting the files and
1149+
* directories in the directory denoted by this abstract pathname.
1150+
* The array will be empty if the directory is empty. Returns
1151+
* {@code null} if this abstract pathname does not denote a
1152+
* directory, or if an I/O error occurs.
1153+
*
1154+
* @throws SecurityException
1155+
* If a security manager exists and its {@link
1156+
* SecurityManager#checkRead(String)} method denies read access to
1157+
* the directory
1158+
*
1159+
* @since 1.2
1160+
*/
1161+
public File[] listFiles(FileFilter filter) {
1162+
String ss[] = list();
1163+
if (ss == null) return null;
1164+
ArrayList<File> files = new ArrayList<File>();
1165+
for (String s : ss) {
1166+
File f = new File(s, this);
1167+
if ((filter == null) || filter.accept(f))
1168+
files.add(f);
1169+
}
1170+
return files.toArray(new File[files.size()]);
1171+
}
1172+
11671173
/**
11681174
* Creates the directory named by this abstract pathname.
11691175
*

0 commit comments

Comments
 (0)