Skip to content

Commit 7d81033

Browse files
committed
last of refactoring - j2s.core.jar refactoring completed.
1 parent b6cd62d commit 7d81033

File tree

11 files changed

+52
-55
lines changed

11 files changed

+52
-55
lines changed
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+
-2.29 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20231125155705
1+
20231125175756
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20231125155705
1+
20231125175756

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

Lines changed: 2 additions & 2 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
/**
@@ -160,7 +160,7 @@ public static Java2ScriptCompiler newCompiler(IJavaProject project, BuildContext
160160
File f = getJ2SConfigName(project, files[0]);
161161
return ( f == null ? null
162162
: J2S_CONFIG_JMOL.equals(j2stype = f.getName()) ?
163-
new Java2ScriptLegacyCompiler(f)
163+
new J2SLegacyCompiler(f)
164164
: J2S_CONFIG_SWINGJS.equals(j2stype) ?
165165
new Java2ScriptSwingJSCompiler(f) : null);
166166
}

sources/net.sf.j2s.core/src/j2s/jmol/J2SASTVisitor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@
3939

4040
/**
4141
*
42-
* ASTVisitor > Java2ScriptASTVisitor > Java2ScriptDependencyVisitor
42+
* ASTVisitor > J2SASTVisitor > J2SDependencyVisitor
4343
*
44-
* ASTVisitor > Java2ScriptASTVisitor > J2SKeywordVisitor > Java2ScriptPrimaryVisitor
44+
* ASTVisitor > J2SASTVisitor > J2SKeywordVisitor > Java2ScriptLegacyVisitor
4545
*
4646
* @author zhou renjian
4747
*/
4848
abstract class J2SASTVisitor extends ASTVisitor {
4949

5050
protected final static String[] preDeclaredPackages = { //
51-
"java.lang", //
51+
"java.lang", //publicfinal refactoring -- Helpers to inner static classes
5252
"java.lang.ref", //
5353
"java.lang.ref.reflect", //
5454
"java.lang.reflect", //

sources/net.sf.j2s.core/src/j2s/jmol/J2SDependencyVisitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
/**
5555
*
56-
* ASTVisitor > Java2ScriptASTVisitor > Java2ScriptDependencyVisitor
56+
* ASTVisitor > J2SASTVisitor > J2SDependencyVisitor
5757
*
5858
* This class is called by root.accept(me) in the first pass of the
5959
* transpiler to catalog all the references to classes and then later
@@ -63,7 +63,7 @@
6363
*
6464
* 2006-5-2
6565
*/
66-
public class J2SDependencyVisitor extends J2SASTVisitor {
66+
class J2SDependencyVisitor extends J2SASTVisitor {
6767

6868
private static class QNTypeBinding {
6969
String qualifiedName;

sources/net.sf.j2s.core/src/j2s/jmol/J2SKeywordVisitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191

9292
/**
9393
*
94-
* ASTVisitor > Java2ScriptASTVisitor > J2SKeywordVisitor > Java2ScriptPrimaryVisitor
94+
* ASTVisitor > J2SASTVisitor > J2SKeywordVisitor > Java2ScriptLegacyVisitor
9595
*
9696
* This class will traverse most of the common keyword and
9797
* common expression.
@@ -101,7 +101,7 @@
101101
* @author zhou renjian
102102
*
103103
*/
104-
public abstract class J2SKeywordVisitor extends J2SASTVisitor {
104+
abstract class J2SKeywordVisitor extends J2SASTVisitor {
105105

106106
/**
107107
* FinalVariable that is used to record variable state, which will provide

sources/net.sf.j2s.core/src/j2s/jmol/J2SLegacyCompiler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import j2s.CorePlugin;
1414
import j2s.core.Java2ScriptCompiler;
1515

16-
public class Java2ScriptLegacyCompiler extends Java2ScriptCompiler {
16+
public class J2SLegacyCompiler extends Java2ScriptCompiler {
1717

1818
private final static String J2S_PACKAGE_FIXES = "j2s.package.fixes";
1919

@@ -32,7 +32,7 @@ public class Java2ScriptLegacyCompiler extends Java2ScriptCompiler {
3232
,"Class.forName", "Clazz._4Name"//
3333
};
3434

35-
public Java2ScriptLegacyCompiler(File f) {
35+
public J2SLegacyCompiler(File f) {
3636
super(false, f);
3737
}
3838

@@ -117,7 +117,7 @@ public boolean compileToJavaScript(IFile javaSource, String trailer) {
117117
return false;
118118
}
119119

120-
Java2ScriptLegacyVisitor visitor = new Java2ScriptLegacyVisitor();
120+
J2SLegacyVisitor visitor = new J2SLegacyVisitor();
121121
isDebugging = "debug".equals(props.getProperty("j2s.compiler.mode"));
122122
errorOccurs = false;
123123
try {
@@ -143,7 +143,7 @@ public boolean compileToJavaScript(IFile javaSource, String trailer) {
143143
return false;
144144
}
145145

146-
private void outputJavaScript(Java2ScriptLegacyVisitor visitor, J2SDependencyVisitor dvisitor, CompilationUnit fRoot,
146+
private void outputJavaScript(J2SLegacyVisitor visitor, J2SDependencyVisitor dvisitor, CompilationUnit fRoot,
147147
String outputPath, String trailer, String sourceLocation) {
148148
String js = finalFixes(dvisitor.cleanLoadCalls(visitor));
149149
String elementName = fRoot.getJavaElement().getElementName();

sources/net.sf.j2s.core/src/j2s/jmol/J2SLegacyVisitor.java

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.eclipse.jdt.core.dom.IPackageBinding;
3737
import org.eclipse.jdt.core.dom.ITypeBinding;
3838
import org.eclipse.jdt.core.dom.IVariableBinding;
39-
import org.eclipse.jdt.core.dom.IfStatement;
4039
import org.eclipse.jdt.core.dom.InfixExpression;
4140
import org.eclipse.jdt.core.dom.Initializer;
4241
import org.eclipse.jdt.core.dom.MethodDeclaration;
@@ -50,18 +49,12 @@
5049
import org.eclipse.jdt.core.dom.PrefixExpression;
5150
import org.eclipse.jdt.core.dom.PrimitiveType;
5251
import org.eclipse.jdt.core.dom.PrimitiveType.Code;
53-
54-
import j2s.jmol.J2SKeywordVisitor.FinalVariable;
55-
import j2s.jmol.J2SKeywordVisitor.MethodReferenceASTVisitor;
56-
import j2s.jmol.J2SKeywordVisitor.VariableHelper;
57-
5852
import org.eclipse.jdt.core.dom.QualifiedName;
5953
import org.eclipse.jdt.core.dom.QualifiedType;
6054
import org.eclipse.jdt.core.dom.ReturnStatement;
6155
import org.eclipse.jdt.core.dom.SimpleName;
6256
import org.eclipse.jdt.core.dom.SimpleType;
6357
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
64-
import org.eclipse.jdt.core.dom.Statement;
6558
import org.eclipse.jdt.core.dom.SuperConstructorInvocation;
6659
import org.eclipse.jdt.core.dom.SuperFieldAccess;
6760
import org.eclipse.jdt.core.dom.SuperMethodInvocation;
@@ -75,7 +68,7 @@
7568

7669
/**
7770
*
78-
* ASTVisitor > Java2ScriptASTVisitor > J2SKeywordVisitor > Java2ScriptPrimaryVisitor
71+
* ASTVisitor > J2SASTVisitor > J2SKeywordVisitor > J2SLegacyVisitor
7972
*
8073
* Formerly ASTScriptVisitor
8174
*
@@ -104,7 +97,7 @@
10497
*
10598
* 2006-12-3
10699
*/
107-
public class Java2ScriptLegacyVisitor extends J2SKeywordVisitor {
100+
class J2SLegacyVisitor extends J2SKeywordVisitor {
108101

109102
// UNFIXED bugs left here because not an issue in Jmol.
110103
//
@@ -1034,11 +1027,11 @@ public boolean visit(EnumDeclaration node) {
10341027
}
10351028
if ((node != rootTypeNode) && node.getParent() != null && node.getParent() instanceof AbstractTypeDeclaration) {
10361029
/* inner static class */
1037-
Java2ScriptLegacyVisitor visitor = null;
1030+
J2SLegacyVisitor visitor = null;
10381031
try {
10391032
visitor = this.getClass().newInstance();
10401033
} catch (@SuppressWarnings("unused") Exception e) {
1041-
visitor = new Java2ScriptLegacyVisitor(); // Default visitor
1034+
visitor = new J2SLegacyVisitor(); // Default visitor
10421035
}
10431036
visitor.rootTypeNode = node;
10441037
visitor.typeHelper.setClassName(this.typeHelper.getClassName());
@@ -1157,7 +1150,7 @@ public boolean processFieldDeclaration(FieldDeclaration node, boolean ignoreInit
11571150
if (checkKeywordViolation(fieldName)) {
11581151
ext += "$";
11591152
}
1160-
if (typeBinding != null && checkSameName(typeBinding, fieldName)) {
1153+
if (typeBinding != null && isSameName(typeBinding, fieldName)) {
11611154
ext += "$";
11621155
}
11631156
buffer.append("this.");
@@ -1904,22 +1897,22 @@ public boolean visit(SimpleName node) {
19041897
if (writeConstantValue(node))
19051898
return false;
19061899
IBinding binding = node.resolveBinding();
1907-
ASTNode xparent = node.getParent();
1908-
if (xparent == null) {
1900+
ASTNode parent = node.getParent();
1901+
if (parent == null) {
19091902
buffer.append(node);
19101903
return false;
19111904
}
19121905
char ch = 0;
19131906
if (buffer.length() > 0) {
19141907
ch = buffer.charAt(buffer.length() - 1);
19151908
}
1916-
if (ch == '.' && xparent instanceof QualifiedName) {
1909+
if (ch == '.' && parent instanceof QualifiedName) {
19171910
if (binding != null && binding instanceof IVariableBinding) {
19181911
IVariableBinding varBinding = (IVariableBinding) binding;
19191912
IVariableBinding variableDeclaration = varBinding.getVariableDeclaration();
19201913
ITypeBinding declaringClass = variableDeclaration.getDeclaringClass();
19211914
String fieldName = getJ2SName(node);
1922-
if (checkSameName(declaringClass, fieldName)) {
1915+
if (isSameName(declaringClass, fieldName)) {
19231916
buffer.append('$');
19241917
}
19251918
if (checkKeywordViolation(fieldName)) {
@@ -1934,7 +1927,7 @@ public boolean visit(SimpleName node) {
19341927
buffer.append(node);
19351928
return false;
19361929
}
1937-
if (xparent instanceof ClassInstanceCreation && !(binding instanceof IVariableBinding)) {
1930+
if (parent instanceof ClassInstanceCreation && !(binding instanceof IVariableBinding)) {
19381931
ITypeBinding binding2 = node.resolveTypeBinding();
19391932
if (binding != null) {
19401933
String name = binding2.getQualifiedName();
@@ -1963,20 +1956,7 @@ public boolean visit(SimpleName node) {
19631956
processSimpleNameInMethodBinding(node, ch, mthBinding);
19641957
} else {
19651958
ITypeBinding typeBinding = node.resolveTypeBinding();
1966-
if (typeBinding != null) {
1967-
String name = typeBinding.getQualifiedName();
1968-
name = assureQualifiedName(shortenQualifiedName(name));
1969-
if (checkKeywordViolation(name)) {
1970-
buffer.append('$');
1971-
}
1972-
buffer.append(name);
1973-
} else {
1974-
String name = node.getFullyQualifiedName();
1975-
if (checkKeywordViolation(name)) {
1976-
buffer.append('$');
1977-
}
1978-
buffer.append(name);
1979-
}
1959+
processSimpleNameInTypeBinding(node, typeBinding);
19801960
}
19811961
return false;
19821962
}
@@ -1998,7 +1978,7 @@ private void processSimpleNameInVarBinding(SimpleName node, char ch, IVariableBi
19981978
}
19991979
}
20001980
String fieldName = getJ2SName(node);
2001-
if (checkSameName(declaringClass, fieldName)) {
1981+
if (isSameName(declaringClass, fieldName)) {
20021982
buffer.append('$');
20031983
}
20041984
if (checkKeywordViolation(fieldName)) {
@@ -2051,11 +2031,10 @@ private void processSimpleNameInVarBinding(SimpleName node, char ch, IVariableBi
20512031
} else {
20522032
fieldName = fieldVar;
20532033
}
2054-
// System.err.println(fieldName);
20552034
if (checkKeywordViolation(fieldName)) {
20562035
buffer.append('$');
20572036
}
2058-
if (declaringClass != null && checkSameName(declaringClass, fieldName)) {
2037+
if (declaringClass != null && isSameName(declaringClass, fieldName)) {
20592038
buffer.append('$');
20602039
}
20612040
if (declaringClass != null && isInheritedFieldName(declaringClass, fieldName)) {
@@ -2086,7 +2065,6 @@ private void processSimpleNameInMethodBinding(SimpleName node, char ch, IMethodB
20862065
}
20872066
}
20882067
}
2089-
// String name = variableDeclaration.getName();
20902068
String name = getJ2SName(node);
20912069
name = shortenQualifiedName(name);
20922070
if (!(isClassString && "valueOf".equals(name)) && checkKeywordViolation(name)) {
@@ -2114,6 +2092,23 @@ private void processSimpleNameInMethodBinding(SimpleName node, char ch, IMethodB
21142092
}
21152093
}
21162094

2095+
private void processSimpleNameInTypeBinding(SimpleName node, ITypeBinding typeBinding) {
2096+
if (typeBinding != null) {
2097+
String name = typeBinding.getQualifiedName();
2098+
name = assureQualifiedName(shortenQualifiedName(name));
2099+
if (checkKeywordViolation(name)) {
2100+
buffer.append('$');
2101+
}
2102+
buffer.append(name);
2103+
} else {
2104+
String name = node.getFullyQualifiedName();
2105+
if (checkKeywordViolation(name)) {
2106+
buffer.append('$');
2107+
}
2108+
buffer.append(name);
2109+
}
2110+
}
2111+
21172112
private void appendFieldName(ASTNode parent, ITypeBinding declaringClass) {
21182113
String name = declaringClass.getQualifiedName();
21192114
boolean isThis = false;
@@ -2810,11 +2805,11 @@ public boolean visit(TypeDeclaration node) {
28102805
if ((node != rootTypeNode) && node.getParent() != null && (node.getParent() instanceof AbstractTypeDeclaration
28112806
|| node.getParent() instanceof TypeDeclarationStatement)) {
28122807
/* inner static class */
2813-
Java2ScriptLegacyVisitor visitor = null;
2808+
J2SLegacyVisitor visitor = null;
28142809
try {
28152810
visitor = this.getClass().newInstance();
28162811
} catch (@SuppressWarnings("unused") Exception e) {
2817-
visitor = new Java2ScriptLegacyVisitor(); // Default visitor
2812+
visitor = new J2SLegacyVisitor(); // Default visitor
28182813
}
28192814
visitor.rootTypeNode = node;
28202815
String className = typeVisitor.getClassName();
@@ -2958,7 +2953,7 @@ public boolean visit(TypeLiteral node) {
29582953

29592954
/// static methods originally in ASTJ2sMapVisitor
29602955

2961-
private static boolean checkSameName(ITypeBinding binding, String name) {
2956+
private static boolean isSameName(ITypeBinding binding, String name) {
29622957
if (binding != null) {
29632958
IMethodBinding[] declaredMethods = binding.getDeclaredMethods();
29642959
for (int i = 0; i < declaredMethods.length; i++) {
@@ -2967,13 +2962,13 @@ private static boolean checkSameName(ITypeBinding binding, String name) {
29672962
}
29682963
}
29692964
ITypeBinding superclass = binding.getSuperclass();
2970-
if (checkSameName(superclass, name)) {
2965+
if (isSameName(superclass, name)) {
29712966
return true;
29722967
}
29732968
ITypeBinding[] interfaces = binding.getInterfaces();
29742969
if (interfaces != null) {
29752970
for (int i = 0; i < interfaces.length; i++) {
2976-
if (checkSameName(interfaces[i], name)) {
2971+
if (isSameName(interfaces[i], name)) {
29772972
return true;
29782973
}
29792974
}

0 commit comments

Comments
 (0)