@@ -451,6 +451,20 @@ public boolean visit(AnonymousClassDeclaration node) {
451
451
}
452
452
453
453
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
+ }
454
468
Type type = node .getType ();
455
469
/*
456
470
* TODO: some casting should have its meaning!
@@ -1197,42 +1211,41 @@ public void endVisit(EnumDeclaration node) {
1197
1211
ASTNode element = (ASTNode ) iter .next ();
1198
1212
if (element instanceof Initializer ) {
1199
1213
element .accept (this );
1200
-
1201
1214
} else if (element instanceof FieldDeclaration ) {
1202
1215
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
+ }
1224
1240
} else {
1225
- buffer .append ("0 " );
1241
+ buffer .append ("null " );
1226
1242
}
1227
- } else {
1228
- buffer .append ("null" );
1229
1243
}
1244
+ buffer .append (";\r \n " );
1230
1245
}
1231
- buffer .append (";\r \n " );
1232
1246
}
1233
1247
}
1234
1248
}
1235
- }
1236
1249
1237
1250
List constants = node .enumConstants ();
1238
1251
for (int i = 0 ; i < constants .size (); i ++) {
@@ -1248,18 +1261,31 @@ public void endVisit(EnumDeclaration node) {
1248
1261
buffer .append ("\" , " + i + ", [" );
1249
1262
visitList (enumConst .arguments (), ", " );
1250
1263
buffer .append ("]);\r \n " );
1251
-
1252
1264
} else {
1253
- ITypeBinding binding = node .resolveBinding ();
1265
+ ITypeBinding binding = anonDeclare .resolveBinding ();
1254
1266
String anonClassName = null ;
1255
1267
if (binding .isAnonymous () || binding .isLocal ()) {
1256
1268
anonClassName = assureQualifiedName (shortenQualifiedName (binding .getBinaryName ()));
1257
1269
} else {
1258
1270
anonClassName = assureQualifiedName (shortenQualifiedName (binding .getQualifiedName ()));
1259
1271
}
1260
1272
//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 ();
1261
1278
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
+
1263
1289
buffer .append ("Clazz.defineEnumConstant (" );
1264
1290
/* replace full class name with short variable name */
1265
1291
buffer .append ("cla$$" );
@@ -1273,7 +1299,6 @@ public void endVisit(EnumDeclaration node) {
1273
1299
// buffer.append("$" + anonCount + ");\r\n");
1274
1300
buffer .append (anonClassName );
1275
1301
buffer .append (");\r \n " );
1276
-
1277
1302
}
1278
1303
}
1279
1304
0 commit comments