APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.tools.javac.code

public Class TypeAnnotations

extends Object
Class Inheritance
Imports
javax.lang.model.element.Element, .ElementKind, javax.lang.model.type.TypeKind, javax.tools.JavaFileObject, com.sun.tools.javac.code.Attribute.TypeCompound, .Symbol.ClassSymbol, .Symbol.RecordComponent, .Symbol.TypeSymbol, .Type.ArrayType, .Type.CapturedType, .Type.ClassType, .Type.ErrorType, .Type.ForAll, .Type.MethodType, .Type.PackageType, .Type.TypeVar, .Type.UndetVar, .Type.Visitor, .Type.WildcardType, .TypeAnnotationPosition.TypePathEntry, .TypeAnnotationPosition.TypePathEntryKind, .Symbol.VarSymbol, .Symbol.MethodSymbol, .Type.ModuleType, .Type.UnionClassType, com.sun.tools.javac.comp.Annotate, .Attr, .AttrContext, .Env, com.sun.tools.javac.resources.CompilerProperties.Errors, .CompilerProperties.Fragments, com.sun.tools.javac.tree.JCTree, .JCTree.JCAnnotatedType, .JCTree.JCAnnotation, .JCTree.JCArrayTypeTree, .JCTree.JCBlock, .JCTree.JCCatch, .JCTree.JCClassDecl, .JCTree.JCExpression, .JCTree.JCFieldAccess, .JCTree.JCLambda, .JCTree.JCMemberReference, .JCTree.JCMethodDecl, .JCTree.JCMethodInvocation, .JCTree.JCNewArray, .JCTree.JCNewClass, .JCTree.JCTry, .JCTree.JCTypeApply, .JCTree.JCTypeIntersection, .JCTree.JCTypeParameter, .JCTree.JCTypeUnion, .JCTree.JCVariableDecl, .JCTree.Tag, .TreeInfo, .TreeScanner, com.sun.tools.javac.util.Assert, .Context, .JCDiagnostic, .List, .ListBuffer, .Log, .Names

Contains operations specific to processing type annotations. This class has two functions: separate declaration from type annotations and insert the type annotations to their types; and determine the TypeAnnotationPositions for all type annotations.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
private class

Field Summary

Modifier and TypeField and Description
pack-priv final Annotate
pack-priv final Attr
pack-priv final Log
pack-priv final Names
pack-priv final Symtab
protected static final Context.Key<TypeAnnotations>
pack-priv final Types

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public List<Attribute>
public TypeAnnotations.AnnotationType
annotationTargetType(JCTree pos, Attribute.Compound a, Symbol s)

Determine whether an annotation is a declaration annotation, a type annotation, or both (or none, i.e a non-annotation masquerading as one).

private TypeAnnotations.AnnotationType
public static TypeAnnotations
instance(Context context)

public void
organizeTypeAnnotationsBodies(JCTree.JCClassDecl tree)

This version only visits types in bodies, that is, field initializers, top-level blocks, and method bodies, and should be called from Attr.

public void
organizeTypeAnnotationsSignatures(final Env<AttrContext> env, final JCTree.JCClassDecl tree)

Separate type annotations from declaration annotations and determine the correct positions for type annotations.

public void
private TypeAnnotations.AnnotationType
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

annotateback to summary
pack-priv final Annotate annotate
attrback to summary
pack-priv final Attr attr
logback to summary
pack-priv final Log log
namesback to summary
pack-priv final Names names
symsback to summary
pack-priv final Symtab syms
typeAnnosKeyback to summary
protected static final Context.Key<TypeAnnotations> typeAnnosKey
typesback to summary
pack-priv final Types types

Constructor Detail

TypeAnnotationsback to summary
protected TypeAnnotations(Context context)
Annotations
@SuppressWarnings:this-escape

Method Detail

annotationTargetsback to summary
public List<Attribute> annotationTargets(Symbol.TypeSymbol tsym)
annotationTargetTypeback to summary
public TypeAnnotations.AnnotationType annotationTargetType(JCTree pos, Attribute.Compound a, Symbol s)

Determine whether an annotation is a declaration annotation, a type annotation, or both (or none, i.e a non-annotation masquerading as one).

combineAnnotationTypeback to summary
private TypeAnnotations.AnnotationType combineAnnotationType(TypeAnnotations.AnnotationType at1, TypeAnnotations.AnnotationType at2)
instanceback to summary
public static TypeAnnotations instance(Context context)
organizeTypeAnnotationsBodiesback to summary
public void organizeTypeAnnotationsBodies(JCTree.JCClassDecl tree)

This version only visits types in bodies, that is, field initializers, top-level blocks, and method bodies, and should be called from Attr.

organizeTypeAnnotationsSignaturesback to summary
public void organizeTypeAnnotationsSignatures(final Env<AttrContext> env, final JCTree.JCClassDecl tree)

Separate type annotations from declaration annotations and determine the correct positions for type annotations. This version only visits types in signatures and should be called from MemberEnter.

organizeTypeAnnotationsSignaturesForLocalVarTypeback to summary
public void organizeTypeAnnotationsSignaturesForLocalVarType(final Env<AttrContext> env, final JCTree.JCVariableDecl tree)
targetToAnnotationTypeback to summary
private TypeAnnotations.AnnotationType targetToAnnotationType(JCTree pos, Attribute.Compound anno, Attribute a, Symbol s)
validateTypeAnnotationsSignaturesback to summary
public void validateTypeAnnotationsSignatures(final Env<AttrContext> env, final JCTree.JCClassDecl tree)
com.sun.tools.javac.code back to summary

public final Enum TypeAnnotations.AnnotationType

extends Enum<TypeAnnotations.AnnotationType>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final TypeAnnotations.AnnotationType
public static final TypeAnnotations.AnnotationType
public static final TypeAnnotations.AnnotationType
public static final TypeAnnotations.AnnotationType

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static TypeAnnotations.AnnotationType
public static TypeAnnotations.AnnotationType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BOTHback to summary
public static final TypeAnnotations.AnnotationType BOTH
DECLARATIONback to summary
public static final TypeAnnotations.AnnotationType DECLARATION
NONEback to summary
public static final TypeAnnotations.AnnotationType NONE
TYPEback to summary
public static final TypeAnnotations.AnnotationType TYPE

Constructor Detail

AnnotationTypeback to summary
private AnnotationType()

Method Detail

valueOfback to summary
public static TypeAnnotations.AnnotationType valueOf(String name)
valuesback to summary
public static TypeAnnotations.AnnotationType[] values()
com.sun.tools.javac.code back to summary

private Class TypeAnnotations.TypeAnnotationPositions

extends TreeScanner
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final JCTree
private JCTree.JCLambda
private List<JCTree>
private boolean
private final boolean

Constructor Summary

AccessConstructor and Description
pack-priv
TypeAnnotationPositions(JCTree contextTree, boolean sigOnly)

Method Summary

Modifier and TypeMethod and Description
private void
private JCTree
private void
findPosition(JCTree tree, JCTree frame, List<JCTree.JCAnnotation> annotations)

private ListBuffer<TypeAnnotationPosition.TypePathEntry>
private int
private JCTree
protected JCTree
pop()

private void
protected void
private TypeAnnotationPosition
resolveFrame(JCTree tree, JCTree frame, List<JCTree> path, JCTree.JCLambda currentLambda, int outer_type_index, ListBuffer<TypeAnnotationPosition.TypePathEntry> location)

private Type
rewriteArrayType(JCTree typetree, Type.ArrayType type, List<Attribute.TypeCompound> annotations, List<Attribute.TypeCompound> onlyTypeAnnotations, TypeAnnotationPosition pos)

Create a copy of the Type type with the help of the Tree for a type JCTree typetree inserting all type annotations in annotations to the innermost array component type.

public void
scan(JCTree tree)

Overrides com.sun.tools.javac.tree.TreeScanner.scan.

Visitor method: Scan a single node.

private void
separateAnnotationsKinds(JCTree pos, JCTree typetree, Type type, Symbol sym, TypeAnnotationPosition typeAnnotationPosition)

Separates type annotations from declaration annotations.

private void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private Attribute.TypeCompound
private Type
typeWithAnnotations(final JCTree typetree, final Type type, final List<Attribute.TypeCompound> annotations, final List<Attribute.TypeCompound> onlyTypeAnnotations, final TypeAnnotationPosition pos)

private Type

Returns:

A copy of type that contains the annotations.
typeWithAnnotations
(final Type
The type to copy.
type
,
final Type
The type to stop at.
stopAt
,
final List<Attribute.TypeCompound>
The annotations to insert.
annotations
)

Return a copy of the first type that only differs by inserting the annotations to the left-most/inner-most type or the type given by stopAt.

public void
public void
public void
public void
public void
visitMethodDef(final JCTree.JCMethodDecl tree)

Overrides com.sun.tools.javac.tree.TreeScanner.visitMethodDef.

Resolve declaration vs. type annotations in methods and then determine the positions.

public void
public void
public void
public void
visitVarDef(final JCTree.JCVariableDecl tree)

Overrides com.sun.tools.javac.tree.TreeScanner.visitVarDef.

Resolve declaration vs. type annotations in variable declarations and then determine the positions.

Inherited from com.sun.tools.javac.tree.TreeScanner:
scanvisitAnnotationvisitAnyPatternvisitApplyvisitAssertvisitAssignvisitAssignopvisitBinaryvisitBindingPatternvisitBreakvisitCasevisitCatchvisitConditionalvisitConstantCaseLabelvisitContinuevisitDefaultCaseLabelvisitDoLoopvisitErroneousvisitExecvisitExportsvisitForeachLoopvisitForLoopvisitIdentvisitIfvisitImportvisitIndexedvisitLabelledvisitLetExprvisitLiteralvisitModifiersvisitModuleDefvisitModuleImportvisitOpensvisitPackageDefvisitParensvisitPatternCaseLabelvisitProvidesvisitRecordPatternvisitReferencevisitRequiresvisitReturnvisitSelectvisitSkipvisitSwitchvisitSwitchExpressionvisitSynchronizedvisitThrowvisitTopLevelvisitTreevisitTryvisitTypeApplyvisitTypeArrayvisitTypeBoundKindvisitTypeCastvisitTypeIdentvisitTypeIntersectionvisitTypeTestvisitTypeUnionvisitUnaryvisitUsesvisitVarTypevisitWhileLoopvisitWildcardvisitYield

Field Detail

contextTreeback to summary
private final JCTree contextTree
currentLambdaback to summary
private JCTree.JCLambda currentLambda
framesback to summary
private List<JCTree> frames
isInClassback to summary
private boolean isInClass
sigOnlyback to summary
private final boolean sigOnly

Constructor Detail

TypeAnnotationPositionsback to summary
pack-priv TypeAnnotationPositions(JCTree contextTree, boolean sigOnly)

Method Detail

appendTypeAnnotationsToOwnerback to summary
private void appendTypeAnnotationsToOwner(Symbol sym, List<Attribute.TypeCompound> typeAnnotations)
arrayElemTypeTreeback to summary
private JCTree arrayElemTypeTree(JCTree typetree)
findPositionback to summary
private void findPosition(JCTree tree, JCTree frame, List<JCTree.JCAnnotation> annotations)
locateNestedTypesback to summary
private ListBuffer<TypeAnnotationPosition.TypePathEntry> locateNestedTypes(Type type, ListBuffer<TypeAnnotationPosition.TypePathEntry> depth)
methodParamIndexback to summary
private int methodParamIndex(List<JCTree> path, JCTree param)
peek2back to summary
private JCTree peek2()
popback to summary
protected JCTree pop()
propagateNewClassAnnotationsToOwnerback to summary
private void propagateNewClassAnnotationsToOwner(JCTree.JCNewClass tree)
pushback to summary
protected void push(JCTree t)
resolveFrameback to summary
private TypeAnnotationPosition resolveFrame(JCTree tree, JCTree frame, List<JCTree> path, JCTree.JCLambda currentLambda, int outer_type_index, ListBuffer<TypeAnnotationPosition.TypePathEntry> location)
rewriteArrayTypeback to summary
private Type rewriteArrayType(JCTree typetree, Type.ArrayType type, List<Attribute.TypeCompound> annotations, List<Attribute.TypeCompound> onlyTypeAnnotations, TypeAnnotationPosition pos)

Create a copy of the Type type with the help of the Tree for a type JCTree typetree inserting all type annotations in annotations to the innermost array component type. SIDE EFFECT: Update position for the annotations to be pos.

scanback to summary
public void scan(JCTree tree)

Overrides com.sun.tools.javac.tree.TreeScanner.scan.

Doc from com.sun.tools.javac.tree.TreeScanner.scan.

Visitor method: Scan a single node.

Annotations
@Override
separateAnnotationsKindsback to summary
private void separateAnnotationsKinds(JCTree pos, JCTree typetree, Type type, Symbol sym, TypeAnnotationPosition typeAnnotationPosition)

Separates type annotations from declaration annotations. This step is needed because in certain locations (where declaration and type annotations can be mixed, e.g. the type of a field) we never build an JCAnnotatedType. This step finds these annotations and marks them as if they were part of the type.

setTypeAnnotationPosback to summary
private void setTypeAnnotationPos(List<JCTree.JCAnnotation> annotations, TypeAnnotationPosition position)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
toTypeCompoundback to summary
private Attribute.TypeCompound toTypeCompound(Attribute.Compound a, TypeAnnotationPosition p)
typeWithAnnotationsback to summary
private Type typeWithAnnotations(final JCTree typetree, final Type type, final List<Attribute.TypeCompound> annotations, final List<Attribute.TypeCompound> onlyTypeAnnotations, final TypeAnnotationPosition pos)
typeWithAnnotationsback to summary
private Type typeWithAnnotations(final Type type, final Type stopAt, final List<Attribute.TypeCompound> annotations)

Return a copy of the first type that only differs by inserting the annotations to the left-most/inner-most type or the type given by stopAt. We need the stopAt parameter to know where on a type to put the annotations. If we have nested classes Outer > Middle > Inner, and we have the source type "@A Middle.Inner", we will invoke this method with type = Outer.Middle.Inner, stopAt = Middle.Inner, and annotations = @A.

Parameters
type:Type

The type to copy.

stopAt:Type

The type to stop at.

annotations:List<Attribute.TypeCompound>

The annotations to insert.

Returns:Type

A copy of type that contains the annotations.

visitAnnotatedTypeback to summary
public void visitAnnotatedType(JCTree.JCAnnotatedType tree)

Overrides com.sun.tools.javac.tree.TreeScanner.visitAnnotatedType.

Annotations
@Override
visitBlockback to summary
public void visitBlock(JCTree.JCBlock tree)

Overrides com.sun.tools.javac.tree.TreeScanner.visitBlock.

Annotations
@Override
visitClassDefback to summary
public void visitClassDef(JCTree.JCClassDecl tree)

Overrides com.sun.tools.javac.tree.TreeScanner.visitClassDef.

Annotations
@Override
visitLambdaback to summary
public void visitLambda(JCTree.JCLambda tree)

Overrides com.sun.tools.javac.tree.TreeScanner.visitLambda.

visitMethodDefback to summary
public void visitMethodDef(final JCTree.JCMethodDecl tree)

Overrides com.sun.tools.javac.tree.TreeScanner.visitMethodDef.

Resolve declaration vs. type annotations in methods and then determine the positions.

Annotations
@Override
visitNewArrayback to summary
public void visitNewArray(JCTree.JCNewArray tree)

Overrides com.sun.tools.javac.tree.TreeScanner.visitNewArray.

Annotations
@Override
visitNewClassback to summary
public void visitNewClass(JCTree.JCNewClass tree)

Overrides com.sun.tools.javac.tree.TreeScanner.visitNewClass.

Annotations
@Override
visitTypeParameterback to summary
public void visitTypeParameter(JCTree.JCTypeParameter tree)

Overrides com.sun.tools.javac.tree.TreeScanner.visitTypeParameter.

Annotations
@Override
visitVarDefback to summary
public void visitVarDef(final JCTree.JCVariableDecl tree)

Overrides com.sun.tools.javac.tree.TreeScanner.visitVarDef.

Resolve declaration vs. type annotations in variable declarations and then determine the positions.

Annotations
@Override