All Known Implementing Classes:
AbstractJavaParserContext, AbstractMethodLikeDeclarationContext, AnnotationDeclarationContext, AnonymousClassDeclarationContext, BinaryExprContext, BlockStmtContext, CatchClauseContext, ClassOrInterfaceDeclarationContext, CompilationUnitContext, ConstructorContext, EnclosedExprContext, EnumDeclarationContext, FieldAccessContext, ForEachStatementContext, ForStatementContext, IfStatementContext, InstanceOfExprContext, LambdaExprContext, MethodCallExprContext, MethodContext, MethodReferenceExprContext, ObjectCreationContext, StatementContext, SwitchEntryContext, TryWithResourceContext, UnaryExprContext, VariableDeclarationExprContext, VariableDeclaratorContext

public interface Context
Context is very similar to scope. In the context we look for solving symbols.
Author:
Federico Tomassetti
  • Method Details

    • 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, solving T within class Foo<T> {} or
      Returns:
      The resolved generic type, if found.
    • solveGenericTypeInParentContext

      default Optional<ResolvedType> solveGenericTypeInParentContext(String name)
    • solveType

      default SymbolReference<ResolvedTypeDeclaration> solveType(String name)
      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, solving List or java.util.List.
      Returns:
      The declaration associated with the given type name.
    • solveTypeInParentContext

      default SymbolReference<ResolvedTypeDeclaration> solveTypeInParentContext(String name)
    • solveSymbol

      default SymbolReference<? extends ResolvedValueDeclaration> solveSymbol(String name)
      Used where a symbol is being used (e.g. solving x when used as an argument doubleThis(x), or calculation return 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. solving x when used as an argument doubleThis(x), or calculation return 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.
    • patternExprsExposedToChild

      default List<PatternExpr> patternExprsExposedToChild(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.
    • patternExprsExposedFromChildren

      default List<PatternExpr> patternExprsExposedFromChildren()
    • negatedPatternExprsExposedFromChildren

      default List<PatternExpr> negatedPatternExprsExposedFromChildren()
    • 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.

    • parameterDeclarationInScope

      default Optional<Parameter> parameterDeclarationInScope(String name)
    • patternExprInScope

      default Optional<PatternExpr> patternExprInScope(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

      default 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.