5353import org .eclipse .jdt .core .dom .ParenthesizedExpression ;
5454import org .eclipse .jdt .core .dom .PostfixExpression ;
5555import org .eclipse .jdt .core .dom .PrefixExpression ;
56- import org .eclipse .jdt .core .dom .PrimitiveType ;
5756import org .eclipse .jdt .core .dom .QualifiedName ;
5857import org .eclipse .jdt .core .dom .ReturnStatement ;
5958import org .eclipse .jdt .core .dom .SimpleName ;
7170import org .eclipse .jdt .core .dom .VariableDeclarationFragment ;
7271import org .eclipse .jdt .core .dom .VariableDeclarationStatement ;
7372import org .eclipse .jdt .core .dom .WhileStatement ;
74- import org .eclipse .jdt .core .dom .PrimitiveType .Code ;
7573
7674/**
7775 * This class will traverse most of the common keyword and
7876 * common expression.
7977 *
8078 * This class will not deal with binding.
8179 *
82- * @author josson smith
80+ * @author zhou renjian
8381 *
8482 */
85- public class ASTKeywordParser extends ASTEmptyParser {
86-
87- protected StringBuffer buffer = new StringBuffer ();
83+ public class ASTKeywordVisitor extends ASTJ2SMapVisitor {
8884
8985 protected int blockLevel = 0 ;
9086
9187 protected Stack methodDeclareStack = new Stack ();
9288
9389 protected int currentBlockForVisit = -1 ;
9490
95- public StringBuffer getBuffer () {
96- return buffer ;
97- }
98-
99- public void setBuffer (StringBuffer buffer ) {
100- this .buffer = buffer ;
101- }
102-
10391 protected void visitList (List list , String seperator ) {
10492 for (Iterator iter = list .iterator (); iter .hasNext ();) {
10593 ASTNode element = (ASTNode ) iter .next ();
@@ -110,73 +98,6 @@ protected void visitList(List list, String seperator) {
11098 }
11199 }
112100
113- protected void boxingNode (ASTNode element ) {
114- if (element instanceof Expression ) {
115- Expression exp = (Expression ) element ;
116- if (exp .resolveBoxing ()) {
117- ITypeBinding typeBinding = exp .resolveTypeBinding ();
118- if (typeBinding .isPrimitive ()) {
119- String name = typeBinding .getName ();
120- Code type = PrimitiveType .toCode (name );
121- String bigName = null ;
122- if (type == PrimitiveType .INT ) {
123- bigName = "Integer" ;
124- } else if (type == PrimitiveType .LONG ) {
125- bigName = "Long" ;
126- } else if (type == PrimitiveType .FLOAT ) {
127- bigName = "Float" ;
128- } else if (type == PrimitiveType .DOUBLE ) {
129- bigName = "Double" ;
130- } else if (type == PrimitiveType .BOOLEAN ) {
131- bigName = "Boolean" ;
132- } else if (type == PrimitiveType .BYTE ) {
133- bigName = "Byte" ;
134- } else if (type == PrimitiveType .SHORT ) {
135- bigName = "Short" ;
136- } else if (type == PrimitiveType .CHAR ) {
137- bigName = "Character" ;
138- }
139- if (bigName != null ) {
140- buffer .append ("new " + bigName + " (" );
141- element .accept (this );
142- buffer .append (")" );
143- return ;
144- }
145- }
146- } else if (exp .resolveUnboxing ()) {
147- ITypeBinding typeBinding = exp .resolveTypeBinding ();
148- if (!typeBinding .isPrimitive ()) {
149- String name = typeBinding .getQualifiedName ();
150- String bigName = null ;
151- if ("java.lang.Integer" .equals (name )) {
152- bigName = "int" ;
153- } else if ("java.lang.Long" .equals (name )) {
154- bigName = "long" ;
155- } else if ("java.lang.Float" .equals (name )) {
156- bigName = "float" ;
157- } else if ("java.lang.Double" .equals (name )) {
158- bigName = "double" ;
159- } else if ("java.lang.Boolean" .equals (name )) {
160- bigName = "boolean" ;
161- } else if ("java.lang.Byte" .equals (name )) {
162- bigName = "byte" ;
163- } else if ("java.lang.Short" .equals (name )) {
164- bigName = "short" ;
165- } else if ("java.lang.Character" .equals (name )) {
166- bigName = "char" ;
167- }
168-
169- if (bigName != null ) {
170- buffer .append ("(" );
171- element .accept (this );
172- buffer .append (")." + bigName + "Value ()" );
173- return ;
174- }
175- }
176- }
177- }
178- element .accept (this );
179- }
180101 protected void visitList (List list , String seperator , int begin , int end ) {
181102 for (int i = begin ; i < end ; i ++) {
182103 ASTNode element = (ASTNode ) list .get (i );
@@ -468,13 +389,13 @@ public void endVisit(Block node) {
468389 buffer .append ("}" );
469390 for (int i = finalVars .size () - 1 ; i >= 0 ; i --) {
470391 FinalVariable var = (FinalVariable ) finalVars .get (i );
471- if (var .getBlockLevel () >= blockLevel ) {
392+ if (var .blockLevel >= blockLevel ) {
472393 finalVars .remove (i );
473394 }
474395 }
475396 for (int i = normalVars .size () - 1 ; i >= 0 ; i --) {
476397 FinalVariable var = (FinalVariable ) normalVars .get (i );
477- if (var .getBlockLevel () >= blockLevel ) {
398+ if (var .blockLevel >= blockLevel ) {
478399 normalVars .remove (i );
479400 }
480401 }
@@ -1143,7 +1064,7 @@ public boolean visit(VariableDeclarationFragment node) {
11431064 String methodSig = (String ) methodDeclareStack .peek ();
11441065 f = new FinalVariable (blockLevel , identifier , methodSig );
11451066 }
1146- f .setToVariableName ( getIndexedVarName (identifier , normalVars .size () ));
1067+ f .toVariableName = getIndexedVarName (identifier , normalVars .size ());
11471068 normalVars .add (f );
11481069 if ((binding .getModifiers () & Modifier .FINAL ) != 0 ) {
11491070 finalVars .add (f );
0 commit comments