Interface NodeWithParameters<N extends Node>

All Known Implementing Classes:
CallableDeclaration, ConstructorDeclaration, LambdaExpr, MethodDeclaration, RecordDeclaration

public interface NodeWithParameters<N extends Node>
  • Method Details

    • getParameters

      NodeList<Parameter> getParameters()
    • getParameter

      default Parameter getParameter(int i)
    • tryAddImportToParentCompilationUnit

      void tryAddImportToParentCompilationUnit(Class<?> clazz)
    • setParameter

      default N setParameter(int i, Parameter parameter)
    • setParameters

      N setParameters(NodeList<Parameter> parameters)
    • addParameter

      default N addParameter(Type type, String name)
    • addParameter

      default N addParameter(Class<?> paramClass, String name)
    • 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 import
      name - the name of the parameter
    • addParameter

      default N addParameter(Parameter parameter)
    • addAndGetParameter

      default Parameter addAndGetParameter(Type type, String name)
    • addAndGetParameter

      default Parameter addAndGetParameter(Class<?> paramClass, String name)
    • 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 import
      name - the name of the parameter
      Returns:
      the Parameter created
    • addAndGetParameter

      default Parameter addAndGetParameter(Parameter parameter)
    • getParameterByName

      default Optional<Parameter> getParameterByName(String name)
      Try to find a Parameter 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 a Parameter 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 a Parameter 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 as List, but not if the parameter type is declared as java.util.List or java.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 as java.util.List, but not if the parameter type is declared as List. Similarly, note that generics are matched as well: If this node has one parameter declared as List&lt;String&gt;, then it will be considered as a match only if the given string is "List&lt;String&gt;", but not if the given string is only "List".
      Parameters:
      paramTypes - the types of parameters like "Map&lt;Integer,String&gt;", "int" to match void foo(Map&lt;Integer,String&gt; 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, so java.awt.List and java.util.List are identical to this algorithm. In addition, note that it is the erasure of each type which is considered, so passing List.class to this method will be considered a match if this node has exactly one parameter whose type is named List, regardless of whether the parameter type is declared without generics as List, or with generics as List&lt;String&gt;, or List&lt;Integer&gt;, etc.
      Parameters:
      paramTypes - the types of parameters like Map.class, int.class to match void foo(Map&lt;Integer,String&gt; myMap, int number).
      Returns:
      true if all parameters match one by one, in the given order.