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

public Class Attr

extends Visitor
Class Inheritance
Imports
java.util.*, java.util.function.BiConsumer, .Consumer, java.util.stream.Stream, javax.lang.model.element.ElementKind, javax.tools.JavaFileObject, com.sun.source.tree.CaseTree, .IdentifierTree, .MemberReferenceTree.ReferenceMode, .MemberSelectTree, .TreeVisitor, com.sun.source.util.SimpleTreeVisitor, com.sun.tools.javac.code.*, .Lint.LintCategory, .LintMapper, .Scope.WriteableScope, .Source.Feature, com.sun.tools.javac.code.Symbol.*, com.sun.tools.javac.code.Type.*, .Types.FunctionDescriptorLookupError, com.sun.tools.javac.comp.ArgumentAttr.LocalCacheContext, .Check.CheckContext, .DeferredAttr.AttrMode, .MatchBindingsComputer.MatchBindings, com.sun.tools.javac.jvm.*, com.sun.tools.javac.resources.CompilerProperties.Errors, .CompilerProperties.Fragments, .CompilerProperties.LintWarnings, .CompilerProperties.Warnings, com.sun.tools.javac.tree.*, com.sun.tools.javac.tree.JCTree.*, com.sun.tools.javac.tree.JCTree.JCPolyExpression.*, com.sun.tools.javac.util.*, .DefinedBy.Api, .JCDiagnostic.DiagnosticPosition, .JCDiagnostic.Error, .JCDiagnostic.Fragment, .JCDiagnostic.Warning, .List

This is the main context-dependent analysis phase in GJC. It encompasses name resolution, type checking and constant folding as subtasks. Some subtasks involve auxiliary classes.
See Also
Check, Resolve, ConstFold, <p><b>This is NOT part of any supported API. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.</b>

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
pack-priv static enum
Attr.CheckMode

Mode controlling behavior of Attr.Check

pack-priv class
pack-priv class
Attr.FunctionalReturnContext

Lambda/method reference have a special check context that ensures that i.e. a lambda return type is compatible with the expected type according to both the inherited context and the assignment context.

private class
pack-priv static class
pack-priv class
pack-priv class
pack-priv class
pack-priv class
pack-priv class
private class

Field Summary

Modifier and TypeField and Description
private final boolean
allowPatternSwitch

Are patterns in switch allowed

private final boolean
allowRecords

Are records allowed

pack-priv boolean
allowReifiableTypesInInstanceof

Switch: reifiable types in instanceof enabled?

private final boolean
allowUnconditionalPatternsInstanceOf

Are unconditional patterns in instanceof allowed

pack-priv final Analyzer
pack-priv final Annotate
pack-priv final ArgumentAttr
protected static final Context.Key<Attr>
pack-priv final AttrRecover
private JCTree
pack-priv final boolean
pack-priv final ConstFold
pack-priv final Check
pack-priv final DeferredAttr
pack-priv final Dependencies
pack-priv final JCDiagnostic.Factory
pack-priv final Enter
pack-priv Env<AttrContext>
env

Visitor argument: the current environment.

pack-priv final Flow
private TreeVisitor<Symbol, Env<AttrContext>>
pack-priv final Infer
pack-priv final Type.MethodType
pack-priv final LintMapper
pack-priv final Log
pack-priv final TreeMaker
pack-priv MatchBindingsComputer.MatchBindings
pack-priv final MatchBindingsComputer
pack-priv final MemberEnter
pack-priv final Attr.ResultInfo
pack-priv final Names
pack-priv final Operators
pack-priv final Preview
pack-priv static final TypeTag[]
pack-priv final Attr.ResultInfo
pack-priv TreeTranslator
pack-priv Type
result

Visitor result: the computed type.

pack-priv Attr.ResultInfo
resultInfo

Visitor argument: the currently expected attribution result.

pack-priv final Resolve
pack-priv String
sourceName

Switch: name of source level; used for error reporting.

pack-priv final Attr.ResultInfo
pack-priv final Symtab
pack-priv final Target
pack-priv Types.MapVisitor<JCDiagnostic.DiagnosticPosition>
pack-priv final TypeAnnotations
pack-priv final TypeEnter
pack-priv final TypeEnvs
pack-priv final Types
pack-priv final Attr.ResultInfo
pack-priv final Attr.ResultInfo
pack-priv final Attr.ResultInfo
pack-priv boolean
useBeforeDeclarationWarning

Switch: warn about use of variable before declaration?

pack-priv final Attr.ResultInfo

Constructor Summary

AccessConstructor and Description
protected
Attr(Context context)

Method Summary

Modifier and TypeMethod and Description
private void
addBindings2Scope(JCTree.JCStatement introducingStatement, List<Symbol.BindingSymbol> bindings)

Add given bindings to the current scope, unless there's a break to an immediately enclosing labeled statement.

private static void
addVars(List<JCTree.JCStatement> stats, Scope.WriteableScope switchScope)

Add any variables defined in stats to the switch scope.

pack-priv Type
adjustMethodReturnType(Symbol msym, Type qualifierType, Name methodName, List<Type> argtypes, Type restype)

public void
attrib(Env<AttrContext> env)

Attribute an env for either a top level tree or class or module declaration.

pack-priv void
attribAnnotationTypes(List<JCTree.JCAnnotation> annotations, Env<AttrContext> env)

Attribute the type references in a list of annotations.

pack-priv List<Type>
attribAnyTypes(List<JCTree.JCExpression> trees, Env<AttrContext> env)

Attribute a type argument list, returning a list of types.

pack-priv Kinds.KindSelector
attribArgs(Kinds.KindSelector initialKind, List<JCTree.JCExpression> trees, Env<AttrContext> env, ListBuffer<Type> argtypes)

Attribute the arguments in a method call, returning the method kind.

pack-priv Type
attribBase(JCTree
The tree making up the type reference.
tree
,
Env<AttrContext>
The environment current at the reference.
env
,
boolean
true if only a class is expected here.
classExpected
,
boolean
true if only an interface is expected here.
interfaceExpected
,
boolean checkExtensible)

Attribute type reference in an `extends', `implements', or 'permits' clause.

public void
attribClass(JCDiagnostic.DiagnosticPosition
The source position at which completion errors are to be reported.
pos
,
Symbol.ClassSymbol
The class symbol whose definition will be attributed.
c
)

Main method: attribute class definition associated with given class symbol.

pack-priv void
attribClass(Symbol.ClassSymbol
The class symbol whose definition will be attributed.
c
)

Attribute class definition associated with given class symbol.

private void
attribClassBody(Env<AttrContext> env, Symbol.ClassSymbol c)

Finish the attribution of a class.

public Type
attribExpr(JCTree tree, Env<AttrContext> env, Type pt)

Derived visitor method: attribute an expression tree.

public Type
attribExpr(JCTree tree, Env<AttrContext> env)

Derived visitor method: attribute an expression tree with no constraints on the computed type.

pack-priv List<Type>
attribExprs(List<JCTree.JCExpression> trees, Env<AttrContext> env, Type pt)

Attribute a list of expressions, returning a list of types.

public Env<AttrContext>
public Symbol
attribIdent(JCTree
Parsed identifier name
tree
,
JCTree.JCCompilationUnit
The toplevel to use
topLevel
)

Attribute a parsed identifier.

public Symbol
attribIdent(JCTree
Parsed identifier name
tree
,
Env<AttrContext>
The env to use
env
)

Attribute a parsed identifier.

pack-priv Type
public Type
public Object
attribLazyConstantValue(Env<AttrContext>
The env for the const value
env
,
Env<AttrContext> enclosingEnv, JCTree.JCVariableDecl
The initializer for the const value
variable
,
Type
The expected type, or null
type
)

Attribute a "lazy constant value".

public void
pack-priv void
public void
pack-priv void
public Type
attribStat(JCTree tree, Env<AttrContext> env)

Derived visitor method: attribute a statement or definition tree.

pack-priv <T extends JCTree> void
attribStats(List<T> trees, Env<AttrContext> env)

Attribute a list of statements, returning nothing.

public Env<AttrContext>
private Env<AttrContext>
attribToTree(JCTree root, Env<AttrContext> env, JCTree tree, Attr.ResultInfo resultInfo)

pack-priv Type
attribTree(JCTree
The tree to be visited.
tree
,
Env<AttrContext>
The environment visitor argument.
env
,
Attr.ResultInfo
The result info visitor argument.
resultInfo
)

Visitor method: attribute a tree, catching any completion failure exceptions.

public Type
public Type
attribType(JCTree tree, Env<AttrContext> env)

Derived visitor method: attribute a type tree.

pack-priv Type
attribType(JCTree tree, Env<AttrContext> env, Type pt)

Derived visitor method: attribute a type tree.

pack-priv List<Type>
attribTypes(List<JCTree.JCExpression> trees, Env<AttrContext> env)

Attribute a type argument list, returning a list of types.

pack-priv void
attribTypeVariables(List<JCTree.JCTypeParameter>
the type variables to enter
typarams
,
Env<AttrContext>
the current environment
env
,
boolean checkCyclic)

Attribute type variables (of generic classes or methods).

private void
pack-priv Env<AttrContext>
pack-priv Env<AttrContext>
private boolean
breaksTo(Env<AttrContext> env, JCTree loop, JCTree body)

protected void
pack-priv JCDiagnostic.Fragment
private Type
capture(Type type)

private Attr.ResultInfo
pack-priv Type
check(final JCTree
The tree whose kind and type is checked
tree
,
final Type
The computed type of the tree
found
,
final Kinds.KindSelector
The computed kind of the tree
ownkind
,
final Attr.ResultInfo
The expected result of the tree
resultInfo
)

Check kind and type of given tree against protokind and prototype.

private void
checkAccessibleTypes(final JCDiagnostic.DiagnosticPosition pos, final Env<AttrContext> env, final InferenceContext inferenceContext, final Type... ts)

private void
checkAccessibleTypes(final JCDiagnostic.DiagnosticPosition pos, final Env<AttrContext> env, final InferenceContext inferenceContext, final List<Type> ts)

pack-priv void
checkAssignable(JCDiagnostic.DiagnosticPosition
The current source code position.
pos
,
Symbol.VarSymbol
The assigned variable
v
,
JCTree
If the variable is referred to in a Select, the part to the left of the `.', null otherwise.
base
,
Env<AttrContext>
The current environment.
env
)

Check that variable can be assigned to.

pack-priv void
checkAutoCloseable(Env<AttrContext> env, JCTree tree, boolean useSite)

pack-priv Type
checkBase(Type t, JCTree tree, Env<AttrContext> env, boolean classExpected, boolean interfaceExpected, boolean checkExtensible)

private void
private boolean
private void
checkEnumInitializer(JCTree
The tree making up the variable reference.
tree
,
Env<AttrContext>
The current environment.
env
,
Symbol.VarSymbol
The variable's symbol.
v
)

Check for illegal references to static members of enum.

pack-priv boolean
checkExConstraints(List<Type> thrownByFuncExpr, List<Type> thrownAtFuncType, InferenceContext inferenceContext)

pack-priv Type
checkId(JCTree
The syntax tree representing the identifier
tree
,
Type
If this is a select, the type of the selected expression, otherwise the type of the current class.
site
,
Symbol
The symbol representing the identifier.
sym
,
Env<AttrContext>
The current environment.
env
,
Attr.ResultInfo
The expected result
resultInfo
)

Determine type of identifier or select expression and check that (1) the referenced symbol is not deprecated (2) the symbol's type is safe (see (checkSafe) (3) if symbol is a variable, check that its type and kind are compatible with the prototype and protokind.

pack-priv Type
checkIdInternal(JCTree tree, Type site, Symbol sym, Type pt, Env<AttrContext> env, Attr.ResultInfo resultInfo)

private void
checkInit(JCTree
The tree making up the variable reference.
tree
,
Env<AttrContext>
The current environment.
env
,
Symbol.VarSymbol
The variable's symbol.
v
,
boolean onlyWarning)

Check that variable is initialized and evaluate the variable's initializer, if not yet done.

pack-priv Type
pack-priv void
checkLambdaCompatible(JCTree.JCLambda tree, Type descriptor, Symbol.TypeSymbol target, Check.CheckContext checkContext)

Lambda compatibility.

public Type
checkMethod(Type site, final Symbol sym, Attr.ResultInfo resultInfo, Env<AttrContext> env, final List<JCTree.JCExpression> argtrees, List<Type> argtypes, List<Type> typeargtypes)

Check that method arguments conform to its instantiation.

pack-priv Type
pack-priv void
pack-priv void
checkReferenceCompatible(JCTree.JCMemberReference tree, Type descriptor, Type refType, Check.CheckContext checkContext, boolean speculativeAttr)

public Type
coerce(Type etype, Type ttype)

pack-priv Check.CheckContext
pack-priv Type
condType(List<JCDiagnostic.DiagnosticPosition> positions, List<Type> condTypes)

Compute the type of a conditional expression, after checking that it exists.

pack-priv Env<AttrContext>
pack-priv Scope.WriteableScope
pack-priv Check.CheckContext
private void
pack-priv Env<AttrContext>
enclosingInitEnv(Env<AttrContext> env)

Returns the enclosing init environment associated with this env (if any).

private Symbol
enumConstant(JCTree tree, Type enumType)

Return the selected enumeration constant symbol, or null.

private Type
private JCTree
findJumpTarget(JCDiagnostic.DiagnosticPosition
The position to be used for error diagnostics
pos
,
JCTree.Tag
The tag of the jump statement. This is either Tree.BREAK or Tree.CONTINUE.
tag
,
Name
The label of the jump statement, or null if no label is given.
label
,
Env<AttrContext>
The environment current at the jump statement.
env
)

Return the target of a break, continue or yield statement, if it exists, report an error if not.

private Pair<JCTree, JCDiagnostic.Error>
findJumpTargetNoError(JCTree.Tag
The tag of the jump statement. This is either Tree.BREAK or Tree.CONTINUE.
tag
,
Name
The label of the jump statement, or null if no label is given.
label
,
Env<AttrContext>
The environment current at the jump statement.
env
)

Return the target of a break or continue statement, if it exists, report an error if not.

private JCDiagnostic.DiagnosticPosition
getDiagnosticPosition(JCTree.JCClassDecl tree, Type t)

get a diagnostic position for an attribute of Type t, or null if attribute missing

pack-priv Attr.TargetInfo
getTargetInfo(JCTree.JCPolyExpression that, Attr.ResultInfo resultInfo, List<Type> explicitParamTypes)

private void
handleLoopConditionBindings(MatchBindingsComputer.MatchBindings condBindings, JCTree.JCStatement loop, JCTree.JCStatement loopBody)

Include condition's bindings when false after the loop, if cannot get out of the loop

private void
public static Attr
instance(Context context)

pack-priv boolean
isAssignableAsBlankFinal(Symbol.VarSymbol
The blank final variable.
v
,
Env<AttrContext>
The current environment.
env
)

Is given blank final variable assignable, i.e. in a scope where it may be assigned to even though it is final?

private boolean
private boolean
private boolean
isStaticEnumField(Symbol.VarSymbol v)

Is the given symbol a static, non-constant field of an Enum?

pack-priv boolean
isStaticReference(JCTree
The candidate tree.
tree
)

Does tree represent a static reference to an identifier?

pack-priv static boolean
isType(Symbol sym)

Is this symbol a type?

pack-priv Attr.ResultInfo
lambdaBodyResult(JCTree.JCLambda that, Type descriptor, Attr.ResultInfo resultInfo)

public Env<AttrContext>
pack-priv Type
litType(TypeTag tag)

Return the type of a literal with given type tag.

public JCTree.JCExpression
makeNullCheck(JCTree.JCExpression arg)

Make an attributed null check tree.

pack-priv Attr.ResultInfo
pack-priv Type
newMethodTemplate(Type restype, List<Type> argtypes, List<Type> typeargtypes)

Obtain a method type with given argument types.

pack-priv Kinds.KindSelector
public void
postAttr(JCTree tree)

Handle missing types/symbols in an AST.

pack-priv void
pack-priv void
pack-priv boolean
pack-priv Type
pt()

private void
private Symbol
selectSym(JCTree.JCFieldAccess
The select tree.
tree
,
Symbol location, Type
The type of the selected expression,
site
,
Env<AttrContext>
The current environment.
env
,
Attr.ResultInfo
The current result.
resultInfo
)

Determine symbol referenced by a Select expression,

private void
setFunctionalInfo(final Env<AttrContext> env, final JCTree.JCFunctionalExpression fExpr, final Type pt, final Type descriptorType, final Type primaryTarget, final Check.CheckContext checkContext)

Set functional type info on the underlying AST.

public void
private void
pack-priv Check.CheckContext
public void
validateTypeAnnotations(JCTree tree, boolean sigOnly)

public void
public void
private void
visitAnonymousClassDefinition(JCTree.JCNewClass tree, JCTree.JCExpression clazz, Type clazztype, JCTree.JCClassDecl cdef, Env<AttrContext> localEnv, List<Type> argtypes, List<Type> typeargtypes, Kinds.KindSelector pkind)

public void
public void
visitApply(JCTree.JCMethodInvocation tree)

Overrides com.sun.tools.javac.tree.JCTree.Visitor.visitApply.

Visitor method for method invocations.

public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
visitTree(JCTree tree)

Overrides com.sun.tools.javac.tree.JCTree.Visitor.visitTree.

Default visitor method for all other trees.

public void
public void
visitTypeApply(JCTree.JCTypeApply tree)

Overrides com.sun.tools.javac.tree.JCTree.Visitor.visitTypeApply.

Visitor method for parameterized types.

public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
public void
Inherited from com.sun.tools.javac.tree.JCTree.Visitor:
visitCasevisitCatchvisitConstantCaseLabelvisitDefaultCaseLabelvisitExportsvisitLetExprvisitModuleImportvisitOpensvisitPackageDefvisitPatternCaseLabelvisitProvidesvisitRequiresvisitTopLevelvisitTypeBoundKindvisitUsesvisitVarType