Package edu.umd.cs.findbugs
Class MethodAnnotation
- java.lang.Object
-
- edu.umd.cs.findbugs.BugAnnotationWithSourceLines
-
- edu.umd.cs.findbugs.PackageMemberAnnotation
-
- edu.umd.cs.findbugs.MethodAnnotation
-
- All Implemented Interfaces:
BugAnnotation
,XMLWriteable
,XMLWriteableWithMessages
,java.io.Serializable
,java.lang.Cloneable
,java.lang.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:
BugAnnotation
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_ROLE
static java.lang.String
METHOD_ALTERNATIVE_TARGET
static java.lang.String
METHOD_CALLED
static java.lang.String
METHOD_COMPUTED_IN
static java.lang.String
METHOD_CONSTRUCTOR
static java.lang.String
METHOD_DANGEROUS_TARGET
static java.lang.String
METHOD_DANGEROUS_TARGET_ACTUAL_GUARANTEED_NULL
static java.lang.String
METHOD_DID_YOU_MEAN_TO_OVERRIDE
static java.lang.String
METHOD_EQUALS_USED
static java.lang.String
METHOD_OVERRIDDEN
static java.lang.String
METHOD_RETURN_VALUE_OF
static java.lang.String
METHOD_SAFE_TARGET
static java.lang.String
METHOD_SUPERCLASS_CONSTRUCTOR
static java.lang.String
SHOULD_CALL
-
Fields inherited from class edu.umd.cs.findbugs.PackageMemberAnnotation
className, description
-
Fields inherited from class edu.umd.cs.findbugs.BugAnnotationWithSourceLines
sourceFileName, sourceLines
-
Fields inherited from interface edu.umd.cs.findbugs.BugAnnotation
MESSAGE_TAG
-
-
Constructor Summary
Constructors Constructor Description MethodAnnotation(java.lang.String className, java.lang.String methodName, java.lang.String methodSig, boolean isStatic)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(BugAnnotationVisitor visitor)
Accept a BugAnnotationVisitor.int
compareTo(BugAnnotation o)
boolean
equals(java.lang.Object o)
protected java.lang.String
formatPackageMember(java.lang.String key, ClassAnnotation primaryClass)
Do default and subclass-specific formatting.static MethodAnnotation
fromCalledMethod(DismantleBytecode visitor)
Factory method to create a MethodAnnotation from a method called by the instruction the given visitor is currently visiting.static MethodAnnotation
fromCalledMethod(java.lang.String className, java.lang.String methodName, java.lang.String methodSig, boolean isStatic)
Create a MethodAnnotation from a method that is not directly accessible.static MethodAnnotation
fromForeignMethod(java.lang.String className, java.lang.String methodName, java.lang.String methodSig, boolean isStatic)
Factory method to create the MethodAnnotation from the classname, method name, signature, etc.static MethodAnnotation
fromForeignMethod(java.lang.String className, java.lang.String methodName, java.lang.String methodSig, int accessFlags)
Factory method to create the MethodAnnotation from the classname, method name, signature, etc.static MethodAnnotation
fromMethodDescriptor(MethodDescriptor methodDescriptor)
Create a MethodAnnotation from a MethodDescriptor.static MethodAnnotation
fromVisitedMethod(PreorderVisitor visitor)
Factory method to create a MethodAnnotation from the method the given visitor is currently visiting.static MethodAnnotation
fromXMethod(XMethod xmethod)
Create a MethodAnnotation from an XMethod.java.lang.String
getFullMethod(ClassAnnotation primaryClass)
Get the "full" method name.java.lang.String
getJavaSourceMethodName()
java.lang.String
getMethodName()
Get the method name.java.lang.String
getMethodSignature()
Get the method type signature.java.lang.String
getNameInClass(boolean shortenPackages, boolean useJVMMethodName, boolean hash)
java.lang.String
getNameInClass(boolean shortenPackages, boolean useJVMMethodName, boolean hash, boolean omitMethodName)
Get the "full" method name.java.lang.String
getNameInClass(ClassAnnotation primaryClass)
Get the "full" method name.java.lang.String
getSignatureInClass(ClassAnnotation primaryClass)
int
hashCode()
boolean
isSignificant()
Is this annotation used to compute instance hashes or match bug instances across versionsboolean
isStatic()
Return whether or not the method is static.java.lang.String
stripJavaLang(java.lang.String className)
MethodDescriptor
toMethodDescriptor()
XMethod
toXMethod()
Convert to an XMethod.void
writeXML(XMLOutput xmlOutput)
Write this object to given XMLOutput.void
writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary)
-
Methods inherited from class edu.umd.cs.findbugs.PackageMemberAnnotation
format, getClassDescriptor, getClassName, getDescription, getPackageName, getSimpleClassName, getSlashedClassName, removePackage, removePackageName, setDescription, shorten, toString, toString
-
Methods inherited from class edu.umd.cs.findbugs.BugAnnotationWithSourceLines
clone, getSourceFileName, getSourceLines, setSourceLines
-
-
-
-
Field Detail
-
DEFAULT_ROLE
public static final java.lang.String DEFAULT_ROLE
- See Also:
- Constant Field Values
-
METHOD_DANGEROUS_TARGET_ACTUAL_GUARANTEED_NULL
public static final java.lang.String METHOD_DANGEROUS_TARGET_ACTUAL_GUARANTEED_NULL
- See Also:
- Constant Field Values
-
METHOD_DANGEROUS_TARGET
public static final java.lang.String METHOD_DANGEROUS_TARGET
- See Also:
- Constant Field Values
-
METHOD_RETURN_VALUE_OF
public static final java.lang.String METHOD_RETURN_VALUE_OF
- See Also:
- Constant Field Values
-
METHOD_SAFE_TARGET
public static final java.lang.String METHOD_SAFE_TARGET
- See Also:
- Constant Field Values
-
METHOD_EQUALS_USED
public static final java.lang.String METHOD_EQUALS_USED
- See Also:
- Constant Field Values
-
METHOD_CALLED
public static final java.lang.String METHOD_CALLED
- See Also:
- Constant Field Values
-
METHOD_SUPERCLASS_CONSTRUCTOR
public static final java.lang.String METHOD_SUPERCLASS_CONSTRUCTOR
- See Also:
- Constant Field Values
-
METHOD_CONSTRUCTOR
public static final java.lang.String METHOD_CONSTRUCTOR
- See Also:
- Constant Field Values
-
METHOD_OVERRIDDEN
public static final java.lang.String METHOD_OVERRIDDEN
- See Also:
- Constant Field Values
-
METHOD_DID_YOU_MEAN_TO_OVERRIDE
public static final java.lang.String METHOD_DID_YOU_MEAN_TO_OVERRIDE
- See Also:
- Constant Field Values
-
METHOD_COMPUTED_IN
public static final java.lang.String METHOD_COMPUTED_IN
- See Also:
- Constant Field Values
-
METHOD_ALTERNATIVE_TARGET
public static final java.lang.String METHOD_ALTERNATIVE_TARGET
- See Also:
- Constant Field Values
-
SHOULD_CALL
public static final java.lang.String SHOULD_CALL
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MethodAnnotation
public MethodAnnotation(@DottedClassName java.lang.String className, java.lang.String methodName, java.lang.String methodSig, boolean isStatic)
Constructor.- Parameters:
className
- the name of the class containing the methodmethodName
- the name of the methodmethodSig
- the Java type signature of the methodisStatic
- true if the method is static, false if not
-
-
Method Detail
-
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 java.lang.String className, java.lang.String methodName, java.lang.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 methodmethodName
- name of the methodmethodSig
- signature of the methodaccessFlags
- the access flags of the method- Returns:
- the MethodAnnotation
-
fromForeignMethod
public static MethodAnnotation fromForeignMethod(java.lang.String className, java.lang.String methodName, java.lang.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 methodmethodName
- name of the methodmethodSig
- signature of the methodisStatic
- true if the method is static, false otherwise- Returns:
- the MethodAnnotation
-
fromCalledMethod
public static MethodAnnotation fromCalledMethod(java.lang.String className, java.lang.String methodName, java.lang.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 methodmethodName
- name of called methodmethodSig
- signature of called methodisStatic
- 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 java.lang.String getMethodName()
Get the method name.
-
getJavaSourceMethodName
public java.lang.String getJavaSourceMethodName()
-
getMethodSignature
public java.lang.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 java.lang.String formatPackageMember(java.lang.String key, ClassAnnotation primaryClass)
Description copied from class:PackageMemberAnnotation
Do default and subclass-specific formatting.- Specified by:
formatPackageMember
in classPackageMemberAnnotation
- Parameters:
key
- the key specifying how to do the formattingprimaryClass
- TODO
-
getNameInClass
public java.lang.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 java.lang.String getSignatureInClass(ClassAnnotation primaryClass)
-
getNameInClass
public java.lang.String getNameInClass(boolean shortenPackages, boolean useJVMMethodName, boolean hash)
-
getNameInClass
public java.lang.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 java.lang.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 java.lang.String stripJavaLang(@DottedClassName java.lang.String className)
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
compareTo
public int compareTo(BugAnnotation o)
-
writeXML
public void writeXML(XMLOutput xmlOutput) throws java.io.IOException
Description copied from interface:XMLWriteable
Write this object to given XMLOutput.- Parameters:
xmlOutput
- the XMLOutput for the document- Throws:
java.io.IOException
-
writeXML
public void writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary) throws java.io.IOException
- Throws:
java.io.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 interfaceBugAnnotation
- Overrides:
isSignificant
in classPackageMemberAnnotation
- Returns:
- true if significant
-
-