Interface NodeWithParameters<N extends Node>
-
- All Known Implementing Classes:
CallableDeclaration
,ConstructorDeclaration
,LambdaExpr
,MethodDeclaration
public interface NodeWithParameters<N extends Node>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Parameter
addAndGetParameter(Parameter parameter)
default Parameter
addAndGetParameter(Type type, String name)
default Parameter
addAndGetParameter(Class<?> paramClass, String name)
default Parameter
addAndGetParameter(String className, String name)
Remember to import the class in the compilation unit yourselfdefault N
addParameter(Parameter parameter)
default N
addParameter(Type type, String name)
default N
addParameter(Class<?> paramClass, String name)
default N
addParameter(String className, String name)
Remember to import the class in the compilation unit yourselfdefault Parameter
getParameter(int i)
default Optional<Parameter>
getParameterByName(String name)
Try to find aParameter
by its namedefault Optional<Parameter>
getParameterByType(Class<?> type)
Try to find aParameter
by its typedefault Optional<Parameter>
getParameterByType(String type)
Try to find aParameter
by its typeNodeList<Parameter>
getParameters()
default boolean
hasParametersOfType(Class<?>... paramTypes)
Check if the parameters have certain types.default boolean
hasParametersOfType(String... paramTypes)
Check if the parameters have certain types.default N
setParameter(int i, Parameter parameter)
N
setParameters(NodeList<Parameter> parameters)
void
tryAddImportToParentCompilationUnit(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
Parameter
created
-
getParameterByName
default Optional<Parameter> getParameterByName(String name)
Try to find aParameter
by 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 aParameter
by 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 aParameter
by 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.List
orjava.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:
true
if 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.List
andjava.util.List
are identical to this algorithm. In addition, note that it is the erasure of each type which is considered, so passingList.class
to 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.class
to matchvoid foo(Map<Integer,String> myMap, int number)
.- Returns:
true
if all parameters match one by one, in the given order.
-
-