Interface NodeWithParameters<N extends Node>
- All Known Implementing Classes:
CallableDeclaration,ConstructorDeclaration,LambdaExpr,MethodDeclaration,RecordDeclaration
public interface NodeWithParameters<N extends Node>
-
Method Summary
Modifier and TypeMethodDescriptiondefault 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)getParameterByName(String name)Try to find aParameterby its namegetParameterByType(Class<?> type)Try to find aParameterby its typegetParameterByType(String type)Try to find aParameterby its typedefault 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)setParameters(NodeList<Parameter> parameters)voidtryAddImportToParentCompilationUnit(Class<?> clazz)
-
Method Details
-
getParameters
-
getParameter
-
tryAddImportToParentCompilationUnit
-
setParameter
-
setParameters
-
addParameter
-
addParameter
-
addParameter
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
-
addParameter
-
addAndGetParameter
-
addAndGetParameter
-
addAndGetParameter
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
-
addAndGetParameter
-
getParameterByName
Try to find aParameterby its name- Parameters:
name- the name of the param- Returns:
- null if not found, the param found otherwise
-
getParameterByType
Try to find aParameterby its type- Parameters:
type- the type of the param- Returns:
- null if not found, the param found otherwise
-
getParameterByType
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
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
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.
-