src/share/classes/com/sun/tools/javac/comp/MemberEnter.java

changeset 308
03944ee4fac4
parent 113
eff38cc97183
child 344
6d0add6ad778
equal deleted inserted replaced
307:ca063536e4a6 308:03944ee4fac4
97 todo = Todo.instance(context); 97 todo = Todo.instance(context);
98 annotate = Annotate.instance(context); 98 annotate = Annotate.instance(context);
99 types = Types.instance(context); 99 types = Types.instance(context);
100 diags = JCDiagnostic.Factory.instance(context); 100 diags = JCDiagnostic.Factory.instance(context);
101 target = Target.instance(context); 101 target = Target.instance(context);
102 skipAnnotations = 102 Options options = Options.instance(context);
103 Options.instance(context).get("skipAnnotations") != null; 103 skipAnnotations = options.get("skipAnnotations") != null;
104 } 104 }
105 105
106 /** A queue for classes whose members still need to be entered into the 106 /** A queue for classes whose members still need to be entered into the
107 * symbol table. 107 * symbol table.
108 */ 108 */
904 // @Deprecated annotation is present. 904 // @Deprecated annotation is present.
905 attr.attribAnnotationTypes(tree.mods.annotations, baseEnv); 905 attr.attribAnnotationTypes(tree.mods.annotations, baseEnv);
906 if (hasDeprecatedAnnotation(tree.mods.annotations)) 906 if (hasDeprecatedAnnotation(tree.mods.annotations))
907 c.flags_field |= DEPRECATED; 907 c.flags_field |= DEPRECATED;
908 annotateLater(tree.mods.annotations, baseEnv, c); 908 annotateLater(tree.mods.annotations, baseEnv, c);
909 // class type parameters use baseEnv but everything uses env
910 for (JCTypeParameter tp : tree.typarams)
911 tp.accept(new TypeAnnotate(baseEnv));
912 tree.accept(new TypeAnnotate(env));
909 913
910 chk.checkNonCyclic(tree.pos(), c.type); 914 chk.checkNonCyclic(tree.pos(), c.type);
911 915
912 attr.attribTypeVariables(tree.typarams, baseEnv); 916 attr.attribTypeVariables(tree.typarams, baseEnv);
913 917
985 989
986 // commit pending annotations 990 // commit pending annotations
987 annotate.flush(); 991 annotate.flush();
988 } 992 }
989 } 993 }
994
995 // A sub-phase that "compiles" annotations in annotated types.
996 private class TypeAnnotate extends TreeScanner {
997 private Env<AttrContext> env;
998 public TypeAnnotate(Env<AttrContext> env) { this.env = env; }
999
1000 private void enterTypeAnnotations(List<JCTypeAnnotation> annotations) {
1001 Set<TypeSymbol> annotated = new HashSet<TypeSymbol>();
1002 if (!skipAnnotations)
1003 for (List<JCTypeAnnotation> al = annotations; al.nonEmpty(); al = al.tail) {
1004 JCTypeAnnotation a = al.head;
1005 Attribute.Compound c = annotate.enterAnnotation(a,
1006 syms.annotationType,
1007 env);
1008 if (c == null) continue;
1009 Attribute.TypeCompound tc = new Attribute.TypeCompound(c.type, c.values, a.annotation_position);
1010 a.attribute_field = tc;
1011 // Note: @Deprecated has no effect on local variables and parameters
1012 if (!annotated.add(a.type.tsym))
1013 log.error(a.pos, "duplicate.annotation");
1014 }
1015 }
1016
1017 // each class (including enclosed inner classes) should be visited
1018 // separately through MemberEnter.complete(Symbol)
1019 // this flag is used to prevent from visiting inner classes.
1020 private boolean isEnclosingClass = false;
1021 @Override
1022 public void visitClassDef(final JCClassDecl tree) {
1023 if (isEnclosingClass)
1024 return;
1025 isEnclosingClass = true;
1026 scan(tree.mods);
1027 // type parameter need to be visited with a separate env
1028 // scan(tree.typarams);
1029 scan(tree.extending);
1030 scan(tree.implementing);
1031 scan(tree.defs);
1032 }
1033
1034 private void annotate(final JCTree tree, final List<JCTypeAnnotation> annotations) {
1035 annotate.later(new Annotate.Annotator() {
1036 public String toString() {
1037 return "annotate " + annotations + " onto " + tree;
1038 }
1039 public void enterAnnotation() {
1040 JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
1041 try {
1042 enterTypeAnnotations(annotations);
1043
1044 // enrich type parameter symbols... easier for annotation processors
1045 if (tree instanceof JCTypeParameter) {
1046 JCTypeParameter typeparam = (JCTypeParameter)tree;
1047 ListBuffer<Attribute.Compound> buf = ListBuffer.lb();
1048 for (JCTypeAnnotation anno : annotations)
1049 buf.add(anno.attribute_field);
1050 typeparam.type.tsym.attributes_field = buf.toList();
1051 }
1052 } finally {
1053 log.useSource(prev);
1054 }
1055 }
1056 });
1057 }
1058
1059 @Override
1060 public void visitAnnotatedType(final JCAnnotatedType tree) {
1061 annotate(tree, tree.annotations);
1062 super.visitAnnotatedType(tree);
1063 }
1064 @Override
1065 public void visitTypeParameter(final JCTypeParameter tree) {
1066 annotate(tree, tree.annotations);
1067 super.visitTypeParameter(tree);
1068 }
1069 @Override
1070 public void visitNewArray(final JCNewArray tree) {
1071 annotate(tree, tree.annotations);
1072 for (List<JCTypeAnnotation> dimAnnos : tree.dimAnnotations)
1073 annotate(tree, dimAnnos);
1074 super.visitNewArray(tree);
1075 }
1076 @Override
1077 public void visitApply(JCMethodInvocation tree) {
1078 super.visitApply(tree);
1079 scan(tree.typeargs);
1080 }
1081 @Override
1082 public void visitMethodDef(JCMethodDecl tree) {
1083 annotate(tree, tree.receiverAnnotations);
1084 super.visitMethodDef(tree);
1085 }
1086 }
1087
990 1088
991 private Env<AttrContext> baseEnv(JCClassDecl tree, Env<AttrContext> env) { 1089 private Env<AttrContext> baseEnv(JCClassDecl tree, Env<AttrContext> env) {
992 Scope typaramScope = new Scope(tree.sym); 1090 Scope typaramScope = new Scope(tree.sym);
993 if (tree.typarams != null) 1091 if (tree.typarams != null)
994 for (List<JCTypeParameter> typarams = tree.typarams; 1092 for (List<JCTypeParameter> typarams = tree.typarams;

mercurial