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, Serializable, Cloneable, Comparable<BugAnnotation>
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.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprivate static final Stringprivate Stringprivate final booleanstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprivate final Stringprivate final Stringprivate static final longstatic final Stringprivate static final booleanFields inherited from class PackageMemberAnnotation
className, descriptionFields inherited from class BugAnnotationWithSourceLines
sourceFileName, sourceLinesFields inherited from interface BugAnnotation
MESSAGE_TAG -
Constructor Summary
ConstructorsConstructorDescriptionMethodAnnotation(String className, String methodName, String methodSig, boolean isStatic) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(BugAnnotationVisitor visitor) Accept a BugAnnotationVisitor.intbooleanprotected StringformatPackageMember(String key, ClassAnnotation primaryClass) Do default and subclass-specific formatting.static MethodAnnotationfromCalledMethod(DismantleBytecode visitor) Factory method to create a MethodAnnotation from a method called by the instruction the given visitor is currently visiting.static MethodAnnotationfromCalledMethod(String className, String methodName, String methodSig, boolean isStatic) Create a MethodAnnotation from a method that is not directly accessible.static MethodAnnotationfromForeignMethod(String className, String methodName, String methodSig, boolean isStatic) Factory method to create the MethodAnnotation from the classname, method name, signature, etc.static MethodAnnotationfromForeignMethod(String className, String methodName, String methodSig, int accessFlags) Factory method to create the MethodAnnotation from the classname, method name, signature, etc.static MethodAnnotationfromMethodDescriptor(MethodDescriptor methodDescriptor) Create a MethodAnnotation from a MethodDescriptor.static MethodAnnotationfromVisitedMethod(PreorderVisitor visitor) Factory method to create a MethodAnnotation from the method the given visitor is currently visiting.static MethodAnnotationfromXMethod(XMethod xmethod) Create a MethodAnnotation from an XMethod.getFullMethod(ClassAnnotation primaryClass) Get the "full" method name.Get the method name.Get the method type signature.getNameInClass(boolean shortenPackages, boolean useJVMMethodName, boolean hash) getNameInClass(boolean shortenPackages, boolean useJVMMethodName, boolean hash, boolean omitMethodName) Get the "full" method name.getNameInClass(ClassAnnotation primaryClass) Get the "full" method name.getSignatureInClass(ClassAnnotation primaryClass) private StringinthashCode()booleanIs this annotation used to compute instance hashes or match bug instances across versionsbooleanisStatic()Return whether or not the method is static.stripJavaLang(String className) Convert to an XMethod.voidWrite this object to given XMLOutput.voidMethods inherited from class PackageMemberAnnotation
format, getClassDescriptor, getClassName, getDescription, getJavaAnnotationNames, getPackageName, getSimpleClassName, getSlashedClassName, removePackage, removePackageName, setDescription, setJavaAnnotationNames, shorten, toString, toStringMethods inherited from class BugAnnotationWithSourceLines
clone, getSourceFileName, getSourceLines, setSourceLines
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
UGLY_METHODS
private static final boolean UGLY_METHODS -
DEFAULT_ROLE
- See Also:
-
methodName
-
methodSig
-
fullMethod
-
isStatic
private final boolean isStatic -
METHOD_DANGEROUS_TARGET_ACTUAL_GUARANTEED_NULL
- See Also:
-
METHOD_DANGEROUS_TARGET
- See Also:
-
METHOD_RETURN_VALUE_OF
- See Also:
-
METHOD_SAFE_TARGET
- See Also:
-
METHOD_EQUALS_USED
- See Also:
-
METHOD_CALLED
- See Also:
-
METHOD_SUPERCLASS_CONSTRUCTOR
- See Also:
-
METHOD_CONSTRUCTOR
- See Also:
-
METHOD_OVERRIDDEN
- See Also:
-
METHOD_DID_YOU_MEAN_TO_OVERRIDE
- See Also:
-
METHOD_COMPUTED_IN
- See Also:
-
METHOD_ALTERNATIVE_TARGET
- See Also:
-
SHOULD_CALL
- See Also:
-
ELEMENT_NAME
- See Also:
-
-
Constructor Details
-
MethodAnnotation
public MethodAnnotation(@DottedClassName String className, String methodName, 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 Details
-
fromVisitedMethod
Factory method to create a MethodAnnotation from the method the given visitor is currently visiting.- Parameters:
visitor- the BetterVisitor currently visiting the method
-
fromCalledMethod
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 methodmethodName- name of the methodmethodSig- signature of the methodaccessFlags- 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 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(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 methodmethodName- name of called methodmethodSig- signature of called methodisStatic- true if called method is static- Returns:
- the MethodAnnotation for the called method
-
fromXMethod
Create a MethodAnnotation from an XMethod.- Parameters:
xmethod- the XMethod- Returns:
- the MethodAnnotation
-
fromMethodDescriptor
Create a MethodAnnotation from a MethodDescriptor.- Parameters:
methodDescriptor- the MethodDescriptor- Returns:
- the MethodAnnotation
-
getMethodName
Get the method name. -
getJavaSourceMethodName
-
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
Convert to an XMethod.- Returns:
- an XMethod specifying the same method as this MethodAnnotation
-
toMethodDescriptor
-
accept
Description copied from interface:BugAnnotationAccept a BugAnnotationVisitor.- Parameters:
visitor- the visitor to accept
-
formatPackageMember
Description copied from class:PackageMemberAnnotationDo default and subclass-specific formatting.- Specified by:
formatPackageMemberin classPackageMemberAnnotation- Parameters:
key- the key specifying how to do the formattingprimaryClass- TODO
-
getNameInClass
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
-
getNameInClass
-
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
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
-
getUglyMethod
-
hashCode
-
equals
-
compareTo
-
writeXML
Description copied from interface:XMLWriteableWrite 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:BugAnnotationIs this annotation used to compute instance hashes or match bug instances across versions- Specified by:
isSignificantin interfaceBugAnnotation- Overrides:
isSignificantin classPackageMemberAnnotation- Returns:
- true if significant
-