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

public Class ArgumentAttr

extends Visitor
Class Inheritance
Imports
com.sun.tools.javac.code.Flags, .Symbol, .Symtab, .Type, .Types.FunctionDescriptorLookupError, com.sun.tools.javac.comp.Attr.ResultInfo, .Attr.TargetInfo, .Check.CheckContext, .DeferredAttr.AttrMode, .DeferredAttr.DeferredAttrContext, .DeferredAttr.DeferredType, .DeferredAttr.LambdaReturnScanner, .DeferredAttr.SwitchExpressionScanner, .Infer.PartiallyInferredMethodType, .Resolve.MethodResolutionPhase, com.sun.tools.javac.resources.CompilerProperties.Fragments, com.sun.tools.javac.tree.JCTree, .JCTree.JCConditional, .JCTree.JCExpression, .JCTree.JCLambda, .JCTree.JCLambda.ParameterKind, .JCTree.JCMemberReference, .JCTree.JCMethodInvocation, .JCTree.JCNewClass, .JCTree.JCParens, .JCTree.JCReturn, .JCTree.JCSwitchExpression, .TreeCopier, .TreeInfo, .JCTree.JCYield, com.sun.tools.javac.util.Context, .DiagnosticSource, .JCDiagnostic, .JCDiagnostic.DiagnosticPosition, .List, .ListBuffer, .Log, java.util.HashMap, .LinkedHashMap, .Map, .Optional, java.util.function.Function, .Supplier

This class performs attribution of method/constructor arguments when target-typing is enabled (source >= 8); for each argument that is potentially a poly expression, this class builds a rich representation (see ArgumentType which can then be used for performing fast overload checks without requiring multiple attribution passes over the same code. The attribution strategy for a given method/constructor argument A is as follows: - if A is potentially a poly expression (i.e. diamond instance creation expression), a speculative pass over A is performed; the results of such speculative attribution are then saved in a special type, so that enclosing overload resolution can be carried by simply checking compatibility against the type determined during this speculative pass. - if A is a standalone expression, regular attribution takes place. To minimize the speculative work, a cache is used, so that already computed argument types associated with a given unique source location are never recomputed multiple times.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv abstract class
ArgumentAttr.ArgumentType<T extends JCTree.JCExpression>

An argument type is similar to a plain deferred type; the most important difference is that the completion logic associated with argument types allows speculative attribution to be skipped during overload resolution - that is, an argument type always has enough information to perform an overload check without the need of calling back to Attr.

pack-priv class
ArgumentAttr.ConditionalType

Argument type for conditionals.

pack-priv class
ArgumentAttr.ExplicitLambdaType

Argument type for explicit lambdas.

pack-priv class
ArgumentAttr.LocalCacheContext

Local cache context; this class keeps track of the previous cache and reverts to it when the LocalCacheContext#leave() method is called.

pack-priv class
ArgumentAttr.ParensType

Argument type for parenthesized expression.

pack-priv class
ArgumentAttr.ResolvedConstructorType

Argument type for constructors.

pack-priv abstract class
ArgumentAttr.ResolvedMemberType<E extends JCTree.JCExpression>

Argument type for methods/constructors.

pack-priv class
ArgumentAttr.ResolvedMethodType

Argument type for methods.

pack-priv class
ArgumentAttr.SwitchExpressionType

Argument type for switch expressions.

pack-priv class
ArgumentAttr.UniquePos

An instance of this class represents a unique position in a compilation unit.

Field Summary

Modifier and TypeField and Description
pack-priv Map<ArgumentAttr.UniquePos, ArgumentAttr.ArgumentType<?>>
argumentTypeCache

Cache for argument types; behavior is influenced by the currently selected cache policy.

private final Attr
private final DeferredAttr
private final JCDiagnostic.Factory
private Env<AttrContext>
env

Attribution environment to be used.

private final Log
protected static final Context.Key<ArgumentAttr>
pack-priv Type
result

Result of method attribution.

private final Symtab

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
pack-priv Type
attribArg(JCTree tree, Env<AttrContext> env)

Main entry point for attributing an argument with given tree and attribution environment.

pack-priv Type
checkSpeculative(JCTree expr, Attr.ResultInfo resultInfo)

Checks a type in the speculative tree against a given result; the type can be either a plain type or an argument type, in which case a more complex check is required.

pack-priv Type
checkSpeculative(JCDiagnostic.DiagnosticPosition pos, Type t, Attr.ResultInfo resultInfo)

Checks a type in the speculative tree against a given result; the type can be either a plain type or an argument type, in which case a more complex check is required.

public static ArgumentAttr
instance(Context context)

pack-priv <T extends JCTree.JCExpression, Z extends ArgumentAttr.ArgumentType<T>> void
processArg(T that, Function<T, Z> argumentTypeFactory)

Process a method argument; this method takes care of performing a speculative pass over the argument tree and calling a well-defined entry point to build the argument type associated with such tree.

pack-priv <T extends JCTree.JCExpression, Z extends ArgumentAttr.ArgumentType<T>> void
processArg(T that, Supplier<Z> argumentTypeFactory)

Process a method argument; this method allows the caller to specify a custom speculative attribution logic (this is used e.g. for lambdas).

pack-priv void
setResult(JCTree.JCExpression tree, Type type)

Set the results of method attribution.

public void
public void
public void
public void
public void
public void
public void
public void
pack-priv ArgumentAttr.LocalCacheContext
withLocalCacheContext()

Returns a local caching context in which argument types can safely be cached without the risk of polluting enclosing contexts.

Inherited from com.sun.tools.javac.tree.JCTree.Visitor:
visitAnnotatedTypevisitAnnotationvisitAnyPatternvisitAssertvisitAssignvisitAssignopvisitBinaryvisitBindingPatternvisitBlockvisitBreakvisitCasevisitCatchvisitClassDefvisitConstantCaseLabelvisitContinuevisitDefaultCaseLabelvisitDoLoopvisitErroneousvisitExecvisitExportsvisitForeachLoopvisitForLoopvisitIdentvisitIfvisitImportvisitIndexedvisitLabelledvisitLetExprvisitLiteralvisitMethodDefvisitModifiersvisitModuleDefvisitModuleImportvisitNewArrayvisitOpensvisitPackageDefvisitPatternCaseLabelvisitProvidesvisitRecordPatternvisitRequiresvisitReturnvisitSelectvisitSkipvisitSwitchvisitSynchronizedvisitThrowvisitTopLevelvisitTryvisitTypeApplyvisitTypeArrayvisitTypeBoundKindvisitTypeCastvisitTypeIdentvisitTypeIntersectionvisitTypeParametervisitTypeTestvisitTypeUnionvisitUnaryvisitUsesvisitVarDefvisitVarTypevisitWhileLoopvisitWildcardvisitYield