Class MethodAnnotation

All Implemented Interfaces:
BugAnnotation, XMLWriteable, XMLWriteableWithMessages, Serializable, Cloneable, Comparable<BugAnnotation>

public class MethodAnnotation extends PackageMemberAnnotation
A BugAnnotation specifying a particular method in a particular class. A MethodAnnotation may (optionally) have a SourceLineAnnotation directly embedded inside it to indicate the range of source lines where the method is defined.
Author:
David Hovemeyer
See Also:
  • Field Details

  • Constructor Details

    • MethodAnnotation

      public MethodAnnotation(@DottedClassName String className, String methodName, String methodSig, boolean isStatic)
      Constructor.
      Parameters:
      className - the name of the class containing the method
      methodName - the name of the method
      methodSig - the Java type signature of the method
      isStatic - true if the method is static, false if not
  • Method Details

    • fromVisitedMethod

      public static MethodAnnotation fromVisitedMethod(PreorderVisitor visitor)
      Factory method to create a MethodAnnotation from the method the given visitor is currently visiting.
      Parameters:
      visitor - the BetterVisitor currently visiting the method
    • fromCalledMethod

      public static MethodAnnotation fromCalledMethod(DismantleBytecode visitor)
      Factory method to create a MethodAnnotation from a method called by the instruction the given visitor is currently visiting.
      Parameters:
      visitor - the visitor
      Returns:
      the MethodAnnotation representing the called method
    • fromForeignMethod

      public static MethodAnnotation fromForeignMethod(@SlashedClassName String className, String methodName, String methodSig, int accessFlags)
      Factory method to create the MethodAnnotation from the classname, method name, signature, etc. The method tries to look up source line information for the method.
      Parameters:
      className - name of the class containing the method
      methodName - name of the method
      methodSig - signature of the method
      accessFlags - the access flags of the method
      Returns:
      the MethodAnnotation
    • fromForeignMethod

      public static MethodAnnotation fromForeignMethod(String className, String methodName, String methodSig, boolean isStatic)
      Factory method to create the MethodAnnotation from the classname, method name, signature, etc. The method tries to look up source line information for the method.
      Parameters:
      className - name of the class containing the method
      methodName - name of the method
      methodSig - signature of the method
      isStatic - true if the method is static, false otherwise
      Returns:
      the MethodAnnotation
    • fromCalledMethod

      public static MethodAnnotation fromCalledMethod(String className, String methodName, String methodSig, boolean isStatic)
      Create a MethodAnnotation from a method that is not directly accessible. We will use the repository to try to find its class in order to populate the information as fully as possible.
      Parameters:
      className - class containing called method
      methodName - name of called method
      methodSig - signature of called method
      isStatic - true if called method is static
      Returns:
      the MethodAnnotation for the called method
    • fromXMethod

      public static MethodAnnotation fromXMethod(XMethod xmethod)
      Create a MethodAnnotation from an XMethod.
      Parameters:
      xmethod - the XMethod
      Returns:
      the MethodAnnotation
    • fromMethodDescriptor

      public static MethodAnnotation fromMethodDescriptor(MethodDescriptor methodDescriptor)
      Create a MethodAnnotation from a MethodDescriptor.
      Parameters:
      methodDescriptor - the MethodDescriptor
      Returns:
      the MethodAnnotation
    • getMethodName

      public String getMethodName()
      Get the method name.
    • getJavaSourceMethodName

      public String getJavaSourceMethodName()
    • getMethodSignature

      public String getMethodSignature()
      Get the method type signature.
    • isStatic

      public boolean isStatic()
      Return whether or not the method is static.
      Returns:
      true if the method is static, false otherwise
    • toXMethod

      public XMethod toXMethod()
      Convert to an XMethod.
      Returns:
      an XMethod specifying the same method as this MethodAnnotation
    • toMethodDescriptor

      public MethodDescriptor toMethodDescriptor()
    • accept

      public void accept(BugAnnotationVisitor visitor)
      Description copied from interface: BugAnnotation
      Accept a BugAnnotationVisitor.
      Parameters:
      visitor - the visitor to accept
    • formatPackageMember

      protected String formatPackageMember(String key, ClassAnnotation primaryClass)
      Description copied from class: PackageMemberAnnotation
      Do default and subclass-specific formatting.
      Specified by:
      formatPackageMember in class PackageMemberAnnotation
      Parameters:
      key - the key specifying how to do the formatting
      primaryClass - TODO
    • getNameInClass

      public String getNameInClass(ClassAnnotation primaryClass)
      Get the "full" method name. This is a format which looks sort of like a method signature that would appear in Java source code.
    • getSignatureInClass

      public String getSignatureInClass(ClassAnnotation primaryClass)
    • getNameInClass

      public String getNameInClass(boolean shortenPackages, boolean useJVMMethodName, boolean hash)
    • getNameInClass

      public String getNameInClass(boolean shortenPackages, boolean useJVMMethodName, boolean hash, boolean omitMethodName)
      Get the "full" method name. This is a format which looks sort of like a method signature that would appear in Java source code. note: If shortenPackeges==true, this will return the same value as getNameInClass(), except that method caches the result and this one does not. Calling this one may be slow.
      Parameters:
      shortenPackages - whether to shorten package names if they are in java or in the same package as this method.
    • getFullMethod

      public String getFullMethod(ClassAnnotation primaryClass)
      Get the "full" method name. This is a format which looks sort of like a method signature that would appear in Java source code.
    • stripJavaLang

      public String stripJavaLang(@DottedClassName String className)
    • hashCode

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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • compareTo

      public int compareTo(BugAnnotation o)
    • writeXML

      public void writeXML(XMLOutput xmlOutput) throws IOException
      Description copied from interface: XMLWriteable
      Write this object to given XMLOutput.
      Parameters:
      xmlOutput - the XMLOutput for the document
      Throws:
      IOException
    • writeXML

      public void writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary) throws IOException
      Throws:
      IOException
    • isSignificant

      public boolean isSignificant()
      Description copied from interface: BugAnnotation
      Is this annotation used to compute instance hashes or match bug instances across versions
      Specified by:
      isSignificant in interface BugAnnotation
      Overrides:
      isSignificant in class PackageMemberAnnotation
      Returns:
      true if significant