Class ClassDecl
- java.lang.Object
-
- com.tonic.analysis.source.ast.decl.ClassDecl
-
-
Constructor Summary
Constructors Constructor Description ClassDecl(String name)Creates an empty class declaration at an unknown location.ClassDecl(String name, SourceLocation location)Creates an empty class declaration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Taccept(SourceVisitor<T> visitor)Accepts a visitor for this node.ClassDecladdAnnotation(AnnotationExpr annotation)Adds an annotation.ClassDecladdConstructor(ConstructorDecl constructor)Adds a constructor.ClassDecladdField(FieldDecl field)Adds a field member.ClassDecladdInnerType(TypeDecl innerType)Adds a nested type.ClassDecladdInstanceInitializer(BlockStmt block)Adds an instance initializer block.ClassDecladdInterface(SourceType iface)Adds an implemented interface.ClassDecladdMethod(MethodDecl method)Adds a method member.ClassDecladdModifier(Modifier modifier)Adds a modifier.ClassDecladdStaticInitializer(BlockStmt block)Adds a static initializer block.ClassDecladdTypeParameter(SourceType typeParam)Adds a type parameter.NodeList<AnnotationExpr>getAnnotations()List<ASTNode>getChildren()Lists the direct children a node holds, in source order.ConstructorDeclgetConstructor(SourceType... paramTypes)Finds a constructor by exact parameter types.NodeList<ConstructorDecl>getConstructors()NodeList<FieldDecl>getFields()NodeList<TypeDecl>getInnerTypes()List<BlockStmt>getInstanceInitializers()NodeList<SourceType>getInterfaces()SourceLocationgetLocation()Gets the source location of this node.MethodDeclgetMethod(String name, SourceType... paramTypes)Finds a method by name and exact parameter types.NodeList<MethodDecl>getMethods()Set<Modifier>getModifiers()StringgetName()ASTNodegetParent()Gets the parent node in the AST tree.List<BlockStmt>getStaticInitializers()SourceTypegetSuperclass()NodeList<SourceType>getTypeParameters()voidsetName(String name)Sets the class name.voidsetParent(ASTNode parent)Sets the parent node.voidsetSuperclass(SourceType superclass)Sets the superclass type.StringtoString()ClassDeclwithModifiers(Set<Modifier> modifiers)Replaces all modifiers with the given set.ClassDeclwithName(String name)Sets the class name.ClassDeclwithSuperclass(SourceType superclass)Sets the superclass type.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.tonic.analysis.source.ast.ASTNode
deepClone, findAll, findAll, findAncestor, findFirst, findFirst, getRoot, isDescendantOf, remove, replaceWith, stream, stream, walk
-
Methods inherited from interface com.tonic.analysis.source.ast.decl.TypeDecl
getField, getInnerType, getMethod, isAbstract, isFinal, isPrivate, isProtected, isPublic, isStatic
-
-
-
-
Constructor Detail
-
ClassDecl
public ClassDecl(String name, SourceLocation location)
Creates an empty class declaration.- Parameters:
name- the simple class namelocation- the source location, or null for unknown
-
ClassDecl
public ClassDecl(String name)
Creates an empty class declaration at an unknown location.- Parameters:
name- the simple class name
-
-
Method Detail
-
setName
public void setName(String name)
Sets the class name.- Parameters:
name- the simple class name
-
getModifiers
public Set<Modifier> getModifiers()
- Specified by:
getModifiersin interfaceTypeDecl- Returns:
- the modifiers
-
getAnnotations
public NodeList<AnnotationExpr> getAnnotations()
- Specified by:
getAnnotationsin interfaceTypeDecl- Returns:
- the annotations
-
getSuperclass
public SourceType getSuperclass()
- Returns:
- the superclass
-
setSuperclass
public void setSuperclass(SourceType superclass)
Sets the superclass type.- Parameters:
superclass- the extended type
-
getInterfaces
public NodeList<SourceType> getInterfaces()
- Returns:
- the interfaces
-
getTypeParameters
public NodeList<SourceType> getTypeParameters()
- Returns:
- the type parameters
-
getMethods
public NodeList<MethodDecl> getMethods()
- Specified by:
getMethodsin interfaceTypeDecl- Returns:
- the methods
-
getConstructors
public NodeList<ConstructorDecl> getConstructors()
- Returns:
- the constructors
-
getInnerTypes
public NodeList<TypeDecl> getInnerTypes()
- Specified by:
getInnerTypesin interfaceTypeDecl- Returns:
- the inner types
-
getStaticInitializers
public List<BlockStmt> getStaticInitializers()
- Returns:
- the static initializers
-
getInstanceInitializers
public List<BlockStmt> getInstanceInitializers()
- Returns:
- the instance initializers
-
getLocation
public SourceLocation getLocation()
Description copied from interface:ASTNodeGets the source location of this node.- Specified by:
getLocationin interfaceASTNode- Returns:
- the location
-
getParent
public ASTNode getParent()
Description copied from interface:ASTNodeGets the parent node in the AST tree.
-
setParent
public void setParent(ASTNode parent)
Sets the parent node.
-
withName
public ClassDecl withName(String name)
Sets the class name.- Parameters:
name- the simple class name- Returns:
- this declaration
-
withSuperclass
public ClassDecl withSuperclass(SourceType superclass)
Sets the superclass type.- Parameters:
superclass- the extended type- Returns:
- this declaration
-
withModifiers
public ClassDecl withModifiers(Set<Modifier> modifiers)
Replaces all modifiers with the given set.- Parameters:
modifiers- the modifiers to apply- Returns:
- this declaration
-
addModifier
public ClassDecl addModifier(Modifier modifier)
Adds a modifier.- Parameters:
modifier- the modifier to add- Returns:
- this declaration
-
addAnnotation
public ClassDecl addAnnotation(AnnotationExpr annotation)
Adds an annotation.- Parameters:
annotation- the annotation to add- Returns:
- this declaration
-
addInterface
public ClassDecl addInterface(SourceType iface)
Adds an implemented interface.- Parameters:
iface- the interface type- Returns:
- this declaration
-
addTypeParameter
public ClassDecl addTypeParameter(SourceType typeParam)
Adds a type parameter.- Parameters:
typeParam- the type parameter- Returns:
- this declaration
-
addField
public ClassDecl addField(FieldDecl field)
Adds a field member.- Parameters:
field- the field declaration- Returns:
- this declaration
-
addMethod
public ClassDecl addMethod(MethodDecl method)
Adds a method member.- Parameters:
method- the method declaration- Returns:
- this declaration
-
addConstructor
public ClassDecl addConstructor(ConstructorDecl constructor)
Adds a constructor.- Parameters:
constructor- the constructor declaration- Returns:
- this declaration
-
addInnerType
public ClassDecl addInnerType(TypeDecl innerType)
Adds a nested type.- Parameters:
innerType- the nested type declaration- Returns:
- this declaration
-
addStaticInitializer
public ClassDecl addStaticInitializer(BlockStmt block)
Adds a static initializer block.- Parameters:
block- the initializer body- Returns:
- this declaration
-
addInstanceInitializer
public ClassDecl addInstanceInitializer(BlockStmt block)
Adds an instance initializer block.- Parameters:
block- the initializer body- Returns:
- this declaration
-
getConstructor
public ConstructorDecl getConstructor(SourceType... paramTypes)
Finds a constructor by exact parameter types.- Parameters:
paramTypes- the parameter types to match- Returns:
- the matching constructor, or null if none
-
getMethod
public MethodDecl getMethod(String name, SourceType... paramTypes)
Finds a method by name and exact parameter types.- Parameters:
name- the method nameparamTypes- the parameter types to match- Returns:
- the matching method, or null if none
-
getChildren
public List<ASTNode> getChildren()
Description copied from interface:ASTNodeLists the direct children a node holds, in source order.- Specified by:
getChildrenin interfaceASTNode- Returns:
- the direct children, empty for a leaf
-
accept
public <T> T accept(SourceVisitor<T> visitor)
Description copied from interface:ASTNodeAccepts a visitor for this node.
-
-