< prev index next >

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

Print this page
@@ -50,10 +50,11 @@
  import javax.lang.model.element.VariableElement;
  import javax.tools.JavaFileManager;
  import javax.tools.JavaFileObject;
  
  import com.sun.tools.javac.code.Kinds.Kind;
+ import com.sun.tools.javac.code.Type.ClassType.Flavor;
  import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata;
  import com.sun.tools.javac.code.Type.*;
  import com.sun.tools.javac.comp.Attr;
  import com.sun.tools.javac.comp.AttrContext;
  import com.sun.tools.javac.comp.Env;

@@ -354,11 +355,11 @@
       *  except for constructors of inner classes which get the enclosing
       *  instance class added as first argument.
       */
      public Type externalType(Types types) {
          Type t = erasure(types);
-         if (name == name.table.names.init && owner.hasOuterInstance()) {
+         if (isInitOrVNew() && owner.hasOuterInstance()) {
              Type outerThisType = types.erasure(owner.type.getEnclosingType());
              return new MethodType(t.getParameterTypes().prepend(outerThisType),
                                    t.getReturnType(),
                                    t.getThrownTypes(),
                                    t.tsym);

@@ -413,10 +414,34 @@
  
      public boolean isPrivate() {
          return (flags_field & Flags.AccessFlags) == PRIVATE;
      }
  
+     public boolean isPrimitiveClass() {
+         return (flags() & PRIMITIVE_CLASS) != 0;
+     }
+ 
+     public boolean isValueClass() {
+         return !isInterface() && (flags() & VALUE_CLASS) != 0;
+     }
+ 
+     public boolean isConcreteValueClass() {
+         return isValueClass() && !isAbstract();
+     }
+ 
+     public boolean isIdentityClass() {
+         return !isInterface() && (flags() & IDENTITY_TYPE) != 0;
+     }
+ 
+     public boolean isValueInterface() {
+         return isInterface() && (flags() & VALUE_CLASS) != 0;
+     }
+ 
+     public boolean isIdentityInterface() {
+         return isInterface() && (flags() & IDENTITY_TYPE) != 0;
+     }
+ 
      public boolean isPublic() {
          return (flags_field & Flags.AccessFlags) == PUBLIC;
      }
  
      public boolean isEnum() {

@@ -454,11 +479,23 @@
      }
  
      /** Is this symbol a constructor?
       */
      public boolean isConstructor() {
-         return name == name.table.names.init;
+         return name == name.table.names.init && (flags() & STATIC) == 0;
+     }
+ 
+     /** Is this symbol a value object factory?
+      */
+     public boolean isValueObjectFactory() {
+         return name == name.table.names.vnew && this.type.getReturnType().tsym == this.owner;
+     }
+ 
+     /** Is this symbol a constructor or value factory?
+      */
+     public boolean isInitOrVNew() {
+         return name.table.names.isInitOrVNew(name);
      }
  
      public boolean isDynamic() {
          return false;
      }

@@ -1316,11 +1353,11 @@
  
          public ClassSymbol(long flags, Name name, Symbol owner) {
              this(
                  flags,
                  name,
-                 new ClassType(Type.noType, null, null),
+                 new ClassType(Type.noType, null, null, List.nil(), Flavor.X_Typeof_X),
                  owner);
              this.type.tsym = this;
          }
  
          /** The Java source which this symbol represents.

@@ -1353,11 +1390,12 @@
  
          public Type erasure(Types types) {
              if (erasure_field == null)
                  erasure_field = new ClassType(types.erasure(type.getEnclosingType()),
                                                List.nil(), this,
-                                               type.getMetadata());
+                                               type.getMetadata(),
+                                               type.getFlavor());
              return erasure_field;
          }
  
          public String className() {
              if (name.isEmpty())

@@ -1414,10 +1452,18 @@
                  ex.dcfh.classSymbolCompleteFailed(this, origCompleter);
                  // quiet error recovery
                  flags_field |= (PUBLIC|STATIC);
                  this.type = new ErrorType(this, Type.noType);
                  throw ex;
+             } finally {
+                 if (this.type != null && this.type.hasTag(CLASS)) {
+                     ClassType ct = (ClassType) this.type;
+                     ct.flavor = ct.flavor.metamorphose((this.flags_field & PRIMITIVE_CLASS) != 0);
+                     if (!this.type.isIntersection() && this.erasure_field != null && this.erasure_field.hasTag(CLASS)) {
+                         ((ClassType) this.erasure_field).flavor = ct.flavor;
+                     }
+                 }
              }
          }
  
          @DefinedBy(Api.LANGUAGE_MODEL)
          public List<Type> getInterfaces() {

@@ -1601,10 +1647,11 @@
                  classType.typarams_field = null;
                  classType.allparams_field = null;
                  classType.supertype_field = null;
                  classType.interfaces_field = null;
                  classType.all_interfaces_field = null;
+                 classType.flavor = Flavor.X_Typeof_X;
              }
              clearAnnotationMetadata();
          }
  
          public void clearAnnotationMetadata() {

@@ -1954,11 +2001,11 @@
           */
          public String toString() {
              if ((flags() & BLOCK) != 0) {
                  return owner.name.toString();
              } else {
-                 String s = (name == name.table.names.init)
+                 String s = isInitOrVNew()
                      ? owner.name.toString()
                      : name.toString();
                  if (type != null) {
                      if (type.hasTag(FORALL))
                          s = "<" + ((ForAll)type).getTypeArguments() + ">" + s;

@@ -2016,18 +2063,18 @@
  
          /** Will the erasure of this method be considered by the VM to
           *  override the erasure of the other when seen from class `origin'?
           */
          public boolean binaryOverrides(Symbol _other, TypeSymbol origin, Types types) {
-             if (isConstructor() || _other.kind != MTH) return false;
+             if (isInitOrVNew() || _other.kind != MTH) return false;
  
              if (this == _other) return true;
              MethodSymbol other = (MethodSymbol)_other;
  
              // check for a direct implementation
              if (other.isOverridableIn((TypeSymbol)owner) &&
-                 types.asSuper(owner.type, other.owner) != null &&
+                 types.asSuper(owner.type.referenceProjectionOrSelf(), other.owner) != null &&
                  types.isSameType(erasure(types), other.erasure(types)))
                  return true;
  
              // check for an inherited implementation
              return

@@ -2085,18 +2132,18 @@
           *
           *  See JLS 8.4.8.1 (without transitivity) and 8.4.8.4
           */
          public boolean overrides(Symbol _other, TypeSymbol origin, Types types, boolean checkResult,
                                              boolean requireConcreteIfInherited) {
-             if (isConstructor() || _other.kind != MTH) return false;
+             if (isInitOrVNew() || _other.kind != MTH) return false;
  
              if (this == _other) return true;
              MethodSymbol other = (MethodSymbol)_other;
  
              // check for a direct implementation
              if (other.isOverridableIn((TypeSymbol)owner) &&
-                 types.asSuper(owner.type, other.owner) != null) {
+                 types.asSuper(owner.type.referenceProjectionOrSelf(), other.owner) != null) {
                  Type mt = types.memberType(owner.type, this);
                  Type ot = types.memberType(owner.type, other);
                  if (types.isSubSignature(mt, ot)) {
                      if (!checkResult)
                          return true;

@@ -2209,11 +2256,11 @@
              return new MethodSymbol(flags_field, name, types.memberType(site, this), owner);
          }
  
          @DefinedBy(Api.LANGUAGE_MODEL)
          public ElementKind getKind() {
-             if (name == name.table.names.init)
+             if (isInitOrVNew())
                  return ElementKind.CONSTRUCTOR;
              else if (name == name.table.names.clinit)
                  return ElementKind.STATIC_INIT;
              else if ((flags() & BLOCK) != 0)
                  return isStatic() ? ElementKind.STATIC_INIT : ElementKind.INSTANCE_INIT;

@@ -2382,11 +2429,11 @@
              if (refSym.kind == VAR) {
                  return getter ?
                          refSym.isStatic() ? ClassFile.REF_getStatic : ClassFile.REF_getField :
                          refSym.isStatic() ? ClassFile.REF_putStatic : ClassFile.REF_putField;
              } else {
-                 if (refSym.isConstructor()) {
+                 if (refSym.isInitOrVNew()) {
                      return ClassFile.REF_newInvokeSpecial;
                  } else {
                      if (refSym.isStatic()) {
                          return ClassFile.REF_invokeStatic;
                      } else if ((refSym.flags() & PRIVATE) != 0 && !allowPrivateInvokeVirtual()) {
< prev index next >