Class PotentialVariableDeclarationFunction

All Implemented Interfaces:
CtConsumableFunction<CtElement>, CtQueryAware

public class PotentialVariableDeclarationFunction extends Object implements CtConsumableFunction<CtElement>, CtQueryAware
This mapping function searches for all CtVariable instances, which might be a declaration of an input CtElement.
It can be used to search for variable declarations of variable references and for detection of variable name conflicts
It returns CtLocalVariable instances, or it returns CtCatchVariable instances of catch blocks, or i returns CtParameter instances of methods, lambdas and catch blocks. or it returns CtField instances from wrapping classes and their super classes too.
The elements are visited in the following order: first elements are thought in the nearest parent blocks, then in the fields of wrapping classes, then in the fields of super classes, etc.
Example: Search for all potential CtVariable declarations
 CtVariableReference varRef = ...; PotentialVariableDeclarationFunction()).forEach(...process result...);
Example: Search for CtVariable declaration of variable named `varName` in scope "scope"
 CtElement scope = ...;
 String varName = "anVariableName";
 CtVariable varOrNull = PotentialVariableDeclarationFunction(varName)).first();
  • Constructor Details

    • PotentialVariableDeclarationFunction

      public PotentialVariableDeclarationFunction()
    • PotentialVariableDeclarationFunction

      public PotentialVariableDeclarationFunction(String variableName)
      Searches for a variable with exact name.
      variableName -
  • Method Details

    • apply

      public void apply(CtElement input, CtConsumer<Object> outputConsumer)
      Description copied from interface: CtConsumableFunction
      Evaluates the function on the given input.
      Specified by:
      apply in interface CtConsumableFunction<CtElement>
      input - the input of the function
      outputConsumer - the consumer which accepts the results of this function.
    • isTypeOnTheWay

      public boolean isTypeOnTheWay()
      This method provides access to current state of this function. It is intended to be called by other mapping functions at query processing time or after query is finished.
      true if there is an local class on the way from the input of this mapping function to the actually found potential variable declaration
    • setQuery

      public void setQuery(CtQuery query)
      Description copied from interface: CtQueryAware
      This method is called when the filter/function is added as a step to a CtQuery by the query engine (CtQueryImpl).
      Specified by:
      setQuery in interface CtQueryAware
      query - an instance registering this function/filter.