--- 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");