Skip to content

Commit f21952c

Browse files
committed
refactored visitors
1 parent 24f811a commit f21952c

26 files changed

+1492
-1848
lines changed

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/AbstractPluginVisitor.java renamed to sources/net.sf.j2s.core/src/net/sf/j2s/core/adapters/AbstractPluginAdapter.java

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,30 @@
1-
/*******************************************************************************
2-
* Copyright (c) 2007 java2script.org and others.
3-
* All rights reserved. This program and the accompanying materials
4-
* are made available under the terms of the Eclipse Public License v1.0
5-
* which accompanies this distribution, and is available at
6-
* http://www.eclipse.org/legal/epl-v10.html
7-
*
8-
* Contributors:
9-
* Zhou Renjian - initial API and implementation
10-
*******************************************************************************/
11-
12-
package net.sf.j2s.core.astvisitors;
13-
14-
15-
/**
16-
* @author zhou renjian
17-
*
18-
* 2006-12-27
19-
*/
20-
public class AbstractPluginVisitor implements IPluginVisitor {
21-
22-
protected ASTEmptyVisitor visitor;
23-
24-
// protected StringBuffer buffer;
25-
26-
public StringBuffer getBuffer() {
27-
return visitor.getBuffer();
28-
}
29-
30-
// public void setBuffer(StringBuffer buffer) {
31-
// this.buffer = buffer;
32-
// }
33-
34-
public ASTEmptyVisitor getVisitor() {
35-
return visitor;
36-
}
37-
38-
public void setVisitor(ASTEmptyVisitor visitor) {
39-
this.visitor = visitor;
40-
}
41-
1+
/*******************************************************************************
2+
* Copyright (c) 2007 java2script.org and others.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Zhou Renjian - initial API and implementation
10+
*******************************************************************************/
11+
12+
package net.sf.j2s.core.adapters;
13+
14+
import net.sf.j2s.core.astvisitors.ASTEmptyVisitor;
15+
import net.sf.j2s.core.astvisitors.IPluginVisitor;
16+
17+
/**
18+
* @author zhou renjian
19+
*
20+
* 2006-12-27
21+
*/
22+
public class AbstractPluginAdapter implements IPluginVisitor {
23+
24+
protected ASTEmptyVisitor visitor;
25+
26+
public void setVisitor(ASTEmptyVisitor visitor) {
27+
this.visitor = visitor;
28+
}
29+
4230
}

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/Bindings.java renamed to sources/net.sf.j2s.core/src/net/sf/j2s/core/adapters/Bindings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* bug "inline method - doesn't handle implicit cast" (see
1212
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=24941).
1313
*******************************************************************************/
14-
package net.sf.j2s.core.astvisitors;
14+
package net.sf.j2s.core.adapters;
1515

1616
import java.util.ArrayList;
1717
import java.util.Collections;

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/ASTFieldVisitor.java renamed to sources/net.sf.j2s.core/src/net/sf/j2s/core/adapters/FieldAdapter.java

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* Zhou Renjian - initial API and implementation
1010
*******************************************************************************/
1111

12-
package net.sf.j2s.core.astvisitors;
12+
package net.sf.j2s.core.adapters;
1313

1414
import java.util.HashSet;
1515

@@ -22,7 +22,7 @@
2222
*
2323
* 2006-12-3
2424
*/
25-
public class ASTFieldVisitor extends AbstractPluginVisitor {
25+
public class FieldAdapter extends AbstractPluginAdapter {
2626

2727
/*
2828
* IE passes the following:
@@ -54,7 +54,7 @@ public class ASTFieldVisitor extends AbstractPluginVisitor {
5454
*
5555
*
5656
*/
57-
public static String[] keywords = new String[] {
57+
static String[] keywords = new String[] {
5858
"class", /*"java", "javax", "sun", */"for", "while", "do", "in", "return", "function", "var",
5959
"class", "pubic", "protected", "private", "new", "delete",
6060
"static", "package", "import", "extends", "implements",
@@ -69,7 +69,7 @@ public class ASTFieldVisitor extends AbstractPluginVisitor {
6969
};
7070

7171

72-
static boolean checkKeywordViolation(String name, HashSet<String> definedPackageNames) {
72+
public static boolean checkKeywordViolation(String name, HashSet<String> definedPackageNames) {
7373
for (int i = 0; i < keywords.length; i++) {
7474
if (keywords[i].equals(name)) {
7575
return true;
@@ -85,7 +85,7 @@ static boolean checkKeywordViolation(String name, HashSet<String> definedPackage
8585
* @param node
8686
* @return
8787
*/
88-
protected boolean isSimpleQualified(QualifiedName node) {
88+
public static boolean isSimpleQualified(QualifiedName node) {
8989
Name qualifier = node.getQualifier();
9090
if (qualifier instanceof SimpleName) {
9191
return true;
@@ -95,29 +95,4 @@ protected boolean isSimpleQualified(QualifiedName node) {
9595
return false;
9696
}
9797

98-
// protected boolean isFieldNeedPreparation(FieldDeclaration node) {
99-
// if ((node.getModifiers() & Modifier.STATIC) != 0) {
100-
// return false;
101-
// }
102-
//
103-
// List<?> fragments = node.fragments();
104-
// for (Iterator<?> iter = fragments.iterator(); iter.hasNext();) {
105-
// VariableDeclarationFragment element = (VariableDeclarationFragment) iter.next();
106-
// Expression initializer = element.getInitializer();
107-
// if (initializer != null) {
108-
// Object constValue = initializer.resolveConstantExpressionValue();
109-
// if (constValue != null && (constValue instanceof Number || constValue instanceof Character
110-
// || constValue instanceof Boolean || constValue instanceof String)) {
111-
// return false;
112-
// }
113-
// if (initializer instanceof NullLiteral) {
114-
// return false;
115-
// }
116-
// return true;
117-
// }
118-
// return false;
119-
// }
120-
// return false;
121-
// }
122-
12398
}

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/ASTFinalVariable.java renamed to sources/net.sf.j2s.core/src/net/sf/j2s/core/adapters/FinalVariable.java

Lines changed: 82 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,83 @@
1-
package net.sf.j2s.core.astvisitors;
2-
3-
/**
4-
* FinalVariable that is used to record variable state, which will provide
5-
* information for compiler to decide the generated name in *.js.
6-
*
7-
* @author zhou renjian
8-
*
9-
* 2006-12-6
10-
*/
11-
public class ASTFinalVariable {
12-
13-
/**
14-
* Level of the block
15-
*/
16-
int blockLevel;
17-
18-
/**
19-
* Final variable may be in a very deep anonymous class
20-
*/
21-
String methodScope;
22-
23-
/**
24-
* Variable name that is defined in Java sources
25-
*/
26-
String variableName;
27-
28-
/**
29-
* Variable name that is to be generated in the compiled *.js
30-
*/
31-
String toVariableName;
32-
33-
public ASTFinalVariable(int blockLevel, String variableName, String methodScope) {
34-
super();
35-
this.blockLevel = blockLevel;
36-
this.variableName = variableName;
37-
this.methodScope = methodScope;
38-
}
39-
40-
public String toString() {
41-
return variableName + ":" + variableName;
42-
}
43-
44-
public int hashCode() {
45-
final int prime = 31;
46-
int result = 1;
47-
result = prime * result + blockLevel;
48-
result = prime * result
49-
+ ((methodScope == null) ? 0 : methodScope.hashCode());
50-
result = prime * result
51-
+ ((toVariableName == null) ? 0 : toVariableName.hashCode());
52-
result = prime * result
53-
+ ((variableName == null) ? 0 : variableName.hashCode());
54-
return result;
55-
}
56-
57-
public boolean equals(Object obj) {
58-
if (this == obj)
59-
return true;
60-
if (obj == null)
61-
return false;
62-
if (getClass() != obj.getClass())
63-
return false;
64-
final ASTFinalVariable other = (ASTFinalVariable) obj;
65-
if (blockLevel != other.blockLevel)
66-
return false;
67-
if (methodScope == null) {
68-
if (other.methodScope != null)
69-
return false;
70-
} else if (!methodScope.equals(other.methodScope))
71-
return false;
72-
if (toVariableName == null) {
73-
if (other.toVariableName != null)
74-
return false;
75-
} else if (!toVariableName.equals(other.toVariableName))
76-
return false;
77-
if (variableName == null) {
78-
if (other.variableName != null)
79-
return false;
80-
} else if (!variableName.equals(other.variableName))
81-
return false;
82-
return true;
83-
}
84-
1+
package net.sf.j2s.core.adapters;
2+
3+
/**
4+
* FinalVariable that is used to record variable state, which will provide
5+
* information for compiler to decide the generated name in *.js.
6+
*
7+
* @author zhou renjian
8+
*
9+
* 2006-12-6
10+
*/
11+
public class FinalVariable {
12+
13+
/**
14+
* Level of the block
15+
*/
16+
public int blockLevel;
17+
18+
/**
19+
* Final variable may be in a very deep anonymous class
20+
*/
21+
public String methodScope;
22+
23+
/**
24+
* Variable name that is defined in Java sources
25+
*/
26+
public String variableName;
27+
28+
/**
29+
* Variable name that is to be generated in the compiled *.js
30+
*/
31+
public String toVariableName;
32+
33+
public FinalVariable(int blockLevel, String variableName, String methodScope) {
34+
super();
35+
this.blockLevel = blockLevel;
36+
this.variableName = variableName;
37+
this.methodScope = methodScope;
38+
}
39+
40+
public String toString() {
41+
return variableName + ":" + variableName;
42+
}
43+
44+
public int hashCode() {
45+
final int prime = 31;
46+
int result = 1;
47+
result = prime * result + blockLevel;
48+
result = prime * result
49+
+ ((methodScope == null) ? 0 : methodScope.hashCode());
50+
result = prime * result
51+
+ ((toVariableName == null) ? 0 : toVariableName.hashCode());
52+
result = prime * result
53+
+ ((variableName == null) ? 0 : variableName.hashCode());
54+
return result;
55+
}
56+
57+
public boolean equals(Object obj) {
58+
if (this == obj)
59+
return true;
60+
if (obj == null || getClass() != obj.getClass())
61+
return false;
62+
final FinalVariable other = (FinalVariable) obj;
63+
if (blockLevel != other.blockLevel)
64+
return false;
65+
if (methodScope == null) {
66+
if (other.methodScope != null)
67+
return false;
68+
} else if (!methodScope.equals(other.methodScope))
69+
return false;
70+
if (toVariableName == null) {
71+
if (other.toVariableName != null)
72+
return false;
73+
} else if (!toVariableName.equals(other.toVariableName))
74+
return false;
75+
if (variableName == null) {
76+
if (other.variableName != null)
77+
return false;
78+
} else if (!variableName.equals(other.variableName))
79+
return false;
80+
return true;
81+
}
82+
8583
}

0 commit comments

Comments
 (0)