Interface Context
-
public interface Context
Context is very similar to scope. In the context we look for solving symbols.- Author:
- Federico Tomassetti
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description default Optional<ResolvedFieldDeclaration>
fieldDeclarationInScope(String name)
default List<ResolvedFieldDeclaration>
fieldsExposedToChild(Node child)
The fields that are declared and in this immediate context made visible to a given child.Optional<Context>
getParent()
<N extends Node>
NgetWrappedNode()
Returns the node wrapped in the contextdefault Optional<VariableDeclarator>
localVariableDeclarationInScope(String name)
Aim to resolve the given name by looking for a variable matching it.default List<VariableDeclarator>
localVariablesExposedToChild(Node child)
The local variables that are declared in this immediate context and made visible to a given child.default List<TypePatternExpr>
negatedTypePatternExprsExposedFromChildren()
default Optional<Parameter>
parameterDeclarationInScope(String name)
default List<Parameter>
parametersExposedToChild(Node child)
The parameters that are declared in this immediate context and made visible to a given child.default SymbolReference<ResolvedConstructorDeclaration>
solveConstructor(List<ResolvedType> argumentsTypes)
We find the method declaration which is the best match for the given name and list of typeParametersValues.default Optional<ResolvedType>
solveGenericType(String name)
Default to no generics available in this context, delegating solving to the parent context.default Optional<ResolvedType>
solveGenericTypeInParentContext(String name)
default SymbolReference<ResolvedMethodDeclaration>
solveMethod(String name, List<ResolvedType> argumentsTypes, boolean staticOnly)
We find the method declaration which is the best match for the given name and list of typeParametersValues.Optional<MethodUsage>
solveMethodAsUsage(String name, List<ResolvedType> argumentsTypes)
Similar to solveMethod but we return a MethodUsage.default SymbolReference<ResolvedMethodDeclaration>
solveMethodInParentContext(String name, List<ResolvedType> argumentsTypes, boolean staticOnly)
default SymbolReference<? extends ResolvedValueDeclaration>
solveSymbol(String name)
Used where a symbol is being used (e.g. solvingx
when used as an argumentdoubleThis(x)
, or calculationreturn x * 2;
).default Optional<Value>
solveSymbolAsValue(String name)
Used where a symbol is being used (e.g. solvingx
when used as an argumentdoubleThis(x)
, or calculationreturn x * 2;
).default Optional<Value>
solveSymbolAsValueInParentContext(String name)
default SymbolReference<? extends ResolvedValueDeclaration>
solveSymbolInParentContext(String name)
default SymbolReference<ResolvedTypeDeclaration>
solveType(String name)
Deprecated.Consider using methodsolveType(String, List)
that also consider the type arguments.default SymbolReference<ResolvedTypeDeclaration>
solveType(String name, List<ResolvedType> typeArguments)
Method used to solve a name with an expected list of type arguments.default SymbolReference<ResolvedTypeDeclaration>
solveTypeInParentContext(String name)
Deprecated.Consider using methodsolveTypeInParentContext(String, List)
that also consider the type arguments.default SymbolReference<ResolvedTypeDeclaration>
solveTypeInParentContext(String name, List<ResolvedType> typeArguments)
Solve a name with type arguments in the parent context.default Optional<TypePatternExpr>
typePatternExprInScope(String name)
With respect to solving, the AST "parent" of a block statement is not necessarily the same as the scope parent.default List<TypePatternExpr>
typePatternExprsExposedFromChildren()
default List<TypePatternExpr>
typePatternExprsExposedToChild(Node child)
The pattern expressions that are declared in this immediate context and made visible to a given child.
-
-
-
Method Detail
-
getWrappedNode
<N extends Node> N getWrappedNode()
Returns the node wrapped in the context
-
getParent
Optional<Context> getParent()
- Returns:
- The parent context, if there is one. For example, a method exists within a compilation unit.
-
solveGenericType
default Optional<ResolvedType> solveGenericType(String name)
Default to no generics available in this context, delegating solving to the parent context. Contexts which have generics available to it will override this method. For example class and method declarations, and method calls.- Parameters:
name
- For example, solvingT
withinclass Foo<T> {}
or- Returns:
- The resolved generic type, if found.
-
solveGenericTypeInParentContext
default Optional<ResolvedType> solveGenericTypeInParentContext(String name)
-
solveType
@Deprecated default SymbolReference<ResolvedTypeDeclaration> solveType(String name)
Deprecated.Consider using methodsolveType(String, List)
that also consider the type arguments. If you want to keep to use the new function, but keep the same behavior consider passing type arguments asnull
.Default to being unable to solve any reference in this context, delegating solving to the parent context. Contexts which exist as the "parent" of a resolvable type will override this method. For example, a compilation unit can contain classes. A class declaration can also contain types (e.g. a subclass).- Parameters:
name
- For example, solvingList
orjava.util.List
.- Returns:
- The declaration associated with the given type name.
-
solveType
default SymbolReference<ResolvedTypeDeclaration> solveType(String name, @Nullable List<ResolvedType> typeArguments)
Method used to solve a name with an expected list of type arguments.
This method differs fromsolveType(String)
by taking the type arguments in consideration. For example, lets imagine that we have a project containing the following classes:- com/example/Alpha.java
- com/example/Beta.java
- Parameters:
name
- The name to be solved.typeArguments
- The list of expected type arguments.- Returns:
- The declaration associated with the given type name.
-
solveTypeInParentContext
@Deprecated default SymbolReference<ResolvedTypeDeclaration> solveTypeInParentContext(String name)
Deprecated.Consider using methodsolveTypeInParentContext(String, List)
that also consider the type arguments. If you want to keep to use the new function, but keep the same behavior consider passing type arguments asnull
.Solve a name in the parent context.- Parameters:
name
- The name to be solved.- Returns:
- The declaration associated with the given type name.
-
solveTypeInParentContext
default SymbolReference<ResolvedTypeDeclaration> solveTypeInParentContext(String name, @Nullable List<ResolvedType> typeArguments)
Solve a name with type arguments in the parent context.- Parameters:
name
- The name to be solved.typeArguments
- The list of expected type arguments.- Returns:
- The declaration associated with the given type name.
-
solveSymbol
default SymbolReference<? extends ResolvedValueDeclaration> solveSymbol(String name)
Used where a symbol is being used (e.g. solvingx
when used as an argumentdoubleThis(x)
, or calculationreturn x * 2;
).- Parameters:
name
- the variable / reference / identifier used.- Returns:
- // FIXME: Better documentation on how this is different to solveSymbolAsValue()
-
solveSymbolInParentContext
default SymbolReference<? extends ResolvedValueDeclaration> solveSymbolInParentContext(String name)
-
solveSymbolAsValue
default Optional<Value> solveSymbolAsValue(String name)
Used where a symbol is being used (e.g. solvingx
when used as an argumentdoubleThis(x)
, or calculationreturn x * 2;
).- Parameters:
name
- the variable / reference / identifier used.- Returns:
- // FIXME: Better documentation on how this is different to solveSymbol()
-
solveSymbolAsValueInParentContext
default Optional<Value> solveSymbolAsValueInParentContext(String name)
-
fieldsExposedToChild
default List<ResolvedFieldDeclaration> fieldsExposedToChild(Node child)
The fields that are declared and in this immediate context made visible to a given child. This list could include values which are shadowed.
-
localVariablesExposedToChild
default List<VariableDeclarator> localVariablesExposedToChild(Node child)
The local variables that are declared in this immediate context and made visible to a given child. This list could include values which are shadowed.
-
parametersExposedToChild
default List<Parameter> parametersExposedToChild(Node child)
The parameters that are declared in this immediate context and made visible to a given child. This list could include values which are shadowed.
-
typePatternExprsExposedToChild
default List<TypePatternExpr> typePatternExprsExposedToChild(Node child)
The pattern expressions that are declared in this immediate context and made visible to a given child. This list could include values which are shadowed.
-
typePatternExprsExposedFromChildren
default List<TypePatternExpr> typePatternExprsExposedFromChildren()
-
negatedTypePatternExprsExposedFromChildren
default List<TypePatternExpr> negatedTypePatternExprsExposedFromChildren()
-
localVariableDeclarationInScope
default Optional<VariableDeclarator> localVariableDeclarationInScope(String name)
Aim to resolve the given name by looking for a variable matching it.To do it consider local variables that are visible in a certain scope as defined in JLS 6.3. Scope of a Declaration.
1. The scope of a local variable declaration in a block (§14.4) is the rest of the block in which the declaration appears, starting with its own initializer and including any further declarators to the right in the local variable declaration statement.
2. The scope of a local variable declared in the ForInit part of a basic for statement (§14.14.1) includes all of the following: 2.1 Its own initializer 2.2 Any further declarators to the right in the ForInit part of the for statement 2.3 The Expression and ForUpdate parts of the for statement 2.4 The contained Statement
3. The scope of a local variable declared in the FormalParameter part of an enhanced for statement (§14.14.2) is the contained Statement. 4. The scope of a parameter of an exception handler that is declared in a catch clause of a try statement (§14.20) is the entire block associated with the catch.
5. The scope of a variable declared in the ResourceSpecification of a try-with-resources statement (§14.20.3) is from the declaration rightward over the remainder of the ResourceSpecification and the entire try block associated with the try-with-resources statement.
-
typePatternExprInScope
default Optional<TypePatternExpr> typePatternExprInScope(String name)
With respect to solving, the AST "parent" of a block statement is not necessarily the same as the scope parent.
Example:
public String x() { if(x) { // Parent node: the block attached to the method declaration // Scope-parent: the block attached to the method declaration } else if { // Parent node: the if // Scope-parent: the block attached to the method declaration } else { // Parent node: the elseif // Scope-parent: the block attached to the method declaration } }
-
fieldDeclarationInScope
default Optional<ResolvedFieldDeclaration> fieldDeclarationInScope(String name)
-
solveConstructor
default SymbolReference<ResolvedConstructorDeclaration> solveConstructor(List<ResolvedType> argumentsTypes)
We find the method declaration which is the best match for the given name and list of typeParametersValues.
-
solveMethod
default SymbolReference<ResolvedMethodDeclaration> solveMethod(String name, List<ResolvedType> argumentsTypes, boolean staticOnly)
We find the method declaration which is the best match for the given name and list of typeParametersValues.
-
solveMethodInParentContext
default SymbolReference<ResolvedMethodDeclaration> solveMethodInParentContext(String name, List<ResolvedType> argumentsTypes, boolean staticOnly)
-
solveMethodAsUsage
Optional<MethodUsage> solveMethodAsUsage(String name, List<ResolvedType> argumentsTypes)
Similar to solveMethod but we return a MethodUsage. A MethodUsage corresponds to a MethodDeclaration plus the resolved type variables.
-
-