--- old/src/share/classes/com/sun/tools/javac/code/Attribute.java 2014-05-09 16:27:50.672149826 -0400 +++ new/src/share/classes/com/sun/tools/javac/code/Attribute.java 2014-05-09 16:27:50.574145667 -0400 @@ -142,7 +142,7 @@ * access this attribute. */ public final List> values; - public TypeAnnotationPosition position; + public final TypeAnnotationPosition position; private boolean synthesized = false; @@ -170,53 +170,9 @@ @Override public TypeAnnotationPosition getPosition() { - if (hasUnknownPosition()) { - if (values.size() != 0) { - Name valueName = values.head.fst.name.table.names.value; - Pair res = getElemPair(valueName); - position = res == null ? null : res.snd.getPosition(); - } - } return position; } - public boolean isContainerTypeCompound() { - if (isSynthesized() && values.size() == 1) - return getFirstEmbeddedTC() != null; - return false; - } - - private Compound getFirstEmbeddedTC() { - if (values.size() == 1) { - Pair val = values.get(0); - if (val.fst.getSimpleName().contentEquals("value") - && val.snd instanceof Array) { - Array arr = (Array) val.snd; - if (arr.values.length != 0 - && arr.values[0] instanceof Attribute.TypeCompound) - return (Attribute.TypeCompound) arr.values[0]; - } - } - return null; - } - - public boolean tryFixPosition() { - if (!isContainerTypeCompound()) - return false; - - Compound from = getFirstEmbeddedTC(); - if (from != null && from.position != null && - from.position.type != TargetType.UNKNOWN) { - position = from.position; - return true; - } - return false; - } - - public boolean hasUnknownPosition() { - return position.type == TargetType.UNKNOWN; - } - public void accept(Visitor v) { v.visitCompound(this); } /** --- old/src/share/classes/com/sun/tools/javac/code/Symbol.java 2014-05-09 16:27:51.122168873 -0400 +++ new/src/share/classes/com/sun/tools/javac/code/Symbol.java 2014-05-09 16:27:51.021164586 -0400 @@ -45,7 +45,7 @@ import static com.sun.tools.javac.code.TypeTag.CLASS; import static com.sun.tools.javac.code.TypeTag.FORALL; import static com.sun.tools.javac.code.TypeTag.TYPEVAR; -import com.sun.tools.javac.tree.JCTree.JCVariableDecl; +import com.sun.tools.javac.tree.JCTree.*; /** Root class for Java symbols. It contains subclasses * for specific sorts of symbols, such as variables, methods and operators, @@ -206,6 +206,12 @@ } } + public void appendDeclarationAttributes(List a) { + if (metadata != null || a.nonEmpty()) { + initedMetadata().append(a); + } + } + public void setTypeAttributes(List a) { if (metadata != null || a.nonEmpty()) { if (metadata == null) @@ -1252,11 +1258,15 @@ public void setLazyConstValue(final Env env, final Attr attr, - final JCVariableDecl variable) + final JCVariableDecl variable, + final JCLambda currentLambda, + final boolean speculative) { setData(new Callable() { public Object call() { - return attr.attribLazyConstantValue(env, variable, type); + return attr.attribLazyConstantValue(env, variable, type, + currentLambda, + speculative); } }); } --- old/src/share/classes/com/sun/tools/javac/code/TargetType.java 2014-05-09 16:27:51.472183714 -0400 +++ new/src/share/classes/com/sun/tools/javac/code/TargetType.java 2014-05-09 16:27:51.375179598 -0400 @@ -107,10 +107,7 @@ CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT(0x4A, true), /** For annotations on a type argument of a method reference. */ - METHOD_REFERENCE_TYPE_ARGUMENT(0x4B, true), - - /** For annotations with an unknown target. */ - UNKNOWN(0xFF); + METHOD_REFERENCE_TYPE_ARGUMENT(0x4B, true); private static final int MAXIMUM_TARGET_TYPE_VALUE = 0x4B; @@ -150,26 +147,15 @@ targets = new TargetType[MAXIMUM_TARGET_TYPE_VALUE + 1]; TargetType[] alltargets = values(); for (TargetType target : alltargets) { - if (target.targetTypeValue != UNKNOWN.targetTypeValue) - targets[target.targetTypeValue] = target; - } - for (int i = 0; i <= MAXIMUM_TARGET_TYPE_VALUE; ++i) { - if (targets[i] == null) - targets[i] = UNKNOWN; + targets[target.targetTypeValue] = target; } } public static boolean isValidTargetTypeValue(int tag) { - if (tag == UNKNOWN.targetTypeValue) - return true; - return (tag >= 0 && tag < targets.length); } public static TargetType fromTargetTypeValue(int tag) { - if (tag == UNKNOWN.targetTypeValue) - return UNKNOWN; - if (tag < 0 || tag >= targets.length) Assert.error("Unknown TargetType: " + tag); return targets[tag]; --- old/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java 2014-05-09 16:27:51.790197205 -0400 +++ new/src/share/classes/com/sun/tools/javac/code/TypeAnnotationPosition.java 2014-05-09 16:27:51.690192965 -0400 @@ -259,9 +259,6 @@ case METHOD_RETURN: case FIELD: break; - case UNKNOWN: - sb.append(", position UNKNOWN!"); - break; default: Assert.error("Unknown target type: " + type); } @@ -428,7 +425,7 @@ } /** - * Create a {@code TypeAnnotationPosition} for a method receiver. + * Create a {@code TypeAnnotationPosition} for a method receiver parameter. * * @param location The type path. * @param onLambda The lambda for this parameter. @@ -445,7 +442,7 @@ } /** - * Create a {@code TypeAnnotationPosition} for a method receiver. + * Create a {@code TypeAnnotationPosition} for a method receiver parameter. * * @param location The type path. */ @@ -455,7 +452,7 @@ } /** - * Create a {@code TypeAnnotationPosition} for a method receiver. + * Create a {@code TypeAnnotationPosition} for a method receiver parameter. * * @param pos The position from the associated tree node. */ @@ -464,7 +461,8 @@ } /** - * Create a {@code TypeAnnotationPosition} for a method formal parameter. + * Create a {@code TypeAnnotationPosition} for a method formal + * parameter parameter. * * @param location The type path. * @param onLambda The lambda for this parameter. @@ -664,10 +662,11 @@ public static TypeAnnotationPosition exceptionParameter(final List location, final JCLambda onLambda, + final int type_index, final int pos) { return new TypeAnnotationPosition(TargetType.EXCEPTION_PARAMETER, pos, Integer.MIN_VALUE, onLambda, - Integer.MIN_VALUE, Integer.MIN_VALUE, + type_index, Integer.MIN_VALUE, location); } @@ -680,7 +679,7 @@ public static TypeAnnotationPosition exceptionParameter(final JCLambda onLambda, final int pos) { - return exceptionParameter(emptyPath, onLambda, pos); + return exceptionParameter(emptyPath, onLambda, Integer.MIN_VALUE, pos); } /** @@ -690,7 +689,7 @@ */ public static TypeAnnotationPosition exceptionParameter(final List location) { - return exceptionParameter(location, null, -1); + return exceptionParameter(location, null, Integer.MIN_VALUE, -1); } @@ -1204,12 +1203,4 @@ return methodTypeParameterBound(location, null, parameter_index, bound_index, -1); } - - // Consider this deprecated on arrival. We eventually want to get - // rid of this value altogether. Do not use it for anything new. - public static final TypeAnnotationPosition unknown = - new TypeAnnotationPosition(TargetType.UNKNOWN, -1, - Integer.MIN_VALUE, null, - Integer.MIN_VALUE, Integer.MIN_VALUE, - emptyPath); } --- old/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java 2014-05-09 16:27:52.149212434 -0400 +++ new/src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java 2014-05-09 16:27:52.051208274 -0400 @@ -73,6 +73,16 @@ import com.sun.tools.javac.util.Names; import com.sun.tools.javac.util.Options; +/*************************************************** + * * + * ! ! I M P O R T A N T ! ! * + * * + * All code in this file is now considered * + * deprecated, and will be removed in a very * + * short timeline. DO NOT modify this file, or * + * introduce code that relies on it in any way * + * * + ***************************************************/ /** * Contains operations specific to processing type annotations. * This class has two functions: @@ -145,11 +155,8 @@ } ); } - /** - * This version only visits types in bodies, that is, field initializers, - * top-level blocks, and method bodies, and should be called from Attr. - */ - public void organizeTypeAnnotationsBodies(JCClassDecl tree) { + // Deprecated, no longer used, no longer functional, and slated for removal + public void organizeTypeAnnotationsBodies(JCTree tree) { new TypeAnnotationPositions(false).scan(tree); } @@ -389,8 +396,6 @@ private Type typeWithAnnotations(final JCTree typetree, final Type type, final List annotations, final List onlyTypeAnnotations) { - //System.err.printf("typeWithAnnotations(typetree: %s, type: %s, annotations: %s, onlyTypeAnnotations: %s)%n", - // typetree, type, annotations, onlyTypeAnnotations); if (annotations.isEmpty()) { return type; } @@ -492,12 +497,12 @@ // The normal declaration annotation checks make sure that the use is valid. break; case 1: - log.error(typetree.pos(), "cant.type.annotate.scoping.1", - onlyTypeAnnotations); + //log.error(typetree.pos(), "cant.type.annotate.scoping.1", + // onlyTypeAnnotations); break; default: - log.error(typetree.pos(), "cant.type.annotate.scoping", - onlyTypeAnnotations); + //log.error(typetree.pos(), "cant.type.annotate.scoping", + // onlyTypeAnnotations); } return type; } @@ -570,7 +575,6 @@ private Type typeWithAnnotations(final Type type, final Type stopAt, final List annotations) { - //System.err.println("typeWithAnnotations " + type + " " + annotations + " stopAt " + stopAt); Visitor> visitor = new Type.Visitor>() { @Override @@ -942,7 +946,7 @@ case EXCEPTION_PARAMETER: return TypeAnnotationPosition .exceptionParameter(location.toList(), - currentLambda, + currentLambda, 0, frame.pos); case RESOURCE_VARIABLE: return TypeAnnotationPosition @@ -1384,7 +1388,7 @@ // attribute might be null during DeferredAttr; // we will be back later. if (anno.attribute != null) { - ((Attribute.TypeCompound) anno.attribute).position = position; + //((Attribute.TypeCompound) anno.attribute).position = position; } } } --- old/src/share/classes/com/sun/tools/javac/comp/Annotate.java 2014-05-09 16:27:52.480226480 -0400 +++ new/src/share/classes/com/sun/tools/javac/comp/Annotate.java 2014-05-09 16:27:52.380222236 -0400 @@ -29,12 +29,14 @@ import java.util.LinkedHashMap; import java.util.Map; +import javax.lang.model.type.TypeKind; import javax.tools.JavaFileObject; import com.sun.tools.javac.util.*; import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Symbol.*; +import com.sun.tools.javac.code.TypeAnnotationPosition.*; import com.sun.tools.javac.tree.*; import com.sun.tools.javac.tree.JCTree.*; @@ -265,10 +267,12 @@ */ Attribute.Compound enterAnnotation(JCAnnotation a, Type expected, - Env env) { - List> elems = - enterAttributeValues(a, expected, env); - Attribute.Compound ac = new Attribute.Compound(a.type, elems); + Env env, + TypeAnnotationPosition position) { + List> buf = + enterAttributeValues(a, expected, env, position); + Attribute.Compound ac = + new Attribute.Compound(a.type, buf, position); a.attribute = ac; return ac; @@ -276,19 +280,15 @@ Attribute.TypeCompound enterTypeAnnotation(JCAnnotation a, Type expected, - Env env) { - List> elems = - enterAttributeValues(a, expected, env); + Env env, + TypeAnnotationPosition position) { + List> buf = + enterAttributeValues(a, expected, env, position); if (a.attribute == null || !(a.attribute instanceof Attribute.TypeCompound)) { // Create a new TypeCompound - Attribute.TypeCompound tc = - new Attribute.TypeCompound(a.type, elems, - // TODO: Eventually, we will get rid of this use of - // unknown, because we'll get a position from - // MemberEnter (task 8027262). - TypeAnnotationPosition.unknown); + new Attribute.TypeCompound(a.type, buf, position); a.attribute = tc; return tc; } else { @@ -300,7 +300,8 @@ private List> enterAttributeValues(JCAnnotation a, Type expected, - Env env) { + Env env, + TypeAnnotationPosition position) { // The annotation might have had its type attributed (but not // checked) by attr.attribAnnotationTypes during MemberEnter, // in which case we do not need to do it again. @@ -325,13 +326,13 @@ JCExpression t = tl.head; if (!t.hasTag(ASSIGN)) { log.error(t.pos(), "annotation.value.must.be.name.value"); - enterAttributeValue(t.type = syms.errType, t, env); + enterAttributeValue(t.type = syms.errType, t, env, position); continue; } JCAssign assign = (JCAssign)t; if (!assign.lhs.hasTag(IDENT)) { log.error(t.pos(), "annotation.value.must.be.name.value"); - enterAttributeValue(t.type = syms.errType, t, env); + enterAttributeValue(t.type = syms.errType, t, env, position); continue; } JCIdent left = (JCIdent)assign.lhs; @@ -346,7 +347,7 @@ if (method.owner != a.type.tsym && !isError) log.error(left.pos(), "no.annotation.member", left.name, a.type); Type result = method.type.getReturnType(); - Attribute value = enterAttributeValue(result, assign.rhs, env); + Attribute value = enterAttributeValue(result, assign.rhs, env, position); if (!method.type.isErroneous()) buf.append(new Pair<>((MethodSymbol)method, value)); t.type = result; @@ -356,7 +357,8 @@ Attribute enterAttributeValue(Type expected, JCExpression tree, - Env env) { + Env env, + TypeAnnotationPosition position) { //first, try completing the attribution value sym - if a completion //error is thrown, we should recover gracefully, and display an //ordinary resolution diagnostic. @@ -378,8 +380,7 @@ ListBuffer buf = new ListBuffer<>(); for (List l = na.elems; l.nonEmpty(); l=l.tail) { buf.append(enterAttributeValue(types.elemtype(expected), - l.head, - env)); + l.head, env, position)); } na.type = expected; return new Attribute. @@ -393,15 +394,13 @@ log.error(na.elemtype.pos(), "new.not.allowed.in.annotation"); } for (List l = na.elems; l.nonEmpty(); l=l.tail) { - enterAttributeValue(syms.errType, - l.head, - env); + enterAttributeValue(syms.errType, l.head, env, position); } return new Attribute.Error(syms.errType); } if ((expected.tsym.flags() & Flags.ANNOTATION) != 0) { if (tree.hasTag(ANNOTATION)) { - return enterAnnotation((JCAnnotation)tree, expected, env); + return enterAnnotation((JCAnnotation)tree, expected, env, position); } else { log.error(tree.pos(), "annotation.value.must.be.annotation"); expected = syms.errType; @@ -410,7 +409,7 @@ if (tree.hasTag(ANNOTATION)) { //error recovery if (!expected.isErroneous()) log.error(tree.pos(), "annotation.not.valid.for.type", expected); - enterAnnotation((JCAnnotation)tree, syms.errType, env); + enterAnnotation((JCAnnotation)tree, syms.errType, env, position); return new Attribute.Error(((JCAnnotation)tree).annotationType.type); } if (expected.isPrimitive() || @@ -479,7 +478,8 @@ */ private T processRepeatedAnnotations(List annotations, AnnotationContext ctx, - Symbol on) { + Symbol on, + TypeAnnotationPosition position) { T firstOccurrence = annotations.head; List repeated = List.nil(); Type origAnnoType = null; @@ -491,12 +491,8 @@ !annotations.tail.isEmpty()); // i.e. size() > 1 int count = 0; - for (List al = annotations; - !al.isEmpty(); - al = al.tail) - { + for (List al = annotations; !al.isEmpty(); al = al.tail) { count++; - // There must be more than a single anno in the annotation list Assert.check(count > 1 || !al.tail.isEmpty()); @@ -536,26 +532,16 @@ new Pair(containerValueSymbol, new Attribute.Array(arrayOfOrigAnnoType, repeated)); if (ctx.isTypeCompound) { - /* TODO: the following code would be cleaner: - Attribute.TypeCompound at = new Attribute.TypeCompound(targetContainerType, List.of(p), - ((Attribute.TypeCompound)annotations.head).position); - JCTypeAnnotation annoTree = m.TypeAnnotation(at); - at = enterTypeAnnotation(annoTree, targetContainerType, ctx.env); - */ - // However, we directly construct the TypeCompound to keep the - // direct relation to the contained TypeCompounds. - Attribute.TypeCompound at = new Attribute.TypeCompound(targetContainerType, List.of(p), - ((Attribute.TypeCompound)annotations.head).position); - - // TODO: annotation applicability checks from below? - + Attribute.TypeCompound at = new Attribute.TypeCompound(targetContainerType, List.of(p), position); at.setSynthesized(true); @SuppressWarnings("unchecked") T x = (T) at; return x; } else { - Attribute.Compound c = new Attribute.Compound(targetContainerType, List.of(p)); + Attribute.Compound c = new Attribute.Compound(targetContainerType, + List.of(p), + position); JCAnnotation annoTree = m.Annotation(c); if (!chk.annotationApplicable(annoTree, on)) @@ -564,7 +550,7 @@ if (!chk.validateAnnotationDeferErrors(annoTree)) log.error(annoTree.pos(), "duplicate.annotation.invalid.repeated", origAnnoType); - c = enterAnnotation(annoTree, targetContainerType, ctx.env); + c = enterAnnotation(annoTree, targetContainerType, ctx.env, position); c.setSynthesized(true); @SuppressWarnings("unchecked") @@ -576,6 +562,7 @@ } } + /** Fetches the actual Type that should be the containing annotation. */ private Type getContainingType(Attribute.Compound currentAnno, DiagnosticPosition pos, @@ -710,13 +697,14 @@ Env env, Symbol sym, AttributeCreator creator, - boolean isTypeCompound) { + boolean isTypeCompound, + TypeAnnotationPosition position) { Map> annotated = new LinkedHashMap<>(); Map pos = new HashMap<>(); for (List al = annotations; !al.isEmpty(); al = al.tail) { JCAnnotation a = al.head; - T c = creator.create(a, syms.annotationType, env); + T c = creator.create(a, syms.annotationType, env, position); Assert.checkNonNull(c, "Failed to create annotation"); @@ -743,7 +731,7 @@ } return new AnnotationContext<>(env, annotated, pos, - isTypeCompound); + isTypeCompound); } // Gather up annotations into a map from type symbols to lists of @@ -754,10 +742,12 @@ final Env env, final Symbol sym, final boolean isTypeCompound, + final TypeAnnotationPosition position, final AttributeCreator creator, final AttributeAttacher attacher) { final AnnotationContext ctx = - prepareEnterAnnotations(annotations, env, sym, creator, isTypeCompound); + prepareEnterAnnotations(annotations, env, sym, creator, + isTypeCompound, position); final Map> annotated = ctx.annotated; boolean hasRepeated = false; @@ -781,51 +771,303 @@ // that @Repeatable and other annotations get attached. // Since the attacher uses setDeclarationAttributes, this // will be overwritten later. - attacher.attach(sym, attrs); + @SuppressWarnings("unchecked") + List tempattrs = (List) attrs; + sym.setDeclarationAttributes(tempattrs); } + if (hasRepeated) { - repeated(new Annotate.Worker() { - @Override - public String toString() { - return "repeated annotation pass of: " + sym + " in: " + sym.owner; + replacePlaceholdersAndAttach(attrs, ctx, env, sym, attacher); + } else { + attachAttributesAfterRepeated(attrs, env, attacher); + } + } + + private + void replacePlaceholdersAndAttach(final List attrs, + final AnnotationContext ctx, + final Env env, + final Symbol sym, + final AttributeAttacher attacher) { + repeated(new Annotate.Worker() { + @Override + public String toString() { + return "repeated annotation pass of: " + sym + " in: " + sym.owner; + } + + @Override + public void run() { + JavaFileObject oldSource = + log.useSource(env.toplevel.sourcefile); + try { + final List replaced = + replacePlaceholders(attrs, ctx, sym); + attachAttributesAfterRepeated(replaced, env, attacher); + } finally { + log.useSource(oldSource); } + } + }); + } - @Override - public void run() { - JavaFileObject oldSource = - log.useSource(env.toplevel.sourcefile); - try { - attacher.attach(sym, replacePlaceholders(attrs, ctx, sym)); - } finally { - log.useSource(oldSource); - } + private + void attachAttributesAfterRepeated(final List attrs, + final Env env, + final AttributeAttacher attacher) { + afterRepeated(new Worker() { + @Override + public String toString() { + return "attach pass for: " + attrs; + } + + @Override + public void run() { + JavaFileObject oldSource = + log.useSource(env.toplevel.sourcefile); + try { + attacher.attach(attrs); + } finally { + log.useSource(oldSource); } - }); + } + }); + } + + public interface AttributeAttacher { + public void attach(List attrs); + } + + public interface Reporter { + public void report(List attrs); + } + + public enum AnnotationType { DECLARATION, TYPE, BOTH } + + /** + * Determine whether an annotation is a declaration annotation, + * a type annotation, or both. + */ + public AnnotationType annotationType(Attribute.Compound a, Symbol s) { + Attribute.Compound atTarget = + a.type.tsym.attribute(syms.annotationTargetType.tsym); + if (atTarget == null) { + return inferTargetMetaInfo(a, s); + } + Attribute atValue = atTarget.member(names.value); + if (!(atValue instanceof Attribute.Array)) { + Assert.error("annotationType(): bad @Target argument " + atValue + + " (" + atValue.getClass() + ")"); + return AnnotationType.DECLARATION; // error recovery + } + Attribute.Array arr = (Attribute.Array) atValue; + boolean isDecl = false, isType = false; + for (Attribute app : arr.values) { + if (!(app instanceof Attribute.Enum)) { + Assert.error("annotationType(): unrecognized Attribute kind " + app + + " (" + app.getClass() + ")"); + isDecl = true; + continue; + } + Attribute.Enum e = (Attribute.Enum) app; + if (e.value.name == names.TYPE) { + if (s.kind == Kinds.TYP) + isDecl = true; + } else if (e.value.name == names.FIELD) { + if (s.kind == Kinds.VAR && + s.owner.kind != Kinds.MTH) + isDecl = true; + } else if (e.value.name == names.METHOD) { + if (s.kind == Kinds.MTH && + !s.isConstructor()) + isDecl = true; + } else if (e.value.name == names.PARAMETER) { + if (s.kind == Kinds.VAR && + s.owner.kind == Kinds.MTH && + (s.flags() & Flags.PARAMETER) != 0) + isDecl = true; + } else if (e.value.name == names.CONSTRUCTOR) { + if (s.kind == Kinds.MTH && + s.isConstructor()) + isDecl = true; + } else if (e.value.name == names.LOCAL_VARIABLE) { + if (s.kind == Kinds.VAR && + s.owner.kind == Kinds.MTH && + (s.flags() & Flags.PARAMETER) == 0) + isDecl = true; + } else if (e.value.name == names.ANNOTATION_TYPE) { + if (s.kind == Kinds.TYP && + (s.flags() & Flags.ANNOTATION) != 0) + isDecl = true; + } else if (e.value.name == names.PACKAGE) { + if (s.kind == Kinds.PCK) + isDecl = true; + } else if (e.value.name == names.TYPE_USE) { + if (s.kind == Kinds.TYP || + s.kind == Kinds.VAR || + (s.kind == Kinds.MTH && !s.isConstructor() && + !s.type.getReturnType().hasTag(TypeTag.VOID)) || + (s.kind == Kinds.MTH && s.isConstructor())) + isType = true; + } else if (e.value.name == names.TYPE_PARAMETER) { + /* Irrelevant in this case */ + // TYPE_PARAMETER doesn't aid in distinguishing between + // Type annotations and declaration annotations on an + // Element + } else { + Assert.error("annotationType(): unrecognized Attribute name " + e.value.name + + " (" + e.value.name.getClass() + ")"); + isDecl = true; + } + } + if (isDecl && isType) { + return AnnotationType.BOTH; + } else if (isType) { + return AnnotationType.TYPE; } else { - attacher.attach(sym, attrs); + return AnnotationType.DECLARATION; } } - private interface AttributeAttacher { - public void attach(Symbol sym, List attrs); + private Attribute.TypeCompound toTypeCompound(Attribute.Compound a) { + // It is safe to alias the position. + return new Attribute.TypeCompound(a, a.position); } - private final AttributeAttacher declAnnotationsAttacher = - new AttributeAttacher() { + /** Infer the target annotation kind, if none is given. + * We only infer declaration annotations. + */ + private static AnnotationType inferTargetMetaInfo(Attribute.Compound a, Symbol s) { + return AnnotationType.DECLARATION; + } + + private AttributeAttacher + declAnnotationsAttacher(final Symbol sym) { + return new AttributeAttacher() { @Override - public void attach(Symbol sym, List attrs) { + public void attach(List attrs) { sym.resetAnnotations(); sym.setDeclarationAttributes(attrs); } }; + } - private final AttributeAttacher typeAnnotationsAttacher = - new AttributeAttacher() { + private AttributeAttacher + typeAnnotationsAttacher(final Symbol sym) { + return new AttributeAttacher() { @Override - public void attach(Symbol sym, List attrs) { - sym.appendUniqueTypeAttributes(attrs); + public void attach(List attrs) { + if (!attrs.isEmpty()) { + attachTypeAnnotations(sym, attrs); + } } }; + } + + private void reportIllegalScoping(List attrs, + int pos) { + switch (attrs.size()) { + case 0: + // Don't issue an error if all type annotations are + // also declaration annotations. + // If the annotations are also declaration annotations, they are + // illegal as type annotations but might be legal as declaration annotations. + // The normal declaration annotation checks make sure that the use is valid. + break; + case 1: + //System.err.println("Reporting illegal scoping"); + log.error(pos, "cant.type.annotate.scoping.1", attrs); + break; + default: + //System.err.println("Reporting illegal scoping"); + log.error(pos, "cant.type.annotate.scoping", attrs); + } + } + + private Reporter + illegalScopingReporter(final int pos) { + return new Reporter() { + @Override + public void report(List attrs) { + reportIllegalScoping(attrs, pos); + } + }; + } + + private AttributeAttacher + classifyingAttacher(final Symbol sym) { + return classifyingAttacher(sym, declAnnotationsAttacher(sym), + typeAnnotationsAttacher(sym), + null); + } + + + private AttributeAttacher + classifyingAttacher(final Symbol sym, + final AttributeAttacher declAttacher, + final AttributeAttacher typeAttacher, + final Reporter reporter) { + return new AttributeAttacher() { + @Override + public void attach(List attrs) { + ListBuffer declAnnos = new ListBuffer<>(); + ListBuffer typeAnnos = new ListBuffer<>(); + ListBuffer onlyTypeAnnos = new ListBuffer<>(); + + for (Attribute.Compound a : attrs) { + Assert.check(!(a instanceof Placeholder), + "Placeholders found in annotations being attached!"); + switch (annotationType(a, sym)) { + case DECLARATION: + declAnnos.append(a); + break; + case BOTH: { + declAnnos.append(a); + Attribute.TypeCompound ta = toTypeCompound(a); + Assert.checkNonNull(ta.position); + typeAnnos.append(ta); + break; + } + case TYPE: { + Attribute.TypeCompound ta = toTypeCompound(a); + Assert.checkNonNull(ta.position); + typeAnnos.append(ta); + // Also keep track which annotations are only type annotations + onlyTypeAnnos.append(ta); + break; + } + default: + throw new AssertionError("Unknown annotation type"); + } + } + + if (declAttacher != null) + declAttacher.attach(declAnnos.toList()); + + if (typeAttacher != null) + typeAttacher.attach(typeAnnos.toList()); + + if (reporter != null) + reporter.report(onlyTypeAnnos.toList()); + } + }; + } + + public void attachTypeAnnotations(Symbol sym, List attrs) { + sym.appendUniqueTypeAttributes(attrs); + + // For type annotations on variables in methods, make + // sure they are attached to the owner too. + switch(sym.getKind()) { + case PARAMETER: + case LOCAL_VARIABLE: + case RESOURCE_VARIABLE: + case EXCEPTION_PARAMETER: + // Make sure all type annotations from the symbol are also + // on the owner. + sym.owner.appendUniqueTypeAttributes(attrs); + break; + } + } private List replacePlaceholders(List buf, @@ -835,7 +1077,7 @@ for (T a : buf) { if (a instanceof Placeholder) { @SuppressWarnings("unchecked") - T replacement = replaceOne((Placeholder) a, ctx, sym); + T replacement = replaceOne((Placeholder) a, ctx, sym); if (null != replacement) { result = result.prepend(replacement); @@ -854,7 +1096,7 @@ // Process repeated annotations T validRepeated = processRepeatedAnnotations(placeholder.getPlaceholderFor(), - ctx, sym); + ctx, sym, placeholder.position); if (validRepeated != null) { // Check that the container isn't manually @@ -875,11 +1117,35 @@ * Annotation processing *********************************************************************/ - /** Queue annotations for later processing. */ + void annotateLater(final List annotations, + final Env localEnv, + final Symbol s) { + annotateLater(annotations, localEnv, s, null); + } + void annotateLater(final List annotations, final Env localEnv, final Symbol s, final DiagnosticPosition deferPos) { + annotateLater(annotations, localEnv, s, deferPos, null, + declAnnotationsAttacher(s)); + } + + void annotateLater(final List annotations, + final Env localEnv, + final Symbol s, + final DiagnosticPosition deferPos, + final TypeAnnotationPosition tapos) { + annotateLater(annotations, localEnv, s, deferPos, tapos, + classifyingAttacher(s)); + } + + void annotateLater(final List annotations, + final Env localEnv, + final Symbol s, + final DiagnosticPosition deferPos, + final TypeAnnotationPosition tapos, + final AttributeAttacher attacher) { if (annotations.isEmpty()) { return; } @@ -894,30 +1160,48 @@ @Override public void run() { - Assert.check(s.kind == PCK || s.annotationsPendingCompletion()); - JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); - DiagnosticPosition prevLintPos = - deferPos != null - ? deferredLintHandler.setPos(deferPos) - : deferredLintHandler.immediate(); - Lint prevLint = deferPos != null ? null : chk.setLint(lint); - try { - if (s.hasAnnotations() && - annotations.nonEmpty()) - log.error(annotations.head.pos, - "already.annotated", - kindName(s), s); - actualEnterAnnotations(annotations, localEnv, s); - } finally { - if (prevLint != null) - chk.setLint(prevLint); - deferredLintHandler.setPos(prevLintPos); - log.useSource(prev); - } + annotateNow(annotations, localEnv, s, deferPos, + tapos, attacher); } }); - validate(new Annotate.Worker() { //validate annotations + validate(annotationValidator(annotations, localEnv, s)); + } + + private void annotateNow(final List annotations, + final Env localEnv, + final Symbol s, + final DiagnosticPosition deferPos, + final TypeAnnotationPosition position, + final AttributeAttacher attacher) { + if (annotations.isEmpty()) { + return; + } + Assert.check(s.kind == PCK || s.annotationsPendingCompletion()); + JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); + DiagnosticPosition prevLintPos = deferPos != null ? + deferredLintHandler.setPos(deferPos) : + deferredLintHandler.immediate(); + Lint prevLint = deferPos != null ? null : chk.setLint(lint); + try { + if (s.hasAnnotations() && + annotations.nonEmpty()) + log.error(annotations.head.pos, + "already.annotated", + kindName(s), s); + actualEnterAnnotations(annotations, localEnv, s, position, attacher); + } finally { + if (prevLint != null) + chk.setLint(prevLint); + deferredLintHandler.setPos(prevLintPos); + log.useSource(prev); + } + } + + private Annotate.Worker annotationValidator(final List annotations, + final Env localEnv, + final Symbol s) { + return new Annotate.Worker() { //validate annotations @Override public void run() { JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); @@ -927,11 +1211,30 @@ log.useSource(prev); } } - }); + }; + } + + private Annotate.Worker typeAnnotationValidator(final List annotations, + final Env localEnv, + final boolean isTypeParameter) { + return new Annotate.Worker() { //validate annotations + @Override + public void run() { + JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); + try { + chk.validateTypeAnnotations(annotations, isTypeParameter); + } finally { + log.useSource(prev); + } + } + }; } private interface AttributeCreator { - public T create(JCAnnotation a, Type expected, Env env); + public T create(JCAnnotation a, + Type expected, + Env env, + TypeAnnotationPosition position); } // TODO: When SE8 features can be used, these can go away and be @@ -941,8 +1244,9 @@ @Override public Attribute.Compound create(JCAnnotation a, Type expected, - Env env) { - return enterAnnotation(a, syms.annotationType, env); + Env env, + TypeAnnotationPosition position) { + return enterAnnotation(a, syms.annotationType, env, position); } }; private final AttributeCreator enterTypeAnnotationsCreator = @@ -950,19 +1254,21 @@ @Override public Attribute.TypeCompound create(JCAnnotation a, Type expected, - Env env) { - return enterTypeAnnotation(a, syms.annotationType, env); + Env env, + TypeAnnotationPosition position) { + return enterTypeAnnotation(a, syms.annotationType, env, position); } }; /** Enter a set of annotations. */ private void actualEnterAnnotations(List annotations, Env env, - Symbol s) { - Assert.checkNonNull(s, "Symbol argument to actualEnterAnnotations is null"); - attachAttributesLater(annotations, env, s, false, - enterAnnotationsCreator, - declAnnotationsAttacher); + Symbol s, + TypeAnnotationPosition position, + AttributeAttacher attacher) { + Assert.checkNonNull(s); + attachAttributesLater(annotations, env, s, false, position, + enterAnnotationsCreator, attacher); } /* @@ -971,8 +1277,10 @@ private void actualEnterTypeAnnotations(final List annotations, final Env env, final Symbol s, - final DiagnosticPosition deferPos) { - Assert.checkNonNull(s, "Symbol argument to actualEnterTypeAnnotations is nul/"); + final DiagnosticPosition deferPos, + final TypeAnnotationPosition position, + final AttributeAttacher attacher) { + Assert.checkNonNull(s); JavaFileObject prev = log.useSource(env.toplevel.sourcefile); DiagnosticPosition prevLintPos = null; @@ -980,9 +1288,8 @@ prevLintPos = deferredLintHandler.setPos(deferPos); } try { - attachAttributesLater(annotations, env, s, true, - enterTypeAnnotationsCreator, - typeAnnotationsAttacher); + attachAttributesLater(annotations, env, s, true, position, + enterTypeAnnotationsCreator, attacher); } finally { if (prevLintPos != null) deferredLintHandler.setPos(prevLintPos); @@ -993,8 +1300,26 @@ public void annotateTypeLater(final JCTree tree, final Env env, final Symbol sym, - final DiagnosticPosition deferPos) { + final DiagnosticPosition deferPos, + final JCLambda currentLambda, + final PositionCreator creator, + final boolean speculative) { + annotateTypeLater(tree, List.nil(), env, sym, + deferPos, currentLambda, creator, speculative); + } + + public void annotateTypeLater(final JCTree tree, + final List declAnnos, + final Env env, + final Symbol sym, + final DiagnosticPosition deferPos, + final JCLambda currentLambda, + final PositionCreator creator, + final boolean speculative) { Assert.checkNonNull(sym); + Assert.checkNonNull(declAnnos); + Assert.checkNonNull(creator); + normal(new Annotate.Worker() { @Override public String toString() { @@ -1002,77 +1327,621 @@ } @Override public void run() { - tree.accept(new TypeAnnotate(env, sym, deferPos)); + if (!declAnnos.isEmpty()) { + sym.resetAnnotations(); // mark Annotations as incomplete for now + } + + tree.accept(typeAnnotater(declAnnos, sym, env, deferPos, + currentLambda, creator, speculative)); } }); } /** - * We need to use a TreeScanner, because it is not enough to visit the top-level - * annotations. We also need to visit type arguments, etc. + * A client passed into various visitors that takes a type path as + * an argument and performs an action (typically creating a + * TypeAnnotationPosition and then creating a {@code Worker} and + * adding it to a queue. */ + public abstract class PositionCreator { + public TypeAnnotationPosition create() { + return create(List.nil(), null, 0); + } + + public TypeAnnotationPosition createNonNull(List path, + JCLambda lambda, + int typeIndex) { + final TypeAnnotationPosition out = create(path, lambda, typeIndex); + + if (out != null) + return out; + else + throw new AssertionError("No annotation creator registered"); + } + + public abstract TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex); + } + + // For when we don't have a creator. Creates null. + public final PositionCreator noCreator = + new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return null; + } + }; + + // Create class extension positions + public final PositionCreator extendsCreator = + new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.classExtends(path, lambda, -1); + } + }; + + // Create interface implementation positions + public PositionCreator implementsCreator(final int idx) { + return new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.classExtends(path, lambda, idx, -1); + } + }; + } + + // Create method parameter positions + public final PositionCreator paramCreator(final int idx) { + return new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.methodParameter(path, lambda, idx, -1); + } + }; + } + + // Create class type parameter positions + public PositionCreator typeParamCreator(final int idx) { + return new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.typeParameter(path, lambda, idx, -1); + } + }; + } + + public PositionCreator typeParamBoundCreator(final JCTypeParameter typaram, + final int param_idx, + final int bound_idx) { + return new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + final int real_bound_idx = + typaram.bounds.head.type.isInterface() ? bound_idx + 1 : bound_idx; + return TypeAnnotationPosition + .typeParameterBound(path, lambda, param_idx, real_bound_idx, -1); + } + }; + } + + // Create field positions + public final PositionCreator fieldCreator = + new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.field(path, lambda, -1); + } + }; + + // Create local variable positions + public PositionCreator localVarCreator(final int pos) { + return new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.localVariable(path, lambda, pos); + } + }; + } + + public PositionCreator resourceVarCreator(final int pos) { + return new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.resourceVariable(path, lambda, pos); + } + }; + } + + public PositionCreator exceptionParamCreator(final int pos) { + return new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.exceptionParameter(path, lambda, + typeIndex, pos); + } + }; + } + + public PositionCreator methodTypeParamCreator(final int idx) { + return new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.methodTypeParameter(path, lambda, idx, -1); + } + }; + } + + public PositionCreator methodRefTypeArgCreator(final int idx, + final int pos) { + return new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.methodRefTypeArg(path, lambda, idx, pos); + } + }; + } + + public PositionCreator constructorRefTypeArgCreator(final int idx, + final int pos) { + return new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition + .constructorRefTypeArg(path, lambda, idx, pos); + } + }; + } + + public PositionCreator methodInvokeTypeArgCreator(final int idx, + final int pos) { + return new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.methodInvocationTypeArg(path, lambda, idx, pos); + } + }; + } + + public PositionCreator constructorInvokeTypeArgCreator(final int idx, + final int pos) { + return new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.constructorInvocationTypeArg(path, lambda, idx, pos); + } + }; + } + + public PositionCreator methodTypeParamBoundCreator(final JCTypeParameter typaram, + final int param_idx, + final int bound_idx) { + return new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + final int real_bound_idx = + typaram.bounds.head.type.isInterface() ? bound_idx + 1 : bound_idx; + return TypeAnnotationPosition + .methodTypeParameterBound(path, lambda, param_idx, real_bound_idx, -1); + } + }; + } + + public PositionCreator throwCreator(final int idx) { + return new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.methodThrows(path, lambda, idx, -1); + } + }; + } + + public final PositionCreator returnCreator = + new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.methodReturn(path, lambda, -1); + } + }; + + public PositionCreator receiverCreator = + new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.methodReceiver(path, lambda, -1); + } + }; + + public PositionCreator methodRefCreator(final int pos) { + return new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.methodRef(path, lambda, pos); + } + }; + } + + public PositionCreator constructorRefCreator(final int pos) { + return new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.constructorRef(path, lambda, pos); + } + }; + } + + public PositionCreator instanceOfCreator(final int pos) { + return new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.instanceOf(path, lambda, pos); + } + }; + } + + public PositionCreator newObjCreator(final int pos) { + return new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.newObj(path, lambda, pos); + } + }; + } + + public PositionCreator castCreator(final int pos) { + return new PositionCreator() { + @Override + public TypeAnnotationPosition create(List path, + JCLambda lambda, + int typeIndex) { + return TypeAnnotationPosition.typeCast(path, lambda, typeIndex, pos); + } + }; + } + + private static List addInners(Type type, + List typepath) { + Type encl = type.getEnclosingType(); + while (encl != null && encl.getKind() != TypeKind.NONE && + encl.getKind() != TypeKind.ERROR) { + typepath = typepath.append(TypePathEntry.INNER_TYPE); + encl = encl.getEnclosingType(); + } + return typepath; + } + + public TypeAnnotate typeAnnotater(final List declAnnos, + final Symbol sym, + final Env env, + final DiagnosticPosition deferPos, + final JCLambda currentLambda, + final PositionCreator creator, + final boolean speculative) { + if (!speculative) { + return new TypeAnnotate(declAnnos, sym, env, deferPos, + currentLambda, creator, + declAnnotationsAttacher(sym), + typeAnnotationsAttacher(sym)); + } else { + return new TypeAnnotate(declAnnos, sym, env, deferPos, + currentLambda, creator, null, null); + } + } + private class TypeAnnotate extends TreeScanner { - private final Env env; + protected PositionCreator creator; + private List typepath = List.nil(); + private JCLambda currentLambda; + private int type_index = 0; + private boolean innermost; + // These attachers are for declaration annotations + private AttributeAttacher declAttacher; + private AttributeAttacher typeAttacher; + private Reporter reporter; private final Symbol sym; - private DiagnosticPosition deferPos; + private final DiagnosticPosition deferPos; + private final Env env; + private final List declAnnos; - public TypeAnnotate(final Env env, + public TypeAnnotate(final List declAnnos, final Symbol sym, - final DiagnosticPosition deferPos) { - - this.env = env; + final Env env, + final DiagnosticPosition deferPos, + final JCLambda currentLambda, + final PositionCreator creator, + final AttributeAttacher declAttacher, + final AttributeAttacher typeAttacher) { + this.declAnnos = declAnnos; this.sym = sym; + this.env = env; this.deferPos = deferPos; + this.currentLambda = currentLambda; + this.creator = creator; + this.innermost = true; + this.declAttacher = declAttacher; + this.typeAttacher = typeAttacher; + this.reporter = null; + } + + private void doDeclAnnos() { + if (!declAnnos.isEmpty()) { + final TypeAnnotationPosition tapos = + creator.createNonNull(typepath, currentLambda, type_index); + annotateNow(declAnnos, env, sym, deferPos, tapos, + classifyingAttacher(sym, declAttacher, + typeAttacher, reporter)); + validate(annotationValidator(declAnnos, env, sym)); + } + } + + private void doTypeAnnos(List annos, + boolean isTypeParameter) { + if (!annos.isEmpty()) { + final AttributeAttacher currTypeAttacher = typeAttacher; + final Reporter currReporter = reporter; + final AttributeAttacher attacher = + new AttributeAttacher() { + @Override + public void attach(List attrs) { + if (currTypeAttacher != null) + currTypeAttacher.attach(attrs); + if (currReporter != null) + currReporter.report(attrs); + } + }; + final TypeAnnotationPosition tapos = + creator.createNonNull(typepath, currentLambda, type_index); + actualEnterTypeAnnotations(annos, env, sym, deferPos, tapos, + attacher); + validate(typeAnnotationValidator(annos, env, isTypeParameter)); + } + } + + @Override + public void visitTypeIdent(final JCPrimitiveTypeTree tree) { + if (innermost) { + final AttributeAttacher oldTypeAttacher = typeAttacher; + typeAttacher = + new AttributeAttacher() { + @Override + public void attach(List attrs) { + if (null != oldTypeAttacher) + oldTypeAttacher.attach(attrs); + + if (!attrs.isEmpty()) { + tree.type = tree.type.annotatedType(attrs); + } + } + }; + doDeclAnnos(); + typeAttacher = oldTypeAttacher; + } + } + + @Override + public void visitIdent(final JCIdent tree) { + if (innermost) { + final AttributeAttacher oldTypeAttacher = typeAttacher; + final Reporter oldReporter = reporter; + typeAttacher = + new AttributeAttacher() { + @Override + public void attach(List attrs) { + if (null != oldTypeAttacher) + oldTypeAttacher.attach(attrs); + + if (!attrs.isEmpty() && + !tree.type.hasTag(TypeTag.PACKAGE)) { + tree.type = tree.type.annotatedType(attrs); + } + } + }; + if (tree.type != null) { + final List oldpath = typepath; + typepath = addInners(tree.type, typepath); + doDeclAnnos(); + typepath = oldpath; + } else { + doDeclAnnos(); + } + reporter = oldReporter; + typeAttacher = oldTypeAttacher; + } + } + + @Override + public void visitAnnotatedType(JCAnnotatedType tree) { + Assert.checkNonNull(tree.getUnderlyingType().type); + final boolean oldinnermost = innermost; + innermost = false; + scan(tree.annotations); + innermost = oldinnermost; + scan(tree.underlyingType); + final Reporter oldReporter = reporter; + final List oldpath = typepath; + typepath = addInners(tree.getUnderlyingType().type, typepath); + doTypeAnnos(tree.annotations, false); + typepath = oldpath; + reporter = oldReporter; } @Override - public void visitAnnotatedType(final JCAnnotatedType tree) { - actualEnterTypeAnnotations(tree.annotations, env, sym, deferPos); - super.visitAnnotatedType(tree); + public void visitTypeArray(JCArrayTypeTree tree) { + final List oldpath = typepath; + typepath = typepath.append(TypePathEntry.ARRAY); + super.visitTypeArray(tree); + typepath = oldpath; } @Override - public void visitTypeParameter(final JCTypeParameter tree) { - actualEnterTypeAnnotations(tree.annotations, env, sym, deferPos); - super.visitTypeParameter(tree); + public void visitTypeApply(JCTypeApply tree) { + Assert.checkNonNull(tree.getType().type); + final List oldpath = typepath; + scan(tree.clazz); + + + if (tree.getType() != null && tree.getType().type != null) { + typepath = addInners(tree.getType().type, typepath); + } + final boolean oldinnermost = innermost; + innermost = false; + int i = 0; + for (List l = tree.arguments; l.nonEmpty(); + l = l.tail, i++) { + final JCExpression arg = l.head; + final List noargpath = typepath; + typepath = typepath.append(new TypePathEntry(TypePathEntryKind.TYPE_ARGUMENT, i)); + scan(arg); + typepath = noargpath; + } + typepath = oldpath; + innermost = oldinnermost; } @Override - public void visitNewArray(final JCNewArray tree) { - actualEnterTypeAnnotations(tree.annotations, env, sym, deferPos); - for (List dimAnnos : tree.dimAnnotations) - actualEnterTypeAnnotations(dimAnnos, env, sym, deferPos); - super.visitNewArray(tree); + public void visitNewArray(JCNewArray tree) { + final List oldpath = typepath; + final PositionCreator oldcreator = creator; + creator = newObjCreator(tree.pos); + doTypeAnnos(tree.annotations, false); + + for (int i = 0; i < tree.dimAnnotations.size(); i++) { + final List dimAnnos = tree.dimAnnotations.get(i); + doTypeAnnos(dimAnnos, false); + // This is right. As per the type annotations spec, + // the first array dimension has no arrays in the type + // path, the second has one, and so on, and the + // element type has n for n dimensions. + typepath = typepath.append(TypePathEntry.ARRAY); + } + + // The element type is sometimes null, in the case of + // array literals. + scan(tree.elemtype); + typepath = oldpath; + creator = oldcreator; } @Override - public void visitMethodDef(final JCMethodDecl tree) { - scan(tree.mods); - scan(tree.restype); - scan(tree.typarams); - scan(tree.recvparam); + public void visitWildcard(JCWildcard tree) { + final List oldpath = typepath; + typepath = typepath.append(TypePathEntry.WILDCARD); + super.visitWildcard(tree); + typepath = oldpath; + } + + @Override + public void visitTypeParameter(JCTypeParameter tree) { + scan(tree.annotations); + Assert.checkNonNull(tree.type); + doTypeAnnos(tree.annotations, true); + } + + @Override + public void visitLambda(JCLambda tree) { + final JCLambda oldLambda = currentLambda; + currentLambda = tree; + scan(tree.body); scan(tree.params); - scan(tree.thrown); - scan(tree.defaultValue); - // Do not annotate the body, just the signature. - // scan(tree.body); + currentLambda = oldLambda; + } @Override - public void visitVarDef(final JCVariableDecl tree) { - DiagnosticPosition prevPos = deferPos; - deferPos = tree.pos(); - try { - if (sym != null && sym.kind == Kinds.VAR) { - // Don't visit a parameter once when the sym is the method - // and once when the sym is the parameter. - scan(tree.mods); - scan(tree.vartype); - } - scan(tree.init); - } finally { - deferPos = prevPos; + public void visitTypeIntersection(JCTypeIntersection tree) { + final boolean oldinnermost = innermost; + for (List l = tree.bounds; l.nonEmpty(); + l = l.tail, type_index++) { + scan(l.head); + // Set innermost to false after the first element + innermost = false; + } + innermost = oldinnermost; + } + + @Override + public void visitTypeUnion(JCTypeUnion tree) { + final boolean oldinnermost = innermost; + for (List l = tree.alternatives; l.nonEmpty(); + l = l.tail, type_index++) { + scan(l.head); + // Set innermost to false after the first element + innermost = false; } + innermost = oldinnermost; + } + + @Override + public void visitSelect(JCFieldAccess tree) { + Symbol sym = tree.sym; + //System.err.println("visitSelect " + tree); + final AttributeAttacher oldTypeAttacher = typeAttacher; + final Reporter oldReporter = reporter; + // If we're selecting from an interface or a static class, + // set up attachers that will only attach declaration + // annotations and will report type annotations as errors. + Type selectedTy = tree.selected.type; + if (sym != null && (sym.isStatic() || sym.isInterface() || + selectedTy.hasTag(TypeTag.PACKAGE))) { + typeAttacher = null; + reporter = illegalScopingReporter(tree.pos); + } + super.visitSelect(tree); + typeAttacher = oldTypeAttacher; + reporter = oldReporter; + } + + // These methods stop the visitor from continuing on when it + // sees a definition. + @Override + public void visitVarDef(final JCVariableDecl tree) { } @Override @@ -1084,11 +1953,57 @@ @Override public void visitNewClass(JCNewClass tree) { - if (tree.def == null) { - // For an anonymous class instantiation the class - // will be visited separately. - super.visitNewClass(tree); - } + // This will be visited by Attr later, so don't do + // anything. + } + } + + private class TypeAnnotateExpr extends TypeAnnotate { + public TypeAnnotateExpr(final Symbol sym, + final Env env, + final DiagnosticPosition deferPos, + final JCLambda currentLambda, + final PositionCreator creator) { + super(List.nil(), sym, env, deferPos, + currentLambda, creator, null, null); + } + + @Override + public void visitTypeCast(final JCTypeCast tree) { + final PositionCreator oldcreator = creator; + creator = castCreator(tree.pos); + super.visitTypeCast(tree); + creator = oldcreator; + } + + @Override + public void visitTypeTest(JCInstanceOf tree) { + final PositionCreator oldcreator = creator; + creator = instanceOfCreator(tree.pos); + super.visitTypeTest(tree); + creator = oldcreator; } } + + public void typeAnnotateExprLater(final JCTree tree, + final Env env, + final Symbol sym, + final DiagnosticPosition deferPos, + final JCLambda currentLambda, + final PositionCreator creator) { + Assert.checkNonNull(sym); + Assert.checkNonNull(creator); + + normal(new Annotate.Worker() { + @Override + public String toString() { + return "type annotate " + tree + " onto " + sym + " in " + sym.owner; + } + @Override + public void run() { + tree.accept(new TypeAnnotateExpr(sym, env, deferPos, + currentLambda, creator)); + } + }); + } } --- old/src/share/classes/com/sun/tools/javac/comp/Attr.java 2014-05-09 16:27:52.881243482 -0400 +++ new/src/share/classes/com/sun/tools/javac/comp/Attr.java 2014-05-09 16:27:52.778239110 -0400 @@ -39,6 +39,7 @@ import com.sun.tools.javac.code.Lint.LintCategory; import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Type.*; +import com.sun.tools.javac.code.TypeAnnotationPosition.*; import com.sun.tools.javac.comp.Check.CheckContext; import com.sun.tools.javac.comp.DeferredAttr.AttrMode; import com.sun.tools.javac.comp.Infer.InferenceContext; @@ -94,6 +95,9 @@ final TypeAnnotations typeAnnotations; final DeferredLintHandler deferredLintHandler; + /** The creator that will be used for any varDef's we visit. */ + Annotate.PositionCreator creator; + public static Attr instance(Context context) { Attr instance = context.get(attrKey); if (instance == null) @@ -122,6 +126,8 @@ annotate = Annotate.instance(context); typeAnnotations = TypeAnnotations.instance(context); deferredLintHandler = DeferredLintHandler.instance(context); + creator = null; + speculative = false; Options options = Options.instance(context); @@ -231,6 +237,11 @@ */ String sourceName; + /** + * Whether or not this is speculative attribution + */ + boolean speculative; + /** Check kind and type of given tree against protokind and prototype. * If check succeeds, store type in tree and return it. * If check fails, store errType in tree and return it. @@ -425,19 +436,25 @@ return cfolder.coerce(etype, ttype); } - public Type attribType(JCTree node, TypeSymbol sym) { + public Type attribType(JCTree node, TypeSymbol sym, + JCLambda currentLambda, boolean speculative) { Env env = enter.typeEnvs.get(sym); Env localEnv = env.dup(node, env.info.dup()); - return attribTree(node, localEnv, unknownTypeInfo); + return attribTree(node, localEnv, currentLambda, + unknownTypeInfo, speculative); } - public Type attribImportQualifier(JCImport tree, Env env) { + public Type attribType(JCTree node, TypeSymbol sym) { + return attribType(node, sym, currentLambda, speculative); + } + + public Type attribImportQualifier(JCImport tree, Env env, + JCLambda currLambda, boolean speculative) { // Attribute qualifying package or class. JCFieldAccess s = (JCFieldAccess)tree.qualid; - return attribTree(s.selected, - env, - new ResultInfo(tree.staticImport ? TYP : (TYP | PCK), - Type.noType)); + return attribTree(s.selected, env, currentLambda, + new ResultInfo(tree.staticImport ? TYP : (TYP | PCK), + Type.noType), speculative); } public Env attribExprToTree(JCTree expr, Env env, JCTree tree) { @@ -571,6 +588,8 @@ */ Env env; + JCLambda currentLambda; + /** Visitor argument: the currently expected attribution result. */ ResultInfo resultInfo; @@ -586,12 +605,18 @@ * @param env The environment visitor argument. * @param resultInfo The result info visitor argument. */ - Type attribTree(JCTree tree, Env env, ResultInfo resultInfo) { + Type attribTree(JCTree tree, Env env, + JCLambda lambda, ResultInfo resultInfo, + boolean speculative) { Env prevEnv = this.env; ResultInfo prevResult = this.resultInfo; + JCLambda prevLambda = this.currentLambda; + boolean prevSpeculative = this.speculative; try { this.env = env; this.resultInfo = resultInfo; + this.currentLambda = lambda; + this.speculative = speculative; tree.accept(this); if (tree == breakTree && resultInfo.checkContext.deferredAttrContext().mode == AttrMode.CHECK) { @@ -604,9 +629,20 @@ } finally { this.env = prevEnv; this.resultInfo = prevResult; + this.currentLambda = prevLambda; + this.speculative = prevSpeculative; } } + Type attribTree(JCTree tree, Env env, + JCLambda currentLambda, ResultInfo resultInfo) { + return attribTree(tree, env, currentLambda, resultInfo, speculative); + } + + Type attribTree(JCTree tree, Env env, ResultInfo resultInfo) { + return attribTree(tree, env, currentLambda, resultInfo, speculative); + } + Env copyEnv(Env env) { Env newEnv = env.dup(env.tree, env.info.dup(copyScope(env.info.scope))); @@ -633,35 +669,65 @@ /** Derived visitor method: attribute an expression tree. */ + public Type attribExpr(JCTree tree, Env env, Type pt, + JCLambda currentLambda, boolean speculative) { + return attribTree(tree, env, currentLambda, + new ResultInfo(VAL, !pt.hasTag(ERROR) ? pt : Type.noType), + speculative); + } + public Type attribExpr(JCTree tree, Env env, Type pt) { - return attribTree(tree, env, new ResultInfo(VAL, !pt.hasTag(ERROR) ? pt : Type.noType)); + return attribExpr(tree, env, pt, currentLambda, speculative); } /** Derived visitor method: attribute an expression tree with * no constraints on the computed type. */ public Type attribExpr(JCTree tree, Env env) { - return attribTree(tree, env, unknownExprInfo); + return attribTree(tree, env, currentLambda, + unknownExprInfo, speculative); } /** Derived visitor method: attribute a type tree. */ + public Type attribType(JCTree tree, Env env) { - Type result = attribType(tree, env, Type.noType); + Type result = attribType(tree, env, Type.noType, + currentLambda, speculative); + return result; + } + + public Type attribType(JCTree tree, Env env, + JCLambda currentLambda, boolean speculative) { + Type result = attribType(tree, env, Type.noType, + currentLambda, speculative); return result; } /** Derived visitor method: attribute a type tree. */ - Type attribType(JCTree tree, Env env, Type pt) { - Type result = attribTree(tree, env, new ResultInfo(TYP, pt)); + Type attribType(JCTree tree, Env env, Type pt, + JCLambda currentLambda, boolean speculative) { + Type result = attribTree(tree, env, currentLambda, + new ResultInfo(TYP, pt), speculative); return result; } /** Derived visitor method: attribute a statement or definition tree. */ + public Type attribStat(JCTree tree, Env env) { - return attribTree(tree, env, statInfo); + return attribTree(tree, env, currentLambda, statInfo, speculative); + } + + public Type attribStat(JCTree tree, JCLambda lambda, + Env env) { + return attribTree(tree, env, lambda, statInfo, speculative); + } + + public Type attribStat(JCTree tree, JCLambda lambda, + Env env, boolean speculative) { + return attribTree(tree, env, lambda, statInfo, speculative); } /** Attribute a list of expressions, returning a list of types. @@ -669,12 +735,25 @@ List attribExprs(List trees, Env env, Type pt) { ListBuffer ts = new ListBuffer<>(); for (List l = trees; l.nonEmpty(); l = l.tail) - ts.append(attribExpr(l.head, env, pt)); + ts.append(attribExpr(l.head, env, pt, currentLambda, speculative)); return ts.toList(); } /** Attribute a list of statements, returning nothing. */ + void attribStats(List trees, JCLambda lambda, + Env env, + boolean speculative) { + for (List l = trees; l.nonEmpty(); l = l.tail) + attribStat(l.head, lambda, env, speculative); + } + + void attribStats(List trees, JCLambda lambda, + Env env) { + for (List l = trees; l.nonEmpty(); l = l.tail) + attribStat(l.head, lambda, env); + } + void attribStats(List trees, Env env) { for (List l = trees; l.nonEmpty(); l = l.tail) attribStat(l.head, env); @@ -686,11 +765,12 @@ int kind = VAL; for (JCExpression arg : trees) { Type argtype; - if (allowPoly && deferredAttr.isDeferred(env, arg)) { - argtype = deferredAttr.new DeferredType(arg, env); + if (allowPoly && deferredAttr.isDeferred(env, arg, currentLambda)) { + argtype = deferredAttr.new DeferredType(arg, env, currentLambda, + annotate.noCreator); kind |= POLY; } else { - argtype = chk.checkNonVoid(arg, attribTree(arg, env, unknownAnyPolyInfo)); + argtype = chk.checkNonVoid(arg, attribTree(arg, env, currentLambda, unknownAnyPolyInfo, speculative)); } argtypes.append(argtype); } @@ -721,15 +801,19 @@ * @param typarams the type variables to enter * @param env the current environment */ - void attribTypeVariables(List typarams, Env env) { + void attribTypeVariables(List typarams, Env env, + JCLambda currentLambda, boolean speculative) { for (JCTypeParameter tvar : typarams) { TypeVar a = (TypeVar)tvar.type; a.tsym.flags_field |= UNATTRIBUTED; a.bound = Type.noType; if (!tvar.bounds.isEmpty()) { - List bounds = List.of(attribType(tvar.bounds.head, env)); + List bounds = + List.of(attribType(tvar.bounds.head, env, + currentLambda, speculative)); for (JCExpression bound : tvar.bounds.tail) - bounds = bounds.prepend(attribType(bound, env)); + bounds = bounds.prepend(attribType(bound, env, currentLambda, + speculative)); types.setBounds(a, bounds.reverse()); } else { // if no bounds are given, assume a single bound of @@ -747,13 +831,20 @@ * Attribute the type references in a list of annotations. */ void attribAnnotationTypes(List annotations, - Env env) { + Env env, + JCLambda currentLambda, + boolean speculative) { for (List al = annotations; al.nonEmpty(); al = al.tail) { JCAnnotation a = al.head; - attribType(a.annotationType, env); + attribType(a.annotationType, env, currentLambda, speculative); } } + void attribAnnotationTypes(List annotations, + Env env) { + attribAnnotationTypes(annotations, env, currentLambda, speculative); + } + /** * Attribute a "lazy constant value". * @param env The env for the const value @@ -761,15 +852,18 @@ * @param type The expected type, or null * @see VarSymbol#setLazyConstValue */ - public Object attribLazyConstantValue(Env env, - JCVariableDecl variable, - Type type) { + public Object attribLazyConstantValue(final Env env, + JCVariableDecl variable, + Type type, + JCLambda currentLambda, + boolean speculative) { DiagnosticPosition prevLintPos = deferredLintHandler.setPos(variable.pos()); try { - Type itype = attribExpr(variable.init, env, type); + Type itype = attribExpr(variable.init, env, type, + currentLambda, speculative); if (itype.constValue() != null) { return coerce(itype, type).constValue(); } else { @@ -792,10 +886,12 @@ Env env, boolean classExpected, boolean interfaceExpected, - boolean checkExtensible) { + boolean checkExtensible, + JCLambda currentLambda, + boolean speculative) { Type t = tree.type != null ? tree.type : - attribType(tree, env); + attribType(tree, env, currentLambda, speculative); return checkBase(t, tree, env, classExpected, interfaceExpected, checkExtensible); } Type checkBase(Type t, @@ -880,6 +976,7 @@ c.flags_field |= NOOUTERTHIS; } attribClass(tree.pos(), c); + result = tree.type = c.type; } } @@ -1017,10 +1114,6 @@ } } - // Attribute all type annotations in the body - annotate.annotateTypeLater(tree.body, localEnv, m, null); - annotate.flush(); - // Attribute method body. attribStat(tree.body, localEnv); } @@ -1034,21 +1127,25 @@ } } - public void visitVarDef(JCVariableDecl tree) { + public void visitVarDef(final JCVariableDecl tree) { // Local variables have not been entered yet, so we need to do it now: if (env.info.scope.owner.kind == MTH) { if (tree.sym != null) { // parameters have already been entered env.info.scope.enter(tree.sym); } else { - memberEnter.memberEnter(tree, env); - annotate.flush(); - } - } else { - if (tree.init != null) { - // Field initializer expression need to be entered. - annotate.annotateTypeLater(tree.init, env, tree.sym, tree.pos()); + Annotate.PositionCreator oldcreator = creator; + + if (creator == null) { + creator = annotate.localVarCreator(tree.pos); + } + + annotate.enterStart(); + memberEnter.memberEnter(tree, env, creator, + currentLambda, speculative); + annotate.enterDone(); annotate.flush(); + creator = oldcreator; } } @@ -1099,17 +1196,15 @@ // Block is a static or instance initializer; // let the owner of the environment be a freshly // created BLOCK-method. - Env localEnv = + final Env localEnv = env.dup(tree, env.info.dup(env.info.scope.dupUnshared())); localEnv.info.scope.owner = new MethodSymbol(tree.flags | BLOCK | env.info.scope.owner.flags() & STRICTFP, names.empty, null, env.info.scope.owner); - if ((tree.flags & STATIC) != 0) localEnv.info.staticLevel++; - // Attribute all type annotations in the block - annotate.annotateTypeLater(tree, localEnv, localEnv.info.scope.owner, null); - annotate.flush(); + if ((tree.flags & STATIC) != 0) localEnv.info.staticLevel++; + attribStats(tree.stats, localEnv); { // Store init and clinit type annotations with the ClassSymbol @@ -1122,8 +1217,6 @@ cs.appendInitTypeAttributes(tas); } } - - attribStats(tree.stats, localEnv); } else { // Create a new local environment with a local scope. Env localEnv = @@ -1346,7 +1439,10 @@ }; ResultInfo twrResult = new ResultInfo(VAL, syms.autoCloseableType, twrContext); if (resource.hasTag(VARDEF)) { + Annotate.PositionCreator oldcreator = creator; + creator = annotate.resourceVarCreator(tree.pos); attribStat(resource, tryEnv); + creator = oldcreator; twrResult.check(resource, resource.type); //check that resource type cannot throw InterruptedException @@ -1371,7 +1467,10 @@ Env catchEnv = localEnv.dup(c, localEnv.info.dup(localEnv.info.scope.dup())); try { + Annotate.PositionCreator oldcreator = creator; + creator = annotate.exceptionParamCreator(tree.pos); Type ctype = attribStat(c.param, catchEnv); + creator = oldcreator; if (TreeInfo.isMultiCatch(c)) { //multi-catch parameter is implicitly marked as final c.param.sym.flags_field |= FINAL | UNION; @@ -1477,17 +1576,22 @@ isBooleanOrNumeric(env, condTree.falsepart); case APPLY: JCMethodInvocation speculativeMethodTree = - (JCMethodInvocation)deferredAttr.attribSpeculative(tree, env, unknownExprInfo); + (JCMethodInvocation)deferredAttr.attribSpeculative(tree, env, unknownExprInfo, + currentLambda, annotate.noCreator); Type owntype = TreeInfo.symbol(speculativeMethodTree.meth).type.getReturnType(); return types.unboxedTypeOrType(owntype).isPrimitive(); case NEWCLASS: JCExpression className = removeClassParams.translate(((JCNewClass)tree).clazz); JCExpression speculativeNewClassTree = - (JCExpression)deferredAttr.attribSpeculative(className, env, unknownTypeInfo); + (JCExpression)deferredAttr.attribSpeculative(className, + env, + unknownTypeInfo, + currentLambda, + annotate.newObjCreator(tree.pos)); return types.unboxedTypeOrType(speculativeNewClassTree.type).isPrimitive(); default: - Type speculativeType = deferredAttr.attribSpeculative(tree, env, unknownExprInfo).type; + Type speculativeType = deferredAttr.attribSpeculative(tree, env, unknownExprInfo, currentLambda, annotate.noCreator).type; speculativeType = types.unboxedTypeOrType(speculativeType); return speculativeType.isPrimitive(); } @@ -1750,7 +1854,27 @@ // Attribute arguments, yielding list of argument types. attribArgs(tree.args, localEnv, argtypesBuf); argtypes = argtypesBuf.toList(); - typeargtypes = attribTypes(tree.typeargs, localEnv); + + // Attribute and annotate the type arguments + ListBuffer typeargtypesbuf = new ListBuffer<>(); + int i = 0; + + for (List l = tree.typeargs; + l.nonEmpty(); l = l.tail, i++) { + final JCExpression arg = l.head; + annotate.enterStart(); + typeargtypesbuf.append(attribType(arg, localEnv)); + annotate.annotateTypeLater(arg, localEnv, + localEnv.info.scope.owner, + tree.pos(), currentLambda, + annotate.constructorInvokeTypeArgCreator(i, tree.pos), + speculative); + annotate.enterDone(); + annotate.flush(); + } + + typeargtypes = + chk.checkRefTypes(tree.typeargs, typeargtypesbuf.toList()); // Variable `site' points to the class in which the called // constructor is defined. @@ -1823,7 +1947,26 @@ // Attribute the arguments, yielding list of argument types, ... int kind = attribArgs(tree.args, localEnv, argtypesBuf); argtypes = argtypesBuf.toList(); - typeargtypes = attribAnyTypes(tree.typeargs, localEnv); + + // Attribute and annotate the type arguments + ListBuffer typeargtypesbuf = new ListBuffer<>(); + int i = 0; + + for (List l = tree.typeargs; + l.nonEmpty(); l = l.tail, i++) { + final JCExpression arg = l.head; + annotate.enterStart(); + typeargtypesbuf.append(attribType(arg, localEnv)); + annotate.annotateTypeLater(arg, localEnv, + localEnv.info.scope.owner, + tree.pos(), currentLambda, + annotate.methodInvokeTypeArgCreator(i, tree.pos), + speculative); + annotate.flush(); + annotate.enterDone(); + } + + typeargtypes = typeargtypesbuf.toList(); // ... and attribute the method using as a prototype a methodtype // whose formal argument types is exactly the list of actual @@ -1848,6 +1991,7 @@ // current context. Also, capture the return type result = check(tree, capture(restype), VAL, resultInfo); } + chk.validate(tree.typeargs, localEnv); } //where @@ -1923,13 +2067,11 @@ annoclazzid = (JCAnnotatedType) clazzid; clazzid = annoclazzid.underlyingType; } + } else if (clazz.hasTag(ANNOTATED_TYPE)) { + annoclazzid = (JCAnnotatedType) clazz; + clazzid = annoclazzid.underlyingType; } else { - if (clazz.hasTag(ANNOTATED_TYPE)) { - annoclazzid = (JCAnnotatedType) clazz; - clazzid = annoclazzid.underlyingType; - } else { - clazzid = clazz; - } + clazzid = clazz; } JCExpression clazzid1 = clazzid; // The same in fully qualified form @@ -1952,11 +2094,12 @@ EndPosTable endPosTable = this.env.toplevel.endPositions; endPosTable.storeEnd(clazzid1, tree.getEndPosition(endPosTable)); - if (clazz.hasTag(ANNOTATED_TYPE)) { - JCAnnotatedType annoType = (JCAnnotatedType) clazz; - List annos = annoType.annotations; + if (annoclazzid != null) { + JCAnnotatedType annoType = annoclazzid; + List annos = annoclazzid.annotations; + + if (clazz.hasTag(TYPEAPPLY)) { - if (annoType.underlyingType.hasTag(TYPEAPPLY)) { clazzid1 = make.at(tree.pos). TypeApply(clazzid1, ((JCTypeApply) clazz).arguments); @@ -1973,12 +2116,19 @@ clazz = clazzid1; } + annotate.enterStart(); // Attribute clazz expression and store // symbol + type back into the attributed tree. Type clazztype = TreeInfo.isEnumInit(env.tree) ? attribIdentAsEnumType(env, (JCIdent)clazz) : attribType(clazz, env); + annotate.annotateTypeLater(clazz, env, env.info.scope.owner, + tree.pos(), currentLambda, + annotate.newObjCreator(tree.pos), + speculative); + annotate.enterDone(); + annotate.flush(); clazztype = chk.checkDiamond(tree, clazztype); chk.validate(clazz, localEnv); if (tree.encl != null) { @@ -2007,7 +2157,27 @@ ListBuffer argtypesBuf = new ListBuffer<>(); int pkind = attribArgs(tree.args, localEnv, argtypesBuf); List argtypes = argtypesBuf.toList(); - List typeargtypes = attribTypes(tree.typeargs, localEnv); + List typeargtypes; + + // Attribute and annotate the type arguments + ListBuffer typeargtypesbuf = new ListBuffer<>(); + int i = 0; + + for (List l = tree.typeargs; + l.nonEmpty(); l = l.tail, i++) { + final JCExpression arg = l.head; + annotate.enterStart(); + typeargtypesbuf.append(attribType(arg, localEnv)); + annotate.annotateTypeLater(arg, localEnv, + localEnv.info.scope.owner, + tree.pos(), currentLambda, + annotate.constructorInvokeTypeArgCreator(i, tree.pos), + speculative); + annotate.flush(); + annotate.enterDone(); + } + typeargtypes = + chk.checkRefTypes(tree.typeargs, typeargtypesbuf.toList()); // If we have made no mistakes in the class type... if (clazztype.hasTag(CLASS)) { @@ -2190,7 +2360,10 @@ ta.arguments = List.nil(); ResultInfo findDiamondResult = new ResultInfo(VAL, resultInfo.checkContext.inferenceContext().free(resultInfo.pt) ? Type.noType : pt()); - Type inferred = deferredAttr.attribSpeculative(tree, env, findDiamondResult).type; + Type inferred = deferredAttr.attribSpeculative(tree, env, + findDiamondResult, + currentLambda, + annotate.newObjCreator(tree.pos)).type; Type polyPt = allowPoly ? syms.objectType : clazztype; @@ -2252,8 +2425,19 @@ Type owntype = types.createErrorType(tree.type); Env localEnv = env.dup(tree); Type elemtype; + + for(List dim : tree.dimAnnotations) { + this.attribAnnotationTypes(dim, localEnv); + } + if (tree.elemtype != null) { + annotate.enterStart(); elemtype = attribType(tree.elemtype, localEnv); + annotate.annotateTypeLater(tree, env, env.info.scope.owner, tree.pos(), + currentLambda, annotate.newObjCreator(tree.pos), + speculative); + annotate.enterDone(); + annotate.flush(); chk.validate(tree.elemtype, localEnv); owntype = elemtype; for (List l = tree.dims; l.nonEmpty(); l = l.tail) { @@ -2274,6 +2458,7 @@ elemtype = types.createErrorType(pt()); } } + if (tree.elems != null) { attribExprs(tree.elems, localEnv, elemtype); owntype = new ArrayType(elemtype, syms.arrayClass, @@ -2312,7 +2497,14 @@ List explicitParamTypes = null; if (that.paramKind == JCLambda.ParameterKind.EXPLICIT) { //attribute lambda parameters - attribStats(that.params, localEnv); + int i = 0; + Annotate.PositionCreator oldcreator = creator; + for (List l = that.params; + l.nonEmpty(); l = l.tail, i++) { + creator = annotate.paramCreator(i); + attribStat(l.head, that, localEnv); + } + creator = oldcreator; explicitParamTypes = TreeInfo.types(that.params); } @@ -2368,7 +2560,7 @@ } //attribute lambda parameters - attribStats(that.params, localEnv); + attribStats(that.params, that, localEnv); if (arityMismatch) { resultInfo.checkContext.report(that, diags.fragment("incompatible.arg.types.in.lambda")); @@ -2393,10 +2585,10 @@ localEnv.info.returnResult = bodyResultInfo; if (that.getBodyKind() == JCLambda.BodyKind.EXPRESSION) { - attribTree(that.getBody(), localEnv, bodyResultInfo); + attribTree(that.getBody(), localEnv, that, bodyResultInfo); } else { JCBlock body = (JCBlock)that.body; - attribStats(body.stats, localEnv); + attribStats(body.stats, that, localEnv); } result = check(that, currentTarget, VAL, resultInfo); @@ -2668,6 +2860,8 @@ @Override public void visitReference(final JCMemberReference that) { + final boolean isConstructor = that.getName() == names.init; + if (pt().isErroneous() || (pt().hasTag(NONE) && pt() != Type.recoveryType)) { if (pt().hasTag(NONE)) { //method reference only allowed in assignment or method invocation/cast context @@ -2678,9 +2872,17 @@ } final Env localEnv = env.dup(that); try { + annotate.enterStart(); //attribute member reference qualifier - if this is a constructor //reference, the expected kind must be a type Type exprType = attribTree(that.expr, env, memberReferenceQualifierResult(that)); + final Annotate.PositionCreator creator = + isConstructor ? annotate.constructorRefCreator(that.pos) : + annotate.methodRefCreator(that.pos); + annotate.annotateTypeLater(that.expr, localEnv, env.info.scope.owner, that.pos(), + currentLambda, creator, speculative); + annotate.enterDone(); + annotate.flush(); if (that.getMode() == JCMemberReference.ReferenceMode.NEW) { exprType = chk.checkConstructorRefType(that.expr, exprType); @@ -2710,7 +2912,22 @@ //attrib type-arguments List typeargtypes = List.nil(); if (that.typeargs != null) { + annotate.enterStart(); typeargtypes = attribTypes(that.typeargs, localEnv); + + // Annotate type arguments + int i = 0; + for (List l = that.typeargs; + l.nonEmpty(); l = l.tail, i++) { + final Annotate.PositionCreator typeArgCreator = + isConstructor ? annotate.constructorRefTypeArgCreator(i, that.pos) : + annotate.methodRefTypeArgCreator(i, that.pos); + final JCExpression arg = l.head; + annotate.annotateTypeLater(arg, env, env.info.scope.owner, that.pos(), + currentLambda, typeArgCreator, speculative); + } + annotate.flush(); + annotate.enterDone(); } Type desc; @@ -3083,7 +3300,14 @@ } public void visitTypeCast(final JCTypeCast tree) { + annotate.enterStart(); Type clazztype = attribType(tree.clazz, env); + annotate.annotateTypeLater(tree.clazz, env, env.info.scope.owner, + tree.pos(), currentLambda, + annotate.castCreator(tree.pos), + speculative); + annotate.flush(); + annotate.enterDone(); chk.validate(tree.clazz, env, false); //a fresh environment is required for 292 inference to work properly --- //see Infer.instantiatePolymorphicSignatureInstance() @@ -3116,7 +3340,14 @@ public void visitTypeTest(JCInstanceOf tree) { Type exprtype = chk.checkNullOrRefType( tree.expr.pos(), attribExpr(tree.expr, env)); + annotate.enterStart(); Type clazztype = attribType(tree.clazz, env); + annotate.annotateTypeLater(tree.clazz, env, env.info.scope.owner, tree.pos(), + currentLambda, annotate.instanceOfCreator(tree.pos), + speculative); + annotate.flush(); + annotate.enterDone(); + if (!clazztype.hasTag(TYPEVAR)) { clazztype = chk.checkClassOrArrayType(tree.clazz.pos(), clazztype); } @@ -4076,8 +4307,13 @@ Assert.error("should be handled in Annotate"); } + /* This needs to be removed or otherwise changed, as it implicitly + * relies on the annotated types having previously been visited by + * Annotate.TypeAnnotate. + */ public void visitAnnotatedType(JCAnnotatedType tree) { - Type underlyingType = attribType(tree.getUnderlyingType(), env); + Type underlyingType = attribTree(tree.getUnderlyingType(), env, + resultInfo); this.attribAnnotationTypes(tree.annotations, env); annotateType(tree, tree.annotations); result = tree.type = underlyingType; @@ -4096,8 +4332,10 @@ public void run() { List compounds = fromAnnotations(annotations); Assert.check(annotations.size() == compounds.size()); - tree.type = tree.type.annotatedType(compounds); + if (!tree.type.hasTag(TypeTag.PACKAGE)) { + tree.type = tree.type.annotatedType(compounds); } + } }); } @@ -4348,13 +4586,6 @@ checkForSerial(c)) { checkSerialVersionUID(tree, c); } - if (allowTypeAnnos) { - // Correctly organize the postions of the type annotations - typeAnnotations.organizeTypeAnnotationsBodies(tree); - - // Check type annotations applicability rules - validateTypeAnnotations(tree, false); - } } // where boolean checkForSerial(ClassSymbol c) { @@ -4428,6 +4659,11 @@ return types.capture(type); } + /************************************** + * * + * This code is considered deprecated * + * * + **************************************/ public void validateTypeAnnotations(JCTree tree, boolean sigOnly) { tree.accept(new TypeAnnotationsValidator(sigOnly)); } @@ -4478,7 +4714,6 @@ } } public void visitVarDef(final JCVariableDecl tree) { - //System.err.println("validateTypeAnnotations.visitVarDef " + tree); if (tree.sym != null && tree.sym.type != null) validateAnnotatedType(tree.vartype, tree.sym.type); scan(tree.mods); @@ -4521,7 +4756,6 @@ super.visitNewArray(tree); } public void visitClassDef(JCClassDecl tree) { - //System.err.println("validateTypeAnnotations.visitClassDef " + tree); if (sigOnly) { scan(tree.mods); scan(tree.typarams); @@ -4550,7 +4784,6 @@ * can occur. */ private void validateAnnotatedType(final JCTree errtree, final Type type) { - //System.err.println("Attr.validateAnnotatedType: " + errtree + " type: " + type); if (type.isPrimitiveOrVoid()) { return; @@ -4590,13 +4823,13 @@ JCAnnotatedType at = (JCTree.JCAnnotatedType) enclTr; if (enclTy == null || enclTy.hasTag(NONE)) { if (at.getAnnotations().size() == 1) { - log.error(at.underlyingType.pos(), "cant.type.annotate.scoping.1", at.getAnnotations().head.attribute); + //log.error(at.underlyingType.pos(), "cant.type.annotate.scoping.1", at.getAnnotations().head.attribute); } else { ListBuffer comps = new ListBuffer<>(); for (JCAnnotation an : at.getAnnotations()) { comps.add(an.attribute); } - log.error(at.underlyingType.pos(), "cant.type.annotate.scoping", comps.toList()); + //log.error(at.underlyingType.pos(), "cant.type.annotate.scoping", comps.toList()); } repeat = false; } @@ -4647,6 +4880,8 @@ // empty annotations, if only declaration annotations were given. // This method will raise an error for such a type. for (JCAnnotation ai : annotations) { + Assert.checkNonNull(ai.type); + if (!ai.type.isErroneous() && typeAnnotations.annotationType(ai.attribute, sym) == TypeAnnotations.AnnotationType.DECLARATION) { log.error(ai.pos(), "annotation.type.not.applicable"); --- old/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java 2014-05-09 16:27:53.321262151 -0400 +++ new/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java 2014-05-09 16:27:53.223257992 -0400 @@ -25,6 +25,7 @@ package com.sun.tools.javac.comp; +import com.sun.source.tree.*; import com.sun.source.tree.LambdaExpressionTree.BodyKind; import com.sun.tools.javac.code.*; import com.sun.tools.javac.tree.*; @@ -76,6 +77,7 @@ final Types types; final Flow flow; final Names names; + final Annotate annotate; public static DeferredAttr instance(Context context) { DeferredAttr instance = context.get(deferredAttrKey); @@ -99,6 +101,7 @@ flow = Flow.instance(context); names = Names.instance(context); stuckTree = make.Ident(names.empty).setType(Type.stuckType); + annotate = Annotate.instance(context); emptyDeferredAttrContext = new DeferredAttrContext(AttrMode.CHECK, null, MethodResolutionPhase.BOX, infer.emptyContext, null, null) { @Override @@ -132,12 +135,19 @@ Env env; AttrMode mode; SpeculativeCache speculativeCache; + final JCLambda currLambda; + final Annotate.PositionCreator creator; - DeferredType(JCExpression tree, Env env) { + DeferredType(JCExpression tree, + Env env, + JCLambda currLambda, + Annotate.PositionCreator creator) { super(null, noAnnotations); this.tree = tree; this.env = attr.copyEnv(env); this.speculativeCache = new SpeculativeCache(); + this.currLambda = currLambda; + this.creator = creator; } @Override @@ -277,12 +287,16 @@ //Note: if a symbol is imported twice we might do two identical //speculative rounds... Assert.check(dt.mode == null || dt.mode == AttrMode.SPECULATIVE); - JCTree speculativeTree = attribSpeculative(dt.tree, dt.env, resultInfo); + JCTree speculativeTree = attribSpeculative(dt.tree, dt.env, + resultInfo, + dt.currLambda, + dt.creator); dt.speculativeCache.put(speculativeTree, resultInfo); return speculativeTree.type; case CHECK: Assert.check(dt.mode != null); - return attr.attribTree(dt.tree, dt.env, resultInfo); + return attr.attribTree(dt.tree, dt.env, dt.currLambda, + resultInfo, false); } Assert.error(); return null; @@ -359,7 +373,11 @@ * restored after type-checking. All diagnostics (but critical ones) are * disabled during speculative type-checking. */ - JCTree attribSpeculative(JCTree tree, Env env, ResultInfo resultInfo) { + JCTree attribSpeculative(JCTree tree, + Env env, + ResultInfo resultInfo, + JCLambda currLambda, + Annotate.PositionCreator creator) { final JCTree newTree = new TreeCopier<>(make).copy(tree); Env speculativeEnv = env.dup(newTree, env.info.dup(env.info.scope.dupUnshared())); speculativeEnv.info.scope.owner = env.info.scope.owner; @@ -384,7 +402,12 @@ } }); try { - attr.attribTree(newTree, speculativeEnv, resultInfo); + attr.attribTree(newTree, speculativeEnv, currLambda, + resultInfo, true); + annotate.typeAnnotateExprLater(newTree, speculativeEnv, + speculativeEnv.info.scope.owner, + newTree.pos(), currLambda, + creator); unenterScanner.scan(newTree); return newTree; } finally { @@ -598,11 +621,13 @@ ResultInfo resultInfo; InferenceContext inferenceContext; Env env; + JCLambda currLambda; public Type complete(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) { this.resultInfo = resultInfo; this.inferenceContext = deferredAttrContext.inferenceContext; this.env = dt.env; + this.currLambda = dt.currLambda; dt.tree.accept(this); dt.speculativeCache.put(stuckTree, resultInfo); return Type.noType; @@ -681,7 +706,11 @@ tmpParams = tmpParams.tail; } - attr.attribStats(newTree.params, localEnv); + int i = 0; + for (List l = newTree.params; + l.nonEmpty(); l = l.tail, i++) { + attr.attribStat(l.head, tree, localEnv, true); + } /* set pt to Type.noType to avoid generating any bound * which may happen if lambda's return type is an @@ -702,7 +731,7 @@ * * while (true) {...} */ - attr.attribStats(body.stats, localEnv); + attr.attribStats(body.stats, tree, localEnv, true); attr.preFlow(newTree); /* make an aliveness / reachability analysis of the lambda @@ -741,8 +770,12 @@ checkContext.report(null, ex.getDiagnostic()); } Env localEnv = env.dup(tree); - JCExpression exprTree = (JCExpression)attribSpeculative(tree.getQualifierExpression(), localEnv, - attr.memberReferenceQualifierResult(tree)); + JCExpression exprTree = + (JCExpression)attribSpeculative(tree.getQualifierExpression(), + localEnv, + attr.memberReferenceQualifierResult(tree), + currLambda, + annotate.methodRefCreator(tree.pos)); ListBuffer argtypes = new ListBuffer<>(); for (Type t : types.findDescriptorType(pt).getParameterTypes()) { argtypes.append(Type.noType); @@ -1084,8 +1117,10 @@ /** * Does the argument expression {@code expr} need speculative type-checking? */ - boolean isDeferred(Env env, JCExpression expr) { - DeferredChecker dc = new DeferredChecker(env); + boolean isDeferred(Env env, + JCExpression expr, + JCLambda currLambda) { + DeferredChecker dc = new DeferredChecker(env, currLambda); dc.scan(expr); return dc.result.isPoly(); } @@ -1146,12 +1181,15 @@ */ final class DeferredChecker extends FilterScanner { + private final JCLambda currLambda; Env env; ArgumentExpressionKind result; - public DeferredChecker(Env env) { + public DeferredChecker(Env env, + JCLambda currLambda) { super(deferredCheckerTags); this.env = env; + this.currLambda = currLambda; } @Override @@ -1164,8 +1202,12 @@ public void visitReference(JCMemberReference tree) { //perform arity-based check Env localEnv = env.dup(tree); - JCExpression exprTree = (JCExpression)attribSpeculative(tree.getQualifierExpression(), localEnv, - attr.memberReferenceQualifierResult(tree)); + JCExpression exprTree = + (JCExpression)attribSpeculative(tree.getQualifierExpression(), + localEnv, + attr.memberReferenceQualifierResult(tree), + currLambda, + annotate.methodRefCreator(tree.pos)); JCMemberReference mref2 = new TreeCopier(make).copy(tree); mref2.expr = exprTree; Symbol res = @@ -1232,7 +1274,8 @@ } Type site = rec != null ? - attribSpeculative(rec, env, attr.unknownTypeExprInfo).type : + attribSpeculative(rec, env, attr.unknownTypeExprInfo, + currLambda, annotate.noCreator).type : env.enclClass.sym.type; while (site.hasTag(TYPEVAR)) { --- old/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java 2014-05-09 16:27:53.658276452 -0400 +++ new/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java 2014-05-09 16:27:53.560272294 -0400 @@ -31,6 +31,7 @@ import java.util.Map; import java.util.Set; +import javax.lang.model.type.TypeKind; import javax.tools.JavaFileObject; import com.sun.tools.javac.code.*; @@ -41,6 +42,7 @@ import com.sun.tools.javac.code.Type.*; import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.tree.JCTree.*; +import com.sun.tools.javac.code.TypeAnnotationPosition.*; import static com.sun.tools.javac.code.Flags.*; import static com.sun.tools.javac.code.Flags.ANNOTATION; @@ -113,6 +115,7 @@ deferredLintHandler = DeferredLintHandler.instance(context); lint = Lint.instance(context); allowTypeAnnos = source.allowTypeAnnotations(); + speculative = false; } /** Switch: support type annotations. @@ -135,6 +138,11 @@ */ boolean completionEnabled = true; + /** The creator that will be used for any varDef's we visit. */ + Annotate.PositionCreator creator; + + boolean speculative; + /* ---------- Processing import clauses ---------------- */ @@ -361,32 +369,75 @@ * @param thrown The method's thrown exceptions. * @param env The method's (local) environment. */ - Type signature(MethodSymbol msym, - List typarams, - List params, - JCTree res, - JCVariableDecl recvparam, - List thrown, - Env env) { + Type signature(final MethodSymbol msym, + final List typarams, + final List params, + final JCTree res, + final JCVariableDecl recvparam, + final List thrown, + final Env env, + final List declAnnos, + final DiagnosticPosition deferPos) { + int i; // Enter and attribute type parameters. List tvars = enter.classEnter(typarams, env); - attr.attribTypeVariables(typarams, env); + attr.attribTypeVariables(typarams, env, currentLambda, speculative); + + // Handle type annotations on type parameters + i = 0; + for (List l = typarams; l.nonEmpty(); + l = l.tail, i++) { + final JCTypeParameter param = l.head; + annotate.annotateTypeLater(param, env, msym, deferPos, currentLambda, + annotate.methodTypeParamCreator(i), + speculative); + + int j = 0; + for (List bounds = param.bounds; + bounds.nonEmpty(); bounds = bounds.tail, j++) { + annotate.annotateTypeLater(bounds.head, env, msym, deferPos, currentLambda, + annotate.methodTypeParamBoundCreator(param, i, j), + speculative); + } + } // Enter and attribute value parameters. ListBuffer argbuf = new ListBuffer<>(); - for (List l = params; l.nonEmpty(); l = l.tail) { - memberEnter(l.head, env); + i = 0; + for (List l = params; l.nonEmpty(); l = l.tail, i++) { + memberEnter(l.head, env, annotate.paramCreator(i)); argbuf.append(l.head.vartype.type); } // Attribute result type, if one is given. - Type restype = res == null ? syms.voidType : attr.attribType(res, env); + Type restype; + + if (res != null) { + restype = attr.attribType(res, env, currentLambda, speculative); + annotate.annotateTypeLater(res, declAnnos, env, msym, deferPos, + currentLambda, annotate.returnCreator, + speculative); + } else { + // For constructors, synthesize a type annotation position + List typepath = List.nil(); + Type encl = msym.owner.type.getEnclosingType(); + while (encl != null && encl.getKind() != TypeKind.NONE && + encl.getKind() != TypeKind.ERROR) { + typepath = typepath.prepend(TypePathEntry.INNER_TYPE); + encl = encl.getEnclosingType(); + } + TypeAnnotationPosition tapos = + TypeAnnotationPosition.methodReturn(typepath, currentLambda, -1); + annotate.annotateLater(declAnnos, env, msym, deferPos, tapos); + restype = syms.voidType; + } + // Attribute receiver type, if one is given. Type recvtype; if (recvparam!=null) { - memberEnter(recvparam, env); + memberEnter(recvparam, env, annotate.receiverCreator); recvtype = recvparam.vartype.type; } else { recvtype = null; @@ -394,8 +445,13 @@ // Attribute thrown exceptions. ListBuffer thrownbuf = new ListBuffer<>(); - for (List l = thrown; l.nonEmpty(); l = l.tail) { - Type exc = attr.attribType(l.head, env); + i = 0; + for (List l = thrown; l.nonEmpty(); l = l.tail, i++) { + Type exc = attr.attribType(l.head, env, currentLambda, speculative); + annotate.annotateTypeLater(l.head, env, msym, deferPos, + currentLambda, + annotate.throwCreator(i), + speculative); if (!exc.hasTag(TYPEVAR)) { exc = chk.checkClassType(l.head.pos(), exc); } else if (exc.tsym.owner == msym) { @@ -421,36 +477,75 @@ */ protected Env env; + protected JCLambda currentLambda; + /** Enter field and method definitions and process import * clauses, catching any completion failure exceptions. */ - protected void memberEnter(JCTree tree, Env env) { + protected void memberEnter(JCTree tree, Env env, + Annotate.PositionCreator creator, + JCLambda lambda, + boolean speculative) { Env prevEnv = this.env; + Annotate.PositionCreator prevCreator = this.creator; + JCLambda prevLambda = this.currentLambda; + boolean prevSpeculative = this.speculative; try { this.env = env; + this.creator = creator; + this.currentLambda = lambda; + this.speculative = speculative; tree.accept(this); } catch (CompletionFailure ex) { chk.completionError(tree.pos(), ex); } finally { + this.creator = prevCreator; this.env = prevEnv; + this.currentLambda = prevLambda; + this.speculative = prevSpeculative; } } + protected void memberEnter(JCTree tree, + Env env, + Annotate.PositionCreator creator) { + memberEnter(tree, env, creator, currentLambda, speculative); + } + + protected void memberEnter(JCTree tree, Env env) { + memberEnter(tree, env, annotate.noCreator, currentLambda, speculative); + } + /** Enter members from a list of trees. */ - void memberEnter(List trees, Env env) { + void memberEnter(List trees, + Env env, + Annotate.PositionCreator creator, + JCLambda lambda, + boolean speculative) { for (List l = trees; l.nonEmpty(); l = l.tail) - memberEnter(l.head, env); + memberEnter(l.head, env, creator, lambda, speculative); + } + + void memberEnter(List trees, + Env env, + Annotate.PositionCreator creator) { + memberEnter(trees, env, creator, currentLambda, speculative); + } + + void memberEnter(List trees, + Env env) { + memberEnter(trees, env, annotate.noCreator, currentLambda, speculative); } /** Enter members for a class. */ - void finishClass(JCClassDecl tree, Env env) { + void finishClass(final JCClassDecl tree, final Env env) { if ((tree.mods.flags & Flags.ENUM) != 0 && (types.supertype(tree.sym.type).tsym.flags() & Flags.ENUM) == 0) { addEnumMembers(tree, env); } - memberEnter(tree.defs, env); + memberEnter(tree.defs, env, annotate.fieldCreator); } /** Add the implicit members for an enum type @@ -525,7 +620,7 @@ } } // process package annotations - annotate.annotateLater(tree.annotations, env, env.toplevel.packge, null); + annotate.annotateLater(tree.annotations, env, env.toplevel.packge); } // process the non-static imports and the static imports of types. @@ -537,7 +632,8 @@ // effects of other imports in Resolve.findGlobalType Env localEnv = env.dup(tree); - TypeSymbol p = attr.attribImportQualifier(tree, localEnv).tsym; + TypeSymbol p = attr.attribImportQualifier(tree, localEnv, currentLambda, + speculative).tsym; if (name == names.asterisk) { // Import on demand. chk.checkCanonical(imp.selected); @@ -578,8 +674,8 @@ // Compute the method type m.type = signature(m, tree.typarams, tree.params, tree.restype, tree.recvparam, - tree.thrown, - localEnv); + tree.thrown, localEnv, + tree.mods.annotations, tree.pos()); } finally { deferredLintHandler.setPos(prevLintPos); } @@ -606,13 +702,9 @@ enclScope.enter(m); } - annotate.annotateLater(tree.mods.annotations, localEnv, m, tree.pos()); - // Visit the signature of the method. Note that - // TypeAnnotate doesn't descend into the body. - annotate.annotateTypeLater(tree, localEnv, m, tree.pos()); - if (tree.defaultValue != null) - annotateDefaultValueLater(tree.defaultValue, localEnv, m); + annotateDefaultValueLater(tree.defaultValue, localEnv, + m, annotate.noCreator); } finally { annotate.enterDone(); } @@ -649,7 +741,8 @@ if (TreeInfo.isEnumInit(tree)) { attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype); } else { - attr.attribType(tree.vartype, localEnv); + attr.attribType(tree.vartype, localEnv, + currentLambda, speculative); if (tree.nameexpr != null) { attr.attribExpr(tree.nameexpr, localEnv); MethodSymbol m = localEnv.enclMethod.sym; @@ -692,15 +785,17 @@ needsLazyConstValue(tree.init)) { Env initEnv = getInitEnv(tree, env); initEnv.info.enclVar = v; - v.setLazyConstValue(initEnv(tree, initEnv), attr, tree); + v.setLazyConstValue(initEnv(tree, initEnv), attr, tree, + currentLambda, speculative); } } if (chk.checkUnique(tree.pos(), v, enclScope)) { chk.checkTransparentVar(tree.pos(), v, enclScope); enclScope.enter(v); } - annotate.annotateLater(tree.mods.annotations, localEnv, v, tree.pos()); - annotate.annotateTypeLater(tree.vartype, env, v, tree.pos()); + annotate.annotateTypeLater(tree.vartype, tree.mods.annotations, + localEnv, v, tree.pos(), + currentLambda, creator, speculative); v.pos = tree.pos; } finally { annotate.enterDone(); @@ -831,7 +926,7 @@ // To prevent deep recursion, suppress completion of some // types. completionEnabled = false; - return attr.attribType(tree, env); + return attr.attribType(tree, env, currentLambda, speculative); } finally { completionEnabled = true; } @@ -853,7 +948,8 @@ /** Queue processing of an attribute default value. */ void annotateDefaultValueLater(final JCExpression defaultValue, final Env localEnv, - final MethodSymbol m) { + final MethodSymbol m, + final Annotate.PositionCreator creator) { annotate.normal(new Annotate.Worker() { @Override public String toString() { @@ -864,8 +960,9 @@ @Override public void run() { JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile); + final TypeAnnotationPosition position = creator.create(); try { - enterDefaultValue(defaultValue, localEnv, m); + enterDefaultValue(defaultValue, localEnv, m, position); } finally { log.useSource(prev); } @@ -889,10 +986,12 @@ /** Enter a default value for an attribute method. */ private void enterDefaultValue(final JCExpression defaultValue, final Env localEnv, - final MethodSymbol m) { + final MethodSymbol m, + final TypeAnnotationPosition position) { m.defaultValue = annotate.enterAttributeValue(m.type.getReturnType(), defaultValue, - localEnv); + localEnv, + position); } /* ******************************************************************** @@ -911,6 +1010,7 @@ return; } + int i; ClassSymbol c = (ClassSymbol)sym; ClassType ct = (ClassType)c.type; Env env = enter.typeEnvs.get(c); @@ -940,22 +1040,26 @@ // create an environment for evaluating the base clauses Env baseEnv = baseEnv(tree, env); - if (tree.extending != null) - annotate.annotateTypeLater(tree.extending, baseEnv, sym, tree.pos()); - for (JCExpression impl : tree.implementing) - annotate.annotateTypeLater(impl, baseEnv, sym, tree.pos()); - annotate.flush(); - // Determine supertype. - Type supertype = - (tree.extending != null) - ? attr.attribBase(tree.extending, baseEnv, true, false, true) - : ((tree.mods.flags & Flags.ENUM) != 0) + Type supertype; + + if (tree.extending != null) { + supertype = attr.attribBase(tree.extending, baseEnv, + true, false, true, currentLambda, + speculative); + annotate.annotateTypeLater(tree.extending, baseEnv, sym, + tree.pos(), currentLambda, + annotate.extendsCreator, + speculative); + } else { + supertype = ((tree.mods.flags & Flags.ENUM) != 0) ? attr.attribBase(enumBase(tree.pos, c), baseEnv, - true, false, false) + true, false, false, currentLambda, + speculative) : (c.fullname == names.java_lang_Object) ? Type.noType : syms.objectType; + } ct.supertype_field = modelMissingTypes(supertype, tree.extending, false); // Determine interfaces. @@ -963,18 +1067,26 @@ ListBuffer all_interfaces = null; // lazy init Set interfaceSet = new HashSet<>(); List interfaceTrees = tree.implementing; + i = 0; for (JCExpression iface : interfaceTrees) { - Type i = attr.attribBase(iface, baseEnv, false, true, true); - if (i.hasTag(CLASS)) { - interfaces.append(i); - if (all_interfaces != null) all_interfaces.append(i); - chk.checkNotRepeated(iface.pos(), types.erasure(i), interfaceSet); + Type it = attr.attribBase(iface, baseEnv, false, true, true, + currentLambda, speculative); + if (it.hasTag(CLASS)) { + interfaces.append(it); + if (all_interfaces != null) all_interfaces.append(it); + chk.checkNotRepeated(iface.pos(), types.erasure(it), interfaceSet); } else { if (all_interfaces == null) all_interfaces = new ListBuffer().appendList(interfaces); - all_interfaces.append(modelMissingTypes(i, iface, true)); + all_interfaces.append(modelMissingTypes(it, iface, true)); + } + annotate.annotateTypeLater(iface, baseEnv, sym, tree.pos(), + currentLambda, annotate.implementsCreator(i++), + speculative); } + annotate.flush(); + if ((c.flags_field & ANNOTATION) != 0) { ct.interfaces_field = List.of(syms.annotationType); ct.all_interfaces_field = ct.interfaces_field; @@ -1001,7 +1113,8 @@ // In general, we cannot fully process annotations yet, but we // can attribute the annotation types and then check to see if the // @Deprecated annotation is present. - attr.attribAnnotationTypes(tree.mods.annotations, baseEnv); + attr.attribAnnotationTypes(tree.mods.annotations, baseEnv, + currentLambda, speculative); if (hasDeprecatedAnnotation(tree.mods.annotations)) c.flags_field |= DEPRECATED; annotate.annotateLater(tree.mods.annotations, baseEnv, c, tree.pos()); @@ -1009,10 +1122,28 @@ chk.checkNonCyclicDecl(tree); - attr.attribTypeVariables(tree.typarams, baseEnv); + attr.attribTypeVariables(tree.typarams, baseEnv, + currentLambda, speculative); // Do this here, where we have the symbol. - for (JCTypeParameter tp : tree.typarams) - annotate.annotateTypeLater(tp, baseEnv, sym, tree.pos()); + i = 0; + for (List l = tree.typarams; l.nonEmpty(); + l = l.tail, i++) { + final JCTypeParameter typaram = l.head; + annotate.annotateTypeLater(typaram, baseEnv, sym, tree.pos(), + currentLambda, annotate.typeParamCreator(i), + speculative); + + int j = 0; + for(List b = typaram.bounds; b.nonEmpty(); + b = b.tail, j++) { + final JCExpression bound = b.head; + annotate.annotateTypeLater(bound, baseEnv, sym, + tree.pos(), currentLambda, + annotate.typeParamBoundCreator(typaram, i, j), + speculative); + } + + } // Add default constructor if needed. if ((c.flags() & INTERFACE) == 0 && @@ -1093,7 +1224,8 @@ Env toFinish = halfcompleted.next(); finish(toFinish); if (allowTypeAnnos) { - typeAnnotations.organizeTypeAnnotationsSignatures(toFinish, (JCClassDecl)toFinish.tree); + // Note: This call is slated for removal in + // the next patch typeAnnotations.validateTypeAnnotationsSignatures(toFinish, (JCClassDecl)toFinish.tree); } } --- old/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java 2014-05-09 16:27:54.007291261 -0400 +++ new/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java 2014-05-09 16:27:53.905286934 -0400 @@ -1673,8 +1673,6 @@ return TypeAnnotationPosition.methodReturn(readTypePath()); case FIELD: return TypeAnnotationPosition.field(readTypePath()); - case UNKNOWN: - throw new AssertionError("jvm.ClassReader: UNKNOWN target type should never occur!"); default: throw new AssertionError("jvm.ClassReader: Unknown target type for position: " + type); } --- old/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java 2014-05-09 16:27:54.357306111 -0400 +++ new/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java 2014-05-09 16:27:54.258301911 -0400 @@ -768,25 +768,13 @@ ListBuffer invisibles = new ListBuffer<>(); for (Attribute.TypeCompound tc : typeAnnos) { - if (tc.hasUnknownPosition()) { - boolean fixed = tc.tryFixPosition(); - - // Could we fix it? - if (!fixed) { - // This happens for nested types like @A Outer. @B Inner. - // For method parameters we get the annotation twice! Once with - // a valid position, once unknown. - // TODO: find a cleaner solution. - PrintWriter pw = log.getWriter(Log.WriterKind.ERROR); - pw.println("ClassWriter: Position UNKNOWN in type annotation: " + tc); - continue; - } - } - - if (tc.position.type.isLocal() != inCode) + Assert.checkNonNull(tc.position); + if (tc.position.type.isLocal() != inCode) { continue; - if (!tc.position.emitToClassfile()) + } + if (!tc.position.emitToClassfile()) { continue; + } switch (types.getRetention(tc)) { case SOURCE: break; case CLASS: invisibles.append(tc); break; @@ -967,8 +955,6 @@ case METHOD_RETURN: case FIELD: break; - case UNKNOWN: - throw new AssertionError("jvm.ClassWriter: UNKNOWN target type should never occur!"); default: throw new AssertionError("jvm.ClassWriter: Unknown target type for position: " + p); } --- old/src/share/classes/com/sun/tools/javac/jvm/Gen.java 2014-05-09 16:27:54.874327991 -0400 +++ new/src/share/classes/com/sun/tools/javac/jvm/Gen.java 2014-05-09 16:27:54.775323788 -0400 @@ -557,7 +557,6 @@ ListBuffer fieldTAs = new ListBuffer<>(); ListBuffer nonfieldTAs = new ListBuffer<>(); for (TypeCompound ta : tas) { - Assert.check(ta.getPosition().type != TargetType.UNKNOWN); if (ta.getPosition().type == TargetType.FIELD) { fieldTAs.add(ta); } else { @@ -1932,10 +1931,7 @@ || code.meth.getKind() == javax.lang.model.element.ElementKind.STATIC_INIT; for (Attribute.TypeCompound ta : meth.getRawTypeAttributes()) { - if (ta.hasUnknownPosition()) - ta.tryFixPosition(); - - if (ta.position.matchesPos(treePos)) + if (ta.position != null && ta.position.matchesPos(treePos)) ta.position.updatePosOffset(code.cp); } @@ -1943,10 +1939,7 @@ return; for (Attribute.TypeCompound ta : meth.owner.getRawTypeAttributes()) { - if (ta.hasUnknownPosition()) - ta.tryFixPosition(); - - if (ta.position.matchesPos(treePos)) + if (ta.position != null && ta.position.matchesPos(treePos)) ta.position.updatePosOffset(code.cp); } @@ -1956,10 +1949,7 @@ continue; for (Attribute.TypeCompound ta : s.getRawTypeAttributes()) { - if (ta.hasUnknownPosition()) - ta.tryFixPosition(); - - if (ta.position.matchesPos(treePos)) + if (ta.position != null && ta.position.matchesPos(treePos)) ta.position.updatePosOffset(code.cp); } } @@ -2331,8 +2321,8 @@ } public void visitTypeTest(JCInstanceOf tree) { - setTypeAnnotationPositions(tree.pos); genExpr(tree.expr, tree.expr.type).load(); + setTypeAnnotationPositions(tree.pos); code.emitop2(instanceof_, makeRef(tree.pos(), tree.clazz.type)); result = items.makeStackItem(syms.booleanType); } --- old/src/share/classes/com/sun/tools/javac/parser/JavacParser.java 2014-05-09 16:27:55.238343430 -0400 +++ new/src/share/classes/com/sun/tools/javac/parser/JavacParser.java 2014-05-09 16:27:55.138339186 -0400 @@ -1187,7 +1187,7 @@ // Type annotations on class literals no longer legal switch (expr.getTag()) { case REFERENCE: { - JCMemberReference mref = (JCMemberReference) expr; + JCMemberReference mref = (JCMemberReference) expr.setPos(pos); mref.expr = toP(F.at(pos).AnnotatedType(typeAnnos, mref.expr)); t = mref; break; --- old/test/tools/javac/annotations/typeAnnotations/TargetTypes.java 2014-05-09 16:27:55.649360849 -0400 +++ new/test/tools/javac/annotations/typeAnnotations/TargetTypes.java 2014-05-09 16:27:55.550356650 -0400 @@ -35,9 +35,41 @@ * @compile TargetTypes.java */ -@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) -@Retention(RetentionPolicy.RUNTIME) -@interface A {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface A {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface B {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface C {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface D {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface E {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface F {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface G {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface H {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface I {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface J {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface K {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface L {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface M {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface N {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface O {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface P {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface Q {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface R {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface S {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface U {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface V {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface W {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface X {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface Y {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface Z {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AA {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AB {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AC {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AD {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AE {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AF {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AG {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AH {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AI {} +@Target({TYPE_USE, TYPE_PARAMETER, TYPE}) @Retention(RetentionPolicy.RUNTIME) @interface AJ {} /** wildcard bound */ class T0x1C { @@ -46,75 +78,75 @@ /** wildcard bound generic/array */ class T0x1D { - void m0x1D(List> lst) {} + void m0x1D(List> lst) {} } /** typecast */ class T0x00 { void m0x00(Long l1) { - Object l2 = (@A Long) l1; + Object l2 = (@C Long) l1; } } /** typecast generic/array */ class T0x01 { void m0x01(List list) { - List l = (List<@A T>) list; + List l = (List<@D T>) list; } } /** instanceof */ class T0x02 { boolean m0x02(String s) { - return (s instanceof @A String); + return (s instanceof @E String); } } /** object creation (new) */ class T0x04 { void m0x04() { - new @A ArrayList(); + new @F ArrayList(); } } /** local variable */ class T0x08 { void m0x08() { - @A String s = null; + @G String s = null; } } /** method parameter generic/array */ class T0x0D { - void m0x0D(HashMap<@A Object, List<@A List<@A Class>>> s1) {} + void m0x0D(HashMap<@H Object, List<@I List<@J Class>>> s1) {} } /** method receiver */ class T0x06 { - void m0x06(@A T0x06 this) {} + void m0x06(@K T0x06 this) {} } /** method return type generic/array */ class T0x0B { - Class<@A Object> m0x0B() { return null; } + Class<@L Object> m0x0B() { return null; } } /** field generic/array */ class T0x0F { - HashMap<@A Object, @A Object> c1; + HashMap<@M Object, @N Object> c1; } /** method type parameter */ class T0x20 { - <@A T, @A U> void m0x20() {} + <@O T, @P U> void m0x20() {} } /** class type parameter */ -class T0x22<@A T, @A U> { +class T0x22<@Q T, @R U> { } /** class type parameter bound */ -class T0x10 { +class T0x10 { } /** method type parameter bound */ @@ -123,43 +155,43 @@ } /** class type parameter bound generic/array */ -class T0x11> { +class T0x11> { } /** method type parameter bound generic/array */ class T0x13 { - static > T m0x13() { + static > T m0x13() { return null; } } /** class extends/implements generic/array */ -class T0x15 extends ArrayList<@A T> { +class T0x15 extends ArrayList<@W T> { } /** type test (instanceof) generic/array */ class T0x03 { void m0x03(T typeObj, Object obj) { - boolean ok = obj instanceof String @A []; + boolean ok = obj instanceof String @X []; } } /** object creation (new) generic/array */ class T0x05 { void m0x05() { - new ArrayList<@A T>(); + new ArrayList<@Y T>(); } } /** local variable generic/array */ class T0x09 { void g() { - List<@A String> l = null; + List<@Z String> l = null; } void a() { - String @A [] as = null; + String @AA [] as = null; } } @@ -168,14 +200,14 @@ T0x19() {} void g() { - new > T0x19(); + new > T0x19(); } } /** type argument in method call generic/array */ class T0x1B { void m0x1B() { - Collections.emptyList(); + Collections.emptyList(); } } @@ -184,7 +216,7 @@ T0x18() {} void m() { - new <@A Integer> T0x18(); + new <@AD Integer> T0x18(); } } @@ -192,15 +224,15 @@ class T0x1A { public static T m() { return null; } static void m0x1A() { - T0x1A.<@A Integer, @A Short>m(); + T0x1A.<@AE Integer, @AF Short>m(); } } /** class extends/implements */ -class T0x14 extends @A Object implements @A Serializable, @A Cloneable { +class T0x14 extends @AG Object implements @AH Serializable, @AI Cloneable { } /** exception type in throws */ class T0x16 { - void m0x16() throws @A Exception {} + void m0x16() throws @AJ Exception {} } --- old/test/tools/javac/annotations/typeAnnotations/TypeParameterTarget.java 2014-05-09 16:27:56.028376907 -0400 +++ new/test/tools/javac/annotations/typeAnnotations/TypeParameterTarget.java 2014-05-09 16:27:55.927372622 -0400 @@ -26,7 +26,7 @@ * @bug 6843077 8006775 * @summary check that type annotations may appear on all type parameter * @author Mahmood Ali - * @compile TypeParameterTarget.java + * @compile -doe TypeParameterTarget.java */ import java.lang.annotation.Target; --- old/test/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java 2014-05-09 16:27:56.405392895 -0400 +++ new/test/tools/javac/annotations/typeAnnotations/classfile/ClassfileTestHelper.java 2014-05-09 16:27:56.306388693 -0400 @@ -36,8 +36,8 @@ //Makes debugging much easier. Set to 'false' for less output. public Boolean verbose = true; - void println(String msg) { if (verbose) System.out.println(msg); } - void print(String msg) { if (verbose) System.out.print(msg); } + void println(String msg) { if (verbose) System.err.println(msg); } + void print(String msg) { if (verbose) System.err.print(msg); } File writeTestFile(String fname, String source) throws IOException { File f = new File(fname); --- old/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotatePackages.out 2014-05-09 16:27:56.748407449 -0400 +++ new/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotatePackages.out 2014-05-09 16:27:56.647403164 -0400 @@ -1,5 +1,5 @@ -CantAnnotatePackages.java:19:14: compiler.err.cant.resolve.location: kindname.class, java, , , (compiler.misc.location: kindname.class, CantAnnotatePackages, null) -CantAnnotatePackages.java:20:9: compiler.err.cant.resolve.location: kindname.class, lang, , , (compiler.misc.location: kindname.package, java, null) -CantAnnotatePackages.java:21:14: compiler.err.cant.resolve.location: kindname.class, lang, , , (compiler.misc.location: kindname.package, java, null) -CantAnnotatePackages.java:14:18: compiler.err.cant.type.annotate.scoping.1: @TA -4 errors \ No newline at end of file +CantAnnotatePackages.java:14:13: compiler.err.cant.type.annotate.scoping.1: @TA +CantAnnotatePackages.java:19:18: compiler.err.cant.type.annotate.scoping.1: @TA +CantAnnotatePackages.java:20:19: compiler.err.cant.type.annotate.scoping.1: @TA +CantAnnotatePackages.java:21:24: compiler.err.cant.type.annotate.scoping.1: @TA +4 errors --- old/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateScoping.out 2014-05-09 16:27:57.085421744 -0400 +++ new/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateScoping.out 2014-05-09 16:27:56.985417500 -0400 @@ -1,12 +1,14 @@ -CantAnnotateScoping.java:61:9: compiler.err.cant.resolve.location: kindname.class, lang, , , (compiler.misc.location: kindname.package, java, null) -CantAnnotateScoping.java:66:9: compiler.err.cant.resolve.location: kindname.class, XXX, , , (compiler.misc.location: kindname.package, java, null) -CantAnnotateScoping.java:70:9: compiler.err.cant.resolve.location: kindname.class, lang, , , (compiler.misc.location: kindname.package, java, null) +CantAnnotateScoping.java:66:18: compiler.err.doesnt.exist: java.XXX CantAnnotateScoping.java:38:14: compiler.err.cant.type.annotate.scoping.1: @TA -CantAnnotateScoping.java:47:18: compiler.err.cant.type.annotate.scoping.1: @TA -CantAnnotateScoping.java:56:37: compiler.err.cant.type.annotate.scoping: @TA,@TA2 -CantAnnotateScoping.java:40:14: compiler.err.cant.type.annotate.scoping.1: @TA -CantAnnotateScoping.java:42:34: compiler.err.cant.type.annotate.scoping: @TA,@DA,@TA2 +CantAnnotateScoping.java:40:19: compiler.err.cant.type.annotate.scoping.1: @TA +CantAnnotateScoping.java:47:13: compiler.err.cant.type.annotate.scoping.1: @TA +CantAnnotateScoping.java:56:32: compiler.err.cant.type.annotate.scoping: @TA,@TA2 +CantAnnotateScoping.java:61:19: compiler.err.cant.type.annotate.scoping.1: @DA +CantAnnotateScoping.java:70:19: compiler.err.cant.type.annotate.scoping.1: @TA +CantAnnotateScoping.java:61:11: compiler.err.annotation.type.not.applicable +CantAnnotateScoping.java:66:11: compiler.err.annotation.type.not.applicable +CantAnnotateScoping.java:42:39: compiler.err.cant.type.annotate.scoping: @TA,@DA,@TA2 CantAnnotateScoping.java:42:25: compiler.err.annotation.type.not.applicable -CantAnnotateScoping.java:44:38: compiler.err.cant.type.annotate.scoping: @TA,@DA +CantAnnotateScoping.java:44:43: compiler.err.cant.type.annotate.scoping: @TA,@DA CantAnnotateScoping.java:44:34: compiler.err.annotation.type.not.applicable -11 errors +13 errors \ No newline at end of file --- old/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass.java 2014-05-09 16:27:57.398435025 -0400 +++ new/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass.java 2014-05-09 16:27:57.299430823 -0400 @@ -12,14 +12,49 @@ import java.lang.annotation.*; class Top { - @Target(ElementType.TYPE_USE) - @interface TA {} - - @Target(ElementType.TYPE_USE) - @interface TB {} - - @Target(ElementType.TYPE_USE) - @interface TC {} + @Target(ElementType.TYPE_USE) @interface TA {} + @Target(ElementType.TYPE_USE) @interface TB1 {} + @Target(ElementType.TYPE_USE) @interface TB2 {} + @Target(ElementType.TYPE_USE) @interface TB3 {} + @Target(ElementType.TYPE_USE) @interface TB4 {} + @Target(ElementType.TYPE_USE) @interface TB5 {} + @Target(ElementType.TYPE_USE) @interface TB6 {} + @Target(ElementType.TYPE_USE) @interface TB7 {} + @Target(ElementType.TYPE_USE) @interface TB8 {} + @Target(ElementType.TYPE_USE) @interface TB9 {} + @Target(ElementType.TYPE_USE) @interface TB10 {} + @Target(ElementType.TYPE_USE) @interface TB11 {} + @Target(ElementType.TYPE_USE) @interface TB12 {} + @Target(ElementType.TYPE_USE) @interface TB13 {} + @Target(ElementType.TYPE_USE) @interface TB14 {} + @Target(ElementType.TYPE_USE) @interface TB15 {} + @Target(ElementType.TYPE_USE) @interface TB16 {} + @Target(ElementType.TYPE_USE) @interface TB17 {} + @Target(ElementType.TYPE_USE) @interface TB18 {} + @Target(ElementType.TYPE_USE) @interface TB19 {} + @Target(ElementType.TYPE_USE) @interface TB20 {} + @Target(ElementType.TYPE_USE) @interface TB21 {} + @Target(ElementType.TYPE_USE) @interface TB22 {} + @Target(ElementType.TYPE_USE) @interface TB23 {} + @Target(ElementType.TYPE_USE) @interface TB24 {} + @Target(ElementType.TYPE_USE) @interface TB25 {} + @Target(ElementType.TYPE_USE) @interface TB26 {} + @Target(ElementType.TYPE_USE) @interface TB27 {} + @Target(ElementType.TYPE_USE) @interface TB28 {} + @Target(ElementType.TYPE_USE) @interface TB29 {} + @Target(ElementType.TYPE_USE) @interface TB30 {} + @Target(ElementType.TYPE_USE) @interface TB31 {} + @Target(ElementType.TYPE_USE) @interface TB32 {} + @Target(ElementType.TYPE_USE) @interface TB33 {} + @Target(ElementType.TYPE_USE) @interface TB34 {} + @Target(ElementType.TYPE_USE) @interface TB35 {} + @Target(ElementType.TYPE_USE) @interface TB36 {} + @Target(ElementType.TYPE_USE) @interface TB37 {} + @Target(ElementType.TYPE_USE) @interface TB38 {} + @Target(ElementType.TYPE_USE) @interface TB39 {} + @Target(ElementType.TYPE_USE) @interface TB40 {} + @Target(ElementType.TYPE_USE) @interface TB41 {} + @Target(ElementType.TYPE_USE) @interface TC {} class Outer { class Inner { @@ -34,63 +69,63 @@ // All combinations are OK - Top.@TB Outer f1; - @TB Outer.Inner f1a; + Top.@TB1 Outer f1; + @TB2 Outer.Inner f1a; Outer. @TC Inner f1b; - @TB Outer. @TC Inner f1c; + @TB3 Outer. @TC Inner f1c; - @TA Top. @TB Outer f2; - @TA Top. @TB Outer.Inner f2a; + @TA Top. @TB4 Outer f2; + @TA Top. @TB5 Outer.Inner f2a; @TA Top. Outer. @TC Inner f2b; - @TA Top. @TB Outer. @TC Inner f2c; + @TA Top. @TB6 Outer. @TC Inner f2c; - @TB Outer f1r() { return null; } - @TB Outer.Inner f1ra() { return null; } + @TB7 Outer f1r() { return null; } + @TB8 Outer.Inner f1ra() { return null; } Outer. @TC Inner f1rb() { return null; } - @TB Outer. @TC Inner f1rc() { return null; } + @TB9 Outer. @TC Inner f1rc() { return null; } - void f1param(@TB Outer p, - @TB Outer.Inner p1, + void f1param(@TB41 Outer p, + @TB10 Outer.Inner p1, Outer. @TC Inner p2, - @TB Outer. @TC Inner p3) { } + @TB11 Outer. @TC Inner p3) { } void f1cast(Object o) { Object l; - l = (@TB Outer) o; - l = (@TB Outer.Inner) o; + l = (@TB12 Outer) o; + l = (@TB13 Outer.Inner) o; l = (Outer. @TC Inner) o; - l = (@TB Outer. @TC Inner) o; + l = (@TB14 Outer. @TC Inner) o; } - List<@TB Outer> g1; - List<@TB Outer.Inner> g1a; + List<@TB15 Outer> g1; + List<@TB16 Outer.Inner> g1a; List g1b; - List<@TB Outer. @TC Inner> g1c; + List<@TB17 Outer. @TC Inner> g1c; - List<@TA Top. @TB Outer> g2; - List<@TA Top. @TB Outer.Inner> g2a; + List<@TA Top. @TB18 Outer> g2; + List<@TA Top. @TB19 Outer.Inner> g2a; List<@TA Top. Outer. @TC Inner> g2b; - List<@TA Top. @TB Outer. @TC Inner> g2c; + List<@TA Top. @TB20 Outer. @TC Inner> g2c; - List<@TB Outer> g1r() { return null; } - List<@TB Outer.Inner> g1ra() { return null; } + List<@TB21 Outer> g1r() { return null; } + List<@TB22 Outer.Inner> g1ra() { return null; } List g1rb() { return null; } - List<@TB Outer. @TC Inner> g1rc() { return null; } + List<@TB23 Outer. @TC Inner> g1rc() { return null; } - void g1param(List<@TB Outer> p, - List<@TB Outer.Inner> p1, + void g1param(List<@TB24 Outer> p, + List<@TB25 Outer.Inner> p1, List p2, - List<@TB Outer. @TC Inner> p3) { } + List<@TB26 Outer. @TC Inner> p3) { } void g1new(Object o) { Object l; - l = new @TB ArrayList<@TB Outer>(); - l = new @TB ArrayList<@TB Outer.Inner>(); - l = new @TB HashMap(); - l = new @TB HashMap(); - l = new @TB HashMap(); - l = new @TB HashMap(); - l = new @TB HashMap(); - l = new @TB HashMap(); + l = new @TB27 ArrayList<@TB28 Outer>(); + l = new @TB29 ArrayList<@TB30 Outer.Inner>(); + l = new @TB31 HashMap(); + l = new @TB32 HashMap(); + l = new @TB34 HashMap(); + l = new @TB36 HashMap(); + l = new @TB37 HashMap(); + l = new @TB39 HashMap(); } } --- old/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.out 2014-05-09 16:27:57.714448433 -0400 +++ new/test/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.out 2014-05-09 16:27:57.613444148 -0400 @@ -1,65 +1,72 @@ CantAnnotateStaticClass2.java:44:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:45:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:52:16: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:53:16: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:55:14: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:56:23: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:57:23: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:58:23: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:60:21: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:61:21: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:62:21: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:64:25: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:65:25: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:66:25: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:52:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:53:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:55:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:56:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:57:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:57:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:58:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:58:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:60:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:61:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:62:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:64:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:65:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:65:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:66:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:66:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:71:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:72:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:79:16: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:80:16: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:79:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:80:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:87:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:89:24: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:89:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB CantAnnotateStaticClass2.java:91:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:93:24: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:57:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:58:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:65:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:66:12: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:120:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:121:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:128:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:129:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:131:14: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:133:14: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:134:17: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:135:17: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:137:14: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:138:14: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:139:14: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:141:14: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:142:17: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:143:17: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:149:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:150:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:157:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:158:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:165:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:167:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:169:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:171:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:105:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:107:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:112:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:114:18: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:184:35: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:186:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:187:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:192:35: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:194:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:195:41: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:199:35: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:200:38: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:201:41: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:202:44: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:203:44: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:204:49: compiler.err.cant.type.annotate.scoping: @Top.TA,@Top.TB,@Top.TC -64 errors +CantAnnotateStaticClass2.java:93:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:120:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:121:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:128:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:129:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:131:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:133:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:134:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:134:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:135:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:135:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:137:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:138:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:139:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:141:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:142:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:142:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:143:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:143:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:149:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:150:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:157:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:158:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:165:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:167:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:169:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:171:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:105:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:107:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:112:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:114:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:184:40: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:186:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:187:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:192:40: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:194:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:195:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:199:38: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:200:38: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:200:49: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:201:44: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:202:44: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:202:55: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:203:44: compiler.err.cant.type.annotate.scoping.1: @Top.TA +CantAnnotateStaticClass2.java:203:55: compiler.err.cant.type.annotate.scoping.1: @Top.TB +CantAnnotateStaticClass2.java:204:52: compiler.err.cant.type.annotate.scoping: @Top.TA,@Top.TB,@Top.TC +71 errors --- old/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.out 2014-05-09 16:27:58.104464965 -0400 +++ new/test/tools/javac/annotations/typeAnnotations/failures/common/arrays/DeclarationAnnotation.out 2014-05-09 16:27:58.003460680 -0400 @@ -1,5 +1,5 @@ -DeclarationAnnotation.java:13:21: compiler.err.annotation.type.not.applicable DeclarationAnnotation.java:10:21: compiler.err.annotation.type.not.applicable DeclarationAnnotation.java:11:21: compiler.err.annotation.type.not.applicable DeclarationAnnotation.java:12:21: compiler.err.annotation.type.not.applicable +DeclarationAnnotation.java:13:21: compiler.err.annotation.type.not.applicable 4 errors --- old/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/MissingAnnotationValue.java 2014-05-09 16:27:58.802494314 -0400 +++ new/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/MissingAnnotationValue.java 2014-05-09 16:27:58.702490122 -0400 @@ -5,8 +5,13 @@ * @author Mahmood Ali * @compile/fail/ref=MissingAnnotationValue.out -XDrawDiagnostics MissingAnnotationValue.java */ +import java.lang.annotation.*; +import static java.lang.annotation.RetentionPolicy.*; +import static java.lang.annotation.ElementType.*; + class MissingAnnotationValue { void test(@A MissingAnnotationValue this) { } } +@Target({TYPE_USE}) @interface A { int field(); } --- old/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/MissingAnnotationValue.out 2014-05-09 16:27:59.175510101 -0400 +++ new/test/tools/javac/annotations/typeAnnotations/failures/common/receiver/MissingAnnotationValue.out 2014-05-09 16:27:59.076505899 -0400 @@ -1,2 +1,2 @@ -MissingAnnotationValue.java:9:13: compiler.err.annotation.missing.default.value: A, field +MissingAnnotationValue.java:13:13: compiler.err.annotation.missing.default.value: A, field 1 error --- old/test/tools/javac/annotations/typeAnnotations/newlocations/Expressions.java 2014-05-09 16:27:59.487523339 -0400 +++ new/test/tools/javac/annotations/typeAnnotations/newlocations/Expressions.java 2014-05-09 16:27:59.386519054 -0400 @@ -52,28 +52,40 @@ } void objectCreationArray() { - Object a1 = new @A String [] [] { }; - Object a2 = new @A String [1] []; - Object a3 = new @A String [1] [2]; - - Object b1 = new @A String @B(0) [] [] { }; - Object b2 = new @A String @B(0) [1] []; - Object b3 = new @A String @B(0) [1] [2]; - - Object c1 = new @A String [] @B(0) [] { }; - Object c2 = new @A String [1] @B(0) []; - Object c3 = new @A String [1] @B(0) [2]; - - Object d1 = new @A String @B(0) [] @B(0) [] { }; - Object d2 = new @A String @B(0) [1] @B(0) []; - Object d3 = new @A String @B(0) [1] @B(0) [2]; + Object a1 = new @C String [] [] { }; + Object a2 = new @D String [1] []; + Object a3 = new @E String [1] [2]; + + Object b1 = new @F String @B(1) [] [] { }; + Object b2 = new @G String @B(2) [1] []; + Object b3 = new @H String @B(3) [1] [2]; + + Object c1 = new @I String [] @B(4) [] { }; + Object c2 = new @J String [1] @B(5) []; + Object c3 = new @K String [1] @B(6) [2]; + + Object d1 = new @L String @B(7) [] @B(8) [] { }; + Object d2 = new @M String @B(9) [1] @B(10) []; + Object d3 = new @N String @B(11) [1] @B(12) [2]; - Object rand = new @A String @B(value = 0) [1] @B(value = 0) [2]; + Object rand = new @O String @B(value = 13) [1] @B(value = 14) [2]; } } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface A { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface C { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface D { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface E { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface F { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface G { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface H { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface I { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface J { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface K { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface L { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface M { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface N { } +@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) @interface O { } @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface A { } -@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) -@interface B { int value(); } + @interface B { int value(); } --- old/test/tools/javac/annotations/typeAnnotations/newlocations/NestedTypes.java 2014-05-09 16:27:59.824537630 -0400 +++ new/test/tools/javac/annotations/typeAnnotations/newlocations/NestedTypes.java 2014-05-09 16:27:59.724533386 -0400 @@ -128,6 +128,7 @@ MyList f9; // Illegal: // MyList<@A Outer . @Cv("Data") Static> f9; + } class Test2 { --- old/test/tools/javac/annotations/typeAnnotations/newlocations/RepeatingTypeAnnotations.out 2014-05-09 16:28:00.270556520 -0400 +++ new/test/tools/javac/annotations/typeAnnotations/newlocations/RepeatingTypeAnnotations.out 2014-05-09 16:28:00.171552319 -0400 @@ -17,12 +17,12 @@ RepeatingTypeAnnotations.java:89:33: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable RepeatingTypeAnnotations.java:93:19: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable RepeatingTypeAnnotations.java:93:35: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable -RepeatingTypeAnnotations.java:97:34: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable RepeatingTypeAnnotations.java:97:19: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable -RepeatingTypeAnnotations.java:101:26: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable +RepeatingTypeAnnotations.java:97:34: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable RepeatingTypeAnnotations.java:101:37: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable -RepeatingTypeAnnotations.java:101:72: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable +RepeatingTypeAnnotations.java:101:26: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable RepeatingTypeAnnotations.java:101:56: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable +RepeatingTypeAnnotations.java:101:72: compiler.err.duplicate.annotation.missing.container: TA, java.lang.annotation.Repeatable - compiler.note.unchecked.filename: RepeatingTypeAnnotations.java - compiler.note.unchecked.recompile 25 errors --- old/test/tools/javac/annotations/typeAnnotations/referenceinfos/Fields.java 2014-05-09 16:28:00.657572929 -0400 +++ new/test/tools/javac/annotations/typeAnnotations/referenceinfos/Fields.java 2014-05-09 16:28:00.557568686 -0400 @@ -30,7 +30,6 @@ * @run main Driver Fields */ public class Fields { - // field types @TADescription(annotation = "TA", type = FIELD) public String fieldAsPrimitive() { @@ -124,5 +123,4 @@ public String staticFieldAsParametrized() { return "static @TA Map<@TB String, @TC List<@TD String>> test;"; } - } --- old/test/tools/javac/warnings/6747671/T6747671.out 2014-05-09 16:28:01.042589239 -0400 +++ new/test/tools/javac/warnings/6747671/T6747671.out 2014-05-09 16:28:00.941584955 -0400 @@ -8,5 +8,5 @@ T6747671.java:32:20: compiler.warn.raw.class.use: T6747671.A, T6747671.A T6747671.java:33:16: compiler.warn.raw.class.use: T6747671.A.Z, T6747671.A.Z T6747671.java:36:9: compiler.warn.raw.class.use: @T6747671.TA T6747671.B, T6747671.B -T6747671.java:36:27: compiler.warn.raw.class.use: T6747671.B, T6747671.B +T6747671.java:36:27: compiler.warn.raw.class.use: @T6747671.TA T6747671.B, T6747671.B 11 warnings --- old/test/tools/javac/warnings/suppress/TypeAnnotations.out 2014-05-09 16:28:01.378603488 -0400 +++ new/test/tools/javac/warnings/suppress/TypeAnnotations.out 2014-05-09 16:28:01.273599032 -0400 @@ -5,28 +5,20 @@ TypeAnnotations.java:14:13: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:14:44: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:14:33: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -TypeAnnotations.java:23:29: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -TypeAnnotations.java:23:18: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:16:14: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -TypeAnnotations.java:17:58: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:17:14: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:17:58: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:20:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -TypeAnnotations.java:21:54: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:21:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:21:54: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:23:18: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:23:29: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:28:14: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -TypeAnnotations.java:29:58: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:29:14: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:29:58: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:32:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -TypeAnnotations.java:33:54: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:33:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:33:54: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -TypeAnnotations.java:35:46: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -TypeAnnotations.java:35:35: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:35:21: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:35:10: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:35:35: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package @@ -35,7 +27,6 @@ TypeAnnotations.java:38:6: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:38:43: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:38:32: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -TypeAnnotations.java:38:32: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:42:40: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package TypeAnnotations.java:42:62: compiler.warn.has.been.deprecated: TA, compiler.misc.unnamed.package -40 warnings \ No newline at end of file +31 warnings --- old/test/tools/javap/output/RepeatingTypeAnnotations.java 2014-05-09 16:28:01.712617655 -0400 +++ new/test/tools/javap/output/RepeatingTypeAnnotations.java 2014-05-09 16:28:01.607613199 -0400 @@ -245,11 +245,11 @@ " @A @A @A String ls = (@B @B @B String) o;", " }"); verify("RuntimeInvisibleTypeAnnotations", - "0: #34(#35=[@#36(),@#36(),@#36()]): CAST, offset=4, type_index=0", - "1: #37(#35=[@#38(),@#38(),@#38()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "0: #34(#35=[@#36(),@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "1: #37(#35=[@#38(),@#38(),@#38()]): CAST, offset=4, type_index=0", "RuntimeInvisibleTypeAnnotations", - "0: #37(#35=[@#38(),@#38(),@#38()]): METHOD_FORMAL_PARAMETER, param_index=0", - "1: #38(): METHOD_FORMAL_PARAMETER, param_index=1"); + "0: #36(): METHOD_FORMAL_PARAMETER, param_index=1", + "1: #34(#35=[@#36(),@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0"); } } @@ -261,15 +261,15 @@ " @A @A @B String ls = (@B @A @B String) o;", " }"); verify("RuntimeInvisibleTypeAnnotations", - "0: #34(#35=[@#36(),@#36()]): CAST, offset=4, type_index=0", - "1: #37(): CAST, offset=4, type_index=0", - "2: #38(#35=[@#37(),@#37()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", - "3: #36(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "0: #34(#35=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "1: #37(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "2: #38(#35=[@#37(),@#37()]): CAST, offset=4, type_index=0", + "3: #36(): CAST, offset=4, type_index=0", "RuntimeInvisibleTypeAnnotations", - "0: #38(#35=[@#37(),@#37()]): METHOD_FORMAL_PARAMETER, param_index=0", - "1: #36(): METHOD_FORMAL_PARAMETER, param_index=0", - "2: #37(): METHOD_FORMAL_PARAMETER, param_index=1", - "3: #36(): METHOD_FORMAL_PARAMETER, param_index=1"); + "0: #36(): METHOD_FORMAL_PARAMETER, param_index=1", + "1: #37(): METHOD_FORMAL_PARAMETER, param_index=1", + "2: #34(#35=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0", + "3: #37(): METHOD_FORMAL_PARAMETER, param_index=0"); } } @@ -282,14 +282,14 @@ " }"); verify("RuntimeVisibleTypeAnnotations", "RuntimeInvisibleTypeAnnotations", - "0: #34(): CAST, offset=4, type_index=0", - "1: #35(#36=[@#34(),@#34()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", - "0: #38(#36=[@#39(),@#39()]): CAST, offset=4, type_index=0", - "1: #39(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", - "0: #35(#36=[@#34(),@#34()]): METHOD_FORMAL_PARAMETER, param_index=0", - "0: #39(): METHOD_FORMAL_PARAMETER, param_index=0", - "1: #39(): METHOD_FORMAL_PARAMETER, param_index=1", - "2: #40(): METHOD_FORMAL_PARAMETER, param_index=1"); + "0: #34(#35=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "1: #36(): CAST, offset=4, type_index=0", + "0: #38(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "1: #39(#35=[@#38(),@#38()]): CAST, offset=4, type_index=0", + "0: #34(#35=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0", + "0: #38(): METHOD_FORMAL_PARAMETER, param_index=1", + "1: #40(): METHOD_FORMAL_PARAMETER, param_index=1", + "2: #38(): METHOD_FORMAL_PARAMETER, param_index=0"); } } @@ -301,13 +301,13 @@ " @A @B @C String ls = (@C @A @B String) o;", " }"); verify("RuntimeVisibleTypeAnnotations", - "0: #34(): CAST, offset=4, type_index=0", - "1: #34(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "0: #34(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "1: #34(): CAST, offset=4, type_index=0", "RuntimeInvisibleTypeAnnotations", - "0: #36(): CAST, offset=4, type_index=0", - "1: #37(): CAST, offset=4, type_index=0", - "2: #36(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", - "3: #37(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "0: #36(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "1: #37(): LOCAL_VARIABLE, {start_pc=10, length=1, index=5}", + "2: #36(): CAST, offset=4, type_index=0", + "3: #37(): CAST, offset=4, type_index=0", "0: #34(): METHOD_FORMAL_PARAMETER, param_index=0", "1: #34(): METHOD_FORMAL_PARAMETER, param_index=1", "0: #36(): METHOD_FORMAL_PARAMETER, param_index=0", @@ -325,13 +325,14 @@ " return (@A @A @A String) o;", " }"); verify("RuntimeInvisibleTypeAnnotations", - "0: #36(#37=[@#38(),@#38(),@#38()]): CAST, offset=0, type_index=0", - "1: #39(#37=[@#40(),@#40(),@#40()]): CAST, offset=6, type_index=0", - "2: #39(#37=[@#40(),@#40(),@#40()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "0: #36(#37=[@#38(),@#38(),@#38()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "1: #39(#37=[@#40(),@#40(),@#40()]): CAST, offset=0, type_index=0", + "2: #36(#37=[@#38(),@#38(),@#38()]): CAST, offset=6, type_index=0", "RuntimeInvisibleTypeAnnotations", - "0: #39(#37=[@#40(),@#40(),@#40()]): METHOD_RETURN", - "1: #39(#37=[@#40(),@#40(),@#40()]): METHOD_FORMAL_PARAMETER, param_index=0", - "2: #40(): METHOD_FORMAL_PARAMETER, param_index=1"); + "0: #38(): METHOD_FORMAL_PARAMETER, param_index=1", + "1: #36(#37=[@#38(),@#38(),@#38()]): METHOD_FORMAL_PARAMETER, param_index=0", + "2: #36(#37=[@#38(),@#38(),@#38()]): METHOD_RETURN" + ); } } @@ -344,20 +345,20 @@ " return (@A @B @B String) o;", " }"); verify( - "RuntimeInvisibleTypeAnnotations:", - "0: #36(#37=[@#38(),@#38()]): CAST, offset=0, type_index=0", - "1: #39(): CAST, offset=0, type_index=0", - "2: #39(): CAST, offset=6, type_index=0", - "3: #36(#37=[@#38(),@#38()]): CAST, offset=6, type_index=0", - "4: #40(#37=[@#39(),@#39()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", - "5: #38(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", - "RuntimeInvisibleTypeAnnotations:", - "0: #39(): METHOD_RETURN", - "1: #36(#37=[@#38(),@#38()]): METHOD_RETURN", - "2: #40(#37=[@#39(),@#39()]): METHOD_FORMAL_PARAMETER, param_index=0", - "3: #38(): METHOD_FORMAL_PARAMETER, param_index=0", - "4: #39(): METHOD_FORMAL_PARAMETER, param_index=1", - "5: #38(): METHOD_FORMAL_PARAMETER, param_index=1" + "RuntimeInvisibleTypeAnnotations:", + "0: #36(#37=[@#38(),@#38()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "1: #39(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "2: #40(#37=[@#39(),@#39()]): CAST, offset=0, type_index=0", + "3: #38(): CAST, offset=0, type_index=0", + "4: #38(): CAST, offset=6, type_index=0", + "5: #40(#37=[@#39(),@#39()]): CAST, offset=6, type_index=0", + "RuntimeInvisibleTypeAnnotations:", + "0: #38(): METHOD_FORMAL_PARAMETER, param_index=1", + "1: #39(): METHOD_FORMAL_PARAMETER, param_index=1", + "2: #36(#37=[@#38(),@#38()]): METHOD_FORMAL_PARAMETER, param_index=0", + "3: #39(): METHOD_FORMAL_PARAMETER, param_index=0", + "4: #38(): METHOD_RETURN", + "5: #40(#37=[@#39(),@#39()]): METHOD_RETURN" ); } } @@ -371,23 +372,23 @@ " return (@C @B @B String) o;", " }"); verify( - "RuntimeVisibleTypeAnnotations:", - "0: #36(): CAST, offset=0, type_index=0", - "1: #36(): CAST, offset=6, type_index=0", - "2: #37(#38=[@#36(),@#36()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", - "RuntimeInvisibleTypeAnnotations:", - "0: #40(#38=[@#41(),@#41()]): CAST, offset=0, type_index=0", - "1: #42(#38=[@#43(),@#43()]): CAST, offset=6, type_index=0", - "2: #41(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", - "RuntimeVisibleTypeAnnotations:", - "0: #36(): METHOD_RETURN", - "1: #37(#38=[@#36(),@#36()]): METHOD_FORMAL_PARAMETER, param_index=0", - "RuntimeInvisibleTypeAnnotations:", - "0: #40(#38=[@#41(),@#41()]): METHOD_RETURN", - "1: #41(): METHOD_FORMAL_PARAMETER, param_index=0", - "2: #41(): METHOD_FORMAL_PARAMETER, param_index=1", - "3: #43(): METHOD_FORMAL_PARAMETER, param_index=1" - ); + "RuntimeVisibleTypeAnnotations:", + "0: #36(#37=[@#38(),@#38()]): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "1: #38(): CAST, offset=0, type_index=0", + "2: #38(): CAST, offset=6, type_index=0", + "RuntimeInvisibleTypeAnnotations:", + "0: #40(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "1: #41(#37=[@#40(),@#40()]): CAST, offset=0, type_index=0", + "2: #42(#37=[@#43(),@#43()]): CAST, offset=6, type_index=0", + "RuntimeVisibleTypeAnnotations:", + "0: #36(#37=[@#38(),@#38()]): METHOD_FORMAL_PARAMETER, param_index=0", + "1: #38(): METHOD_RETURN", + "RuntimeInvisibleTypeAnnotations:", + "0: #40(): METHOD_FORMAL_PARAMETER, param_index=1", + "1: #43(): METHOD_FORMAL_PARAMETER, param_index=1", + "2: #40(): METHOD_FORMAL_PARAMETER, param_index=0", + "3: #41(#37=[@#40(),@#40()]): METHOD_RETURN" + ); } } @@ -400,27 +401,27 @@ " return (@B @A @C String) o;", " }"); verify( - "RuntimeVisibleTypeAnnotations:", - "0: #36(): CAST, offset=0, type_index=0", - "1: #36(): CAST, offset=6, type_index=0", - "2: #36(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", - "RuntimeInvisibleTypeAnnotations:", - "0: #38(): CAST, offset=0, type_index=0", - "1: #39(): CAST, offset=0, type_index=0", - "2: #39(): CAST, offset=6, type_index=0", - "3: #38(): CAST, offset=6, type_index=0", - "4: #38(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", - "5: #39(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", - "RuntimeVisibleTypeAnnotations:", - "0: #36(): METHOD_RETURN", - "1: #36(): METHOD_FORMAL_PARAMETER, param_index=0", - "2: #36(): METHOD_FORMAL_PARAMETER, param_index=1", - "RuntimeInvisibleTypeAnnotations:", - "0: #38(): METHOD_RETURN", - "1: #39(): METHOD_RETURN", - "2: #38(): METHOD_FORMAL_PARAMETER, param_index=0", - "3: #39(): METHOD_FORMAL_PARAMETER, param_index=0", - "4: #38(): METHOD_FORMAL_PARAMETER, param_index=1" + "RuntimeVisibleTypeAnnotations:", + "0: #36(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "1: #36(): CAST, offset=0, type_index=0", + "2: #36(): CAST, offset=6, type_index=0", + "RuntimeInvisibleTypeAnnotations:", + "0: #38(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "1: #39(): LOCAL_VARIABLE, {start_pc=6, length=5, index=5}", + "2: #38(): CAST, offset=0, type_index=0", + "3: #39(): CAST, offset=0, type_index=0", + "4: #39(): CAST, offset=6, type_index=0", + "5: #38(): CAST, offset=6, type_index=0", + "RuntimeVisibleTypeAnnotations:", + "0: #36(): METHOD_FORMAL_PARAMETER, param_index=0", + "1: #36(): METHOD_FORMAL_PARAMETER, param_index=1", + "2: #36(): METHOD_RETURN", + "RuntimeInvisibleTypeAnnotations:", + "0: #38(): METHOD_FORMAL_PARAMETER, param_index=0", + "1: #39(): METHOD_FORMAL_PARAMETER, param_index=0", + "2: #38(): METHOD_FORMAL_PARAMETER, param_index=1", + "3: #38(): METHOD_RETURN", + "4: #39(): METHOD_RETURN" ); } } --- /dev/null 2014-05-09 10:56:06.919782239 -0400 +++ new/test/tools/javac/annotations/typeAnnotations/newlocations/Stress.java 2014-05-09 16:28:01.932626990 -0400 @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8027262 + * @summary Stress test for type annotatons + * @compile Stress.java + */ + +import java.util.function.Function; +import java.lang.annotation.*; +import static java.lang.annotation.RetentionPolicy.*; +import static java.lang.annotation.ElementType.*; +import java.io.*; + +public class Stress { + + public class ParamStream extends FileOutputStream { + public ParamStream(File f) throws FileNotFoundException { super(f); } + } + + public class Inner { + public Inner() {} + public <@A T> Inner(@B Object o) {} + public <@C T> Object g(Inner<@D S> this, Object @E [] o) { + return new @F int @G [5]; + } + } + + public <@H T extends @I Inner<@J ? extends @K String>> Stress(Object o) {} + + public @L Object @M [] @N [] arr = new @O Object @P [5] @Q [5]; + + public Inner<@R ? extends @S Inner<@T ? extends @U Integer>> inner; + + public Function func(@V Stress this) { + try (final ParamStream<@W Integer @X []> fs = new ParamStream<@Y Integer @Z []>(new File("testfile"))) { + return @AA Stress.Inner<@AB String>::<@AC Integer>new; + } catch(@AD Exception ex) { + return null; + } + } + + public <@AE T extends @AF Inner<@AG Integer @AH []>> Function func2() { + arr[0][0] = new @AI Inner((@AJ Object) arr[0]); + return Ext.f((@AK Object) arr[0]) instanceof @AL Inner @AM [] @AN [] ? + @AO @AP Ext::<@AQ @AR Integer> f : + @AS @AT Ext::<@AU @AV Integer> f; + } + + public Object func3(Object @AW [] arr) { + Inner<@AX ? extends @AY Inner<@AZ ? extends @BA Integer>> loc; + if (arr[0] instanceof @BB Inner @BC [] @BD []) + return this.> func4(); + else + return new <@BG Inner<@BH Integer>> @BI Inner<@BJ Inner<@BK Integer>>(null); + } + + public <@BL T extends @BO Inner<@BP Integer @BQ []>> + @BR Inner<@BS Inner<@BT String>> func4() { + return (@BU Inner<@BV Inner<@BW String>>) + new <@BX Inner<@BY Integer>> @BZ Inner<@CA Inner<@CB String>>(null) {}; + } + + { Inner<@CC ? extends @CD Inner<@CE ? extends @CF Integer>> loc = + new @CG Inner<@CH Inner<@CI Integer>>() {}; + } + +} + +class Ext { + public static <@CJ T> Object f(Object o) { + return null; + } +} + + +@Retention(RUNTIME) @Target({TYPE_USE}) @interface A { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface B { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface C { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface D { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface E { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface F { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface G { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface H { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface I { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface J { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface K { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface L { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface M { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface N { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface O { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface P { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface Q { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface R { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface S { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface T { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface U { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface V { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface W { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface X { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface Y { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface Z { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AA { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AB { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AC { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AD { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AE { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AF { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AG { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AH { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AI { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AJ { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AK { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AL { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AM { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AN { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AO { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AP { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AQ { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AR { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AS { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AT { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AU { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AV { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AW { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AX { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AY { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface AZ { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BA { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BB { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BC { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BD { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BE { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BF { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BG { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BH { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BI { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BJ { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BK { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BL { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BM { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BN { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BO { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BP { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BQ { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BR { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BS { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BT { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BU { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BV { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BW { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BX { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BY { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface BZ { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CA { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CB { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CC { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CD { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CE { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CF { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CG { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CH { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CI { } +@Retention(RUNTIME) @Target({TYPE_USE}) @interface CJ { } +