Interface NodeWithMembers<N extends Node>
-
- All Known Subinterfaces:
NodeWithConstructors<N>
- All Known Implementing Classes:
AnnotationDeclaration
,ClassOrInterfaceDeclaration
,EnumDeclaration
,TypeDeclaration
public interface NodeWithMembers<N extends Node>
A node having members.The main reason for this interface is to permit users to manipulate homogeneously all nodes with a getMembers method.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default FieldDeclaration
addField(Type type, String name, Modifier.Keyword... modifiers)
Add a field to this.default FieldDeclaration
addField(Class<?> typeClass, String name, Modifier.Keyword... modifiers)
Add a field to this and automatically add the import of the type if neededdefault FieldDeclaration
addField(String type, String name, 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 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 neededdefault FieldDeclaration
addFieldWithInitializer(String 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(Type type, String name)
Add a private field 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
addProtectedField(Type type, String name)
Add a protected 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
addPublicField(Type type, String name)
Add a public 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 BlockStmt
addStaticInitializer()
Add a static initializer block (InitializerDeclaration
) to this.default Optional<FieldDeclaration>
getFieldByName(String name)
Try to find aFieldDeclaration
by its namedefault 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 aMethodDeclaration
by its namedefault List<MethodDeclaration>
getMethodsByParameterTypes(Class<?>... paramTypes)
Try to find aMethodDeclaration
by its parameters typesdefault List<MethodDeclaration>
getMethodsByParameterTypes(String... paramTypes)
Try to find aMethodDeclaration
by its parameters typesdefault List<MethodDeclaration>
getMethodsBySignature(String name, String... paramTypes)
Try to findMethodDeclaration
s by their name and parameters typesdefault N
setMember(int i, BodyDeclaration<?> member)
N
setMembers(NodeList<BodyDeclaration<?>> members)
void
tryAddImportToParentCompilationUnit(Class<?> clazz)
-
-
-
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)
-
getMember
default BodyDeclaration<?> getMember(int i)
-
setMember
default N setMember(int i, BodyDeclaration<?> member)
-
addMember
default N addMember(BodyDeclaration<?> member)
-
setMembers
N setMembers(NodeList<BodyDeclaration<?>> members)
-
addField
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- Parameters:
typeClass
- the type of the fieldname
- the name of the fieldmodifiers
- the modifiers likeModifier.Keyword.PUBLIC
- Returns:
- the
FieldDeclaration
created
-
addField
default FieldDeclaration addField(String type, String name, Modifier.Keyword... modifiers)
Add a field to this.- Parameters:
type
- the type of the fieldname
- the name of the fieldmodifiers
- the modifiers likeModifier.Keyword.PUBLIC
- Returns:
- the
FieldDeclaration
created
-
addField
default FieldDeclaration addField(Type type, String name, Modifier.Keyword... modifiers)
Add a field to this.- Parameters:
type
- the type of the fieldname
- the name of the fieldmodifiers
- the modifiers likeModifier.Keyword.PUBLIC
- Returns:
- the
FieldDeclaration
created
-
addFieldWithInitializer
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- Parameters:
typeClass
- the type of the fieldname
- the name of the fieldinitializer
- the initializer of the fieldmodifiers
- the modifiers likeModifier.Keyword.PUBLIC
- Returns:
- the
FieldDeclaration
created
-
addFieldWithInitializer
default FieldDeclaration addFieldWithInitializer(String type, String name, Expression initializer, Modifier.Keyword... modifiers)
Add a field to this.- Parameters:
type
- the type of the fieldname
- the name of the fieldinitializer
- the initializer of the fieldmodifiers
- the modifiers likeModifier.Keyword.PUBLIC
- Returns:
- the
FieldDeclaration
created
-
addFieldWithInitializer
default FieldDeclaration addFieldWithInitializer(Type type, String name, Expression initializer, Modifier.Keyword... modifiers)
Add a field to this.- Parameters:
type
- the type of the fieldname
- the name of the fieldinitializer
- the initializer of the fieldmodifiers
- the modifiers likeModifier.Keyword.PUBLIC
- Returns:
- the
FieldDeclaration
created
-
addPrivateField
default FieldDeclaration addPrivateField(Class<?> typeClass, String name)
Add a private field to this.- Parameters:
typeClass
- the type of the fieldname
- 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 fieldname
- 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 fieldname
- 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 fieldname
- 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 fieldname
- 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 fieldname
- 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 fieldname
- 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 fieldname
- 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 fieldname
- the name of the field- Returns:
- the
FieldDeclaration
created
-
addMethod
default MethodDeclaration addMethod(String methodName, Modifier.Keyword... modifiers)
Adds a methods with void return by default to this.- Parameters:
methodName
- the method namemodifiers
- the modifiers likeModifier.Keyword.PUBLIC
- Returns:
- the
MethodDeclaration
created
-
addInitializer
default BlockStmt addInitializer()
Add an initializer block (InitializerDeclaration
) to this.
-
addStaticInitializer
default BlockStmt addStaticInitializer()
Add a static initializer block (InitializerDeclaration
) to this.
-
getMethodsByName
default List<MethodDeclaration> getMethodsByName(String name)
Try to find aMethodDeclaration
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 aMethodDeclaration
by its parameters types- Parameters:
paramTypes
- the types of parameters like "Map<Integer,String>","int" to match
void foo(Map<Integer,String> myMap,int number)- Returns:
- the methods found (multiple in case of overloading)
-
getMethodsBySignature
default List<MethodDeclaration> getMethodsBySignature(String name, String... paramTypes)
Try to findMethodDeclaration
s by their name and parameters types- Parameters:
paramTypes
- the types of parameters like "Map<Integer,String>","int" to match
void foo(Map<Integer,String> myMap,int number)- Returns:
- the methods found (multiple in case of overloading)
-
getMethodsByParameterTypes
default List<MethodDeclaration> getMethodsByParameterTypes(Class<?>... paramTypes)
Try to find aMethodDeclaration
by its parameters types- Parameters:
paramTypes
- the types of parameters like "Map<Integer,String>","int" to match
void foo(Map<Integer,String> myMap,int number)- Returns:
- the methods found (multiple in case of overloading)
-
getFieldByName
default Optional<FieldDeclaration> getFieldByName(String name)
Try to find aFieldDeclaration
by its name- Parameters:
name
- the name of the field- Returns:
- null if not found, the FieldDeclaration otherwise
-
getFields
default List<FieldDeclaration> getFields()
Find all fields in the members of this node.- Returns:
- the fields found. This list is immutable.
-
-