Skip to content

Commit aaff3cc

Browse files
committed
Refactoring
1 parent 2447642 commit aaff3cc

22 files changed

+675
-862
lines changed
-654 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20231119163724
1+
20231121063606
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20231119163724
1+
20231121063606

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ 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.21 -- 5.0.1-v2 adds Java8 syntaxes for try and switch; removes dependency for instanceOf
3435
// BH 2023.11.09 -- 5.0.1-v1 merges Jmol legacy (.j2sjmol) with Java8//11 (.j2s)
3536
// BH 2023.03.29 -- 3.3.1-v7 fixes outer static method call from within lambda expression.
3637
// BH 2023.02.09 -- 3.3.1.v6 fixes j2s.excluded.paths needing /src/xxxx

sources/net.sf.j2s.core/src/j2s/jmol/common/ASTFieldVisitor.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
* 2006-12-3
2929
*/
30-
public class ASTFieldVisitor extends AbstractPluginVisitor {
30+
public class ASTFieldVisitor extends ASTVisitor {
3131

3232
/*
3333
* IE passes the following:
@@ -57,7 +57,7 @@ public class ASTFieldVisitor extends AbstractPluginVisitor {
5757
* volatile, while, with,
5858
*
5959
*/
60-
public static String[] keywods = new String[] {
60+
public static String[] keywords = new String[] {
6161
"class", /*"java", "javax", "sun", */"for", "while", "do", "in", "return", "function", "var",
6262
"class", "pubic", "protected", "private", "new", "delete",
6363
"static", "package", "import", "extends", "implements",
@@ -71,8 +71,8 @@ public class ASTFieldVisitor extends AbstractPluginVisitor {
7171

7272

7373
boolean checkKeyworkViolation(String name) {
74-
for (int i = 0; i < keywods.length; i++) {
75-
if (keywods[i].equals(name)) {
74+
for (int i = 0; i < keywords.length; i++) {
75+
if (keywords[i].equals(name)) {
7676
return true;
7777
}
7878
}
@@ -101,25 +101,22 @@ protected boolean isFieldNeedPreparation(FieldDeclaration node) {
101101
return false;
102102
}
103103

104-
List fragments = node.fragments();
105-
for (Iterator iter = fragments.iterator(); iter.hasNext();) {
104+
List<?> fragments = node.fragments();
105+
for (Iterator<?> iter = fragments.iterator(); iter.hasNext();) {
106106
VariableDeclarationFragment element = (VariableDeclarationFragment) iter.next();
107107
Expression initializer = element.getInitializer();
108108
if (initializer != null) {
109109
Object constValue = initializer.resolveConstantExpressionValue();
110-
if (constValue != null && (constValue instanceof Number
111-
|| constValue instanceof Character
112-
|| constValue instanceof Boolean
113-
|| constValue instanceof String)) {
114-
return false;
110+
if (constValue != null && (constValue instanceof Number || constValue instanceof Character
111+
|| constValue instanceof Boolean || constValue instanceof String)) {
112+
break;
115113
}
116114
if (initializer instanceof NullLiteral) {
117-
return false;
115+
break;
118116
}
119117
return true;
120-
} else {
121-
return false;
122118
}
119+
break;
123120
}
124121
return false;
125122
}

sources/net.sf.j2s.core/src/j2s/jmol/common/ASTMethodVisitor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
*
2828
* 2006-12-3
2929
*/
30-
public class ASTMethodVisitor extends AbstractPluginVisitor {
30+
public class ASTMethodVisitor extends ASTVisitor {
3131

32-
private static Set methodSet;
33-
private static Map pmMap;
32+
private static Set<String> methodSet;
33+
private static Map<String, String> pmMap;
3434
public static final String PACKAGE_PREFIX;
3535
public static String[] mapDocument;
3636
public static String[] mapNode;
@@ -125,8 +125,8 @@ public class ASTMethodVisitor extends AbstractPluginVisitor {
125125
}
126126

127127
public static void init() {
128-
pmMap = new HashMap();
129-
methodSet = new HashSet();
128+
pmMap = new HashMap<String, String>();
129+
methodSet = new HashSet<String>();
130130
register("java.lang.String", "length", "length");
131131
register("java.lang.CharSequence", "length", "length");//sgurin: fix for bug: CharSequence cs = "123"; cs.length();
132132
register("java.lang.String", "replace", "~replace");
@@ -144,7 +144,7 @@ public static void register(String className, String methodName, String property
144144
}
145145

146146
public String translate(String className, String methodName) {
147-
return (String) pmMap.get(className + "." + methodName);
147+
return pmMap.get(className + "." + methodName);
148148
}
149149

150150
protected static void registerMap(String[] map) {

sources/net.sf.j2s.core/src/j2s/jmol/common/ASTPackageVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* 2006-12-3
1919
*/
20-
public class ASTPackageVisitor extends AbstractPluginVisitor {
20+
public class ASTPackageVisitor extends ASTVisitor {
2121

2222
protected String thisPackageName = "";
2323

sources/net.sf.j2s.core/src/j2s/jmol/common/ASTTigerVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*
2525
* 2006-12-6
2626
*/
27-
public class ASTTigerVisitor extends AbstractPluginVisitor {
27+
public class ASTTigerVisitor extends ASTVisitor {
2828

2929
protected void boxingNode(ASTNode element) {
3030
if (element instanceof Expression) {

sources/net.sf.j2s.core/src/j2s/jmol/common/ASTTypeVisitor.java

Lines changed: 24 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
* 2006-12-3
2727
*/
28-
public class ASTTypeVisitor extends AbstractPluginVisitor {
28+
public class ASTTypeVisitor extends ASTVisitor {
2929

3030
protected String thisClassName = "";
3131

@@ -66,11 +66,8 @@ public String getFullClassName() {
6666
* @param name
6767
* @return
6868
*/
69-
public String discardGenericType(String name) {
70-
if (name == null) {
71-
return null;
72-
}
73-
return Bindings.removeBrackets(name);
69+
public static String discardGenericType(String name) {
70+
return (name == null ? null : Bindings.removeBrackets(name));
7471
}
7572

7673
/**
@@ -86,7 +83,7 @@ public String discardGenericType(String name) {
8683
* @param name
8784
* @return
8885
*/
89-
public boolean isInheritedClassName(ITypeBinding binding, String name) {
86+
private static boolean isInheritedClassName(ITypeBinding binding, String name) {
9087
if (binding == null) {
9188
return false;
9289
}
@@ -121,7 +118,7 @@ public boolean isInheritedClassName(ITypeBinding binding, String name) {
121118
* @param name
122119
* @return
123120
*/
124-
public String shortenQualifiedName(String name) {
121+
static String shortenQualifiedName(String name) {
125122
name = Bindings.removeBrackets(name);
126123
int index = name.indexOf("java.lang.");
127124
char ch = 0;
@@ -133,7 +130,7 @@ public String shortenQualifiedName(String name) {
133130
return name;
134131
}
135132

136-
public String shortenPackageName(String fullName) {
133+
static String shortenPackageName(String fullName) {
137134
String name = fullName.substring(0, fullName.lastIndexOf('.'));
138135
name = Bindings.removeBrackets(name);
139136
int index = name.indexOf("java.lang.");
@@ -148,33 +145,10 @@ public String shortenPackageName(String fullName) {
148145
name = name.substring(10);
149146
}
150147
}
151-
String swt = "org.eclipse.swt.SWT";
152-
index = name.indexOf(swt);
153-
if (index != -1) {
154-
String after = name.substring(swt.length());
155-
if (after.length() == 0 || after.startsWith(".")) {
156-
name = "$WT" + after;
157-
}
158-
} else {
159-
String os = "org.eclipse.swt.internal.browser.OS";
160-
index = name.indexOf(os);
161-
if (index != -1) {
162-
String after = name.substring(os.length());
163-
if (after.length() == 0 || after.startsWith(".")) {
164-
name = "O$" + after;
165-
}
166-
}
167-
}
168-
swt = "org.eclipse.swt";
169-
index = name.indexOf(swt);
170-
if (index != -1) {
171-
String after = name.substring(swt.length());
172-
name = "$wt" + after;
173-
}
174148
return name;
175149
}
176150

177-
public String getTypeStringName(Type type) {
151+
static String getTypeStringName(Type type) {
178152
if (type == null) {
179153
return null;
180154
}
@@ -200,11 +174,11 @@ public String getTypeStringName(Type type) {
200174
return null;
201175
}
202176

203-
public String assureQualifiedName(String name) {
177+
static String assureQualifiedName(String name) {
204178
if (name == null || name.length() == 0) {
205179
return name;
206180
}
207-
String[] keywords = ASTFieldVisitor.keywods;
181+
String[] keywords = ASTFieldVisitor.keywords;
208182
String[] packages = null;
209183
boolean existedKeyword = false;
210184
for (int i = 0; i < keywords.length; i++) {
@@ -220,28 +194,26 @@ public String assureQualifiedName(String name) {
220194
}
221195
}
222196
}
223-
if (existedKeyword) {
224-
StringBuffer sb = new StringBuffer();
225-
for (int i = 0; i < packages.length; i++) {
226-
if (packages[i].charAt(0) == '[') {
227-
if (i == 0) {
228-
sb.append("window");
229-
}
230-
sb.append(packages[i]);
231-
} else {
232-
if (i != 0) {
233-
sb.append('.');
234-
}
235-
sb.append(packages[i]);
197+
if (!existedKeyword || packages == null)
198+
return name;
199+
StringBuffer sb = new StringBuffer();
200+
for (int i = 0; i < packages.length; i++) {
201+
if (packages[i].charAt(0) == '[') {
202+
if (i == 0) {
203+
sb.append("window");
236204
}
205+
sb.append(packages[i]);
206+
} else {
207+
if (i != 0) {
208+
sb.append('.');
209+
}
210+
sb.append(packages[i]);
237211
}
238-
return sb.toString();
239-
} else {
240-
return name;
241212
}
213+
return sb.toString();
242214
}
243215

244-
public boolean isIntegerType(String type) {
216+
static boolean isIntegerType(String type) {
245217
if ("int".equals(type)
246218
|| "long".equals(type)
247219
|| "byte".equals(type)

sources/net.sf.j2s.core/src/j2s/jmol/common/ASTVariableVisitor.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
*
2626
* 2006-12-3
2727
*/
28-
public class ASTVariableVisitor extends AbstractPluginVisitor {
28+
public class ASTVariableVisitor extends ASTVisitor {
2929

3030
/**
3131
* List of variables that are declared as final.
3232
*/
33-
protected List finalVars = new ArrayList();
33+
protected List<ASTFinalVariable> finalVars = new ArrayList<>();
3434

3535
/**
3636
* Final variables only make senses (need "this.f$[...]") inside anonymous
@@ -41,13 +41,13 @@ public class ASTVariableVisitor extends AbstractPluginVisitor {
4141
/**
4242
* Normal (non-final) variables may be affected by final variable names.
4343
*/
44-
protected List normalVars = new ArrayList();
44+
protected List<ASTFinalVariable> normalVars = new ArrayList<>();
4545

4646
/**
4747
* Only those final variables that are referenced inside anonymous class
4848
* need to be passed into anonymous class.
4949
*/
50-
protected List visitedVars = new ArrayList();
50+
protected List<ASTFinalVariable> visitedVars = new ArrayList<>();
5151

5252
/**
5353
* Whether to compile variable names into minimized names or not
@@ -64,7 +64,7 @@ public class ASTVariableVisitor extends AbstractPluginVisitor {
6464
//
6565
protected String getVariableName(String name) {
6666
for (int i = normalVars.size() - 1; i >= 0; i--) {
67-
ASTFinalVariable var = (ASTFinalVariable) normalVars.get(i);
67+
ASTFinalVariable var = normalVars.get(i);
6868
if (name.equals(var.variableName)) {
6969
//return getIndexedVarName(name, i);
7070
return var.toVariableName;
@@ -99,17 +99,17 @@ public String getIndexedVarName(String name, int i) {
9999
int l = i % 26;
100100
newName = String.valueOf((char) ('a' + h)) + String.valueOf((char) ('a' + l));
101101
}
102-
for (Iterator iter = finalVars.iterator(); iter.hasNext();) {
103-
ASTFinalVariable f = (ASTFinalVariable) iter.next();
102+
for (Iterator<ASTFinalVariable> iter = finalVars.iterator(); iter.hasNext();) {
103+
ASTFinalVariable f = iter.next();
104104
if (newName.equals(f.toVariableName)) {
105105
newName = null;
106106
i++;
107107
break;
108108
}
109109
}
110110
if (newName != null) {
111-
for (Iterator iter = normalVars.iterator(); iter.hasNext();) {
112-
ASTFinalVariable f = (ASTFinalVariable) iter.next();
111+
for (Iterator<ASTFinalVariable> iter = normalVars.iterator(); iter.hasNext();) {
112+
ASTFinalVariable f = iter.next();
113113
if (newName.equals(f.toVariableName)) {
114114
newName = null;
115115
i++;
@@ -138,13 +138,13 @@ public String getIndexedVarName(String name, int i) {
138138
* @param scope
139139
* @return
140140
*/
141-
protected String listFinalVariables(List list, String seperator, String scope) {
141+
protected String listFinalVariables(List<?> list, String seperator, String scope) {
142142
if (list.size() == 0) {
143143
return "null";
144144
}
145145
StringBuffer buf = new StringBuffer();
146146
buf.append("Clazz.cloneFinals (");
147-
for (Iterator iter = list.iterator(); iter.hasNext();) {
147+
for (Iterator<?> iter = list.iterator(); iter.hasNext();) {
148148
ASTFinalVariable fv = (ASTFinalVariable) iter.next();
149149
String name = fv.variableName;
150150
if (fv.toVariableName != null) {

0 commit comments

Comments
 (0)