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

changeset 1313
873ddd9f4900
parent 1297
e5cf1569d3a4
child 1341
db36841709e4
equal deleted inserted replaced
1310:542c87b8ce7f 1313:873ddd9f4900
660 // ... but ... 660 // ... but ...
661 // There's a problem with evaluating annotations in the right order, such that 661 // There's a problem with evaluating annotations in the right order, such that
662 // env.info.enclVar.attributes_field might not yet have been evaluated, and so might be 662 // env.info.enclVar.attributes_field might not yet have been evaluated, and so might be
663 // null. In that case, calling augment will throw an NPE. To avoid this, for now we 663 // null. In that case, calling augment will throw an NPE. To avoid this, for now we
664 // revert to the jdk 6 behavior and ignore the (unevaluated) attributes. 664 // revert to the jdk 6 behavior and ignore the (unevaluated) attributes.
665 if (env.info.enclVar.attributes_field == null) 665 if (env.info.enclVar.annotations.pendingCompletion()) {
666 env.info.lint = lintEnv.info.lint; 666 env.info.lint = lintEnv.info.lint;
667 else 667 } else {
668 env.info.lint = lintEnv.info.lint.augment(env.info.enclVar.attributes_field, env.info.enclVar.flags()); 668 env.info.lint = lintEnv.info.lint.augment(env.info.enclVar.annotations,
669 env.info.enclVar.flags());
670 }
669 671
670 Lint prevLint = chk.setLint(env.info.lint); 672 Lint prevLint = chk.setLint(env.info.lint);
671 JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile); 673 JavaFileObject prevSource = log.useSource(env.toplevel.sourcefile);
672 674
673 try { 675 try {
774 } 776 }
775 777
776 public void visitMethodDef(JCMethodDecl tree) { 778 public void visitMethodDef(JCMethodDecl tree) {
777 MethodSymbol m = tree.sym; 779 MethodSymbol m = tree.sym;
778 780
779 Lint lint = env.info.lint.augment(m.attributes_field, m.flags()); 781 Lint lint = env.info.lint.augment(m.annotations, m.flags());
780 Lint prevLint = chk.setLint(lint); 782 Lint prevLint = chk.setLint(lint);
781 MethodSymbol prevMethod = chk.setMethod(m); 783 MethodSymbol prevMethod = chk.setMethod(m);
782 try { 784 try {
783 deferredLintHandler.flush(tree.pos()); 785 deferredLintHandler.flush(tree.pos());
784 chk.checkDeprecatedAnnotation(tree.pos(), m); 786 chk.checkDeprecatedAnnotation(tree.pos(), m);
919 annotate.flush(); 921 annotate.flush();
920 } 922 }
921 } 923 }
922 924
923 VarSymbol v = tree.sym; 925 VarSymbol v = tree.sym;
924 Lint lint = env.info.lint.augment(v.attributes_field, v.flags()); 926 Lint lint = env.info.lint.augment(v.annotations, v.flags());
925 Lint prevLint = chk.setLint(lint); 927 Lint prevLint = chk.setLint(lint);
926 928
927 // Check that the variable's declared type is well-formed. 929 // Check that the variable's declared type is well-formed.
928 chk.validate(tree.vartype, env); 930 chk.validate(tree.vartype, env);
929 deferredLintHandler.flush(tree.pos()); 931 deferredLintHandler.flush(tree.pos());
3067 Env<AttrContext> lintEnv = env; 3069 Env<AttrContext> lintEnv = env;
3068 while (lintEnv.info.lint == null) 3070 while (lintEnv.info.lint == null)
3069 lintEnv = lintEnv.next; 3071 lintEnv = lintEnv.next;
3070 3072
3071 // Having found the enclosing lint value, we can initialize the lint value for this class 3073 // Having found the enclosing lint value, we can initialize the lint value for this class
3072 env.info.lint = lintEnv.info.lint.augment(c.attributes_field, c.flags()); 3074 env.info.lint = lintEnv.info.lint.augment(c.annotations, c.flags());
3073 3075
3074 Lint prevLint = chk.setLint(env.info.lint); 3076 Lint prevLint = chk.setLint(env.info.lint);
3075 JavaFileObject prev = log.useSource(c.sourcefile); 3077 JavaFileObject prev = log.useSource(c.sourcefile);
3076 3078
3077 try { 3079 try {
3131 log.error(tree.implementing.head.pos(), 3133 log.error(tree.implementing.head.pos(),
3132 "cant.extend.intf.annotation"); 3134 "cant.extend.intf.annotation");
3133 if (tree.typarams.nonEmpty()) 3135 if (tree.typarams.nonEmpty())
3134 log.error(tree.typarams.head.pos(), 3136 log.error(tree.typarams.head.pos(),
3135 "intf.annotation.cant.have.type.params"); 3137 "intf.annotation.cant.have.type.params");
3138
3139 // If this annotation has a @ContainedBy, validate
3140 Attribute.Compound containedBy = c.attribute(syms.containedByType.tsym);
3141 if (containedBy != null) {
3142 // get diagnositc position for error reporting
3143 DiagnosticPosition cbPos = getDiagnosticPosition(tree, containedBy.type);
3144 Assert.checkNonNull(cbPos);
3145
3146 chk.validateContainedBy(c, containedBy, cbPos);
3147 }
3148
3149 // If this annotation has a @ContainerFor, validate
3150 Attribute.Compound containerFor = c.attribute(syms.containerForType.tsym);
3151 if (containerFor != null) {
3152 // get diagnositc position for error reporting
3153 DiagnosticPosition cfPos = getDiagnosticPosition(tree, containerFor.type);
3154 Assert.checkNonNull(cfPos);
3155
3156 chk.validateContainerFor(c, containerFor, cfPos);
3157 }
3136 } else { 3158 } else {
3137 // Check that all extended classes and interfaces 3159 // Check that all extended classes and interfaces
3138 // are compatible (i.e. no two define methods with same arguments 3160 // are compatible (i.e. no two define methods with same arguments
3139 // yet different return types). (JLS 8.4.6.3) 3161 // yet different return types). (JLS 8.4.6.3)
3140 chk.checkCompatibleSupertypes(tree.pos(), c.type); 3162 chk.checkCompatibleSupertypes(tree.pos(), c.type);
3192 (c.flags() & ABSTRACT) == 0) { 3214 (c.flags() & ABSTRACT) == 0) {
3193 checkSerialVersionUID(tree, c); 3215 checkSerialVersionUID(tree, c);
3194 } 3216 }
3195 } 3217 }
3196 // where 3218 // where
3219 /** get a diagnostic position for an attribute of Type t, or null if attribute missing */
3220 private DiagnosticPosition getDiagnosticPosition(JCClassDecl tree, Type t) {
3221 for(List<JCAnnotation> al = tree.mods.annotations; !al.isEmpty(); al = al.tail) {
3222 if (types.isSameType(al.head.annotationType.type, t))
3223 return al.head.pos();
3224 }
3225
3226 return null;
3227 }
3228
3197 /** check if a class is a subtype of Serializable, if that is available. */ 3229 /** check if a class is a subtype of Serializable, if that is available. */
3198 private boolean isSerializable(ClassSymbol c) { 3230 private boolean isSerializable(ClassSymbol c) {
3199 try { 3231 try {
3200 syms.serializableType.complete(); 3232 syms.serializableType.complete();
3201 } 3233 }

mercurial