Interface NodeWithParameters<N extends Node>
-
- All Known Implementing Classes:
CallableDeclaration,ConstructorDeclaration,LambdaExpr,MethodDeclaration,RecordDeclaration
public interface NodeWithParameters<N extends Node>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default ParameteraddAndGetParameter(Parameter parameter)default ParameteraddAndGetParameter(Type type, String name)default ParameteraddAndGetParameter(Class<?> paramClass, String name)default ParameteraddAndGetParameter(String className, String name)Remember to import the class in the compilation unit yourselfdefault NaddParameter(Parameter parameter)default NaddParameter(Type type, String name)default NaddParameter(Class<?> paramClass, String name)default NaddParameter(String className, String name)Remember to import the class in the compilation unit yourselfdefault ParametergetParameter(int i)default Optional<Parameter>getParameterByName(String name)Try to find aParameterby its namedefault Optional<Parameter>getParameterByType(Class<?> type)Try to find aParameterby its typedefault Optional<Parameter>getParameterByType(String type)Try to find aParameterby its typeNodeList<Parameter>getParameters()default booleanhasParametersOfType(Class<?>... paramTypes)Check if the parameters have certain types.default booleanhasParametersOfType(String... paramTypes)Check if the parameters have certain types.default NsetParameter(int i, Parameter parameter)NsetParameters(NodeList<Parameter> parameters)voidtryAddImportToParentCompilationUnit(Class<?> clazz)
-
-
-
Method Detail
-
getParameter
default Parameter getParameter(int i)
-
tryAddImportToParentCompilationUnit
void tryAddImportToParentCompilationUnit(Class<?> clazz)
-
addParameter
default N addParameter(String className, String name)
Remember to import the class in the compilation unit yourself- Parameters:
className- the name of the class, ex : org.test.Foo or Foo if you added manually the importname- the name of the parameter
-
addAndGetParameter
default Parameter addAndGetParameter(String className, String name)
Remember to import the class in the compilation unit yourself- Parameters:
className- the name of the class, ex : org.test.Foo or Foo if you added manually the importname- the name of the parameter- Returns:
- the
Parametercreated
-
getParameterByName
default Optional<Parameter> getParameterByName(String name)
Try to find aParameterby its name- Parameters:
name- the name of the param- Returns:
- null if not found, the param found otherwise
-
getParameterByType
default Optional<Parameter> getParameterByType(String type)
Try to find aParameterby its type- Parameters:
type- the type of the param- Returns:
- null if not found, the param found otherwise
-
getParameterByType
default Optional<Parameter> getParameterByType(Class<?> type)
Try to find aParameterby its type- Parameters:
type- the type of the param take care about generics, it wont work- Returns:
- null if not found, the param found otherwise
-
hasParametersOfType
default boolean hasParametersOfType(String... paramTypes)
Check if the parameters have certain types. The given parameter types must literally match the declared types of this node's parameters, so passing the string"List"to this method will be considered a match if this node has exactly one parameter whose type is declared asList, but not if the parameter type is declared asjava.util.Listorjava.awt.List. Conversely, passing the string"java.util.List"to this method will be considered a match if this node has exactly one parameter whose type is declared asjava.util.List, but not if the parameter type is declared asList. Similarly, note that generics are matched as well: If this node has one parameter declared asList<String>, then it will be considered as a match only if the given string is"List<String>", but not if the given string is only"List".- Parameters:
paramTypes- the types of parameters like"Map<Integer,String>", "int"to matchvoid foo(Map<Integer,String> myMap, int number).- Returns:
trueif all parameters match one by one, in the given order.
-
hasParametersOfType
default boolean hasParametersOfType(Class<?>... paramTypes)
Check if the parameters have certain types. Note that this is a match in SimpleName, sojava.awt.Listandjava.util.Listare identical to this algorithm. In addition, note that it is the erasure of each type which is considered, so passingList.classto this method will be considered a match if this node has exactly one parameter whose type is namedList, regardless of whether the parameter type is declared without generics asList, or with generics asList<String>, orList<Integer>, etc.- Parameters:
paramTypes- the types of parameters likeMap.class, int.classto matchvoid foo(Map<Integer,String> myMap, int number).- Returns:
trueif all parameters match one by one, in the given order.
-
-