< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java

Print this page
*** 50,10 ***
--- 50,11 ---
  import com.sun.tools.javac.code.Type.ErrorType;
  import com.sun.tools.javac.code.Type.JCPrimitiveType;
  import com.sun.tools.javac.code.Type.JCVoidType;
  import com.sun.tools.javac.code.Type.MethodType;
  import com.sun.tools.javac.code.Type.UnknownType;
+ import com.sun.tools.javac.code.Type.WildcardType;
  import com.sun.tools.javac.code.Types.UniqueType;
  import com.sun.tools.javac.comp.Modules;
  import com.sun.tools.javac.jvm.Target;
  import com.sun.tools.javac.util.Assert;
  import com.sun.tools.javac.util.Context;

*** 63,10 ***
--- 64,11 ---
  import com.sun.tools.javac.util.Iterators;
  import com.sun.tools.javac.util.JavacMessages;
  import com.sun.tools.javac.util.List;
  import com.sun.tools.javac.util.Name;
  import com.sun.tools.javac.util.Names;
+ import com.sun.tools.javac.util.Options;
  
  import static com.sun.tools.javac.code.Flags.*;
  import static com.sun.tools.javac.code.Kinds.Kind.*;
  import static com.sun.tools.javac.code.TypeTag.*;
  

*** 91,10 ***
--- 93,12 ---
          if (instance == null)
              instance = new Symtab(context);
          return instance;
      }
  
+     private final boolean allowPrimitiveClasses;
+ 
      /** Builtin types.
       */
      public final JCPrimitiveType byteType = new JCPrimitiveType(BYTE, null);
      public final JCPrimitiveType charType = new JCPrimitiveType(CHAR, null);
      public final JCPrimitiveType shortType = new JCPrimitiveType(SHORT, null);

*** 285,12 ***
  
      public VarSymbol getClassField(Type type, Types types) {
          return classFields.computeIfAbsent(
              new UniqueType(type, types), k -> {
                  Type arg = null;
!                 if (type.getTag() == ARRAY || type.getTag() == CLASS)
!                     arg = types.erasure(type);
                  else if (type.isPrimitiveOrVoid())
                      arg = types.boxedClass(type).type;
                  else
                      throw new AssertionError(type);
  
--- 289,21 ---
  
      public VarSymbol getClassField(Type type, Types types) {
          return classFields.computeIfAbsent(
              new UniqueType(type, types), k -> {
                  Type arg = null;
!                 if (type.getTag() == ARRAY || type.getTag() == CLASS) {
!                     /* Temporary treatment for primitive class: Given a primitive class V that implements
+                        I1, I2, ... In, V.class is typed to be Class<? extends Object & I1 & I2 .. & In>
+                     */
+                     if (allowPrimitiveClasses && type.isPrimitiveClass()) {
+                         List<Type> bounds = List.of(objectType).appendList(((ClassSymbol) type.tsym).getInterfaces());
+                         arg = new WildcardType(bounds.size() > 1 ? types.makeIntersectionType(bounds) : objectType, BoundKind.EXTENDS, boundClass);
+                     } else {
+                         arg = types.erasure(type);
+                     }
+                 }
                  else if (type.isPrimitiveOrVoid())
                      arg = types.boxedClass(type).type;
                  else
                      throw new AssertionError(type);
  

*** 675,11 ***
              arrayClass);
          arrayClass.members().enter(arrayCloneMethod);
  
          if (java_base != noModule)
              java_base.completer = moduleCompleter::complete; //bootstrap issues
! 
      }
  
      /** Define a new class given its name and owner.
       */
      public ClassSymbol defineClass(Name name, Symbol owner) {
--- 688,12 ---
              arrayClass);
          arrayClass.members().enter(arrayCloneMethod);
  
          if (java_base != noModule)
              java_base.completer = moduleCompleter::complete; //bootstrap issues
!         Options options = Options.instance(context);
+         allowPrimitiveClasses = Feature.PRIMITIVE_CLASSES.allowedInSource(source) && options.isSet("enablePrimitiveClasses");
      }
  
      /** Define a new class given its name and owner.
       */
      public ClassSymbol defineClass(Name name, Symbol owner) {
< prev index next >