edu.umd.cs.findbugs

Class MethodAnnotation

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

Field Summary
static StringMETHOD_DANGEROUS_TARGET
static StringMETHOD_DANGEROUS_TARGET_ACTUAL_GUARANTEED_NULL
static StringMETHOD_SAFE_TARGET
Constructor Summary
MethodAnnotation(String className, String methodName, String methodSig, boolean isStatic)
Constructor.
Method Summary
voidaccept(BugAnnotationVisitor visitor)
intcompareTo(BugAnnotation o)
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, int accessFlags)
Factory method to create the MethodAnnotation from the classname, method name, signature, etc.
static MethodAnnotationfromForeignMethod(String className, String methodName, String methodSig, boolean isStatic)
Factory method to create the MethodAnnotation from the classname, method name, signature, etc.
static BugAnnotationfromMethodDescriptor(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.
StringgetFullMethod(ClassAnnotation primaryClass)
Get the "full" method name.
StringgetJavaSourceMethodName()
StringgetMethodName()
Get the method name.
StringgetMethodSignature()
Get the method type signature.
StringgetNameInClass(ClassAnnotation primaryClass)
Get the "full" method name.
StringgetNameInClass(boolean shortenPackages, boolean useJVMMethodName, boolean hash)
Get the "full" method name.
booleanisStatic()
Return whether or not the method is static.
XMethodtoXMethod()
Convert to an XMethod.
voidwriteXML(XMLOutput xmlOutput)
voidwriteXML(XMLOutput xmlOutput, boolean addMessages)

Field Detail

METHOD_DANGEROUS_TARGET

public static final String METHOD_DANGEROUS_TARGET

METHOD_DANGEROUS_TARGET_ACTUAL_GUARANTEED_NULL

public static final String METHOD_DANGEROUS_TARGET_ACTUAL_GUARANTEED_NULL

METHOD_SAFE_TARGET

public static final String METHOD_SAFE_TARGET

Constructor Detail

MethodAnnotation

public MethodAnnotation(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 Detail

accept

public void accept(BugAnnotationVisitor visitor)

compareTo

public int compareTo(BugAnnotation o)

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

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

fromForeignMethod

public static MethodAnnotation fromForeignMethod(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 isStatic true if the method is static, false otherwise

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

fromMethodDescriptor

public static BugAnnotation fromMethodDescriptor(MethodDescriptor methodDescriptor)
Create a MethodAnnotation from a MethodDescriptor.

Parameters: methodDescriptor the MethodDescriptor

Returns: the MethodAnnotation

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

fromXMethod

public static MethodAnnotation fromXMethod(XMethod xmethod)
Create a MethodAnnotation from an XMethod.

Parameters: xmethod the XMethod

Returns: the MethodAnnotation

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.

Parameters: primaryClass TODO

getJavaSourceMethodName

public String getJavaSourceMethodName()

getMethodName

public String getMethodName()
Get the method name.

getMethodSignature

public String getMethodSignature()
Get the method type signature.

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.

Parameters: primaryClass TODO

getNameInClass

public String getNameInClass(boolean shortenPackages, boolean useJVMMethodName, boolean hash)
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. useJVMMethodName TODO hash TODO

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

writeXML

public void writeXML(XMLOutput xmlOutput)

writeXML

public void writeXML(XMLOutput xmlOutput, boolean addMessages)
FindBugs™ is licenced under the LGPL. Copyright © 2006 University of Maryland.