public interface NodeWithMembers<N extends Node> extends NodeWithSimpleName<N>
The main reason for this interface is to permit users to manipulate homogeneously all nodes with a getMembers method.
Modifier and Type | Method and Description |
---|---|
default ConstructorDeclaration |
addConstructor(Modifier.Keyword... modifiers)
Adds a constructor to this node with members.
|
default FieldDeclaration |
addField(Class<?> typeClass,
String name,
Modifier.Keyword... modifiers)
Add a field to this and automatically add the import of the type if needed
|
default FieldDeclaration |
addField(String type,
String name,
Modifier.Keyword... modifiers)
Add a field to this.
|
default FieldDeclaration |
addField(Type type,
String name,
Modifier.Keyword... modifiers)
Add a field to this.
|
default FieldDeclaration |
addFieldWithInitializer(Class<?> typeClass,
String name,
Expression initializer,
Modifier.Keyword... modifiers)
Add a field to this and automatically add the import of the type if needed
|
default FieldDeclaration |
addFieldWithInitializer(String type,
String name,
Expression initializer,
Modifier.Keyword... modifiers)
Add a field to this.
|
default FieldDeclaration |
addFieldWithInitializer(Type type,
String name,
Expression initializer,
Modifier.Keyword... modifiers)
Add a field to this.
|
default BlockStmt |
addInitializer()
Add an initializer block (
InitializerDeclaration ) to this. |
default N |
addMember(BodyDeclaration<?> member) |
default MethodDeclaration |
addMethod(String methodName,
Modifier.Keyword... modifiers)
Adds a methods with void return by default to this.
|
default FieldDeclaration |
addPrivateField(Class<?> typeClass,
String name)
Add a private field to this.
|
default FieldDeclaration |
addPrivateField(String type,
String name)
Add a private field to this and automatically add the import of the type if
needed.
|
default FieldDeclaration |
addPrivateField(Type type,
String name)
Add a private field to this.
|
default FieldDeclaration |
addProtectedField(Class<?> typeClass,
String name)
Add a protected field to this.
|
default FieldDeclaration |
addProtectedField(String type,
String name)
Add a protected field to this and automatically add the import of the type
if needed.
|
default FieldDeclaration |
addProtectedField(Type type,
String name)
Add a protected field to this.
|
default FieldDeclaration |
addPublicField(Class<?> typeClass,
String name)
Add a public field to this.
|
default FieldDeclaration |
addPublicField(String type,
String name)
Add a public field to this and automatically add the import of the type if
needed.
|
default FieldDeclaration |
addPublicField(Type type,
String name)
Add a public field to this.
|
default BlockStmt |
addStaticInitializer()
Add a static initializer block (
InitializerDeclaration ) to this. |
default Optional<ConstructorDeclaration> |
getConstructorByParameterTypes(Class<?>... paramTypes)
Try to find a
ConstructorDeclaration by its parameter types. |
default Optional<ConstructorDeclaration> |
getConstructorByParameterTypes(String... paramTypes)
Try to find a
ConstructorDeclaration by its parameter types. |
default List<ConstructorDeclaration> |
getConstructors()
Find all constructors in the members of this node.
|
default Optional<ConstructorDeclaration> |
getDefaultConstructor()
Try to find a
ConstructorDeclaration with no parameters. |
default Optional<FieldDeclaration> |
getFieldByName(String name)
Try to find a
FieldDeclaration by its name |
default List<FieldDeclaration> |
getFields()
Find all fields in the members of this node.
|
default BodyDeclaration<?> |
getMember(int i) |
NodeList<BodyDeclaration<?>> |
getMembers() |
default List<MethodDeclaration> |
getMethods()
Find all methods in the members of this node.
|
default List<MethodDeclaration> |
getMethodsByName(String name)
Try to find a
MethodDeclaration by its name |
default List<MethodDeclaration> |
getMethodsByParameterTypes(Class<?>... paramTypes)
Try to find a
MethodDeclaration by its parameter types. |
default List<MethodDeclaration> |
getMethodsByParameterTypes(String... paramTypes)
Try to find a
MethodDeclaration by its parameter types. |
default List<MethodDeclaration> |
getMethodsBySignature(String name,
String... paramTypes)
Try to find
MethodDeclaration s by their name and parameter types. |
default boolean |
isEmpty() |
default N |
setMember(int i,
BodyDeclaration<?> member) |
N |
setMembers(NodeList<BodyDeclaration<?>> members) |
void |
tryAddImportToParentCompilationUnit(Class<?> clazz) |
getName, getNameAsExpression, getNameAsString, setName, setName
NodeList<BodyDeclaration<?>> getMembers()
void tryAddImportToParentCompilationUnit(Class<?> clazz)
default BodyDeclaration<?> getMember(int i)
default N setMember(int i, BodyDeclaration<?> member)
default N addMember(BodyDeclaration<?> member)
N setMembers(NodeList<BodyDeclaration<?>> members)
default FieldDeclaration addField(Class<?> typeClass, String name, Modifier.Keyword... modifiers)
typeClass
- the type of the fieldname
- the name of the fieldmodifiers
- the modifiers like Modifier.Keyword#PUBLIC
FieldDeclaration
createddefault FieldDeclaration addField(String type, String name, Modifier.Keyword... modifiers)
type
- the type of the fieldname
- the name of the fieldmodifiers
- the modifiers like Modifier.Keyword#PUBLIC
FieldDeclaration
createddefault FieldDeclaration addField(Type type, String name, Modifier.Keyword... modifiers)
type
- the type of the fieldname
- the name of the fieldmodifiers
- the modifiers like Modifier.Keyword#PUBLIC
FieldDeclaration
createddefault FieldDeclaration addFieldWithInitializer(Class<?> typeClass, String name, Expression initializer, Modifier.Keyword... modifiers)
typeClass
- the type of the fieldname
- the name of the fieldinitializer
- the initializer of the fieldmodifiers
- the modifiers like Modifier.Keyword#PUBLIC
FieldDeclaration
createddefault FieldDeclaration addFieldWithInitializer(String type, String name, Expression initializer, Modifier.Keyword... modifiers)
type
- the type of the fieldname
- the name of the fieldinitializer
- the initializer of the fieldmodifiers
- the modifiers like Modifier.Keyword#PUBLIC
FieldDeclaration
createddefault FieldDeclaration addFieldWithInitializer(Type type, String name, Expression initializer, Modifier.Keyword... modifiers)
type
- the type of the fieldname
- the name of the fieldinitializer
- the initializer of the fieldmodifiers
- the modifiers like Modifier.Keyword#PUBLIC
FieldDeclaration
createddefault FieldDeclaration addPrivateField(Class<?> typeClass, String name)
typeClass
- the type of the fieldname
- the name of the fieldFieldDeclaration
createddefault FieldDeclaration addPrivateField(String type, String name)
type
- the type of the fieldname
- the name of the fieldFieldDeclaration
createddefault FieldDeclaration addPrivateField(Type type, String name)
type
- the type of the fieldname
- the name of the fieldFieldDeclaration
createddefault FieldDeclaration addPublicField(Class<?> typeClass, String name)
typeClass
- the type of the fieldname
- the name of the fieldFieldDeclaration
createddefault FieldDeclaration addPublicField(String type, String name)
type
- the type of the fieldname
- the name of the fieldFieldDeclaration
createddefault FieldDeclaration addPublicField(Type type, String name)
type
- the type of the fieldname
- the name of the fieldFieldDeclaration
createddefault FieldDeclaration addProtectedField(Class<?> typeClass, String name)
typeClass
- the type of the fieldname
- the name of the fieldFieldDeclaration
createddefault FieldDeclaration addProtectedField(String type, String name)
type
- the type of the fieldname
- the name of the fieldFieldDeclaration
createddefault FieldDeclaration addProtectedField(Type type, String name)
type
- the type of the fieldname
- the name of the fieldFieldDeclaration
createddefault MethodDeclaration addMethod(String methodName, Modifier.Keyword... modifiers)
methodName
- the method namemodifiers
- the modifiers like Modifier.Keyword#PUBLIC
MethodDeclaration
createddefault ConstructorDeclaration addConstructor(Modifier.Keyword... modifiers)
modifiers
- the modifiers like Modifier.Keyword#PUBLIC
default BlockStmt addInitializer()
InitializerDeclaration
) to this.default BlockStmt addStaticInitializer()
InitializerDeclaration
) to this.default List<MethodDeclaration> getMethodsByName(String name)
MethodDeclaration
by its namename
- the name of the methoddefault List<MethodDeclaration> getMethods()
default List<MethodDeclaration> getMethodsByParameterTypes(String... paramTypes)
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<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"
.paramTypes
- the types of parameters like "Map<Integer, String>", "int"
to match
void foo(Map<Integer,String> myMap, int number)
default List<MethodDeclaration> getMethodsBySignature(String name, String... paramTypes)
MethodDeclaration
s by their name and parameter types. Parameter types are matched exactly as
in the case of getMethodsByParameterTypes(String...)
.paramTypes
- the types of parameters like "Map<Integer, String>", "int"
to match
void foo(Map<Integer,String> myMap, int number)
default List<MethodDeclaration> getMethodsByParameterTypes(Class<?>... paramTypes)
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<String>
, or
List<Integer>
, etc.paramTypes
- the types of parameters like Map.class, int.class
to match
void foo(Map<Integer,String> myMap, int number)
default List<ConstructorDeclaration> getConstructors()
RecordDeclaration
are included in the output of this method.default Optional<ConstructorDeclaration> getDefaultConstructor()
ConstructorDeclaration
with no parameters.default Optional<ConstructorDeclaration> getConstructorByParameterTypes(String... paramTypes)
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<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"
.paramTypes
- the types of parameters like "Map<Integer, String>", "int"
to match
Foo(Map<Integer,String> myMap, int number)
default Optional<ConstructorDeclaration> getConstructorByParameterTypes(Class<?>... paramTypes)
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<String>
, or
List<Integer>
, etc.paramTypes
- the types of parameters like Map.class, int.class
to match
Foo(Map<Integer,String> myMap, int number)
default Optional<FieldDeclaration> getFieldByName(String name)
FieldDeclaration
by its namename
- the name of the fielddefault List<FieldDeclaration> getFields()
default boolean isEmpty()
Copyright © 2007–2023. All rights reserved.