import eclipse 3.1 M4 compiler
[org.ibex.tool.git] / src / org / eclipse / jdt / internal / compiler / ast / ClassLiteralAccess.java
index 4a4136e..4e35315 100644 (file)
@@ -11,6 +11,7 @@
 package org.eclipse.jdt.internal.compiler.ast;
 
 import org.eclipse.jdt.internal.compiler.ASTVisitor;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
 import org.eclipse.jdt.internal.compiler.codegen.*;
 import org.eclipse.jdt.internal.compiler.flow.*;
 import org.eclipse.jdt.internal.compiler.lookup.*;
@@ -35,10 +36,11 @@ public class ClassLiteralAccess extends Expression {
                // if reachable, request the addition of a synthetic field for caching the class descriptor
                SourceTypeBinding sourceType =
                        currentScope.outerMostMethodScope().enclosingSourceType();
-               if (!(sourceType.isInterface()
-                       // no field generated in interface case (would'nt verify) see 1FHHEZL
-                       || sourceType.isBaseType())) {
-                       syntheticField = sourceType.addSyntheticField(targetType, currentScope);
+               if ((!(sourceType.isInterface()
+                               // no field generated in interface case (would'nt verify) see 1FHHEZL
+                               || sourceType.isBaseType()))
+                               && currentScope.environment().options.sourceLevel <= ClassFileConstants.JDK1_5) {
+                       syntheticField = sourceType.addSyntheticFieldForClassLiteral(targetType, currentScope);
                }
                return flowInfo;
        }
@@ -57,8 +59,10 @@ public class ClassLiteralAccess extends Expression {
                int pc = codeStream.position;
 
                // in interface case, no caching occurs, since cannot make a cache field for interface
-               if (valueRequired)
+               if (valueRequired) {
                        codeStream.generateClassLiteralAccessForType(type.resolvedType, syntheticField);
+                       codeStream.generateImplicitConversion(this.implicitConversion);
+               }
                codeStream.recordPositionsFrom(pc, this.sourceStart);
        }
 
@@ -70,16 +74,24 @@ public class ClassLiteralAccess extends Expression {
        public TypeBinding resolveType(BlockScope scope) {
 
                constant = NotAConstant;
-               if ((targetType = type.resolveType(scope)) == null)
+               if ((targetType = type.resolveType(scope, true /* check bounds*/)) == null)
                        return null;
 
                if (targetType.isArrayType()
                        && ((ArrayBinding) targetType).leafComponentType == VoidBinding) {
                        scope.problemReporter().cannotAllocateVoidArray(this);
                        return null;
+               } else if (targetType.isTypeVariable()) {
+                       scope.problemReporter().illegalClassLiteralForTypeVariable((TypeVariableBinding)targetType, this);
                }
-
-               return this.resolvedType = scope.getJavaLangClass();
+               ReferenceBinding classType = scope.getJavaLangClass();
+               if (classType.isGenericType()) {
+                   // Integer.class --> Class<Integer>, perform boxing of base types (int.class --> Class<Integer>)
+                   this.resolvedType = scope.createParameterizedType(classType, new TypeBinding[]{ scope.boxing(targetType) }, null/*not a member*/);
+               } else {
+                   this.resolvedType = classType;
+               }
+               return this.resolvedType;
        }
 
        public void traverse(