RECODER 0.92

recoder.java.declaration
Class MethodDeclaration

java.lang.Object
  extended by recoder.java.JavaSourceElement
      extended by recoder.java.JavaProgramElement
          extended by recoder.java.JavaNonTerminalProgramElement
              extended by recoder.java.declaration.JavaDeclaration
                  extended by recoder.java.declaration.MethodDeclaration
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ClassTypeContainer, Member, Method, ProgramModelElement, AccessFlags, Declaration, MemberDeclaration, TypeDeclarationContainer, NamedProgramElement, NonTerminalProgramElement, ParameterContainer, ProgramElement, TypeReferenceContainer, ScopeDefiningElement, SourceElement, StatementContainer, TypeScope, VariableScope, ModelElement, NamedModelElement
Direct Known Subclasses:
AnnotationPropertyDeclaration, ConstructorDeclaration

public class MethodDeclaration
extends JavaDeclaration
implements MemberDeclaration, TypeReferenceContainer, NamedProgramElement, ParameterContainer, Method, VariableScope, TypeDeclarationContainer, TypeScope

Method declaration.

Author:
AutoDoc
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface recoder.abstraction.ProgramModelElement
ProgramModelElement.LexicalOrder
 
Nested classes/interfaces inherited from interface recoder.abstraction.ProgramModelElement
ProgramModelElement.LexicalOrder
 
Field Summary
 
Fields inherited from class recoder.java.JavaSourceElement
factory
 
Fields inherited from interface recoder.abstraction.ProgramModelElement
LEXICAL_ORDER
 
Fields inherited from interface recoder.bytecode.AccessFlags
ABSTRACT, ANNOTATION, BRIDGE, ENUM, FINAL, INTERFACE, NATIVE, PRIVATE, PROTECTED, PUBLIC, STATIC, STRICT, SUPER, SYNCHRONIZED, SYNTHETIC, TRANSIENT, VARARGS, VOLATILE
 
Fields inherited from interface recoder.abstraction.ProgramModelElement
LEXICAL_ORDER
 
Fields inherited from interface recoder.bytecode.AccessFlags
ABSTRACT, ANNOTATION, BRIDGE, ENUM, FINAL, INTERFACE, NATIVE, PRIVATE, PROTECTED, PUBLIC, STATIC, STRICT, SUPER, SYNCHRONIZED, SYNTHETIC, TRANSIENT, VARARGS, VOLATILE
 
Constructor Summary
  MethodDeclaration()
          Method declaration.
  MethodDeclaration(ASTList<DeclarationSpecifier> modifiers, TypeReference returnType, Identifier name, ASTList<ParameterDeclaration> parameters, Throws exceptions)
          Method declaration.
  MethodDeclaration(ASTList<DeclarationSpecifier> modifiers, TypeReference returnType, Identifier name, ASTList<ParameterDeclaration> parameters, Throws exceptions, StatementBlock body)
          Method declaration.
protected MethodDeclaration(MethodDeclaration proto)
          Method declaration.
 
Method Summary
 void accept(SourceVisitor v)
          Receive a visitor, for instance a pretty printer.
 void addTypeToScope(ClassType type, java.lang.String name)
           
 void addVariableToScope(VariableSpecification var)
           
 MethodDeclaration deepClone()
          Deep clone.
 NonTerminalProgramElement getASTParent()
          Get AST parent.
 java.lang.String getBinaryName()
          Returns the binary name.
 StatementBlock getBody()
          Get body.
 ProgramElement getChildAt(int index)
          Returns the child at the specified index in this node's "virtual" child array
 int getChildCount()
          Returns the number of children of this node.
 int getChildPositionCode(ProgramElement child)
          Returns the positional code of the given child, or -1 if there is no such child.
 ClassTypeContainer getContainer()
          Returns the enclosing package or class type, or method.
 ClassType getContainingClassType()
          Returns the logical parent type of this member.
 java.util.List<ClassType> getExceptions()
          Returns the exceptions of this method or constructor.
 SourceElement getFirstElement()
          Finds the source element that occurs first in the source.
 java.lang.String getFullName()
          Returns the maximal expanded name including all applicable qualifiers.
 Identifier getIdentifier()
          Get identifier.
 SourceElement getLastElement()
          Finds the source element that occurs last in the source.
 TypeDeclaration getMemberParent()
          Get member parent.
 java.lang.String getName()
          Get name.
 Package getPackage()
          Returns the package this element is defined in.
 ParameterDeclaration getParameterDeclarationAt(int index)
           
 int getParameterDeclarationCount()
          Get the number of parameters in this container.
 ASTList<ParameterDeclaration> getParameters()
          Get parameters.
 ProgramModelInfo getProgramModelInfo()
          Returns the instance that can retrieve information about this program model element.
 Type getReturnType()
          Returns the return type of this method.
 java.util.List<Type> getSignature()
          Returns the signature of this method or constructor.
 Statement getStatementAt(int index)
           
 int getStatementCount()
          Get the number of statements in this container.
 Throws getThrown()
          Get thrown.
 TypeDeclaration getTypeDeclarationAt(int index)
           
 int getTypeDeclarationCount()
          Get the number of type declarations in this container.
 ClassType getTypeInScope(java.lang.String typename)
           
 ASTList<TypeParameterDeclaration> getTypeParameters()
           
 TypeReference getTypeReference()
          Get return type.
 TypeReference getTypeReferenceAt(int index)
           
 int getTypeReferenceCount()
          Get the number of type references in this container.
 java.util.List<TypeDeclaration> getTypes()
          returns the types declared in the corresponding StatementBlock, if there is any (i.e. method is not abstract).
 java.util.List<TypeDeclaration> getTypesInScope()
           
 VariableSpecification getVariableInScope(java.lang.String tname)
           
 java.util.List<VariableSpecification> getVariablesInScope()
           
 boolean isAbstract()
          Test whether the declaration is abstract.
 boolean isDefinedScope()
          Check if the scope has been set up.
 boolean isFinal()
          Test whether the declaration is final.
 boolean isNative()
          Test whether the declaration is native.
 boolean isPrivate()
          Test whether the declaration is private.
 boolean isProtected()
          Test whether the declaration is protected.
 boolean isPublic()
          Test whether the declaration is public.
 boolean isStatic()
          Test whether the declaration is static.
 boolean isStrictFp()
          Test whether the declaration is strictfp.
 boolean isSynchronized()
          Test whether the declaration is synchronized.
 boolean isVarArgMethod()
          Checks if this method takes a variable number of arguments.
 void makeParentRoleValid()
          Make parent role valid.
 void removeTypeFromScope(java.lang.String name)
           
 void removeVariableFromScope(java.lang.String tname)
           
 boolean replaceChild(ProgramElement p, ProgramElement q)
          Replace a single child in the current node.
 void setBody(StatementBlock body)
          Set body.
 void setDefinedScope(boolean defined)
          Sets the scope to be defined or undefined.
 void setIdentifier(Identifier id)
          Set identifier.
 void setMemberParent(TypeDeclaration decl)
          Set member parent.
 void setParameters(ASTList<ParameterDeclaration> list)
          Set parameters.
 void setProgramModelInfo(ProgramModelInfo service)
          Sets the instance that can retrieve information about this program model element.
 void setThrown(Throws exceptions)
          Set thrown.
 void setTypeParameters(ASTList<TypeParameterDeclaration> typeParameters)
           
 void setTypeReference(TypeReference type)
          Sets the return type.
 java.lang.String toString()
           
 
Methods inherited from class recoder.java.declaration.JavaDeclaration
getAnnotations, getDeclarationSpecifiers, getModifiers, getVisibilityModifier, isTransient, isVolatile, setDeclarationSpecifiers
 
Methods inherited from class recoder.java.JavaNonTerminalProgramElement
getIndexOfChild, getRoleOfChild, makeAllParentRolesValid, validateAll
 
Methods inherited from class recoder.java.JavaProgramElement
getComments, getID, setComments, validate
 
Methods inherited from class recoder.java.JavaSourceElement
getEndPosition, getFactory, getRelativePosition, getStartPosition, setEndPosition, setRelativePosition, setStartPosition, toSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface recoder.java.Declaration
getDeclarationSpecifiers, setDeclarationSpecifiers
 
Methods inherited from interface recoder.abstraction.Member
getAnnotations
 

Constructor Detail

MethodDeclaration

public MethodDeclaration()
Method declaration.


MethodDeclaration

public MethodDeclaration(ASTList<DeclarationSpecifier> modifiers,
                         TypeReference returnType,
                         Identifier name,
                         ASTList<ParameterDeclaration> parameters,
                         Throws exceptions)
Method declaration.

Parameters:
modifiers - a modifier mutable list.
returnType - a type reference.
name - an identifier.
parameters - a parameter declaration mutable list.
exceptions - a throws.

MethodDeclaration

public MethodDeclaration(ASTList<DeclarationSpecifier> modifiers,
                         TypeReference returnType,
                         Identifier name,
                         ASTList<ParameterDeclaration> parameters,
                         Throws exceptions,
                         StatementBlock body)
Method declaration.

Parameters:
modifiers - a modifier mutable list.
returnType - a type reference.
name - an identifier.
parameters - a parameter declaration mutable list.
exceptions - a throws.
body - a statement block.

MethodDeclaration

protected MethodDeclaration(MethodDeclaration proto)
Method declaration.

Parameters:
proto - a method declaration.
Method Detail

deepClone

public MethodDeclaration deepClone()
Deep clone.

Specified by:
deepClone in interface SourceElement
Returns:
the object.

makeParentRoleValid

public void makeParentRoleValid()
Make parent role valid.

Specified by:
makeParentRoleValid in interface NonTerminalProgramElement
Overrides:
makeParentRoleValid in class JavaDeclaration

getChildPositionCode

public int getChildPositionCode(ProgramElement child)
Description copied from interface: NonTerminalProgramElement
Returns the positional code of the given child, or -1 if there is no such child. The result contains an encoding of the relative position of the child as well as the role it has been playing in this parent element. This information is required internally for proper undo of transformations and is to be delivered to the detached method of the ChangeHistory.

Specified by:
getChildPositionCode in interface NonTerminalProgramElement
Parameters:
child - the exact child to look for.
Returns:
the positional code of the given child, or -1.
See Also:
ChangeHistory.detached(recoder.java.ProgramElement, recoder.java.NonTerminalProgramElement, int)

getFirstElement

public SourceElement getFirstElement()
Description copied from class: JavaSourceElement
Finds the source element that occurs first in the source. The default implementation returns this element, which is correct for all terminal program elements, and many non terminals such as statements and prefixed operators.

Specified by:
getFirstElement in interface SourceElement
Overrides:
getFirstElement in class JavaSourceElement
Returns:
the first source element in the syntactical representation of this element, may be equals to this element.
See Also:
JavaSourceElement.toSource(), JavaSourceElement.getStartPosition()

getLastElement

public SourceElement getLastElement()
Description copied from class: JavaSourceElement
Finds the source element that occurs last in the source. The default implementation returns this element, which is correct for all terminal program elements, and many non terminals such as statements and prefixed operators.

Specified by:
getLastElement in interface SourceElement
Overrides:
getLastElement in class JavaSourceElement
Returns:
the last source element in the syntactical representation of this element, may be equals to this element.
See Also:
JavaSourceElement.toSource(), JavaSourceElement.getEndPosition()

getASTParent

public NonTerminalProgramElement getASTParent()
Get AST parent.

Specified by:
getASTParent in interface ProgramElement
Returns:
the non terminal program element.

getMemberParent

public TypeDeclaration getMemberParent()
Get member parent.

Specified by:
getMemberParent in interface MemberDeclaration
Returns:
the type declaration.

setMemberParent

public void setMemberParent(TypeDeclaration decl)
Set member parent.

Specified by:
setMemberParent in interface MemberDeclaration
Parameters:
decl - a type declaration.

getChildCount

public int getChildCount()
Returns the number of children of this node.

Specified by:
getChildCount in interface NonTerminalProgramElement
Returns:
an int giving the number of children of this node

getChildAt

public ProgramElement getChildAt(int index)
Returns the child at the specified index in this node's "virtual" child array

Specified by:
getChildAt in interface NonTerminalProgramElement
Parameters:
index - an index into this node's "virtual" child array
Returns:
the program element at the given position
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index is out of bounds

getStatementCount

public int getStatementCount()
Get the number of statements in this container.

Specified by:
getStatementCount in interface StatementContainer
Returns:
the number of statements.

getStatementAt

public Statement getStatementAt(int index)
Specified by:
getStatementAt in interface StatementContainer

replaceChild

public boolean replaceChild(ProgramElement p,
                            ProgramElement q)
Replace a single child in the current node. The child to replace is matched by identity and hence must be known exactly. The replacement element can be null - in that case, the child is effectively removed. The parent role of the new child is validated, while the parent link of the replaced child is left untouched.

Specified by:
replaceChild in interface NonTerminalProgramElement
Parameters:
p - the old child.
p - the new child.
Returns:
true if a replacement has occured, false otherwise.
Throws:
java.lang.ClassCastException - if the new child cannot take over the role of the old one.

getTypeReferenceCount

public int getTypeReferenceCount()
Get the number of type references in this container.

Specified by:
getTypeReferenceCount in interface TypeReferenceContainer
Returns:
the number of type references.

getTypeReferenceAt

public TypeReference getTypeReferenceAt(int index)
Specified by:
getTypeReferenceAt in interface TypeReferenceContainer

getParameterDeclarationCount

public int getParameterDeclarationCount()
Get the number of parameters in this container.

Specified by:
getParameterDeclarationCount in interface ParameterContainer
Returns:
the number of parameters.

getParameterDeclarationAt

public ParameterDeclaration getParameterDeclarationAt(int index)
Specified by:
getParameterDeclarationAt in interface ParameterContainer

getTypeReference

public TypeReference getTypeReference()
Get return type.

Returns:
the type reference.

setTypeReference

public void setTypeReference(TypeReference type)
Sets the return type. Null is okay for subclass ConstructorDeclaration.


getName

public final java.lang.String getName()
Get name.

Specified by:
getName in interface NamedModelElement
Returns:
the string.

getIdentifier

public Identifier getIdentifier()
Get identifier.

Specified by:
getIdentifier in interface NamedProgramElement
Returns:
the identifier.

setIdentifier

public void setIdentifier(Identifier id)
Set identifier.

Specified by:
setIdentifier in interface NamedProgramElement
Parameters:
id - an identifier.

getParameters

public ASTList<ParameterDeclaration> getParameters()
Get parameters.

Returns:
the parameter declaration mutable list.

setParameters

public void setParameters(ASTList<ParameterDeclaration> list)
Set parameters.

Parameters:
list - a parameter declaration mutable list.

getThrown

public Throws getThrown()
Get thrown.

Returns:
the throws.

setThrown

public void setThrown(Throws exceptions)
Set thrown.

Parameters:
exceptions - a throws.

getBody

public StatementBlock getBody()
Get body.

Returns:
the statement block.

setBody

public void setBody(StatementBlock body)
Set body.

Parameters:
body - a statement block.

isFinal

public boolean isFinal()
Test whether the declaration is final.

Specified by:
isFinal in interface Member
Overrides:
isFinal in class JavaDeclaration
Returns:
true if this member is final, false otherwise.

isPrivate

public boolean isPrivate()
Test whether the declaration is private.

Specified by:
isPrivate in interface Member
Specified by:
isPrivate in interface MemberDeclaration
Overrides:
isPrivate in class JavaDeclaration
Returns:
true if this member is private, false otherwise.

isProtected

public boolean isProtected()
Test whether the declaration is protected.

Specified by:
isProtected in interface Member
Specified by:
isProtected in interface MemberDeclaration
Overrides:
isProtected in class JavaDeclaration
Returns:
true if this member is protected, false otherwise.

isPublic

public boolean isPublic()
Test whether the declaration is public. Methods of interfaces are always public.

Specified by:
isPublic in interface Member
Specified by:
isPublic in interface MemberDeclaration
Overrides:
isPublic in class JavaDeclaration
Returns:
true if this member is public, false otherwise.

isStatic

public boolean isStatic()
Test whether the declaration is static.

Specified by:
isStatic in interface Member
Specified by:
isStatic in interface MemberDeclaration
Overrides:
isStatic in class JavaDeclaration
Returns:
true if this member is static, false otherwise.

isStrictFp

public boolean isStrictFp()
Test whether the declaration is strictfp.

Specified by:
isStrictFp in interface Member
Specified by:
isStrictFp in interface MemberDeclaration
Overrides:
isStrictFp in class JavaDeclaration
Returns:
true if this member is strictfp, false otherwise.

isAbstract

public boolean isAbstract()
Test whether the declaration is abstract. Methods of interfaces are always abstract.

Specified by:
isAbstract in interface Method
Overrides:
isAbstract in class JavaDeclaration
Returns:
true if this member is abstract, false otherwise.
See Also:
Constructor

isNative

public boolean isNative()
Test whether the declaration is native. Constructors are never native.

Specified by:
isNative in interface Method
Overrides:
isNative in class JavaDeclaration
Returns:
true if this method is native, false otherwise.
See Also:
Constructor

isSynchronized

public boolean isSynchronized()
Test whether the declaration is synchronized.

Specified by:
isSynchronized in interface Method
Overrides:
isSynchronized in class JavaDeclaration
Returns:
true if this method is synchronized, false otherwise.
See Also:
Constructor

getProgramModelInfo

public ProgramModelInfo getProgramModelInfo()
Description copied from interface: ProgramModelElement
Returns the instance that can retrieve information about this program model element.

Specified by:
getProgramModelInfo in interface ProgramModelElement
Returns:
the program model info of this element.

setProgramModelInfo

public void setProgramModelInfo(ProgramModelInfo service)
Description copied from interface: ProgramModelElement
Sets the instance that can retrieve information about this program model element. Should not be called from outside a service.

Specified by:
setProgramModelInfo in interface ProgramModelElement
Parameters:
service - the program model info to be used for this element.

getContainingClassType

public ClassType getContainingClassType()
Description copied from interface: Member
Returns the logical parent type of this member.

Specified by:
getContainingClassType in interface Member
Returns:
the class type containing this member.

getReturnType

public Type getReturnType()
Description copied from interface: Method
Returns the return type of this method.

Specified by:
getReturnType in interface Method
Returns:
the return type of this method.

getSignature

public java.util.List<Type> getSignature()
Description copied from interface: Method
Returns the signature of this method or constructor.

Specified by:
getSignature in interface Method
Returns:
the signature of this method.

getExceptions

public java.util.List<ClassType> getExceptions()
Description copied from interface: Method
Returns the exceptions of this method or constructor.

Specified by:
getExceptions in interface Method
Returns:
the exceptions of this method.

getContainer

public ClassTypeContainer getContainer()
Description copied from interface: ClassTypeContainer
Returns the enclosing package or class type, or method. A package will report null, a methods its enclosing class.

Specified by:
getContainer in interface ClassTypeContainer
Returns:
the container of this element.

getPackage

public Package getPackage()
Description copied from interface: ClassTypeContainer
Returns the package this element is defined in. Packages have no recursive scope and report themselves.

Specified by:
getPackage in interface ClassTypeContainer
Returns:
the package of this element.

getTypes

public java.util.List<TypeDeclaration> getTypes()
returns the types declared in the corresponding StatementBlock, if there is any (i.e. method is not abstract). Returns RecoderList.EMPTY_LIST otherwise. WARNING: Former (incorrect) implementations of this method returned the member types of the declaring class instead.

Specified by:
getTypes in interface ClassTypeContainer
Returns:
a list of contained class types.

getFullName

public java.lang.String getFullName()
Description copied from interface: ProgramModelElement
Returns the maximal expanded name including all applicable qualifiers.

Specified by:
getFullName in interface ProgramModelElement
Returns:
the full name of this program model element.

getBinaryName

public java.lang.String getBinaryName()
Description copied from interface: ProgramModelElement
Returns the binary name. The binary name is the name this program model element would have in bytecode, i.e., how it either is read by the bytecode parser, or the name a compiler would give this element during the compilation process (if this program model element is represented in source code). See JLS, §13.1

Specified by:
getBinaryName in interface ProgramModelElement
Returns:
the bytecode name of this program model element

isDefinedScope

public boolean isDefinedScope()
Description copied from interface: ScopeDefiningElement
Check if the scope has been set up.

Specified by:
isDefinedScope in interface ScopeDefiningElement

setDefinedScope

public void setDefinedScope(boolean defined)
Description copied from interface: ScopeDefiningElement
Sets the scope to be defined or undefined. If set to defined, the scope cache becomes initialized. If set to undefined, the scope cache becomes erased.

Specified by:
setDefinedScope in interface ScopeDefiningElement

getVariablesInScope

public java.util.List<VariableSpecification> getVariablesInScope()
Specified by:
getVariablesInScope in interface VariableScope

getVariableInScope

public VariableSpecification getVariableInScope(java.lang.String tname)
Specified by:
getVariableInScope in interface VariableScope

addVariableToScope

public void addVariableToScope(VariableSpecification var)
Specified by:
addVariableToScope in interface VariableScope

removeVariableFromScope

public void removeVariableFromScope(java.lang.String tname)
Specified by:
removeVariableFromScope in interface VariableScope

accept

public void accept(SourceVisitor v)
Description copied from interface: SourceElement
Receive a visitor, for instance a pretty printer.

Specified by:
accept in interface SourceElement
Parameters:
v - a source visitor.

isVarArgMethod

public boolean isVarArgMethod()
Description copied from interface: Method
Checks if this method takes a variable number of arguments.

Specified by:
isVarArgMethod in interface Method
Returns:
true if this methods takes a variable number of arguments, false otherwise.

getTypeParameters

public ASTList<TypeParameterDeclaration> getTypeParameters()
Specified by:
getTypeParameters in interface Method
Returns:

setTypeParameters

public void setTypeParameters(ASTList<TypeParameterDeclaration> typeParameters)

getTypeDeclarationCount

public int getTypeDeclarationCount()
Description copied from interface: TypeDeclarationContainer
Get the number of type declarations in this container.

Specified by:
getTypeDeclarationCount in interface TypeDeclarationContainer
Returns:
the number of type declarations.

getTypeDeclarationAt

public TypeDeclaration getTypeDeclarationAt(int index)
Specified by:
getTypeDeclarationAt in interface TypeDeclarationContainer

getTypesInScope

public java.util.List<TypeDeclaration> getTypesInScope()
Specified by:
getTypesInScope in interface TypeScope

getTypeInScope

public ClassType getTypeInScope(java.lang.String typename)
Specified by:
getTypeInScope in interface TypeScope

addTypeToScope

public void addTypeToScope(ClassType type,
                           java.lang.String name)
Specified by:
addTypeToScope in interface TypeScope

removeTypeFromScope

public void removeTypeFromScope(java.lang.String name)
Specified by:
removeTypeFromScope in interface TypeScope

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

RECODER 0.92