Class JavaMethod

java.lang.Object
org.jtool.srcmodel.JavaElement
org.jtool.srcmodel.JavaMethod

public class JavaMethod extends JavaElement
An object representing a method, a constructor, a static initializer, or a lambda expression.
  • Field Details

    • callingMethods

      protected Set<JavaMethod> callingMethods
      The collection of methods that invoke this method.
    • overriddenMethods

      protected Set<JavaMethod> overriddenMethods
      The collection of methods that this method overrides.
  • Constructor Details

    • JavaMethod

      public JavaMethod(org.eclipse.jdt.core.dom.MethodDeclaration node, JavaClass jclass) throws JavaElementException
      Creates a new object representing a method. This constructor is not intended to be invoked by clients.
      Parameters:
      node - the AST node for this method
      jclass - the class that declares this method
      Throws:
      JavaElementException - the exception occurs when the creation of a new object fails
    • JavaMethod

      public JavaMethod(org.eclipse.jdt.core.dom.Initializer node, JavaClass jclass)
      Creates a new object representing a method. This constructor is not intended to be invoked by clients.
      Parameters:
      node - the AST node for this static initializer
      jclass - the class that declares this method
    • JavaMethod

      public JavaMethod(org.eclipse.jdt.core.dom.LambdaExpression node, org.eclipse.jdt.core.dom.IMethodBinding mbinding, JavaClass jclass)
      Creates a new object representing a method. This constructor is not intended to be invoked by clients.
      Parameters:
      node - the AST node for this method for a lambda expression
      mbinding - the binding information on this method
      jclass - the class that declares this method
  • Method Details

    • getJavaProject

      public JavaProject getJavaProject()
      Returns the project which this method exists in.
      Specified by:
      getJavaProject in class JavaElement
      Returns:
      the project
    • getFile

      public JavaFile getFile()
      Returns the file that declares this method.
      Specified by:
      getFile in class JavaElement
      Returns:
      the declaring file
    • getQualifiedName

      public QualifiedName getQualifiedName()
      Returns the fully-qualified name of this method.
      Specified by:
      getQualifiedName in class JavaElement
      Returns:
      the fully-qualified method name
    • getName

      public String getName()
      Returns the name of this method.
      Returns:
      the method name
    • getClassName

      public String getClassName()
      Returns the name of this method.
      Returns:
      the class name
    • getSignature

      public String getSignature()
      Returns the signature of this method.
      Returns:
      the method signature
    • getReturnType

      public String getReturnType()
      Returns the return type of this method.
      Returns:
      the type name
    • isPrimitiveReturnType

      public boolean isPrimitiveReturnType()
      Tests if the return type of this method is primitive.
      Returns:
      true if the return type of this method is primitive, otherwise false
    • isVoid

      public boolean isVoid()
      Tests if the return type of this method is void, that is, it does not have the return type.
      Returns:
      true if the return type of this method is void, otherwise false
    • getModifiers

      public int getModifiers()
      The the value that stores information on the modifiers of this variable.
      Returns:
      the modifier value of this variable
    • getMethodBinding

      public org.eclipse.jdt.core.dom.IMethodBinding getMethodBinding()
      Returns the method binding information on this method.
      Returns:
      the method binding information
    • isInProject

      public boolean isInProject()
      Tests if this method exists inside the target project, which can resent the corresponding source code.
      Returns:
      true if this method exists inside the target project, otherwise false
    • getDeclaringClass

      public JavaClass getDeclaringClass()
      A class that declares (and encloses the declaration of) this method.
      Returns:
      the declaring class
    • isMethod

      public boolean isMethod()
      Tests if this is a method.
      Returns:
      true if this is a method, otherwise false
    • isConstructor

      public boolean isConstructor()
      Tests if this is a constructor.
      Returns:
      true if this is a constructor, otherwise false
    • isInitializer

      public boolean isInitializer()
      Tests if this is a static initializer.
      Returns:
      true if this is a static initializer, otherwise false
    • isLambda

      public boolean isLambda()
      Tests if this is a lambda expression.
      Returns:
      true if this is lambda expression, otherwise false
    • isSynthetic

      public boolean isSynthetic()
      Tests if this is a synthetic method that was made up by the compiler.
      Returns:
      true if this is a synthetic method, otherwise false
    • getParameters

      public List<JavaLocalVar> getParameters()
      Obtains the list of all parameters of this method.
      Returns:
      the parameter list
    • getParameterSize

      public int getParameterSize()
      Obtains the number of parameters of this method.
      Returns:
      the number of the parameters
    • getParameter

      public JavaLocalVar getParameter(int index)
      Obtains a parameter specified by the index for the parameter list.
      Parameters:
      index - the index number of the parameter of this method
      Returns:
      the local variable of the found parameter
    • getParameter

      public JavaLocalVar getParameter(String name)
      Obtains a parameter having a given name for the parameter list.
      Parameters:
      name - the parameter name
      Returns:
      the local variable of the found parameter
    • getParameterIndex

      public int getParameterIndex(String name)
      Obtains the index value of a parameter having a given name for the parameter list.
      Parameters:
      name - the parameter name
      Returns:
      the local variable of the found parameter
    • getLocalVariables

      public List<JavaLocalVar> getLocalVariables()
      Obtains the list of local variables used in this method.
      Returns:
      the local variable list
    • getLocalVariable

      public JavaLocalVar getLocalVariable(String name, int id)
      Obtains a local variable having a given name and identification number.
      Parameters:
      name - the name of the local variable to be retrieved
      id - the identification number of the local variable to be retrieved
      Returns:
      the found local variable, or null if any local variable is not found
    • getExceptionTypeNodes

      public Collection<org.eclipse.jdt.core.dom.Type> getExceptionTypeNodes()
      Returns the collection of AST nodes corresponding to the types of exceptions that this method might throw.
      Returns:
      the collection of type nodes for the thrown exceptions
    • getExceptionTypeNode

      public org.eclipse.jdt.core.dom.ASTNode getExceptionTypeNode(String type)
      Obtains the AST node corresponding to the type of an exception.
      Parameters:
      type - the type of the thrown exception
      Returns:
      the type node for the the thrown exception, or null if there is no corresponding type node
    • isPublic

      public boolean isPublic()
      Tests if this method has the public visibility.
      Returns:
      true if this method has the public visibility, otherwise false
    • isProtected

      public boolean isProtected()
      Tests if this method has the protected visibility.
      Returns:
      true if this method has the protected visibility, otherwise false
    • isPrivate

      public boolean isPrivate()
      Tests if this method has the private visibility.
      Returns:
      true if this method has the private visibility, otherwise false
    • isDefault

      public boolean isDefault()
      Tests if this method has the default visibility.
      Returns:
      true if this method has the default visibility, otherwise false
    • isFinal

      public boolean isFinal()
      Tests if this is a final method.
      Returns:
      true if this is a final method, otherwise false
    • isAbstract

      public boolean isAbstract()
      Tests if this is an abstract method.
      Returns:
      true if this is an abstract method, otherwise false
    • isStatic

      public boolean isStatic()
      Tests if this is a static method.
      Returns:
      true if this is a static method, otherwise false
    • isSynchronized

      public boolean isSynchronized()
      Tests if this is a synchronized method.
      Returns:
      true if this is a synchronized method, otherwise false
    • isNative

      public boolean isNative()
      Tests if this is a native method.
      Returns:
      true if this is a native method, otherwise false
    • isStrictfp

      public boolean isStrictfp()
      Tests if this is a strict-floating-point method.
      Returns:
      true if this is a strict-floating-point method, otherwise false
    • getSignature

      public static String getSignature(org.eclipse.jdt.core.dom.IMethodBinding mbinding)
      Obtains the signature of a method having a given method binding information.
      Parameters:
      mbinding - the method binding information
      Returns:
      the string representing the signature
    • getParameterString

      public static String getParameterString(org.eclipse.jdt.core.dom.IMethodBinding mbinding)
      Obtains the string that represents parameters of a method having a given method binding information.
      Parameters:
      mbinding - the method binding information
      Returns:
      the string representing the parameters
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • equals

      public boolean equals(JavaMethod jmethod)
      Tests if a given method is equal to this method.
      Parameters:
      jmethod - the method to be checked
      Returns:
      the true if the given method is equal to this method
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Obtains information on this field.
      Overrides:
      toString in class Object
      Returns:
      the string representing the information
    • toStringForParameters

      public String toStringForParameters()
      Obtains information on all parameters of this method.
      Returns:
      the string representing the information
    • getExceptions

      public Set<JavaClass> getExceptions()
      Obtains classes corresponding to the types of exceptions.
      Returns:
      the collection of the corresponding classes
    • getCalledMethods

      public Set<JavaMethod> getCalledMethods()
      Obtains methods that this method invokes.
      Returns:
      the collection of the called methods
    • getCalledMethodsInProject

      public Set<JavaMethod> getCalledMethodsInProject()
      Obtains methods that this method invokes, which are enclosed in the target project.
      Returns:
      the collection of the called methods
    • getCallingMethods

      public Set<JavaMethod> getCallingMethods()
      Obtains methods that invoke this method.
      Returns:
      the collection of the calling methods
    • getCallingMethodsInProject

      public Set<JavaMethod> getCallingMethodsInProject()
      Obtains methods that invoke this method, which are enclosed in the target project.
      Returns:
      the collection of the calling methods
    • getAccessedFields

      public Set<JavaField> getAccessedFields()
      Obtains fields that this method accesses.
      Returns:
      the collection of the accessed fields
    • getAccessedFieldsInProject

      public Set<JavaField> getAccessedFieldsInProject()
      Obtains fields that this method accesses, which are enclosed in the target project.
      Returns:
      the collection of the accessed fields
    • getAccessingFields

      public Set<JavaField> getAccessingFields()
      Obtains fields that call this method in their declaration.
      Returns:
      the collection of the accessing fields
    • getAccessingFieldsInProject

      public Set<JavaField> getAccessingFieldsInProject()
      Obtains fields that call this method in their declaration, which are enclosed in the target project.
      Returns:
      the collection of the accessing fields
    • getOverriddenMethods

      public Set<JavaMethod> getOverriddenMethods()
      Obtains methods that this method overrides.
      Returns:
      the collection of the overridden methods
    • getOverridingMethods

      public Set<JavaMethod> getOverridingMethods()
      Obtains methods that override this method.
      Returns:
      the collection of the overriding methods