Interface NodeWithMembers<N extends Node>

    • Method Detail

      • getMembers

        NodeList<BodyDeclaration<?>> getMembers()
        Returns:
        all members inside the braces of this node, like fields, methods, nested types, etc.
      • tryAddImportToParentCompilationUnit

        void tryAddImportToParentCompilationUnit​(Class<?> clazz)
      • addPrivateField

        default FieldDeclaration addPrivateField​(Class<?> typeClass,
                                                 String name)
        Add a private field to this.
        Parameters:
        typeClass - the type of the field
        name - the name of the field
        Returns:
        the FieldDeclaration created
      • addPrivateField

        default FieldDeclaration addPrivateField​(String type,
                                                 String name)
        Add a private field to this and automatically add the import of the type if needed.
        Parameters:
        type - the type of the field
        name - the name of the field
        Returns:
        the FieldDeclaration created
      • addPrivateField

        default FieldDeclaration addPrivateField​(Type type,
                                                 String name)
        Add a private field to this.
        Parameters:
        type - the type of the field
        name - the name of the field
        Returns:
        the FieldDeclaration created
      • addPublicField

        default FieldDeclaration addPublicField​(Class<?> typeClass,
                                                String name)
        Add a public field to this.
        Parameters:
        typeClass - the type of the field
        name - the name of the field
        Returns:
        the FieldDeclaration created
      • addPublicField

        default FieldDeclaration addPublicField​(String type,
                                                String name)
        Add a public field to this and automatically add the import of the type if needed.
        Parameters:
        type - the type of the field
        name - the name of the field
        Returns:
        the FieldDeclaration created
      • addPublicField

        default FieldDeclaration addPublicField​(Type type,
                                                String name)
        Add a public field to this.
        Parameters:
        type - the type of the field
        name - the name of the field
        Returns:
        the FieldDeclaration created
      • addProtectedField

        default FieldDeclaration addProtectedField​(Class<?> typeClass,
                                                   String name)
        Add a protected field to this.
        Parameters:
        typeClass - the type of the field
        name - the name of the field
        Returns:
        the FieldDeclaration created
      • addProtectedField

        default FieldDeclaration addProtectedField​(String type,
                                                   String name)
        Add a protected field to this and automatically add the import of the type if needed.
        Parameters:
        type - the type of the field
        name - the name of the field
        Returns:
        the FieldDeclaration created
      • addProtectedField

        default FieldDeclaration addProtectedField​(Type type,
                                                   String name)
        Add a protected field to this.
        Parameters:
        type - the type of the field
        name - the name of the field
        Returns:
        the FieldDeclaration created
      • getMethodsByName

        default List<MethodDeclaration> getMethodsByName​(String name)
        Try to find a MethodDeclaration by its name
        Parameters:
        name - the name of the method
        Returns:
        the methods found (multiple in case of overloading)
      • getMethods

        default List<MethodDeclaration> getMethods()
        Find all methods in the members of this node.
        Returns:
        the methods found. This list is immutable.
      • getMethodsByParameterTypes

        default List<MethodDeclaration> getMethodsByParameterTypes​(String... paramTypes)
        Try to find a MethodDeclaration by its parameter 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 find all methods that have exactly one parameter whose type is declared as List, but not methods with exactly one parameter whose type is declared as java.util.List or java.awt.List. Conversely, passing the string "java.util.List" to this method will find all methods that have 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 there is a method that has a 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:
        the methods found
      • getMethodsBySignature

        default List<MethodDeclaration> getMethodsBySignature​(String name,
                                                              String... paramTypes)
        Try to find MethodDeclarations by their name and parameter types. Parameter types are matched exactly as in the case of getMethodsByParameterTypes(String...).
        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:
        the methods found
      • getMethodsByParameterTypes

        default List<MethodDeclaration> getMethodsByParameterTypes​(Class<?>... paramTypes)
        Try to find a MethodDeclaration by its parameter 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 return all methods that have 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:
        the methods found
      • getConstructors

        default List<ConstructorDeclaration> getConstructors()
        Find all constructors in the members of this node.
        Returns:
        the constructors found. This list is immutable.
      • getConstructorByParameterTypes

        default Optional<ConstructorDeclaration> getConstructorByParameterTypes​(String... paramTypes)
        Try to find a ConstructorDeclaration by its parameter types. The given parameter types must literally match the declared types of the desired constructor, so passing the string "List" to this method will search for a constructor that has exactly one parameter whose type is declared as List, but not for a constructor with exactly one parameter whose type is declared as java.util.List or java.awt.List. Conversely, passing the string "java.util.List" to this method will search for a constructor that has exactly one parameter whose type is declared as java.util.List, but not for a constructor whose type is declared as List. Similarly, note that generics are matched as well: If there is a constructor that has a 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 Foo(Map&lt;Integer,String&gt; myMap, int number)
        Returns:
        the constructor found, if any.
      • getConstructorByParameterTypes

        default Optional<ConstructorDeclaration> getConstructorByParameterTypes​(Class<?>... paramTypes)
        Try to find a ConstructorDeclaration by its parameter 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 search for a constructor that 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 Foo(Map&lt;Integer,String&gt; myMap, int number)
        Returns:
        the constructor found, if any.
      • getFields

        default List<FieldDeclaration> getFields()
        Find all fields in the members of this node.
        Returns:
        the fields found. This list is immutable.
      • isEmpty

        default boolean isEmpty()
        Returns:
        true if there are no members contained in this node.