Package spoon.reflect.visitor.filter
Class PotentialVariableDeclarationFunction
java.lang.Object
spoon.reflect.visitor.filter.PotentialVariableDeclarationFunction
- All Implemented Interfaces:
CtConsumableFunction<CtElement>,CtQueryAware
public class PotentialVariableDeclarationFunction
extends Object
implements CtConsumableFunction<CtElement>, CtQueryAware
This mapping function searches for all
It can be used to search for variable declarations of variable references and for detection of variable name conflicts
It returns
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 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 = ...;
varRef.map(new PotentialVariableDeclarationFunction()).forEach(...process result...);
Example: Search for CtVariable declaration of variable named `varName` in scope "scope"
CtElement scope = ...;
String varName = "anVariableName";
CtVariable varOrNull = scope.map(new PotentialVariableDeclarationFunction(varName)).first();
-
Constructor Summary
ConstructorsConstructorDescriptionPotentialVariableDeclarationFunction(String variableName) Searches for a variable with exact name. -
Method Summary
Modifier and TypeMethodDescriptionvoidapply(CtElement input, CtConsumer<Object> outputConsumer) Evaluates the function on the given input.booleanThis method provides access to current state of this function.voidThis method is called when the filter/function is added as a step to aCtQueryby the query engine (CtQueryImpl).
-
Constructor Details
-
PotentialVariableDeclarationFunction
public PotentialVariableDeclarationFunction() -
PotentialVariableDeclarationFunction
Searches for a variable with exact name.- Parameters:
variableName-
-
-
Method Details
-
apply
Description copied from interface:CtConsumableFunctionEvaluates the function on the given input.- Specified by:
applyin interfaceCtConsumableFunction<CtElement>- Parameters:
input- the input of the functionoutputConsumer- 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.- Returns:
- 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
Description copied from interface:CtQueryAwareThis method is called when the filter/function is added as a step to aCtQueryby the query engine (CtQueryImpl).- Specified by:
setQueryin interfaceCtQueryAware- Parameters:
query- an instance registering this function/filter.
-