// UnionClassType uct = (com.sun.tools.javac.code.Type.UnionClassType)type;
// Return the un-annotated union-type.
return type;
} else {
Type enclTy = type;
Element enclEl = type.asElement();
JCTree enclTr = typetree;
while (enclEl != null &&
enclEl.getKind() != ElementKind.PACKAGE &&
enclTy != null &&
enclTy.getKind() != TypeKind.NONE &&
enclTy.getKind() != TypeKind.ERROR &&
(enclTr.getKind() == JCTree.Kind.MEMBER_SELECT ||
enclTr.getKind() == JCTree.Kind.PARAMETERIZED_TYPE ||
enclTr.getKind() == JCTree.Kind.ANNOTATED_TYPE)) {
// Iterate also over the type tree, not just the type: the type is already
// completely resolved and we cannot distinguish where the annotation
// belongs for a nested type.
if (enclTr.getKind() == JCTree.Kind.MEMBER_SELECT) {
// only change encl in this case.
enclTy = enclTy.getEnclosingType();
enclEl = enclEl.getEnclosingElement();
enclTr = ((JCFieldAccess)enclTr).getExpression();
} else if (enclTr.getKind() == JCTree.Kind.PARAMETERIZED_TYPE) {
enclTr = ((JCTypeApply)enclTr).getType();
} else {
// only other option because of while condition
enclTr = ((JCAnnotatedType)enclTr).getUnderlyingType();
}
}
/** We are trying to annotate some enclosing type,
* but nothing more exists.
*/
if (enclTy != null &&
enclTy.hasTag(TypeTag.NONE)) {
switch (onlyTypeAnnotations.size()) {
case 0:
// Don't issue an error if all type annotations are
// also declaration annotations.
// If the annotations are also declaration annotations, they are
// illegal as type annotations but might be legal as declaration annotations.
// The normal declaration annotation checks make sure that the use is valid.
break;
case 1:
log.error(typetree.pos(), "cant.type.annotate.scoping.1",
onlyTypeAnnotations);
break;
default:
log.error(typetree.pos(), "cant.type.annotate.scoping",
onlyTypeAnnotations);
}
return type;
}
// At this point we have visited the part of the nested
// type that is written in the source code.
// Now count from here to the actual top-level class to determine
// the correct nesting.
// The genericLocation for the annotation.
ListBuffer<TypePathEntry> depth = new ListBuffer<>();
Type topTy = enclTy;
while (enclEl != null &&
enclEl.getKind() != ElementKind.PACKAGE &&
topTy != null &&
topTy.getKind() != TypeKind.NONE &&
topTy.getKind() != TypeKind.ERROR) {
topTy = topTy.getEnclosingType();
enclEl = enclEl.getEnclosingElement();
if (topTy != null && topTy.getKind() != TypeKind.NONE) {
// Only count enclosing types.
depth = depth.append(TypePathEntry.INNER_TYPE);
}