@@ -451,6 +451,20 @@ public boolean visit(AnonymousClassDeclaration node) {
451451 }
452452
453453 public boolean visit (CastExpression node ) {
454+ Object nodeConstantValue = node .resolveConstantExpressionValue ();
455+ if (nodeConstantValue != null ) {
456+ Type type = node .getType ();
457+ if (type .isPrimitiveType ()) {
458+ PrimitiveType pType = (PrimitiveType ) type ;
459+ if (pType .getPrimitiveTypeCode () == PrimitiveType .INT
460+ || pType .getPrimitiveTypeCode () == PrimitiveType .BYTE
461+ || pType .getPrimitiveTypeCode () == PrimitiveType .SHORT
462+ || pType .getPrimitiveTypeCode () == PrimitiveType .LONG ) {
463+ buffer .append (nodeConstantValue );
464+ return false ;
465+ }
466+ }
467+ }
454468 Type type = node .getType ();
455469 /*
456470 * TODO: some casting should have its meaning!
@@ -1197,42 +1211,41 @@ public void endVisit(EnumDeclaration node) {
11971211 ASTNode element = (ASTNode ) iter .next ();
11981212 if (element instanceof Initializer ) {
11991213 element .accept (this );
1200-
12011214 } else if (element instanceof FieldDeclaration ) {
12021215 FieldDeclaration field = (FieldDeclaration ) element ;
1203- if ((field .getModifiers () & Modifier .STATIC ) != 0 ) {
1204- List fragments = field .fragments ();
1205- for (int j = 0 ; j < fragments .size (); j ++) {
1206- //if (fragments.size () == 1) {
1207- /* replace full class name with short variable name */
1208- buffer .append ("cla$$" );
1209- //buffer.append(fullClassName);
1210- buffer .append ("." );
1211- VariableDeclarationFragment vdf = (VariableDeclarationFragment ) fragments .get (j );
1212- //buffer.append(vdf.getName());
1213- vdf .getName ().accept (this );
1214- buffer .append (" = " );
1215- Expression initializer = vdf .getInitializer ();
1216- if (initializer != null ) {
1217- initializer .accept (this );
1218- } else {
1219- Type type = field .getType ();
1220- if (type .isPrimitiveType ()){
1221- PrimitiveType pType = (PrimitiveType ) type ;
1222- if (pType .getPrimitiveTypeCode () == PrimitiveType .BOOLEAN ) {
1223- buffer .append ("false" );
1216+ if ((field .getModifiers () & Modifier .STATIC ) != 0 ) {
1217+ List fragments = field .fragments ();
1218+ for (int j = 0 ; j < fragments .size (); j ++) {
1219+ //if (fragments.size () == 1) {
1220+ /* replace full class name with short variable name */
1221+ buffer .append ("cla$$" );
1222+ //buffer.append(fullClassName);
1223+ buffer .append ("." );
1224+ VariableDeclarationFragment vdf = (VariableDeclarationFragment ) fragments .get (j );
1225+ //buffer.append(vdf.getName());
1226+ vdf .getName ().accept (this );
1227+ buffer .append (" = " );
1228+ Expression initializer = vdf .getInitializer ();
1229+ if (initializer != null ) {
1230+ initializer .accept (this );
1231+ } else {
1232+ Type type = field .getType ();
1233+ if (type .isPrimitiveType ()){
1234+ PrimitiveType pType = (PrimitiveType ) type ;
1235+ if (pType .getPrimitiveTypeCode () == PrimitiveType .BOOLEAN ) {
1236+ buffer .append ("false" );
1237+ } else {
1238+ buffer .append ("0" );
1239+ }
12241240 } else {
1225- buffer .append ("0 " );
1241+ buffer .append ("null " );
12261242 }
1227- } else {
1228- buffer .append ("null" );
12291243 }
1244+ buffer .append (";\r \n " );
12301245 }
1231- buffer .append (";\r \n " );
12321246 }
12331247 }
12341248 }
1235- }
12361249
12371250 List constants = node .enumConstants ();
12381251 for (int i = 0 ; i < constants .size (); i ++) {
@@ -1248,18 +1261,31 @@ public void endVisit(EnumDeclaration node) {
12481261 buffer .append ("\" , " + i + ", [" );
12491262 visitList (enumConst .arguments (), ", " );
12501263 buffer .append ("]);\r \n " );
1251-
12521264 } else {
1253- ITypeBinding binding = node .resolveBinding ();
1265+ ITypeBinding binding = anonDeclare .resolveBinding ();
12541266 String anonClassName = null ;
12551267 if (binding .isAnonymous () || binding .isLocal ()) {
12561268 anonClassName = assureQualifiedName (shortenQualifiedName (binding .getBinaryName ()));
12571269 } else {
12581270 anonClassName = assureQualifiedName (shortenQualifiedName (binding .getQualifiedName ()));
12591271 }
12601272 //int anonCount = ((ASTTypeVisitor) getAdaptable(ASTTypeVisitor.class)).getAnonymousCount() + 1;
1273+
1274+ StringBuffer tmpBuffer = buffer ;
1275+ StringBuffer tmpMethodBuffer = methodBuffer ;
1276+ buffer = new StringBuffer ();
1277+ methodBuffer = new StringBuffer ();
12611278 anonDeclare .accept (this );
1262-
1279+
1280+ tmpBuffer .append (methodBuffer );
1281+
1282+ tmpBuffer .append (buffer );
1283+ tmpBuffer .append (";\r \n " );
1284+
1285+ buffer = tmpBuffer ;
1286+ methodBuffer = tmpMethodBuffer ;
1287+
1288+
12631289 buffer .append ("Clazz.defineEnumConstant (" );
12641290 /* replace full class name with short variable name */
12651291 buffer .append ("cla$$" );
@@ -1273,7 +1299,6 @@ public void endVisit(EnumDeclaration node) {
12731299// buffer.append("$" + anonCount + ");\r\n");
12741300 buffer .append (anonClassName );
12751301 buffer .append (");\r \n " );
1276-
12771302 }
12781303 }
12791304
0 commit comments