src/share/classes/com/sun/tools/javac/code/TypeAnnotations.java

Wed, 28 Aug 2013 15:40:33 -0700

author
jjg
date
Wed, 28 Aug 2013 15:40:33 -0700
changeset 1984
189942cdf585
parent 1969
7de231613e4a
child 2047
5f915a0c9615
permissions
-rw-r--r--

8010310: [javadoc] Error processing sources with -private
Reviewed-by: vromero, mcimadamore

jjg@1521 1 /*
jjg@1521 2 * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
jjg@1521 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@1521 4 *
jjg@1521 5 * This code is free software; you can redistribute it and/or modify it
jjg@1521 6 * under the terms of the GNU General Public License version 2 only, as
jjg@1521 7 * published by the Free Software Foundation. Oracle designates this
jjg@1521 8 * particular file as subject to the "Classpath" exception as provided
jjg@1521 9 * by Oracle in the LICENSE file that accompanied this code.
jjg@1521 10 *
jjg@1521 11 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@1521 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@1521 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@1521 14 * version 2 for more details (a copy is included in the LICENSE file that
jjg@1521 15 * accompanied this code).
jjg@1521 16 *
jjg@1521 17 * You should have received a copy of the GNU General Public License version
jjg@1521 18 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@1521 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@1521 20 *
jjg@1521 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jjg@1521 22 * or visit www.oracle.com if you need additional information or have any
jjg@1521 23 * questions.
jjg@1521 24 */
jjg@1521 25
jjg@1521 26 package com.sun.tools.javac.code;
jjg@1521 27
jjg@1521 28 import javax.lang.model.element.Element;
jjg@1521 29 import javax.lang.model.element.ElementKind;
jjg@1521 30 import javax.lang.model.type.TypeKind;
jjg@1521 31
jjg@1969 32 import javax.tools.JavaFileObject;
jjg@1969 33
jjg@1521 34 import com.sun.tools.javac.code.Attribute;
jjg@1521 35 import com.sun.tools.javac.code.Attribute.TypeCompound;
jjg@1521 36 import com.sun.tools.javac.code.Flags;
jjg@1521 37 import com.sun.tools.javac.code.Kinds;
jjg@1521 38 import com.sun.tools.javac.code.Type.AnnotatedType;
jjg@1521 39 import com.sun.tools.javac.code.Type.ArrayType;
jjg@1521 40 import com.sun.tools.javac.code.Type.CapturedType;
jjg@1521 41 import com.sun.tools.javac.code.Type.ClassType;
jjg@1521 42 import com.sun.tools.javac.code.Type.ErrorType;
jjg@1521 43 import com.sun.tools.javac.code.Type.ForAll;
jjg@1521 44 import com.sun.tools.javac.code.Type.MethodType;
jjg@1521 45 import com.sun.tools.javac.code.Type.PackageType;
jjg@1521 46 import com.sun.tools.javac.code.Type.TypeVar;
jjg@1521 47 import com.sun.tools.javac.code.Type.UndetVar;
jjg@1521 48 import com.sun.tools.javac.code.Type.Visitor;
jjg@1521 49 import com.sun.tools.javac.code.Type.WildcardType;
jjg@1521 50 import com.sun.tools.javac.code.TypeAnnotationPosition.TypePathEntry;
jjg@1521 51 import com.sun.tools.javac.code.TypeAnnotationPosition.TypePathEntryKind;
jjg@1521 52 import com.sun.tools.javac.code.TypeTag;
jjg@1521 53 import com.sun.tools.javac.code.Symbol.VarSymbol;
jjg@1755 54 import com.sun.tools.javac.code.Symbol.MethodSymbol;
jjg@1755 55 import com.sun.tools.javac.comp.Annotate;
jjg@1521 56 import com.sun.tools.javac.comp.Annotate.Annotator;
jjg@1969 57 import com.sun.tools.javac.comp.AttrContext;
jjg@1969 58 import com.sun.tools.javac.comp.Env;
jjg@1521 59 import com.sun.tools.javac.tree.JCTree;
jjg@1969 60 import com.sun.tools.javac.tree.TreeInfo;
jjg@1521 61 import com.sun.tools.javac.tree.JCTree.JCBlock;
jjg@1521 62 import com.sun.tools.javac.tree.JCTree.JCClassDecl;
jjg@1521 63 import com.sun.tools.javac.tree.JCTree.JCExpression;
jjg@1755 64 import com.sun.tools.javac.tree.JCTree.JCLambda;
jjg@1521 65 import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
jjg@1969 66 import com.sun.tools.javac.tree.JCTree.JCMethodInvocation;
jjg@1755 67 import com.sun.tools.javac.tree.JCTree.JCNewClass;
jjg@1521 68 import com.sun.tools.javac.tree.JCTree.JCTypeApply;
jjg@1521 69 import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
jjg@1521 70 import com.sun.tools.javac.tree.TreeScanner;
jjg@1521 71 import com.sun.tools.javac.tree.JCTree.*;
jjg@1521 72 import com.sun.tools.javac.util.Assert;
jjg@1521 73 import com.sun.tools.javac.util.List;
jjg@1521 74 import com.sun.tools.javac.util.ListBuffer;
jjg@1521 75 import com.sun.tools.javac.util.Log;
jjg@1521 76 import com.sun.tools.javac.util.Names;
jjg@1521 77
jjg@1521 78 /**
jjg@1521 79 * Contains operations specific to processing type annotations.
jjg@1521 80 * This class has two functions:
jjg@1521 81 * separate declaration from type annotations and insert the type
jjg@1521 82 * annotations to their types;
jjg@1521 83 * and determine the TypeAnnotationPositions for all type annotations.
jjg@1521 84 */
jjg@1521 85 public class TypeAnnotations {
jjg@1521 86 // Class cannot be instantiated.
jjg@1521 87 private TypeAnnotations() {}
jjg@1521 88
jjg@1521 89 /**
jjg@1521 90 * Separate type annotations from declaration annotations and
jjg@1521 91 * determine the correct positions for type annotations.
jjg@1521 92 * This version only visits types in signatures and should be
jjg@1521 93 * called from MemberEnter.
jjg@1755 94 * The method takes the Annotate object as parameter and
jjg@1755 95 * adds an Annotator to the correct Annotate queue for
jjg@1755 96 * later processing.
jjg@1521 97 */
jjg@1755 98 public static void organizeTypeAnnotationsSignatures(final Symtab syms, final Names names,
jjg@1969 99 final Log log, final Env<AttrContext> env, final JCClassDecl tree, final Annotate annotate) {
jjg@1755 100 annotate.afterRepeated( new Annotator() {
jjg@1521 101 @Override
jjg@1521 102 public void enterAnnotation() {
jjg@1969 103 JavaFileObject oldSource = log.useSource(env.toplevel.sourcefile);
jjg@1969 104
jjg@1969 105 try {
jjg@1969 106 new TypeAnnotationPositions(syms, names, log, true).scan(tree);
jjg@1969 107 } finally {
jjg@1969 108 log.useSource(oldSource);
jjg@1969 109 }
jjg@1521 110 }
jjg@1755 111 } );
jjg@1521 112 }
jjg@1521 113
jjg@1521 114 /**
jjg@1521 115 * This version only visits types in bodies, that is, field initializers,
jjg@1521 116 * top-level blocks, and method bodies, and should be called from Attr.
jjg@1521 117 */
jjg@1521 118 public static void organizeTypeAnnotationsBodies(Symtab syms, Names names, Log log, JCClassDecl tree) {
jjg@1521 119 new TypeAnnotationPositions(syms, names, log, false).scan(tree);
jjg@1521 120 }
jjg@1521 121
jjg@1755 122 public enum AnnotationType { DECLARATION, TYPE, BOTH };
jjg@1755 123
jjg@1755 124 /**
jjg@1755 125 * Determine whether an annotation is a declaration annotation,
jjg@1755 126 * a type annotation, or both.
jjg@1755 127 */
jjg@1755 128 public static AnnotationType annotationType(Symtab syms, Names names,
jjg@1755 129 Attribute.Compound a, Symbol s) {
jjg@1755 130 Attribute.Compound atTarget =
jjg@1755 131 a.type.tsym.attribute(syms.annotationTargetType.tsym);
jjg@1755 132 if (atTarget == null) {
jjg@1755 133 return inferTargetMetaInfo(a, s);
jjg@1755 134 }
jjg@1755 135 Attribute atValue = atTarget.member(names.value);
jjg@1755 136 if (!(atValue instanceof Attribute.Array)) {
jjg@1755 137 Assert.error("annotationType(): bad @Target argument " + atValue +
jjg@1755 138 " (" + atValue.getClass() + ")");
jjg@1755 139 return AnnotationType.DECLARATION; // error recovery
jjg@1755 140 }
jjg@1755 141 Attribute.Array arr = (Attribute.Array) atValue;
jjg@1755 142 boolean isDecl = false, isType = false;
jjg@1755 143 for (Attribute app : arr.values) {
jjg@1755 144 if (!(app instanceof Attribute.Enum)) {
jjg@1755 145 Assert.error("annotationType(): unrecognized Attribute kind " + app +
jjg@1755 146 " (" + app.getClass() + ")");
jjg@1755 147 isDecl = true;
jjg@1755 148 continue;
jjg@1755 149 }
jjg@1755 150 Attribute.Enum e = (Attribute.Enum) app;
jjg@1755 151 if (e.value.name == names.TYPE) {
jjg@1755 152 if (s.kind == Kinds.TYP)
jjg@1755 153 isDecl = true;
jjg@1755 154 } else if (e.value.name == names.FIELD) {
jjg@1755 155 if (s.kind == Kinds.VAR &&
jjg@1755 156 s.owner.kind != Kinds.MTH)
jjg@1755 157 isDecl = true;
jjg@1755 158 } else if (e.value.name == names.METHOD) {
jjg@1755 159 if (s.kind == Kinds.MTH &&
jjg@1755 160 !s.isConstructor())
jjg@1755 161 isDecl = true;
jjg@1755 162 } else if (e.value.name == names.PARAMETER) {
jjg@1755 163 if (s.kind == Kinds.VAR &&
jjg@1755 164 s.owner.kind == Kinds.MTH &&
jjg@1755 165 (s.flags() & Flags.PARAMETER) != 0)
jjg@1755 166 isDecl = true;
jjg@1755 167 } else if (e.value.name == names.CONSTRUCTOR) {
jjg@1755 168 if (s.kind == Kinds.MTH &&
jjg@1755 169 s.isConstructor())
jjg@1755 170 isDecl = true;
jjg@1755 171 } else if (e.value.name == names.LOCAL_VARIABLE) {
jjg@1755 172 if (s.kind == Kinds.VAR &&
jjg@1755 173 s.owner.kind == Kinds.MTH &&
jjg@1755 174 (s.flags() & Flags.PARAMETER) == 0)
jjg@1755 175 isDecl = true;
jjg@1755 176 } else if (e.value.name == names.ANNOTATION_TYPE) {
jjg@1755 177 if (s.kind == Kinds.TYP &&
jjg@1755 178 (s.flags() & Flags.ANNOTATION) != 0)
jjg@1755 179 isDecl = true;
jjg@1755 180 } else if (e.value.name == names.PACKAGE) {
jjg@1755 181 if (s.kind == Kinds.PCK)
jjg@1755 182 isDecl = true;
jjg@1755 183 } else if (e.value.name == names.TYPE_USE) {
jjg@1755 184 if (s.kind == Kinds.TYP ||
jjg@1755 185 s.kind == Kinds.VAR ||
jjg@1755 186 (s.kind == Kinds.MTH && !s.isConstructor() &&
jjg@1755 187 !s.type.getReturnType().hasTag(TypeTag.VOID)) ||
jjg@1755 188 (s.kind == Kinds.MTH && s.isConstructor()))
jjg@1755 189 isType = true;
jjg@1755 190 } else if (e.value.name == names.TYPE_PARAMETER) {
jjg@1755 191 /* Irrelevant in this case */
jjg@1755 192 // TYPE_PARAMETER doesn't aid in distinguishing between
jjg@1755 193 // Type annotations and declaration annotations on an
jjg@1755 194 // Element
jjg@1755 195 } else {
jjg@1755 196 Assert.error("annotationType(): unrecognized Attribute name " + e.value.name +
jjg@1755 197 " (" + e.value.name.getClass() + ")");
jjg@1755 198 isDecl = true;
jjg@1755 199 }
jjg@1755 200 }
jjg@1755 201 if (isDecl && isType) {
jjg@1755 202 return AnnotationType.BOTH;
jjg@1755 203 } else if (isType) {
jjg@1755 204 return AnnotationType.TYPE;
jjg@1755 205 } else {
jjg@1755 206 return AnnotationType.DECLARATION;
jjg@1755 207 }
jjg@1755 208 }
jjg@1755 209
jjg@1755 210 /** Infer the target annotation kind, if none is give.
jjg@1755 211 * We only infer declaration annotations.
jjg@1755 212 */
jjg@1755 213 private static AnnotationType inferTargetMetaInfo(Attribute.Compound a, Symbol s) {
jjg@1755 214 return AnnotationType.DECLARATION;
jjg@1755 215 }
jjg@1755 216
jjg@1755 217
jjg@1521 218 private static class TypeAnnotationPositions extends TreeScanner {
jjg@1521 219
jjg@1521 220 private final Symtab syms;
jjg@1521 221 private final Names names;
jjg@1521 222 private final Log log;
jjg@1521 223 private final boolean sigOnly;
jjg@1521 224
jjg@1521 225 private TypeAnnotationPositions(Symtab syms, Names names, Log log, boolean sigOnly) {
jjg@1521 226 this.syms = syms;
jjg@1521 227 this.names = names;
jjg@1521 228 this.log = log;
jjg@1521 229 this.sigOnly = sigOnly;
jjg@1521 230 }
jjg@1521 231
jjg@1521 232 /*
jjg@1521 233 * When traversing the AST we keep the "frames" of visited
jjg@1521 234 * trees in order to determine the position of annotations.
jjg@1521 235 */
jjg@1521 236 private ListBuffer<JCTree> frames = ListBuffer.lb();
jjg@1521 237
jjg@1521 238 protected void push(JCTree t) { frames = frames.prepend(t); }
jjg@1521 239 protected JCTree pop() { return frames.next(); }
jjg@1521 240 // could this be frames.elems.tail.head?
jjg@1521 241 private JCTree peek2() { return frames.toList().tail.head; }
jjg@1521 242
jjg@1521 243 @Override
jjg@1521 244 public void scan(JCTree tree) {
jjg@1521 245 push(tree);
jjg@1521 246 super.scan(tree);
jjg@1521 247 pop();
jjg@1521 248 }
jjg@1521 249
jjg@1521 250 /**
jjg@1521 251 * Separates type annotations from declaration annotations.
jjg@1521 252 * This step is needed because in certain locations (where declaration
jjg@1521 253 * and type annotations can be mixed, e.g. the type of a field)
jjg@1521 254 * we never build an JCAnnotatedType. This step finds these
jjg@1521 255 * annotations and marks them as if they were part of the type.
jjg@1521 256 */
jjg@1521 257 private void separateAnnotationsKinds(JCTree typetree, Type type, Symbol sym,
jjg@1521 258 TypeAnnotationPosition pos) {
jjg@1521 259 /*
jjg@1521 260 System.out.printf("separateAnnotationsKinds(typetree: %s, type: %s, symbol: %s, pos: %s%n",
jjg@1521 261 typetree, type, sym, pos);
jjg@1521 262 */
jjg@1521 263 List<Attribute.Compound> annotations = sym.getRawAttributes();
jjg@1521 264 ListBuffer<Attribute.Compound> declAnnos = new ListBuffer<Attribute.Compound>();
jjg@1521 265 ListBuffer<Attribute.TypeCompound> typeAnnos = new ListBuffer<Attribute.TypeCompound>();
jjg@1521 266
jjg@1521 267 for (Attribute.Compound a : annotations) {
jjg@1755 268 switch (annotationType(syms, names, a, sym)) {
jjg@1521 269 case DECLARATION:
jjg@1521 270 declAnnos.append(a);
jjg@1521 271 break;
jjg@1521 272 case BOTH: {
jjg@1521 273 declAnnos.append(a);
jjg@1521 274 Attribute.TypeCompound ta = toTypeCompound(a, pos);
jjg@1521 275 typeAnnos.append(ta);
jjg@1521 276 break;
jjg@1521 277 }
jjg@1521 278 case TYPE: {
jjg@1521 279 Attribute.TypeCompound ta = toTypeCompound(a, pos);
jjg@1521 280 typeAnnos.append(ta);
jjg@1521 281 break;
jjg@1521 282 }
jjg@1521 283 }
jjg@1521 284 }
jjg@1521 285
jjg@1802 286 sym.resetAnnotations();
jjg@1802 287 sym.setDeclarationAttributes(declAnnos.toList());
jjg@1521 288
jjg@1755 289 if (typeAnnos.isEmpty()) {
jjg@1755 290 return;
jjg@1755 291 }
jjg@1755 292
jjg@1521 293 List<Attribute.TypeCompound> typeAnnotations = typeAnnos.toList();
jjg@1521 294
jjg@1521 295 if (type == null) {
jjg@1521 296 // When type is null, put the type annotations to the symbol.
jjg@1521 297 // This is used for constructor return annotations, for which
jjg@1521 298 // no appropriate type exists.
jjg@1802 299 sym.appendUniqueTypeAttributes(typeAnnotations);
jjg@1521 300 return;
jjg@1521 301 }
jjg@1521 302
jjg@1521 303 // type is non-null and annotations are added to that type
jjg@1521 304 type = typeWithAnnotations(typetree, type, typeAnnotations, log);
jjg@1521 305
jjg@1521 306 if (sym.getKind() == ElementKind.METHOD) {
jjg@1521 307 sym.type.asMethodType().restype = type;
jjg@1755 308 } else if (sym.getKind() == ElementKind.PARAMETER) {
jjg@1755 309 sym.type = type;
jjg@1755 310 if (sym.getQualifiedName().equals(names._this)) {
jjg@1755 311 sym.owner.type.asMethodType().recvtype = type;
jjg@1755 312 // note that the typeAnnotations will also be added to the owner below.
jjg@1755 313 } else {
jjg@1755 314 MethodType methType = sym.owner.type.asMethodType();
jjg@1755 315 List<VarSymbol> params = ((MethodSymbol)sym.owner).params;
jjg@1755 316 List<Type> oldArgs = methType.argtypes;
jjg@1755 317 ListBuffer<Type> newArgs = new ListBuffer<Type>();
jjg@1755 318 while (params.nonEmpty()) {
jjg@1755 319 if (params.head == sym) {
jjg@1755 320 newArgs.add(type);
jjg@1755 321 } else {
jjg@1755 322 newArgs.add(oldArgs.head);
jjg@1755 323 }
jjg@1755 324 oldArgs = oldArgs.tail;
jjg@1755 325 params = params.tail;
jjg@1755 326 }
jjg@1755 327 methType.argtypes = newArgs.toList();
jjg@1755 328 }
jjg@1521 329 } else {
jjg@1521 330 sym.type = type;
jjg@1521 331 }
jjg@1521 332
jjg@1802 333 sym.appendUniqueTypeAttributes(typeAnnotations);
jjg@1755 334
jjg@1521 335 if (sym.getKind() == ElementKind.PARAMETER ||
jjg@1521 336 sym.getKind() == ElementKind.LOCAL_VARIABLE ||
jjg@1521 337 sym.getKind() == ElementKind.RESOURCE_VARIABLE ||
jjg@1521 338 sym.getKind() == ElementKind.EXCEPTION_PARAMETER) {
jjg@1521 339 // Make sure all type annotations from the symbol are also
jjg@1521 340 // on the owner.
jjg@1802 341 sym.owner.appendUniqueTypeAttributes(sym.getRawTypeAttributes());
jjg@1521 342 }
jjg@1521 343 }
jjg@1521 344
jjg@1521 345 // This method has a similar purpose as
jjg@1521 346 // {@link com.sun.tools.javac.parser.JavacParser.insertAnnotationsToMostInner(JCExpression, List<JCTypeAnnotation>, boolean)}
jjg@1521 347 // We found a type annotation in a declaration annotation position,
jjg@1521 348 // for example, on the return type.
jjg@1521 349 // Such an annotation is _not_ part of an JCAnnotatedType tree and we therefore
jjg@1521 350 // need to set its position explicitly.
jjg@1521 351 // The method returns a copy of type that contains these annotations.
jjg@1563 352 //
jjg@1563 353 // As a side effect the method sets the type annotation position of "annotations".
jjg@1563 354 // Note that it is assumed that all annotations share the same position.
jjg@1521 355 private static Type typeWithAnnotations(final JCTree typetree, final Type type,
jjg@1521 356 final List<Attribute.TypeCompound> annotations, Log log) {
jjg@1521 357 // System.out.printf("typeWithAnnotations(typetree: %s, type: %s, annotations: %s)%n",
jjg@1521 358 // typetree, type, annotations);
jjg@1521 359 if (annotations.isEmpty()) {
jjg@1521 360 return type;
jjg@1521 361 }
jjg@1521 362 if (type.hasTag(TypeTag.ARRAY)) {
jjg@1521 363 Type toreturn;
jjg@1521 364 Type.ArrayType tomodify;
jjg@1521 365 Type.ArrayType arType;
jjg@1521 366 {
jjg@1521 367 Type touse = type;
jjg@1644 368 if (type.isAnnotated()) {
jjg@1521 369 Type.AnnotatedType atype = (Type.AnnotatedType)type;
jjg@1521 370 toreturn = new Type.AnnotatedType(atype.underlyingType);
jjg@1521 371 ((Type.AnnotatedType)toreturn).typeAnnotations = atype.typeAnnotations;
jjg@1521 372 touse = atype.underlyingType;
jjg@1521 373 arType = (Type.ArrayType) touse;
jjg@1521 374 tomodify = new Type.ArrayType(null, arType.tsym);
jjg@1521 375 ((Type.AnnotatedType)toreturn).underlyingType = tomodify;
jjg@1521 376 } else {
jjg@1521 377 arType = (Type.ArrayType) touse;
jjg@1521 378 tomodify = new Type.ArrayType(null, arType.tsym);
jjg@1521 379 toreturn = tomodify;
jjg@1521 380 }
jjg@1521 381 }
jjg@1521 382 JCArrayTypeTree arTree = arrayTypeTree(typetree);
jjg@1521 383
jjg@1521 384 ListBuffer<TypePathEntry> depth = ListBuffer.lb();
jjg@1521 385 depth = depth.append(TypePathEntry.ARRAY);
jjg@1521 386 while (arType.elemtype.hasTag(TypeTag.ARRAY)) {
jjg@1644 387 if (arType.elemtype.isAnnotated()) {
jjg@1521 388 Type.AnnotatedType aelemtype = (Type.AnnotatedType) arType.elemtype;
jjg@1521 389 Type.AnnotatedType newAT = new Type.AnnotatedType(aelemtype.underlyingType);
jjg@1521 390 tomodify.elemtype = newAT;
jjg@1521 391 newAT.typeAnnotations = aelemtype.typeAnnotations;
jjg@1521 392 arType = (Type.ArrayType) aelemtype.underlyingType;
jjg@1521 393 tomodify = new Type.ArrayType(null, arType.tsym);
jjg@1521 394 newAT.underlyingType = tomodify;
jjg@1521 395 } else {
jjg@1521 396 arType = (Type.ArrayType) arType.elemtype;
jjg@1521 397 tomodify.elemtype = new Type.ArrayType(null, arType.tsym);
jjg@1521 398 tomodify = (Type.ArrayType) tomodify.elemtype;
jjg@1521 399 }
jjg@1521 400 arTree = arrayTypeTree(arTree.elemtype);
jjg@1521 401 depth = depth.append(TypePathEntry.ARRAY);
jjg@1521 402 }
jjg@1521 403 Type arelemType = typeWithAnnotations(arTree.elemtype, arType.elemtype, annotations, log);
jjg@1521 404 tomodify.elemtype = arelemType;
jjg@1563 405 {
jjg@1563 406 // All annotations share the same position; modify the first one.
jjg@1563 407 Attribute.TypeCompound a = annotations.get(0);
jjg@1521 408 TypeAnnotationPosition p = a.position;
jjg@1521 409 p.location = p.location.prependList(depth.toList());
jjg@1521 410 }
jjg@1755 411 typetree.type = toreturn;
jjg@1521 412 return toreturn;
jjg@1521 413 } else if (type.hasTag(TypeTag.TYPEVAR)) {
jjg@1521 414 // Nothing to do for type variables.
jjg@1521 415 return type;
jjg@1755 416 } else if (type.getKind() == TypeKind.UNION) {
jjg@1755 417 // There is a TypeKind, but no TypeTag.
jjg@1755 418 JCTypeUnion tutree = (JCTypeUnion) typetree;
jjg@1755 419 JCExpression fst = tutree.alternatives.get(0);
jjg@1755 420 Type res = typeWithAnnotations(fst, fst.type, annotations, log);
jjg@1755 421 fst.type = res;
jjg@1755 422 // TODO: do we want to set res as first element in uct.alternatives?
jjg@1755 423 // UnionClassType uct = (com.sun.tools.javac.code.Type.UnionClassType)type;
jjg@1755 424 // Return the un-annotated union-type.
jjg@1755 425 return type;
jjg@1521 426 } else {
jjg@1521 427 Type enclTy = type;
jjg@1521 428 Element enclEl = type.asElement();
jjg@1521 429 JCTree enclTr = typetree;
jjg@1521 430
jjg@1521 431 while (enclEl != null &&
jjg@1521 432 enclEl.getKind() != ElementKind.PACKAGE &&
jjg@1521 433 enclTy != null &&
jjg@1521 434 enclTy.getKind() != TypeKind.NONE &&
jjg@1521 435 enclTy.getKind() != TypeKind.ERROR &&
jjg@1521 436 (enclTr.getKind() == JCTree.Kind.MEMBER_SELECT ||
jjg@1521 437 enclTr.getKind() == JCTree.Kind.PARAMETERIZED_TYPE ||
jjg@1521 438 enclTr.getKind() == JCTree.Kind.ANNOTATED_TYPE)) {
jjg@1521 439 // Iterate also over the type tree, not just the type: the type is already
jjg@1521 440 // completely resolved and we cannot distinguish where the annotation
jjg@1521 441 // belongs for a nested type.
jjg@1521 442 if (enclTr.getKind() == JCTree.Kind.MEMBER_SELECT) {
jjg@1521 443 // only change encl in this case.
jjg@1521 444 enclTy = enclTy.getEnclosingType();
jjg@1521 445 enclEl = enclEl.getEnclosingElement();
jjg@1521 446 enclTr = ((JCFieldAccess)enclTr).getExpression();
jjg@1521 447 } else if (enclTr.getKind() == JCTree.Kind.PARAMETERIZED_TYPE) {
jjg@1521 448 enclTr = ((JCTypeApply)enclTr).getType();
jjg@1521 449 } else {
jjg@1521 450 // only other option because of while condition
jjg@1521 451 enclTr = ((JCAnnotatedType)enclTr).getUnderlyingType();
jjg@1521 452 }
jjg@1521 453 }
jjg@1521 454
jjg@1521 455 /** We are trying to annotate some enclosing type,
jjg@1521 456 * but nothing more exists.
jjg@1521 457 */
jjg@1521 458 if (enclTy != null &&
jjg@1521 459 enclTy.getKind() == TypeKind.NONE &&
jjg@1521 460 (enclTr.getKind() == JCTree.Kind.IDENTIFIER ||
jjg@1521 461 enclTr.getKind() == JCTree.Kind.MEMBER_SELECT ||
jjg@1521 462 enclTr.getKind() == JCTree.Kind.PARAMETERIZED_TYPE ||
jjg@1521 463 enclTr.getKind() == JCTree.Kind.ANNOTATED_TYPE)) {
jjg@1521 464 // TODO: also if it's "java. @A lang.Object", that is,
jjg@1521 465 // if it's on a package?
jjg@1521 466 log.error(enclTr.pos(), "cant.annotate.nested.type", enclTr.toString());
jjg@1521 467 return type;
jjg@1521 468 }
jjg@1521 469
jjg@1521 470 // At this point we have visited the part of the nested
jjg@1521 471 // type that is written in the source code.
jjg@1521 472 // Now count from here to the actual top-level class to determine
jjg@1521 473 // the correct nesting.
jjg@1521 474
jjg@1521 475 // The genericLocation for the annotation.
jjg@1521 476 ListBuffer<TypePathEntry> depth = ListBuffer.lb();
jjg@1521 477
jjg@1521 478 Type topTy = enclTy;
jjg@1521 479 while (enclEl != null &&
jjg@1521 480 enclEl.getKind() != ElementKind.PACKAGE &&
jjg@1521 481 topTy != null &&
jjg@1521 482 topTy.getKind() != TypeKind.NONE &&
jjg@1521 483 topTy.getKind() != TypeKind.ERROR) {
jjg@1521 484 topTy = topTy.getEnclosingType();
jjg@1521 485 enclEl = enclEl.getEnclosingElement();
jjg@1521 486
jjg@1521 487 if (topTy != null && topTy.getKind() != TypeKind.NONE) {
jjg@1521 488 // Only count enclosing types.
jjg@1521 489 depth = depth.append(TypePathEntry.INNER_TYPE);
jjg@1521 490 }
jjg@1521 491 }
jjg@1521 492
jjg@1521 493 if (depth.nonEmpty()) {
jjg@1521 494 // Only need to change the annotation positions
jjg@1521 495 // if they are on an enclosed type.
jjg@1563 496 // All annotations share the same position; modify the first one.
jjg@1563 497 Attribute.TypeCompound a = annotations.get(0);
jjg@1563 498 TypeAnnotationPosition p = a.position;
jjg@1563 499 p.location = p.location.appendList(depth.toList());
jjg@1521 500 }
jjg@1521 501
jjg@1521 502 Type ret = typeWithAnnotations(type, enclTy, annotations);
jjg@1755 503 typetree.type = ret;
jjg@1521 504 return ret;
jjg@1521 505 }
jjg@1521 506 }
jjg@1521 507
jjg@1521 508 private static JCArrayTypeTree arrayTypeTree(JCTree typetree) {
jjg@1521 509 if (typetree.getKind() == JCTree.Kind.ARRAY_TYPE) {
jjg@1521 510 return (JCArrayTypeTree) typetree;
jjg@1521 511 } else if (typetree.getKind() == JCTree.Kind.ANNOTATED_TYPE) {
jjg@1521 512 return (JCArrayTypeTree) ((JCAnnotatedType)typetree).underlyingType;
jjg@1521 513 } else {
jjg@1521 514 Assert.error("Could not determine array type from type tree: " + typetree);
jjg@1521 515 return null;
jjg@1521 516 }
jjg@1521 517 }
jjg@1521 518
jjg@1521 519 /** Return a copy of the first type that only differs by
jjg@1521 520 * inserting the annotations to the left-most/inner-most type
jjg@1521 521 * or the type given by stopAt.
jjg@1521 522 *
jjg@1521 523 * We need the stopAt parameter to know where on a type to
jjg@1521 524 * put the annotations.
jjg@1521 525 * If we have nested classes Outer > Middle > Inner, and we
jjg@1521 526 * have the source type "@A Middle.Inner", we will invoke
jjg@1521 527 * this method with type = Outer.Middle.Inner,
jjg@1521 528 * stopAt = Middle.Inner, and annotations = @A.
jjg@1521 529 *
jjg@1521 530 * @param type The type to copy.
jjg@1521 531 * @param stopAt The type to stop at.
jjg@1521 532 * @param annotations The annotations to insert.
jjg@1521 533 * @return A copy of type that contains the annotations.
jjg@1521 534 */
jjg@1521 535 private static Type typeWithAnnotations(final Type type,
jjg@1521 536 final Type stopAt,
jjg@1521 537 final List<Attribute.TypeCompound> annotations) {
jjg@1521 538 Visitor<Type, List<TypeCompound>> visitor =
jjg@1521 539 new Type.Visitor<Type, List<Attribute.TypeCompound>>() {
jjg@1521 540 @Override
jjg@1521 541 public Type visitClassType(ClassType t, List<TypeCompound> s) {
jjg@1521 542 // assert that t.constValue() == null?
jjg@1521 543 if (t == stopAt ||
jjg@1521 544 t.getEnclosingType() == Type.noType) {
jjg@1521 545 return new AnnotatedType(s, t);
jjg@1521 546 } else {
jjg@1521 547 ClassType ret = new ClassType(t.getEnclosingType().accept(this, s),
jjg@1521 548 t.typarams_field, t.tsym);
jjg@1521 549 ret.all_interfaces_field = t.all_interfaces_field;
jjg@1521 550 ret.allparams_field = t.allparams_field;
jjg@1521 551 ret.interfaces_field = t.interfaces_field;
jjg@1521 552 ret.rank_field = t.rank_field;
jjg@1521 553 ret.supertype_field = t.supertype_field;
jjg@1521 554 return ret;
jjg@1521 555 }
jjg@1521 556 }
jjg@1521 557
jjg@1521 558 @Override
jjg@1521 559 public Type visitAnnotatedType(AnnotatedType t, List<TypeCompound> s) {
jjg@1521 560 return new AnnotatedType(t.typeAnnotations, t.underlyingType.accept(this, s));
jjg@1521 561 }
jjg@1521 562
jjg@1521 563 @Override
jjg@1521 564 public Type visitWildcardType(WildcardType t, List<TypeCompound> s) {
jjg@1521 565 return new AnnotatedType(s, t);
jjg@1521 566 }
jjg@1521 567
jjg@1521 568 @Override
jjg@1521 569 public Type visitArrayType(ArrayType t, List<TypeCompound> s) {
jjg@1521 570 ArrayType ret = new ArrayType(t.elemtype.accept(this, s), t.tsym);
jjg@1521 571 return ret;
jjg@1521 572 }
jjg@1521 573
jjg@1521 574 @Override
jjg@1521 575 public Type visitMethodType(MethodType t, List<TypeCompound> s) {
jjg@1521 576 // Impossible?
jjg@1521 577 return t;
jjg@1521 578 }
jjg@1521 579
jjg@1521 580 @Override
jjg@1521 581 public Type visitPackageType(PackageType t, List<TypeCompound> s) {
jjg@1521 582 // Impossible?
jjg@1521 583 return t;
jjg@1521 584 }
jjg@1521 585
jjg@1521 586 @Override
jjg@1521 587 public Type visitTypeVar(TypeVar t, List<TypeCompound> s) {
jjg@1521 588 return new AnnotatedType(s, t);
jjg@1521 589 }
jjg@1521 590
jjg@1521 591 @Override
jjg@1521 592 public Type visitCapturedType(CapturedType t, List<TypeCompound> s) {
jjg@1521 593 return new AnnotatedType(s, t);
jjg@1521 594 }
jjg@1521 595
jjg@1521 596 @Override
jjg@1521 597 public Type visitForAll(ForAll t, List<TypeCompound> s) {
jjg@1521 598 // Impossible?
jjg@1521 599 return t;
jjg@1521 600 }
jjg@1521 601
jjg@1521 602 @Override
jjg@1521 603 public Type visitUndetVar(UndetVar t, List<TypeCompound> s) {
jjg@1521 604 // Impossible?
jjg@1521 605 return t;
jjg@1521 606 }
jjg@1521 607
jjg@1521 608 @Override
jjg@1521 609 public Type visitErrorType(ErrorType t, List<TypeCompound> s) {
jjg@1521 610 return new AnnotatedType(s, t);
jjg@1521 611 }
jjg@1521 612
jjg@1521 613 @Override
jjg@1521 614 public Type visitType(Type t, List<TypeCompound> s) {
jjg@1563 615 return new AnnotatedType(s, t);
jjg@1521 616 }
jjg@1521 617 };
jjg@1521 618
jjg@1521 619 return type.accept(visitor, annotations);
jjg@1521 620 }
jjg@1521 621
jjg@1521 622 private static Attribute.TypeCompound toTypeCompound(Attribute.Compound a, TypeAnnotationPosition p) {
jjg@1521 623 // It is safe to alias the position.
jjg@1521 624 return new Attribute.TypeCompound(a, p);
jjg@1521 625 }
jjg@1521 626
jjg@1521 627
jjg@1521 628 /* This is the beginning of the second part of organizing
jjg@1521 629 * type annotations: determine the type annotation positions.
jjg@1521 630 */
jjg@1521 631
jjg@1521 632 private void resolveFrame(JCTree tree, JCTree frame,
jjg@1521 633 List<JCTree> path, TypeAnnotationPosition p) {
jjg@1521 634 /*
jjg@1521 635 System.out.println("Resolving tree: " + tree + " kind: " + tree.getKind());
jjg@1521 636 System.out.println(" Framing tree: " + frame + " kind: " + frame.getKind());
jjg@1521 637 */
jjg@1563 638
jjg@1563 639 // Note that p.offset is set in
jjg@1563 640 // com.sun.tools.javac.jvm.Gen.setTypeAnnotationPositions(int)
jjg@1563 641
jjg@1521 642 switch (frame.getKind()) {
jjg@1521 643 case TYPE_CAST:
jjg@1755 644 JCTypeCast frameTC = (JCTypeCast) frame;
jjg@1521 645 p.type = TargetType.CAST;
jjg@1755 646 if (frameTC.clazz.hasTag(Tag.TYPEINTERSECTION)) {
jjg@1755 647 // This case was already handled by INTERSECTION_TYPE
jjg@1755 648 } else {
jjg@1755 649 p.type_index = 0;
jjg@1755 650 }
jjg@1521 651 p.pos = frame.pos;
jjg@1521 652 return;
jjg@1521 653
jjg@1521 654 case INSTANCE_OF:
jjg@1521 655 p.type = TargetType.INSTANCEOF;
jjg@1521 656 p.pos = frame.pos;
jjg@1521 657 return;
jjg@1521 658
jjg@1521 659 case NEW_CLASS:
jjg@1755 660 JCNewClass frameNewClass = (JCNewClass) frame;
jjg@1755 661 if (frameNewClass.def != null) {
jjg@1755 662 // Special handling for anonymous class instantiations
jjg@1755 663 JCClassDecl frameClassDecl = frameNewClass.def;
jjg@1755 664 if (frameClassDecl.extending == tree) {
jjg@1755 665 p.type = TargetType.CLASS_EXTENDS;
jjg@1755 666 p.type_index = -1;
jjg@1755 667 } else if (frameClassDecl.implementing.contains(tree)) {
jjg@1755 668 p.type = TargetType.CLASS_EXTENDS;
jjg@1755 669 p.type_index = frameClassDecl.implementing.indexOf(tree);
jjg@1755 670 } else {
jjg@1755 671 // In contrast to CLASS below, typarams cannot occur here.
jjg@1755 672 Assert.error("Could not determine position of tree " + tree +
jjg@1755 673 " within frame " + frame);
jjg@1755 674 }
jjg@1755 675 } else if (frameNewClass.typeargs.contains(tree)) {
jjg@1521 676 p.type = TargetType.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT;
jjg@1521 677 p.type_index = frameNewClass.typeargs.indexOf(tree);
jjg@1521 678 } else {
jjg@1521 679 p.type = TargetType.NEW;
jjg@1521 680 }
jjg@1521 681 p.pos = frame.pos;
jjg@1521 682 return;
jjg@1521 683
jjg@1521 684 case NEW_ARRAY:
jjg@1521 685 p.type = TargetType.NEW;
jjg@1521 686 p.pos = frame.pos;
jjg@1521 687 return;
jjg@1521 688
jjg@1521 689 case ANNOTATION_TYPE:
jjg@1521 690 case CLASS:
jjg@1521 691 case ENUM:
jjg@1521 692 case INTERFACE:
jjg@1521 693 p.pos = frame.pos;
jjg@1521 694 if (((JCClassDecl)frame).extending == tree) {
jjg@1521 695 p.type = TargetType.CLASS_EXTENDS;
jjg@1521 696 p.type_index = -1;
jjg@1521 697 } else if (((JCClassDecl)frame).implementing.contains(tree)) {
jjg@1521 698 p.type = TargetType.CLASS_EXTENDS;
jjg@1521 699 p.type_index = ((JCClassDecl)frame).implementing.indexOf(tree);
jjg@1521 700 } else if (((JCClassDecl)frame).typarams.contains(tree)) {
jjg@1521 701 p.type = TargetType.CLASS_TYPE_PARAMETER;
jjg@1521 702 p.parameter_index = ((JCClassDecl)frame).typarams.indexOf(tree);
jjg@1521 703 } else {
jjg@1521 704 Assert.error("Could not determine position of tree " + tree +
jjg@1521 705 " within frame " + frame);
jjg@1521 706 }
jjg@1521 707 return;
jjg@1521 708
jjg@1521 709 case METHOD: {
jjg@1521 710 JCMethodDecl frameMethod = (JCMethodDecl) frame;
jjg@1521 711 p.pos = frame.pos;
jjg@1521 712 if (frameMethod.thrown.contains(tree)) {
jjg@1521 713 p.type = TargetType.THROWS;
jjg@1521 714 p.type_index = frameMethod.thrown.indexOf(tree);
jjg@1521 715 } else if (frameMethod.restype == tree) {
jjg@1521 716 p.type = TargetType.METHOD_RETURN;
jjg@1521 717 } else if (frameMethod.typarams.contains(tree)) {
jjg@1521 718 p.type = TargetType.METHOD_TYPE_PARAMETER;
jjg@1521 719 p.parameter_index = frameMethod.typarams.indexOf(tree);
jjg@1521 720 } else {
jjg@1521 721 Assert.error("Could not determine position of tree " + tree +
jjg@1521 722 " within frame " + frame);
jjg@1521 723 }
jjg@1521 724 return;
jjg@1521 725 }
jjg@1521 726
jjg@1521 727 case PARAMETERIZED_TYPE: {
jjg@1755 728 List<JCTree> newPath = path.tail;
jjg@1755 729
jjg@1521 730 if (((JCTypeApply)frame).clazz == tree) {
jjg@1521 731 // generic: RAW; noop
jjg@1521 732 } else if (((JCTypeApply)frame).arguments.contains(tree)) {
jjg@1521 733 JCTypeApply taframe = (JCTypeApply) frame;
jjg@1521 734 int arg = taframe.arguments.indexOf(tree);
jjg@1521 735 p.location = p.location.prepend(new TypePathEntry(TypePathEntryKind.TYPE_ARGUMENT, arg));
jjg@1521 736
jjg@1755 737 Type typeToUse;
jjg@1755 738 if (newPath.tail != null && newPath.tail.head.hasTag(Tag.NEWCLASS)) {
jjg@1755 739 // If we are within an anonymous class instantiation, use its type,
jjg@1755 740 // because it contains a correctly nested type.
jjg@1755 741 typeToUse = newPath.tail.head.type;
jjg@1755 742 } else {
jjg@1755 743 typeToUse = taframe.type;
jjg@1755 744 }
jjg@1755 745
jjg@1755 746 locateNestedTypes(typeToUse, p);
jjg@1521 747 } else {
jjg@1521 748 Assert.error("Could not determine type argument position of tree " + tree +
jjg@1521 749 " within frame " + frame);
jjg@1521 750 }
jjg@1521 751
jjg@1521 752 resolveFrame(newPath.head, newPath.tail.head, newPath, p);
jjg@1521 753 return;
jjg@1521 754 }
jjg@1521 755
jjg@1563 756 case MEMBER_REFERENCE: {
jjg@1563 757 JCMemberReference mrframe = (JCMemberReference) frame;
jjg@1563 758
jjg@1563 759 if (mrframe.expr == tree) {
jjg@1563 760 switch (mrframe.mode) {
jjg@1563 761 case INVOKE:
jjg@1563 762 p.type = TargetType.METHOD_REFERENCE;
jjg@1563 763 break;
jjg@1563 764 case NEW:
jjg@1563 765 p.type = TargetType.CONSTRUCTOR_REFERENCE;
jjg@1563 766 break;
jjg@1563 767 default:
jjg@1563 768 Assert.error("Unknown method reference mode " + mrframe.mode +
jjg@1563 769 " for tree " + tree + " within frame " + frame);
jjg@1563 770 }
jjg@1563 771 p.pos = frame.pos;
jjg@1563 772 } else if (mrframe.typeargs != null &&
jjg@1563 773 mrframe.typeargs.contains(tree)) {
jjg@1563 774 int arg = mrframe.typeargs.indexOf(tree);
jjg@1563 775 p.type_index = arg;
jjg@1563 776 switch (mrframe.mode) {
jjg@1563 777 case INVOKE:
jjg@1563 778 p.type = TargetType.METHOD_REFERENCE_TYPE_ARGUMENT;
jjg@1563 779 break;
jjg@1563 780 case NEW:
jjg@1563 781 p.type = TargetType.CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT;
jjg@1563 782 break;
jjg@1563 783 default:
jjg@1563 784 Assert.error("Unknown method reference mode " + mrframe.mode +
jjg@1563 785 " for tree " + tree + " within frame " + frame);
jjg@1563 786 }
jjg@1563 787 p.pos = frame.pos;
jjg@1563 788 } else {
jjg@1563 789 Assert.error("Could not determine type argument position of tree " + tree +
jjg@1563 790 " within frame " + frame);
jjg@1563 791 }
jjg@1563 792 return;
jjg@1563 793 }
jjg@1563 794
jjg@1521 795 case ARRAY_TYPE: {
jjg@1521 796 ListBuffer<TypePathEntry> index = ListBuffer.lb();
jjg@1521 797 index = index.append(TypePathEntry.ARRAY);
jjg@1521 798 List<JCTree> newPath = path.tail;
jjg@1521 799 while (true) {
jjg@1521 800 JCTree npHead = newPath.tail.head;
jjg@1521 801 if (npHead.hasTag(JCTree.Tag.TYPEARRAY)) {
jjg@1521 802 newPath = newPath.tail;
jjg@1521 803 index = index.append(TypePathEntry.ARRAY);
jjg@1521 804 } else if (npHead.hasTag(JCTree.Tag.ANNOTATED_TYPE)) {
jjg@1521 805 newPath = newPath.tail;
jjg@1521 806 } else {
jjg@1521 807 break;
jjg@1521 808 }
jjg@1521 809 }
jjg@1521 810 p.location = p.location.prependList(index.toList());
jjg@1521 811 resolveFrame(newPath.head, newPath.tail.head, newPath, p);
jjg@1521 812 return;
jjg@1521 813 }
jjg@1521 814
jjg@1521 815 case TYPE_PARAMETER:
jjg@1521 816 if (path.tail.tail.head.hasTag(JCTree.Tag.CLASSDEF)) {
jjg@1521 817 JCClassDecl clazz = (JCClassDecl)path.tail.tail.head;
jjg@1521 818 p.type = TargetType.CLASS_TYPE_PARAMETER_BOUND;
jjg@1521 819 p.parameter_index = clazz.typarams.indexOf(path.tail.head);
jjg@1521 820 p.bound_index = ((JCTypeParameter)frame).bounds.indexOf(tree);
jjg@1521 821 if (((JCTypeParameter)frame).bounds.get(0).type.isInterface()) {
jjg@1521 822 // Account for an implicit Object as bound 0
jjg@1521 823 p.bound_index += 1;
jjg@1521 824 }
jjg@1521 825 } else if (path.tail.tail.head.hasTag(JCTree.Tag.METHODDEF)) {
jjg@1521 826 JCMethodDecl method = (JCMethodDecl)path.tail.tail.head;
jjg@1521 827 p.type = TargetType.METHOD_TYPE_PARAMETER_BOUND;
jjg@1521 828 p.parameter_index = method.typarams.indexOf(path.tail.head);
jjg@1521 829 p.bound_index = ((JCTypeParameter)frame).bounds.indexOf(tree);
jjg@1521 830 if (((JCTypeParameter)frame).bounds.get(0).type.isInterface()) {
jjg@1521 831 // Account for an implicit Object as bound 0
jjg@1521 832 p.bound_index += 1;
jjg@1521 833 }
jjg@1521 834 } else {
jjg@1521 835 Assert.error("Could not determine position of tree " + tree +
jjg@1521 836 " within frame " + frame);
jjg@1521 837 }
jjg@1521 838 p.pos = frame.pos;
jjg@1521 839 return;
jjg@1521 840
jjg@1521 841 case VARIABLE:
jjg@1521 842 VarSymbol v = ((JCVariableDecl)frame).sym;
jjg@1521 843 p.pos = frame.pos;
jjg@1521 844 switch (v.getKind()) {
jjg@1521 845 case LOCAL_VARIABLE:
jjg@1521 846 p.type = TargetType.LOCAL_VARIABLE;
jjg@1521 847 break;
jjg@1521 848 case FIELD:
jjg@1521 849 p.type = TargetType.FIELD;
jjg@1521 850 break;
jjg@1521 851 case PARAMETER:
jjg@1521 852 if (v.getQualifiedName().equals(names._this)) {
jjg@1521 853 // TODO: Intro a separate ElementKind?
jjg@1521 854 p.type = TargetType.METHOD_RECEIVER;
jjg@1521 855 } else {
jjg@1521 856 p.type = TargetType.METHOD_FORMAL_PARAMETER;
jjg@1521 857 p.parameter_index = methodParamIndex(path, frame);
jjg@1521 858 }
jjg@1521 859 break;
jjg@1521 860 case EXCEPTION_PARAMETER:
jjg@1521 861 p.type = TargetType.EXCEPTION_PARAMETER;
jjg@1521 862 break;
jjg@1521 863 case RESOURCE_VARIABLE:
jjg@1521 864 p.type = TargetType.RESOURCE_VARIABLE;
jjg@1521 865 break;
jjg@1521 866 default:
jjg@1521 867 Assert.error("Found unexpected type annotation for variable: " + v + " with kind: " + v.getKind());
jjg@1521 868 }
jjg@1755 869 if (v.getKind() != ElementKind.FIELD) {
jjg@1802 870 v.owner.appendUniqueTypeAttributes(v.getRawTypeAttributes());
jjg@1755 871 }
jjg@1521 872 return;
jjg@1521 873
jjg@1521 874 case ANNOTATED_TYPE: {
jjg@1521 875 if (frame == tree) {
jjg@1521 876 // This is only true for the first annotated type we see.
jjg@1521 877 // For any other annotated types along the path, we do
jjg@1521 878 // not care about inner types.
jjg@1521 879 JCAnnotatedType atypetree = (JCAnnotatedType) frame;
jjg@1521 880 final Type utype = atypetree.underlyingType.type;
jjg@1755 881 if (utype == null) {
jjg@1755 882 // This might happen during DeferredAttr;
jjg@1755 883 // we will be back later.
jjg@1755 884 return;
jjg@1755 885 }
jjg@1521 886 Symbol tsym = utype.tsym;
jjg@1521 887 if (tsym.getKind().equals(ElementKind.TYPE_PARAMETER) ||
jjg@1521 888 utype.getKind().equals(TypeKind.WILDCARD) ||
jjg@1521 889 utype.getKind().equals(TypeKind.ARRAY)) {
jjg@1521 890 // Type parameters, wildcards, and arrays have the declaring
jjg@1521 891 // class/method as enclosing elements.
jjg@1521 892 // There is actually nothing to do for them.
jjg@1521 893 } else {
jjg@1521 894 locateNestedTypes(utype, p);
jjg@1521 895 }
jjg@1521 896 }
jjg@1521 897 List<JCTree> newPath = path.tail;
jjg@1521 898 resolveFrame(newPath.head, newPath.tail.head, newPath, p);
jjg@1521 899 return;
jjg@1521 900 }
jjg@1521 901
jjg@1521 902 case UNION_TYPE: {
jjg@1521 903 List<JCTree> newPath = path.tail;
jjg@1521 904 resolveFrame(newPath.head, newPath.tail.head, newPath, p);
jjg@1521 905 return;
jjg@1521 906 }
jjg@1521 907
jjg@1563 908 case INTERSECTION_TYPE: {
jjg@1563 909 JCTypeIntersection isect = (JCTypeIntersection)frame;
jjg@1563 910 p.type_index = isect.bounds.indexOf(tree);
jjg@1563 911 List<JCTree> newPath = path.tail;
jjg@1563 912 resolveFrame(newPath.head, newPath.tail.head, newPath, p);
jjg@1563 913 return;
jjg@1563 914 }
jjg@1563 915
jjg@1521 916 case METHOD_INVOCATION: {
jjg@1521 917 JCMethodInvocation invocation = (JCMethodInvocation)frame;
jjg@1521 918 if (!invocation.typeargs.contains(tree)) {
jjg@1521 919 Assert.error("{" + tree + "} is not an argument in the invocation: " + invocation);
jjg@1521 920 }
jjg@1969 921 MethodSymbol exsym = (MethodSymbol) TreeInfo.symbol(invocation.getMethodSelect());
jjg@1969 922 if (exsym == null) {
jjg@1969 923 Assert.error("could not determine symbol for {" + invocation + "}");
jjg@1969 924 } else if (exsym.isConstructor()) {
jjg@1969 925 p.type = TargetType.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT;
jjg@1969 926 } else {
jjg@1969 927 p.type = TargetType.METHOD_INVOCATION_TYPE_ARGUMENT;
jjg@1969 928 }
jjg@1521 929 p.pos = invocation.pos;
jjg@1521 930 p.type_index = invocation.typeargs.indexOf(tree);
jjg@1521 931 return;
jjg@1521 932 }
jjg@1521 933
jjg@1521 934 case EXTENDS_WILDCARD:
jjg@1521 935 case SUPER_WILDCARD: {
jjg@1521 936 // Annotations in wildcard bounds
jjg@1521 937 p.location = p.location.prepend(TypePathEntry.WILDCARD);
jjg@1521 938 List<JCTree> newPath = path.tail;
jjg@1521 939 resolveFrame(newPath.head, newPath.tail.head, newPath, p);
jjg@1521 940 return;
jjg@1521 941 }
jjg@1521 942
jjg@1521 943 case MEMBER_SELECT: {
jjg@1521 944 List<JCTree> newPath = path.tail;
jjg@1521 945 resolveFrame(newPath.head, newPath.tail.head, newPath, p);
jjg@1521 946 return;
jjg@1521 947 }
jjg@1521 948
jjg@1521 949 default:
jjg@1521 950 Assert.error("Unresolved frame: " + frame + " of kind: " + frame.getKind() +
jjg@1521 951 "\n Looking for tree: " + tree);
jjg@1521 952 return;
jjg@1521 953 }
jjg@1521 954 }
jjg@1521 955
jjg@1521 956 private static void locateNestedTypes(Type type, TypeAnnotationPosition p) {
jjg@1521 957 // The number of "steps" to get from the full type to the
jjg@1521 958 // left-most outer type.
jjg@1521 959 ListBuffer<TypePathEntry> depth = ListBuffer.lb();
jjg@1521 960
jjg@1521 961 Type encl = type.getEnclosingType();
jjg@1521 962 while (encl != null &&
jjg@1521 963 encl.getKind() != TypeKind.NONE &&
jjg@1521 964 encl.getKind() != TypeKind.ERROR) {
jjg@1521 965 depth = depth.append(TypePathEntry.INNER_TYPE);
jjg@1521 966 encl = encl.getEnclosingType();
jjg@1521 967 }
jjg@1521 968 if (depth.nonEmpty()) {
jjg@1521 969 p.location = p.location.prependList(depth.toList());
jjg@1521 970 }
jjg@1521 971 }
jjg@1521 972
jjg@1521 973 private static int methodParamIndex(List<JCTree> path, JCTree param) {
jjg@1521 974 List<JCTree> curr = path;
jjg@1755 975 while (curr.head.getTag() != Tag.METHODDEF &&
jjg@1755 976 curr.head.getTag() != Tag.LAMBDA) {
jjg@1521 977 curr = curr.tail;
jjg@1521 978 }
jjg@1755 979 if (curr.head.getTag() == Tag.METHODDEF) {
jjg@1755 980 JCMethodDecl method = (JCMethodDecl)curr.head;
jjg@1755 981 return method.params.indexOf(param);
jjg@1755 982 } else if (curr.head.getTag() == Tag.LAMBDA) {
jjg@1755 983 JCLambda lambda = (JCLambda)curr.head;
jjg@1755 984 return lambda.params.indexOf(param);
jjg@1755 985 } else {
jjg@1755 986 Assert.error("methodParamIndex expected to find method or lambda for param: " + param);
jjg@1755 987 return -1;
jjg@1755 988 }
jjg@1521 989 }
jjg@1521 990
jjg@1521 991 // Each class (including enclosed inner classes) is visited separately.
jjg@1521 992 // This flag is used to prevent from visiting inner classes.
jjg@1521 993 private boolean isInClass = false;
jjg@1521 994
jjg@1521 995 @Override
jjg@1521 996 public void visitClassDef(JCClassDecl tree) {
jjg@1521 997 if (isInClass)
jjg@1521 998 return;
jjg@1521 999 isInClass = true;
jjg@1755 1000
jjg@1521 1001 if (sigOnly) {
jjg@1521 1002 scan(tree.mods);
jjg@1521 1003 scan(tree.typarams);
jjg@1521 1004 scan(tree.extending);
jjg@1521 1005 scan(tree.implementing);
jjg@1521 1006 }
jjg@1521 1007 scan(tree.defs);
jjg@1521 1008 }
jjg@1521 1009
jjg@1521 1010 /**
jjg@1521 1011 * Resolve declaration vs. type annotations in methods and
jjg@1521 1012 * then determine the positions.
jjg@1521 1013 */
jjg@1521 1014 @Override
jjg@1521 1015 public void visitMethodDef(final JCMethodDecl tree) {
jjg@1521 1016 if (tree.sym == null) {
jjg@1521 1017 // Something most be wrong, e.g. a class not found.
jjg@1521 1018 // Quietly ignore. (See test FailOver15.java)
jjg@1521 1019 return;
jjg@1521 1020 }
jjg@1521 1021 if (sigOnly) {
jjg@1755 1022 if (!tree.mods.annotations.isEmpty()) {
jjg@1755 1023 // Nothing to do for separateAnnotationsKinds if
jjg@1755 1024 // there are no annotations of either kind.
jjg@1521 1025 TypeAnnotationPosition pos = new TypeAnnotationPosition();
jjg@1521 1026 pos.type = TargetType.METHOD_RETURN;
jjg@1521 1027 if (tree.sym.isConstructor()) {
jjg@1521 1028 pos.pos = tree.pos;
jjg@1521 1029 // Use null to mark that the annotations go with the symbol.
jjg@1521 1030 separateAnnotationsKinds(tree, null, tree.sym, pos);
jjg@1521 1031 } else {
jjg@1521 1032 pos.pos = tree.restype.pos;
jjg@1521 1033 separateAnnotationsKinds(tree.restype, tree.sym.type.getReturnType(),
jjg@1521 1034 tree.sym, pos);
jjg@1521 1035 }
jjg@1521 1036 }
jjg@1755 1037 if (tree.recvparam != null && tree.recvparam.sym != null &&
jjg@1755 1038 !tree.recvparam.mods.annotations.isEmpty()) {
jjg@1755 1039 // Nothing to do for separateAnnotationsKinds if
jjg@1755 1040 // there are no annotations of either kind.
jjg@1521 1041 // TODO: make sure there are no declaration annotations.
jjg@1521 1042 TypeAnnotationPosition pos = new TypeAnnotationPosition();
jjg@1521 1043 pos.type = TargetType.METHOD_RECEIVER;
jjg@1521 1044 pos.pos = tree.recvparam.vartype.pos;
jjg@1521 1045 separateAnnotationsKinds(tree.recvparam.vartype, tree.recvparam.sym.type,
jjg@1521 1046 tree.recvparam.sym, pos);
jjg@1521 1047 }
jjg@1521 1048 int i = 0;
jjg@1521 1049 for (JCVariableDecl param : tree.params) {
jjg@1755 1050 if (!param.mods.annotations.isEmpty()) {
jjg@1755 1051 // Nothing to do for separateAnnotationsKinds if
jjg@1755 1052 // there are no annotations of either kind.
jjg@1755 1053 TypeAnnotationPosition pos = new TypeAnnotationPosition();
jjg@1755 1054 pos.type = TargetType.METHOD_FORMAL_PARAMETER;
jjg@1755 1055 pos.parameter_index = i;
jjg@1755 1056 pos.pos = param.vartype.pos;
jjg@1755 1057 separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos);
jjg@1755 1058 }
jjg@1521 1059 ++i;
jjg@1521 1060 }
jjg@1521 1061 }
jjg@1521 1062
jjg@1521 1063 push(tree);
jjg@1521 1064 // super.visitMethodDef(tree);
jjg@1521 1065 if (sigOnly) {
jjg@1521 1066 scan(tree.mods);
jjg@1521 1067 scan(tree.restype);
jjg@1521 1068 scan(tree.typarams);
jjg@1521 1069 scan(tree.recvparam);
jjg@1521 1070 scan(tree.params);
jjg@1521 1071 scan(tree.thrown);
jjg@1521 1072 } else {
jjg@1521 1073 scan(tree.defaultValue);
jjg@1521 1074 scan(tree.body);
jjg@1521 1075 }
jjg@1521 1076 pop();
jjg@1521 1077 }
jjg@1521 1078
jjg@1755 1079 /* Store a reference to the current lambda expression, to
jjg@1755 1080 * be used by all type annotations within this expression.
jjg@1755 1081 */
jjg@1755 1082 private JCLambda currentLambda = null;
jjg@1755 1083
jjg@1755 1084 public void visitLambda(JCLambda tree) {
jjg@1755 1085 JCLambda prevLambda = currentLambda;
jjg@1755 1086 try {
jjg@1755 1087 currentLambda = tree;
jjg@1755 1088
jjg@1755 1089 int i = 0;
jjg@1755 1090 for (JCVariableDecl param : tree.params) {
jjg@1755 1091 if (!param.mods.annotations.isEmpty()) {
jjg@1755 1092 // Nothing to do for separateAnnotationsKinds if
jjg@1755 1093 // there are no annotations of either kind.
jjg@1755 1094 TypeAnnotationPosition pos = new TypeAnnotationPosition();
jjg@1755 1095 pos.type = TargetType.METHOD_FORMAL_PARAMETER;
jjg@1755 1096 pos.parameter_index = i;
jjg@1755 1097 pos.pos = param.vartype.pos;
jjg@1755 1098 pos.onLambda = tree;
jjg@1755 1099 separateAnnotationsKinds(param.vartype, param.sym.type, param.sym, pos);
jjg@1755 1100 }
jjg@1755 1101 ++i;
jjg@1755 1102 }
jjg@1755 1103
jjg@1755 1104 push(tree);
jjg@1755 1105 scan(tree.body);
jjg@1755 1106 scan(tree.params);
jjg@1755 1107 pop();
jjg@1755 1108 } finally {
jjg@1755 1109 currentLambda = prevLambda;
jjg@1755 1110 }
jjg@1755 1111 }
jjg@1755 1112
jjg@1521 1113 /**
jjg@1521 1114 * Resolve declaration vs. type annotations in variable declarations and
jjg@1521 1115 * then determine the positions.
jjg@1521 1116 */
jjg@1521 1117 @Override
jjg@1521 1118 public void visitVarDef(final JCVariableDecl tree) {
jjg@1755 1119 if (tree.mods.annotations.isEmpty()) {
jjg@1755 1120 // Nothing to do for separateAnnotationsKinds if
jjg@1755 1121 // there are no annotations of either kind.
jjg@1755 1122 } else if (tree.sym == null) {
jjg@1521 1123 // Something is wrong already. Quietly ignore.
jjg@1563 1124 } else if (tree.sym.getKind() == ElementKind.PARAMETER) {
jjg@1755 1125 // Parameters are handled in visitMethodDef or visitLambda.
jjg@1521 1126 } else if (tree.sym.getKind() == ElementKind.FIELD) {
jjg@1521 1127 if (sigOnly) {
jjg@1521 1128 TypeAnnotationPosition pos = new TypeAnnotationPosition();
jjg@1521 1129 pos.type = TargetType.FIELD;
jjg@1521 1130 pos.pos = tree.pos;
jjg@1521 1131 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
jjg@1521 1132 }
jjg@1521 1133 } else if (tree.sym.getKind() == ElementKind.LOCAL_VARIABLE) {
jjg@1521 1134 TypeAnnotationPosition pos = new TypeAnnotationPosition();
jjg@1521 1135 pos.type = TargetType.LOCAL_VARIABLE;
jjg@1521 1136 pos.pos = tree.pos;
jjg@1755 1137 pos.onLambda = currentLambda;
jjg@1521 1138 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
jjg@1521 1139 } else if (tree.sym.getKind() == ElementKind.EXCEPTION_PARAMETER) {
jjg@1521 1140 TypeAnnotationPosition pos = new TypeAnnotationPosition();
jjg@1521 1141 pos.type = TargetType.EXCEPTION_PARAMETER;
jjg@1521 1142 pos.pos = tree.pos;
jjg@1755 1143 pos.onLambda = currentLambda;
jjg@1521 1144 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
jjg@1521 1145 } else if (tree.sym.getKind() == ElementKind.RESOURCE_VARIABLE) {
jjg@1521 1146 TypeAnnotationPosition pos = new TypeAnnotationPosition();
jjg@1521 1147 pos.type = TargetType.RESOURCE_VARIABLE;
jjg@1521 1148 pos.pos = tree.pos;
jjg@1755 1149 pos.onLambda = currentLambda;
jjg@1521 1150 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
jjg@1563 1151 } else if (tree.sym.getKind() == ElementKind.ENUM_CONSTANT) {
jjg@1563 1152 // No type annotations can occur here.
jjg@1521 1153 } else {
jjg@1521 1154 // There is nothing else in a variable declaration that needs separation.
jjg@1563 1155 Assert.error("Unhandled variable kind: " + tree + " of kind: " + tree.sym.getKind());
jjg@1521 1156 }
jjg@1521 1157
jjg@1521 1158 push(tree);
jjg@1521 1159 // super.visitVarDef(tree);
jjg@1521 1160 scan(tree.mods);
jjg@1521 1161 scan(tree.vartype);
jjg@1521 1162 if (!sigOnly) {
jjg@1521 1163 scan(tree.init);
jjg@1521 1164 }
jjg@1521 1165 pop();
jjg@1521 1166 }
jjg@1521 1167
jjg@1521 1168 @Override
jjg@1521 1169 public void visitBlock(JCBlock tree) {
jjg@1521 1170 // Do not descend into top-level blocks when only interested
jjg@1521 1171 // in the signature.
jjg@1521 1172 if (!sigOnly) {
jjg@1521 1173 scan(tree.stats);
jjg@1521 1174 }
jjg@1521 1175 }
jjg@1521 1176
jjg@1521 1177 @Override
jjg@1521 1178 public void visitAnnotatedType(JCAnnotatedType tree) {
jjg@1521 1179 push(tree);
jjg@1521 1180 findPosition(tree, tree, tree.annotations);
jjg@1521 1181 pop();
jjg@1521 1182 super.visitAnnotatedType(tree);
jjg@1521 1183 }
jjg@1521 1184
jjg@1521 1185 @Override
jjg@1521 1186 public void visitTypeParameter(JCTypeParameter tree) {
jjg@1521 1187 findPosition(tree, peek2(), tree.annotations);
jjg@1521 1188 super.visitTypeParameter(tree);
jjg@1521 1189 }
jjg@1521 1190
jjg@1521 1191 @Override
jjg@1755 1192 public void visitNewClass(JCNewClass tree) {
jjg@1755 1193 if (tree.def != null &&
jjg@1755 1194 !tree.def.mods.annotations.isEmpty()) {
jjg@1755 1195 JCClassDecl classdecl = tree.def;
jjg@1755 1196 TypeAnnotationPosition pos = new TypeAnnotationPosition();
jjg@1755 1197 pos.type = TargetType.CLASS_EXTENDS;
jjg@1755 1198 pos.pos = tree.pos;
jjg@1755 1199 if (classdecl.extending == tree.clazz) {
jjg@1755 1200 pos.type_index = -1;
jjg@1755 1201 } else if (classdecl.implementing.contains(tree.clazz)) {
jjg@1755 1202 pos.type_index = classdecl.implementing.indexOf(tree.clazz);
jjg@1755 1203 } else {
jjg@1755 1204 // In contrast to CLASS elsewhere, typarams cannot occur here.
jjg@1755 1205 Assert.error("Could not determine position of tree " + tree);
jjg@1755 1206 }
jjg@1755 1207 Type before = classdecl.sym.type;
jjg@1755 1208 separateAnnotationsKinds(classdecl, tree.clazz.type, classdecl.sym, pos);
jjg@1755 1209
jjg@1755 1210 // classdecl.sym.type now contains an annotated type, which
jjg@1755 1211 // is not what we want there.
jjg@1755 1212 // TODO: should we put this type somewhere in the superclass/interface?
jjg@1755 1213 classdecl.sym.type = before;
jjg@1755 1214 }
jjg@1755 1215
jjg@1755 1216 scan(tree.encl);
jjg@1755 1217 scan(tree.typeargs);
jjg@1755 1218 scan(tree.clazz);
jjg@1755 1219 scan(tree.args);
jjg@1755 1220
jjg@1755 1221 // The class body will already be scanned.
jjg@1755 1222 // scan(tree.def);
jjg@1755 1223 }
jjg@1755 1224
jjg@1755 1225 @Override
jjg@1521 1226 public void visitNewArray(JCNewArray tree) {
jjg@1521 1227 findPosition(tree, tree, tree.annotations);
jjg@1521 1228 int dimAnnosCount = tree.dimAnnotations.size();
jjg@1521 1229 ListBuffer<TypePathEntry> depth = ListBuffer.lb();
jjg@1521 1230
jjg@1521 1231 // handle annotations associated with dimensions
jjg@1521 1232 for (int i = 0; i < dimAnnosCount; ++i) {
jjg@1521 1233 TypeAnnotationPosition p = new TypeAnnotationPosition();
jjg@1521 1234 p.pos = tree.pos;
jjg@1755 1235 p.onLambda = currentLambda;
jjg@1521 1236 p.type = TargetType.NEW;
jjg@1521 1237 if (i != 0) {
jjg@1521 1238 depth = depth.append(TypePathEntry.ARRAY);
jjg@1521 1239 p.location = p.location.appendList(depth.toList());
jjg@1521 1240 }
jjg@1521 1241
jjg@1521 1242 setTypeAnnotationPos(tree.dimAnnotations.get(i), p);
jjg@1521 1243 }
jjg@1521 1244
jjg@1521 1245 // handle "free" annotations
jjg@1521 1246 // int i = dimAnnosCount == 0 ? 0 : dimAnnosCount - 1;
jjg@1521 1247 // TODO: is depth.size == i here?
jjg@1521 1248 JCExpression elemType = tree.elemtype;
jjg@1755 1249 depth = depth.append(TypePathEntry.ARRAY);
jjg@1521 1250 while (elemType != null) {
jjg@1521 1251 if (elemType.hasTag(JCTree.Tag.ANNOTATED_TYPE)) {
jjg@1521 1252 JCAnnotatedType at = (JCAnnotatedType)elemType;
jjg@1521 1253 TypeAnnotationPosition p = new TypeAnnotationPosition();
jjg@1521 1254 p.type = TargetType.NEW;
jjg@1521 1255 p.pos = tree.pos;
jjg@1755 1256 p.onLambda = currentLambda;
jjg@1755 1257 locateNestedTypes(elemType.type, p);
jjg@1755 1258 p.location = p.location.prependList(depth.toList());
jjg@1521 1259 setTypeAnnotationPos(at.annotations, p);
jjg@1521 1260 elemType = at.underlyingType;
jjg@1521 1261 } else if (elemType.hasTag(JCTree.Tag.TYPEARRAY)) {
jjg@1521 1262 depth = depth.append(TypePathEntry.ARRAY);
jjg@1521 1263 elemType = ((JCArrayTypeTree)elemType).elemtype;
jjg@1755 1264 } else if (elemType.hasTag(JCTree.Tag.SELECT)) {
jjg@1755 1265 elemType = ((JCFieldAccess)elemType).selected;
jjg@1521 1266 } else {
jjg@1521 1267 break;
jjg@1521 1268 }
jjg@1521 1269 }
jjg@1521 1270 scan(tree.elems);
jjg@1521 1271 }
jjg@1521 1272
jjg@1521 1273 private void findPosition(JCTree tree, JCTree frame, List<JCAnnotation> annotations) {
jjg@1521 1274 if (!annotations.isEmpty()) {
jjg@1521 1275 /*
jjg@1521 1276 System.out.println("Finding pos for: " + annotations);
jjg@1755 1277 System.out.println(" tree: " + tree + " kind: " + tree.getKind());
jjg@1755 1278 System.out.println(" frame: " + frame + " kind: " + frame.getKind());
jjg@1521 1279 */
jjg@1521 1280 TypeAnnotationPosition p = new TypeAnnotationPosition();
jjg@1755 1281 p.onLambda = currentLambda;
jjg@1521 1282 resolveFrame(tree, frame, frames.toList(), p);
jjg@1521 1283 setTypeAnnotationPos(annotations, p);
jjg@1521 1284 }
jjg@1521 1285 }
jjg@1521 1286
jjg@1521 1287 private static void setTypeAnnotationPos(List<JCAnnotation> annotations,
jjg@1521 1288 TypeAnnotationPosition position) {
jjg@1521 1289 for (JCAnnotation anno : annotations) {
jjg@1755 1290 // attribute might be null during DeferredAttr;
jjg@1755 1291 // we will be back later.
jjg@1755 1292 if (anno.attribute != null) {
jjg@1755 1293 ((Attribute.TypeCompound) anno.attribute).position = position;
jjg@1755 1294 }
jjg@1521 1295 }
jjg@1521 1296 }
jjg@1755 1297
jjg@1755 1298 @Override
jjg@1755 1299 public String toString() {
jjg@1755 1300 return super.toString() + ": sigOnly: " + sigOnly;
jjg@1755 1301 }
jjg@1521 1302 }
jjg@1521 1303 }

mercurial