200 sym.owner.type.asMethodType().recvtype = type;
201 // note that the typeAnnotations will also be added to the owner below.
202 }
203 if (sym.getKind() == ElementKind.PARAMETER ||
204 sym.getKind() == ElementKind.LOCAL_VARIABLE ||
205 sym.getKind() == ElementKind.RESOURCE_VARIABLE ||
206 sym.getKind() == ElementKind.EXCEPTION_PARAMETER) {
207 // Make sure all type annotations from the symbol are also
208 // on the owner.
209 sym.owner.annotations.appendUniqueTypes(sym.getTypeAnnotationMirrors());
210 }
211 }
212
213 // This method has a similar purpose as
214 // {@link com.sun.tools.javac.parser.JavacParser.insertAnnotationsToMostInner(JCExpression, List<JCTypeAnnotation>, boolean)}
215 // We found a type annotation in a declaration annotation position,
216 // for example, on the return type.
217 // Such an annotation is _not_ part of an JCAnnotatedType tree and we therefore
218 // need to set its position explicitly.
219 // The method returns a copy of type that contains these annotations.
220 private static Type typeWithAnnotations(final JCTree typetree, final Type type,
221 final List<Attribute.TypeCompound> annotations, Log log) {
222 // System.out.printf("typeWithAnnotations(typetree: %s, type: %s, annotations: %s)%n",
223 // typetree, type, annotations);
224 if (annotations.isEmpty()) {
225 return type;
226 }
227 if (type.hasTag(TypeTag.ARRAY)) {
228 Type toreturn;
229 Type.ArrayType tomodify;
230 Type.ArrayType arType;
231 {
232 Type touse = type;
233 if (type.getKind() == TypeKind.ANNOTATED) {
234 Type.AnnotatedType atype = (Type.AnnotatedType)type;
235 toreturn = new Type.AnnotatedType(atype.underlyingType);
236 ((Type.AnnotatedType)toreturn).typeAnnotations = atype.typeAnnotations;
237 touse = atype.underlyingType;
238 arType = (Type.ArrayType) touse;
239 tomodify = new Type.ArrayType(null, arType.tsym);
250 depth = depth.append(TypePathEntry.ARRAY);
251 while (arType.elemtype.hasTag(TypeTag.ARRAY)) {
252 if (arType.elemtype.getKind() == TypeKind.ANNOTATED) {
253 Type.AnnotatedType aelemtype = (Type.AnnotatedType) arType.elemtype;
254 Type.AnnotatedType newAT = new Type.AnnotatedType(aelemtype.underlyingType);
255 tomodify.elemtype = newAT;
256 newAT.typeAnnotations = aelemtype.typeAnnotations;
257 arType = (Type.ArrayType) aelemtype.underlyingType;
258 tomodify = new Type.ArrayType(null, arType.tsym);
259 newAT.underlyingType = tomodify;
260 } else {
261 arType = (Type.ArrayType) arType.elemtype;
262 tomodify.elemtype = new Type.ArrayType(null, arType.tsym);
263 tomodify = (Type.ArrayType) tomodify.elemtype;
264 }
265 arTree = arrayTypeTree(arTree.elemtype);
266 depth = depth.append(TypePathEntry.ARRAY);
267 }
268 Type arelemType = typeWithAnnotations(arTree.elemtype, arType.elemtype, annotations, log);
269 tomodify.elemtype = arelemType;
270 for (Attribute.TypeCompound a : annotations) {
271 TypeAnnotationPosition p = a.position;
272 p.location = p.location.prependList(depth.toList());
273 }
274 return toreturn;
275 } else if (type.hasTag(TypeTag.TYPEVAR)) {
276 // Nothing to do for type variables.
277 return type;
278 } else {
279 Type enclTy = type;
280 Element enclEl = type.asElement();
281 JCTree enclTr = typetree;
282
283 while (enclEl != null &&
284 enclEl.getKind() != ElementKind.PACKAGE &&
285 enclTy != null &&
286 enclTy.getKind() != TypeKind.NONE &&
287 enclTy.getKind() != TypeKind.ERROR &&
288 (enclTr.getKind() == JCTree.Kind.MEMBER_SELECT ||
289 enclTr.getKind() == JCTree.Kind.PARAMETERIZED_TYPE ||
290 enclTr.getKind() == JCTree.Kind.ANNOTATED_TYPE)) {
328 ListBuffer<TypePathEntry> depth = ListBuffer.lb();
329
330 Type topTy = enclTy;
331 while (enclEl != null &&
332 enclEl.getKind() != ElementKind.PACKAGE &&
333 topTy != null &&
334 topTy.getKind() != TypeKind.NONE &&
335 topTy.getKind() != TypeKind.ERROR) {
336 topTy = topTy.getEnclosingType();
337 enclEl = enclEl.getEnclosingElement();
338
339 if (topTy != null && topTy.getKind() != TypeKind.NONE) {
340 // Only count enclosing types.
341 depth = depth.append(TypePathEntry.INNER_TYPE);
342 }
343 }
344
345 if (depth.nonEmpty()) {
346 // Only need to change the annotation positions
347 // if they are on an enclosed type.
348 for (Attribute.TypeCompound a : annotations) {
349 TypeAnnotationPosition p = a.position;
350 p.location = p.location.appendList(depth.toList());
351 }
352 }
353
354 Type ret = typeWithAnnotations(type, enclTy, annotations);
355 return ret;
356 }
357 }
358
359 private static JCArrayTypeTree arrayTypeTree(JCTree typetree) {
360 if (typetree.getKind() == JCTree.Kind.ARRAY_TYPE) {
361 return (JCArrayTypeTree) typetree;
362 } else if (typetree.getKind() == JCTree.Kind.ANNOTATED_TYPE) {
363 return (JCArrayTypeTree) ((JCAnnotatedType)typetree).underlyingType;
364 } else {
365 Assert.error("Could not determine array type from type tree: " + typetree);
366 return null;
367 }
368 }
369
370 /** Return a copy of the first type that only differs by
371 * inserting the annotations to the left-most/inner-most type
372 * or the type given by stopAt.
446
447 @Override
448 public Type visitForAll(ForAll t, List<TypeCompound> s) {
449 // Impossible?
450 return t;
451 }
452
453 @Override
454 public Type visitUndetVar(UndetVar t, List<TypeCompound> s) {
455 // Impossible?
456 return t;
457 }
458
459 @Override
460 public Type visitErrorType(ErrorType t, List<TypeCompound> s) {
461 return new AnnotatedType(s, t);
462 }
463
464 @Override
465 public Type visitType(Type t, List<TypeCompound> s) {
466 // Error?
467 return t;
468 }
469 };
470
471 return type.accept(visitor, annotations);
472 }
473
474 private static Attribute.TypeCompound toTypeCompound(Attribute.Compound a, TypeAnnotationPosition p) {
475 // It is safe to alias the position.
476 return new Attribute.TypeCompound(a, p);
477 }
478
479 private AnnotationType annotationType(Attribute.Compound a, Symbol s) {
480 Attribute.Compound atTarget =
481 a.type.tsym.attribute(syms.annotationTargetType.tsym);
482 if (atTarget == null) {
483 return inferTargetMetaInfo(a, s);
484 }
485 Attribute atValue = atTarget.member(names.value);
486 if (!(atValue instanceof Attribute.Array)) {
487 Assert.error("annotationType(): bad @Target argument " + atValue +
558 }
559
560 /** Infer the target annotation kind, if none is give.
561 * We only infer declaration annotations.
562 */
563 private static AnnotationType inferTargetMetaInfo(Attribute.Compound a, Symbol s) {
564 return AnnotationType.DECLARATION;
565 }
566
567
568 /* This is the beginning of the second part of organizing
569 * type annotations: determine the type annotation positions.
570 */
571
572 private void resolveFrame(JCTree tree, JCTree frame,
573 List<JCTree> path, TypeAnnotationPosition p) {
574 /*
575 System.out.println("Resolving tree: " + tree + " kind: " + tree.getKind());
576 System.out.println(" Framing tree: " + frame + " kind: " + frame.getKind());
577 */
578 switch (frame.getKind()) {
579 case TYPE_CAST:
580 p.type = TargetType.CAST;
581 p.pos = frame.pos;
582 return;
583
584 case INSTANCE_OF:
585 p.type = TargetType.INSTANCEOF;
586 p.pos = frame.pos;
587 return;
588
589 case NEW_CLASS:
590 JCNewClass frameNewClass = (JCNewClass)frame;
591 if (frameNewClass.typeargs.contains(tree)) {
592 p.type = TargetType.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT;
593 p.type_index = frameNewClass.typeargs.indexOf(tree);
594 } else {
595 p.type = TargetType.NEW;
596 }
597 p.pos = frame.pos;
642
643 case PARAMETERIZED_TYPE: {
644 if (((JCTypeApply)frame).clazz == tree) {
645 // generic: RAW; noop
646 } else if (((JCTypeApply)frame).arguments.contains(tree)) {
647 JCTypeApply taframe = (JCTypeApply) frame;
648 int arg = taframe.arguments.indexOf(tree);
649 p.location = p.location.prepend(new TypePathEntry(TypePathEntryKind.TYPE_ARGUMENT, arg));
650
651 locateNestedTypes(taframe.type, p);
652 } else {
653 Assert.error("Could not determine type argument position of tree " + tree +
654 " within frame " + frame);
655 }
656
657 List<JCTree> newPath = path.tail;
658 resolveFrame(newPath.head, newPath.tail.head, newPath, p);
659 return;
660 }
661
662 case ARRAY_TYPE: {
663 ListBuffer<TypePathEntry> index = ListBuffer.lb();
664 index = index.append(TypePathEntry.ARRAY);
665 List<JCTree> newPath = path.tail;
666 while (true) {
667 JCTree npHead = newPath.tail.head;
668 if (npHead.hasTag(JCTree.Tag.TYPEARRAY)) {
669 newPath = newPath.tail;
670 index = index.append(TypePathEntry.ARRAY);
671 } else if (npHead.hasTag(JCTree.Tag.ANNOTATED_TYPE)) {
672 newPath = newPath.tail;
673 } else {
674 break;
675 }
676 }
677 p.location = p.location.prependList(index.toList());
678 resolveFrame(newPath.head, newPath.tail.head, newPath, p);
679 return;
680 }
681
749 // Type parameters, wildcards, and arrays have the declaring
750 // class/method as enclosing elements.
751 // There is actually nothing to do for them.
752 } else {
753 locateNestedTypes(utype, p);
754 }
755 }
756 List<JCTree> newPath = path.tail;
757 resolveFrame(newPath.head, newPath.tail.head, newPath, p);
758 return;
759 }
760
761 case UNION_TYPE: {
762 // TODO: can we store any information here to help in
763 // determining the final position?
764 List<JCTree> newPath = path.tail;
765 resolveFrame(newPath.head, newPath.tail.head, newPath, p);
766 return;
767 }
768
769 case METHOD_INVOCATION: {
770 JCMethodInvocation invocation = (JCMethodInvocation)frame;
771 if (!invocation.typeargs.contains(tree)) {
772 Assert.error("{" + tree + "} is not an argument in the invocation: " + invocation);
773 }
774 p.type = TargetType.METHOD_INVOCATION_TYPE_ARGUMENT;
775 p.pos = invocation.pos;
776 p.type_index = invocation.typeargs.indexOf(tree);
777 return;
778 }
779
780 case EXTENDS_WILDCARD:
781 case SUPER_WILDCARD: {
782 // Annotations in wildcard bounds
783 p.location = p.location.prepend(TypePathEntry.WILDCARD);
784 List<JCTree> newPath = path.tail;
785 resolveFrame(newPath.head, newPath.tail.head, newPath, p);
786 return;
787 }
788
894 scan(tree.restype);
895 scan(tree.typarams);
896 scan(tree.recvparam);
897 scan(tree.params);
898 scan(tree.thrown);
899 } else {
900 scan(tree.defaultValue);
901 scan(tree.body);
902 }
903 pop();
904 }
905
906 /**
907 * Resolve declaration vs. type annotations in variable declarations and
908 * then determine the positions.
909 */
910 @Override
911 public void visitVarDef(final JCVariableDecl tree) {
912 if (tree.sym == null) {
913 // Something is wrong already. Quietly ignore.
914 } else if (tree.sym.getKind() == ElementKind.FIELD) {
915 if (sigOnly) {
916 TypeAnnotationPosition pos = new TypeAnnotationPosition();
917 pos.type = TargetType.FIELD;
918 pos.pos = tree.pos;
919 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
920 }
921 } else if (tree.sym.getKind() == ElementKind.LOCAL_VARIABLE) {
922 TypeAnnotationPosition pos = new TypeAnnotationPosition();
923 pos.type = TargetType.LOCAL_VARIABLE;
924 pos.pos = tree.pos;
925 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
926 } else if (tree.sym.getKind() == ElementKind.EXCEPTION_PARAMETER) {
927 // System.out.println("Found exception param: " + tree);
928 TypeAnnotationPosition pos = new TypeAnnotationPosition();
929 pos.type = TargetType.EXCEPTION_PARAMETER;
930 pos.pos = tree.pos;
931 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
932 } else if (tree.sym.getKind() == ElementKind.RESOURCE_VARIABLE) {
933 TypeAnnotationPosition pos = new TypeAnnotationPosition();
934 pos.type = TargetType.RESOURCE_VARIABLE;
935 pos.pos = tree.pos;
936 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
937 } else {
938 // There is nothing else in a variable declaration that needs separation.
939 // System.out.println("We found a: " + tree);
940 }
941
942 push(tree);
943 // super.visitVarDef(tree);
944 scan(tree.mods);
945 scan(tree.vartype);
946 if (!sigOnly) {
947 scan(tree.init);
948 }
949 pop();
950 }
951
952 @Override
953 public void visitBlock(JCBlock tree) {
954 // Do not descend into top-level blocks when only interested
955 // in the signature.
956 if (!sigOnly) {
957 scan(tree.stats);
958 }
959 }
|
200 sym.owner.type.asMethodType().recvtype = type;
201 // note that the typeAnnotations will also be added to the owner below.
202 }
203 if (sym.getKind() == ElementKind.PARAMETER ||
204 sym.getKind() == ElementKind.LOCAL_VARIABLE ||
205 sym.getKind() == ElementKind.RESOURCE_VARIABLE ||
206 sym.getKind() == ElementKind.EXCEPTION_PARAMETER) {
207 // Make sure all type annotations from the symbol are also
208 // on the owner.
209 sym.owner.annotations.appendUniqueTypes(sym.getTypeAnnotationMirrors());
210 }
211 }
212
213 // This method has a similar purpose as
214 // {@link com.sun.tools.javac.parser.JavacParser.insertAnnotationsToMostInner(JCExpression, List<JCTypeAnnotation>, boolean)}
215 // We found a type annotation in a declaration annotation position,
216 // for example, on the return type.
217 // Such an annotation is _not_ part of an JCAnnotatedType tree and we therefore
218 // need to set its position explicitly.
219 // The method returns a copy of type that contains these annotations.
220 //
221 // As a side effect the method sets the type annotation position of "annotations".
222 // Note that it is assumed that all annotations share the same position.
223 private static Type typeWithAnnotations(final JCTree typetree, final Type type,
224 final List<Attribute.TypeCompound> annotations, Log log) {
225 // System.out.printf("typeWithAnnotations(typetree: %s, type: %s, annotations: %s)%n",
226 // typetree, type, annotations);
227 if (annotations.isEmpty()) {
228 return type;
229 }
230 if (type.hasTag(TypeTag.ARRAY)) {
231 Type toreturn;
232 Type.ArrayType tomodify;
233 Type.ArrayType arType;
234 {
235 Type touse = type;
236 if (type.getKind() == TypeKind.ANNOTATED) {
237 Type.AnnotatedType atype = (Type.AnnotatedType)type;
238 toreturn = new Type.AnnotatedType(atype.underlyingType);
239 ((Type.AnnotatedType)toreturn).typeAnnotations = atype.typeAnnotations;
240 touse = atype.underlyingType;
241 arType = (Type.ArrayType) touse;
242 tomodify = new Type.ArrayType(null, arType.tsym);
253 depth = depth.append(TypePathEntry.ARRAY);
254 while (arType.elemtype.hasTag(TypeTag.ARRAY)) {
255 if (arType.elemtype.getKind() == TypeKind.ANNOTATED) {
256 Type.AnnotatedType aelemtype = (Type.AnnotatedType) arType.elemtype;
257 Type.AnnotatedType newAT = new Type.AnnotatedType(aelemtype.underlyingType);
258 tomodify.elemtype = newAT;
259 newAT.typeAnnotations = aelemtype.typeAnnotations;
260 arType = (Type.ArrayType) aelemtype.underlyingType;
261 tomodify = new Type.ArrayType(null, arType.tsym);
262 newAT.underlyingType = tomodify;
263 } else {
264 arType = (Type.ArrayType) arType.elemtype;
265 tomodify.elemtype = new Type.ArrayType(null, arType.tsym);
266 tomodify = (Type.ArrayType) tomodify.elemtype;
267 }
268 arTree = arrayTypeTree(arTree.elemtype);
269 depth = depth.append(TypePathEntry.ARRAY);
270 }
271 Type arelemType = typeWithAnnotations(arTree.elemtype, arType.elemtype, annotations, log);
272 tomodify.elemtype = arelemType;
273 {
274 // All annotations share the same position; modify the first one.
275 Attribute.TypeCompound a = annotations.get(0);
276 TypeAnnotationPosition p = a.position;
277 p.location = p.location.prependList(depth.toList());
278 }
279 return toreturn;
280 } else if (type.hasTag(TypeTag.TYPEVAR)) {
281 // Nothing to do for type variables.
282 return type;
283 } else {
284 Type enclTy = type;
285 Element enclEl = type.asElement();
286 JCTree enclTr = typetree;
287
288 while (enclEl != null &&
289 enclEl.getKind() != ElementKind.PACKAGE &&
290 enclTy != null &&
291 enclTy.getKind() != TypeKind.NONE &&
292 enclTy.getKind() != TypeKind.ERROR &&
293 (enclTr.getKind() == JCTree.Kind.MEMBER_SELECT ||
294 enclTr.getKind() == JCTree.Kind.PARAMETERIZED_TYPE ||
295 enclTr.getKind() == JCTree.Kind.ANNOTATED_TYPE)) {
333 ListBuffer<TypePathEntry> depth = ListBuffer.lb();
334
335 Type topTy = enclTy;
336 while (enclEl != null &&
337 enclEl.getKind() != ElementKind.PACKAGE &&
338 topTy != null &&
339 topTy.getKind() != TypeKind.NONE &&
340 topTy.getKind() != TypeKind.ERROR) {
341 topTy = topTy.getEnclosingType();
342 enclEl = enclEl.getEnclosingElement();
343
344 if (topTy != null && topTy.getKind() != TypeKind.NONE) {
345 // Only count enclosing types.
346 depth = depth.append(TypePathEntry.INNER_TYPE);
347 }
348 }
349
350 if (depth.nonEmpty()) {
351 // Only need to change the annotation positions
352 // if they are on an enclosed type.
353 // All annotations share the same position; modify the first one.
354 Attribute.TypeCompound a = annotations.get(0);
355 TypeAnnotationPosition p = a.position;
356 p.location = p.location.appendList(depth.toList());
357 }
358
359 Type ret = typeWithAnnotations(type, enclTy, annotations);
360 return ret;
361 }
362 }
363
364 private static JCArrayTypeTree arrayTypeTree(JCTree typetree) {
365 if (typetree.getKind() == JCTree.Kind.ARRAY_TYPE) {
366 return (JCArrayTypeTree) typetree;
367 } else if (typetree.getKind() == JCTree.Kind.ANNOTATED_TYPE) {
368 return (JCArrayTypeTree) ((JCAnnotatedType)typetree).underlyingType;
369 } else {
370 Assert.error("Could not determine array type from type tree: " + typetree);
371 return null;
372 }
373 }
374
375 /** Return a copy of the first type that only differs by
376 * inserting the annotations to the left-most/inner-most type
377 * or the type given by stopAt.
451
452 @Override
453 public Type visitForAll(ForAll t, List<TypeCompound> s) {
454 // Impossible?
455 return t;
456 }
457
458 @Override
459 public Type visitUndetVar(UndetVar t, List<TypeCompound> s) {
460 // Impossible?
461 return t;
462 }
463
464 @Override
465 public Type visitErrorType(ErrorType t, List<TypeCompound> s) {
466 return new AnnotatedType(s, t);
467 }
468
469 @Override
470 public Type visitType(Type t, List<TypeCompound> s) {
471 return new AnnotatedType(s, t);
472 }
473 };
474
475 return type.accept(visitor, annotations);
476 }
477
478 private static Attribute.TypeCompound toTypeCompound(Attribute.Compound a, TypeAnnotationPosition p) {
479 // It is safe to alias the position.
480 return new Attribute.TypeCompound(a, p);
481 }
482
483 private AnnotationType annotationType(Attribute.Compound a, Symbol s) {
484 Attribute.Compound atTarget =
485 a.type.tsym.attribute(syms.annotationTargetType.tsym);
486 if (atTarget == null) {
487 return inferTargetMetaInfo(a, s);
488 }
489 Attribute atValue = atTarget.member(names.value);
490 if (!(atValue instanceof Attribute.Array)) {
491 Assert.error("annotationType(): bad @Target argument " + atValue +
562 }
563
564 /** Infer the target annotation kind, if none is give.
565 * We only infer declaration annotations.
566 */
567 private static AnnotationType inferTargetMetaInfo(Attribute.Compound a, Symbol s) {
568 return AnnotationType.DECLARATION;
569 }
570
571
572 /* This is the beginning of the second part of organizing
573 * type annotations: determine the type annotation positions.
574 */
575
576 private void resolveFrame(JCTree tree, JCTree frame,
577 List<JCTree> path, TypeAnnotationPosition p) {
578 /*
579 System.out.println("Resolving tree: " + tree + " kind: " + tree.getKind());
580 System.out.println(" Framing tree: " + frame + " kind: " + frame.getKind());
581 */
582
583 // Note that p.offset is set in
584 // com.sun.tools.javac.jvm.Gen.setTypeAnnotationPositions(int)
585
586 switch (frame.getKind()) {
587 case TYPE_CAST:
588 p.type = TargetType.CAST;
589 p.pos = frame.pos;
590 return;
591
592 case INSTANCE_OF:
593 p.type = TargetType.INSTANCEOF;
594 p.pos = frame.pos;
595 return;
596
597 case NEW_CLASS:
598 JCNewClass frameNewClass = (JCNewClass)frame;
599 if (frameNewClass.typeargs.contains(tree)) {
600 p.type = TargetType.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT;
601 p.type_index = frameNewClass.typeargs.indexOf(tree);
602 } else {
603 p.type = TargetType.NEW;
604 }
605 p.pos = frame.pos;
650
651 case PARAMETERIZED_TYPE: {
652 if (((JCTypeApply)frame).clazz == tree) {
653 // generic: RAW; noop
654 } else if (((JCTypeApply)frame).arguments.contains(tree)) {
655 JCTypeApply taframe = (JCTypeApply) frame;
656 int arg = taframe.arguments.indexOf(tree);
657 p.location = p.location.prepend(new TypePathEntry(TypePathEntryKind.TYPE_ARGUMENT, arg));
658
659 locateNestedTypes(taframe.type, p);
660 } else {
661 Assert.error("Could not determine type argument position of tree " + tree +
662 " within frame " + frame);
663 }
664
665 List<JCTree> newPath = path.tail;
666 resolveFrame(newPath.head, newPath.tail.head, newPath, p);
667 return;
668 }
669
670 case MEMBER_REFERENCE: {
671 JCMemberReference mrframe = (JCMemberReference) frame;
672
673 if (mrframe.expr == tree) {
674 switch (mrframe.mode) {
675 case INVOKE:
676 p.type = TargetType.METHOD_REFERENCE;
677 break;
678 case NEW:
679 p.type = TargetType.CONSTRUCTOR_REFERENCE;
680 break;
681 default:
682 Assert.error("Unknown method reference mode " + mrframe.mode +
683 " for tree " + tree + " within frame " + frame);
684 }
685 p.pos = frame.pos;
686 } else if (mrframe.typeargs != null &&
687 mrframe.typeargs.contains(tree)) {
688 int arg = mrframe.typeargs.indexOf(tree);
689 p.type_index = arg;
690 switch (mrframe.mode) {
691 case INVOKE:
692 p.type = TargetType.METHOD_REFERENCE_TYPE_ARGUMENT;
693 break;
694 case NEW:
695 p.type = TargetType.CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT;
696 break;
697 default:
698 Assert.error("Unknown method reference mode " + mrframe.mode +
699 " for tree " + tree + " within frame " + frame);
700 }
701 p.pos = frame.pos;
702 } else {
703 Assert.error("Could not determine type argument position of tree " + tree +
704 " within frame " + frame);
705 }
706 return;
707 }
708
709 case ARRAY_TYPE: {
710 ListBuffer<TypePathEntry> index = ListBuffer.lb();
711 index = index.append(TypePathEntry.ARRAY);
712 List<JCTree> newPath = path.tail;
713 while (true) {
714 JCTree npHead = newPath.tail.head;
715 if (npHead.hasTag(JCTree.Tag.TYPEARRAY)) {
716 newPath = newPath.tail;
717 index = index.append(TypePathEntry.ARRAY);
718 } else if (npHead.hasTag(JCTree.Tag.ANNOTATED_TYPE)) {
719 newPath = newPath.tail;
720 } else {
721 break;
722 }
723 }
724 p.location = p.location.prependList(index.toList());
725 resolveFrame(newPath.head, newPath.tail.head, newPath, p);
726 return;
727 }
728
796 // Type parameters, wildcards, and arrays have the declaring
797 // class/method as enclosing elements.
798 // There is actually nothing to do for them.
799 } else {
800 locateNestedTypes(utype, p);
801 }
802 }
803 List<JCTree> newPath = path.tail;
804 resolveFrame(newPath.head, newPath.tail.head, newPath, p);
805 return;
806 }
807
808 case UNION_TYPE: {
809 // TODO: can we store any information here to help in
810 // determining the final position?
811 List<JCTree> newPath = path.tail;
812 resolveFrame(newPath.head, newPath.tail.head, newPath, p);
813 return;
814 }
815
816 case INTERSECTION_TYPE: {
817 JCTypeIntersection isect = (JCTypeIntersection)frame;
818 p.type_index = isect.bounds.indexOf(tree);
819 List<JCTree> newPath = path.tail;
820 resolveFrame(newPath.head, newPath.tail.head, newPath, p);
821 return;
822 }
823
824 case METHOD_INVOCATION: {
825 JCMethodInvocation invocation = (JCMethodInvocation)frame;
826 if (!invocation.typeargs.contains(tree)) {
827 Assert.error("{" + tree + "} is not an argument in the invocation: " + invocation);
828 }
829 p.type = TargetType.METHOD_INVOCATION_TYPE_ARGUMENT;
830 p.pos = invocation.pos;
831 p.type_index = invocation.typeargs.indexOf(tree);
832 return;
833 }
834
835 case EXTENDS_WILDCARD:
836 case SUPER_WILDCARD: {
837 // Annotations in wildcard bounds
838 p.location = p.location.prepend(TypePathEntry.WILDCARD);
839 List<JCTree> newPath = path.tail;
840 resolveFrame(newPath.head, newPath.tail.head, newPath, p);
841 return;
842 }
843
949 scan(tree.restype);
950 scan(tree.typarams);
951 scan(tree.recvparam);
952 scan(tree.params);
953 scan(tree.thrown);
954 } else {
955 scan(tree.defaultValue);
956 scan(tree.body);
957 }
958 pop();
959 }
960
961 /**
962 * Resolve declaration vs. type annotations in variable declarations and
963 * then determine the positions.
964 */
965 @Override
966 public void visitVarDef(final JCVariableDecl tree) {
967 if (tree.sym == null) {
968 // Something is wrong already. Quietly ignore.
969 } else if (tree.sym.getKind() == ElementKind.PARAMETER) {
970 // Parameters are handled in visitMethodDef above.
971 } else if (tree.sym.getKind() == ElementKind.FIELD) {
972 if (sigOnly) {
973 TypeAnnotationPosition pos = new TypeAnnotationPosition();
974 pos.type = TargetType.FIELD;
975 pos.pos = tree.pos;
976 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
977 }
978 } else if (tree.sym.getKind() == ElementKind.LOCAL_VARIABLE) {
979 TypeAnnotationPosition pos = new TypeAnnotationPosition();
980 pos.type = TargetType.LOCAL_VARIABLE;
981 pos.pos = tree.pos;
982 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
983 } else if (tree.sym.getKind() == ElementKind.EXCEPTION_PARAMETER) {
984 TypeAnnotationPosition pos = new TypeAnnotationPosition();
985 pos.type = TargetType.EXCEPTION_PARAMETER;
986 pos.pos = tree.pos;
987 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
988 } else if (tree.sym.getKind() == ElementKind.RESOURCE_VARIABLE) {
989 TypeAnnotationPosition pos = new TypeAnnotationPosition();
990 pos.type = TargetType.RESOURCE_VARIABLE;
991 pos.pos = tree.pos;
992 separateAnnotationsKinds(tree.vartype, tree.sym.type, tree.sym, pos);
993 } else if (tree.sym.getKind() == ElementKind.ENUM_CONSTANT) {
994 // No type annotations can occur here.
995 } else {
996 // There is nothing else in a variable declaration that needs separation.
997 Assert.error("Unhandled variable kind: " + tree + " of kind: " + tree.sym.getKind());
998 }
999
1000 push(tree);
1001 // super.visitVarDef(tree);
1002 scan(tree.mods);
1003 scan(tree.vartype);
1004 if (!sigOnly) {
1005 scan(tree.init);
1006 }
1007 pop();
1008 }
1009
1010 @Override
1011 public void visitBlock(JCBlock tree) {
1012 // Do not descend into top-level blocks when only interested
1013 // in the signature.
1014 if (!sigOnly) {
1015 scan(tree.stats);
1016 }
1017 }
|