< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TypeEnter.java

Print this page
*** 39,10 ***
--- 39,11 ---
  import com.sun.tools.javac.code.Scope.NamedImportScope;
  import com.sun.tools.javac.code.Scope.StarImportScope;
  import com.sun.tools.javac.code.Scope.WriteableScope;
  import com.sun.tools.javac.code.Source.Feature;
  import com.sun.tools.javac.comp.Annotate.AnnotationTypeMetadata;
+ import com.sun.tools.javac.jvm.Target;
  import com.sun.tools.javac.tree.*;
  import com.sun.tools.javac.util.*;
  import com.sun.tools.javac.util.DefinedBy.Api;
  
  import com.sun.tools.javac.code.Symbol.*;

*** 50,10 ***
--- 51,11 ---
  import com.sun.tools.javac.resources.CompilerProperties.Errors;
  import com.sun.tools.javac.tree.JCTree.*;
  
  import static com.sun.tools.javac.code.Flags.*;
  import static com.sun.tools.javac.code.Flags.ANNOTATION;
+ import static com.sun.tools.javac.code.Flags.SYNCHRONIZED;
  import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE;
  import static com.sun.tools.javac.code.Kinds.Kind.*;
  import static com.sun.tools.javac.code.TypeTag.CLASS;
  import static com.sun.tools.javac.code.TypeTag.ERROR;
  import com.sun.tools.javac.resources.CompilerProperties.Fragments;

*** 1107,12 ***
--- 1109,67 ---
              }
              if (tree.sym.isAnnotationType()) {
                  Assert.check(tree.sym.isCompleted());
                  tree.sym.setAnnotationTypeMetadata(new AnnotationTypeMetadata(tree.sym, annotate.annotationTypeSourceCompleter()));
              }
+ 
+             if (tree.sym != syms.objectType.tsym && tree.sym != syms.recordType.tsym) {
+                 if ((tree.sym.flags() & (ABSTRACT | INTERFACE | VALUE_CLASS)) == 0) {
+                     tree.sym.flags_field |= IDENTITY_TYPE;
+                 }
+                 if ((tree.sym.flags() & (ABSTRACT | IDENTITY_TYPE | INTERFACE)) == ABSTRACT) {
+                     if (abstractClassHasImplicitIdentity(tree)) {
+                         tree.sym.flags_field |= IDENTITY_TYPE;
+                     }
+                 }
+             }
          }
  
+             // where
+             private boolean abstractClassHasImplicitIdentity(JCClassDecl tree) {
+ 
+                 Type t = tree.sym.type;
+ 
+                 if (t == null || t.tsym == null || t.tsym.kind == ERR)
+                     return false;
+ 
+                 if ((t.tsym.flags() & HASINITBLOCK) != 0) {
+                     return true;
+                 }
+ 
+                 // No instance fields and no arged constructors both mean inner classes cannot be value class supers.
+                 Type encl = t.getEnclosingType();
+                 if (encl != null && encl.hasTag(CLASS)) {
+                     return true;
+                 }
+                 for (Symbol s : t.tsym.members().getSymbols(NON_RECURSIVE)) {
+                     switch (s.kind) {
+                         case VAR:
+                             if ((s.flags() & STATIC) == 0) {
+                                 return true;
+                             }
+                             break;
+                         case MTH:
+                             if ((s.flags() & (SYNCHRONIZED | STATIC)) == SYNCHRONIZED) {
+                                 return true;
+                             } else if (s.isInitOrVNew()) {
+                                 MethodSymbol m = (MethodSymbol)s;
+                                 if (m.getParameters().size() > 0
+                                         || m.getTypeParameters().size() > 0
+                                         || m.type.getThrownTypes().nonEmpty()
+                                         || (m.flags() & EMPTYNOARGCONSTR) == 0
+                                         || (Check.protection(m.flags()) > Check.protection(m.owner.flags()))) {
+                                     return true;
+                                 }
+                             }
+                             break;
+                     }
+                 }
+                 return false;
+             }
+ 
+ 
          private void addAccessor(JCVariableDecl tree, Env<AttrContext> env) {
              MethodSymbol implSym = lookupMethod(env.enclClass.sym, tree.sym.name, List.nil());
              RecordComponent rec = ((ClassSymbol) tree.sym.owner).getRecordComponent(tree.sym);
              if (implSym == null || (implSym.flags_field & GENERATED_MEMBER) != 0) {
                  /* here we are pushing the annotations present in the corresponding field down to the accessor

*** 1302,11 ***
                      // constructors of true enums are private
                      flags = PRIVATE | GENERATEDCONSTR;
                  } else {
                      flags = (owner().flags() & AccessFlags) | GENERATEDCONSTR;
                  }
!                 constructorSymbol = new MethodSymbol(flags, names.init,
                      constructorType(), owner());
              }
              return constructorSymbol;
          }
  
--- 1359,12 ---
                      // constructors of true enums are private
                      flags = PRIVATE | GENERATEDCONSTR;
                  } else {
                      flags = (owner().flags() & AccessFlags) | GENERATEDCONSTR;
                  }
!                 Name constructorName = owner().isConcreteValueClass() ? names.vnew : names.init;
+                 constructorSymbol = new MethodSymbol(flags, constructorName,
                      constructorType(), owner());
              }
              return constructorSymbol;
          }
  
< prev index next >