Package edu.umd.cs.findbugs.model
Class ClassFeatureSet
- java.lang.Object
-
- edu.umd.cs.findbugs.model.ClassFeatureSet
-
- All Implemented Interfaces:
XMLWriteable
public class ClassFeatureSet extends java.lang.Object implements XMLWriteable
Features of a class which may be used to identify it if it is renamed or modified.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CLASS_NAME_KEY
private java.lang.String
className
static java.lang.String
CODE_LENGTH_KEY
static java.lang.String
ELEMENT_NAME
static double
EXACT_CLASS_NAME_MATCH
Similarity of classes which don't have enough features to match exactly, but whose class names match exactly.static java.lang.String
FEATURE_ELEMENT_NAME
private java.util.Set<java.lang.String>
featureSet
static java.lang.String
FIELD_NAME_KEY
private boolean
isInterface
static java.lang.String
METHOD_NAME_KEY
static int
MIN_CODE_LENGTH
Minimum code length required to add a CodeLength feature.static int
MIN_FEATURES
Minimum number of features which must be present in order to declare two classes similar.static double
MIN_MATCH
Minimum similarity required to declare two classes similar.
-
Constructor Summary
Constructors Constructor Description ClassFeatureSet()
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFeature(java.lang.String feature)
java.util.Iterator<java.lang.String>
featureIterator()
java.lang.String
getClassName()
int
getNumFeatures()
boolean
hasFeature(java.lang.String feature)
ClassFeatureSet
initialize(org.apache.bcel.classfile.JavaClass javaClass)
Initialize from given JavaClass.boolean
isInterface()
private boolean
isSynthetic(org.apache.bcel.classfile.FieldOrMethod member)
Figure out if a class member (field or method) is synthetic.static boolean
isUnlikelyToBeRenamed(java.lang.String pkg)
Return true if classes in the given package is unlikely to be renamed: e.g., because they are part of a public API.static void
main(java.lang.String[] args)
private boolean
overridesSuperclassMethod(org.apache.bcel.classfile.JavaClass javaClass, org.apache.bcel.classfile.Method method)
Determine if given method overrides a superclass or superinterface method.void
setClassName(java.lang.String className)
void
setInterface(boolean isInterface)
static double
similarity(ClassFeatureSet a, ClassFeatureSet b)
boolean
similarTo(ClassFeatureSet other)
static java.lang.String
transformClassName(java.lang.String className)
Transform a class name by stripping its package name.static java.lang.String
transformMethodSignature(java.lang.String signature)
Transform a method signature to allow it to be compared even if any of its parameter types are moved to another package.static java.lang.String
transformSignature(java.lang.String signature)
Transform a field or method parameter signature to allow it to be compared even if it is moved to another package.void
writeXML(XMLOutput xmlOutput)
Write this object to given XMLOutput.
-
-
-
Field Detail
-
CLASS_NAME_KEY
public static final java.lang.String CLASS_NAME_KEY
- See Also:
- Constant Field Values
-
METHOD_NAME_KEY
public static final java.lang.String METHOD_NAME_KEY
- See Also:
- Constant Field Values
-
CODE_LENGTH_KEY
public static final java.lang.String CODE_LENGTH_KEY
- See Also:
- Constant Field Values
-
FIELD_NAME_KEY
public static final java.lang.String FIELD_NAME_KEY
- See Also:
- Constant Field Values
-
className
private java.lang.String className
-
isInterface
private boolean isInterface
-
featureSet
private final java.util.Set<java.lang.String> featureSet
-
MIN_CODE_LENGTH
public static final int MIN_CODE_LENGTH
Minimum code length required to add a CodeLength feature.- See Also:
- Constant Field Values
-
MIN_FEATURES
public static final int MIN_FEATURES
Minimum number of features which must be present in order to declare two classes similar.- See Also:
- Constant Field Values
-
MIN_MATCH
public static final double MIN_MATCH
Minimum similarity required to declare two classes similar.- See Also:
- Constant Field Values
-
EXACT_CLASS_NAME_MATCH
public static final double EXACT_CLASS_NAME_MATCH
Similarity of classes which don't have enough features to match exactly, but whose class names match exactly.- See Also:
- Constant Field Values
-
ELEMENT_NAME
public static final java.lang.String ELEMENT_NAME
- See Also:
- Constant Field Values
-
FEATURE_ELEMENT_NAME
public static final java.lang.String FEATURE_ELEMENT_NAME
- See Also:
- Constant Field Values
-
-
Method Detail
-
initialize
public ClassFeatureSet initialize(org.apache.bcel.classfile.JavaClass javaClass)
Initialize from given JavaClass.- Parameters:
javaClass
- the JavaClass- Returns:
- this object
-
overridesSuperclassMethod
private boolean overridesSuperclassMethod(org.apache.bcel.classfile.JavaClass javaClass, org.apache.bcel.classfile.Method method)
Determine if given method overrides a superclass or superinterface method.- Parameters:
javaClass
- class defining the methodmethod
- the method- Returns:
- true if the method overrides a superclass/superinterface method, false if not
-
isSynthetic
private boolean isSynthetic(org.apache.bcel.classfile.FieldOrMethod member)
Figure out if a class member (field or method) is synthetic.- Parameters:
member
- a field or method- Returns:
- true if the member is synthetic
-
getClassName
public java.lang.String getClassName()
- Returns:
- Returns the className.
-
setClassName
public void setClassName(java.lang.String className)
- Parameters:
className
- The className to set.
-
isInterface
public boolean isInterface()
- Returns:
- Returns the isInterface.
-
setInterface
public void setInterface(boolean isInterface)
- Parameters:
isInterface
- The isInterface to set.
-
getNumFeatures
public int getNumFeatures()
-
addFeature
public void addFeature(java.lang.String feature)
-
featureIterator
public java.util.Iterator<java.lang.String> featureIterator()
-
hasFeature
public boolean hasFeature(java.lang.String feature)
-
transformClassName
public static java.lang.String transformClassName(java.lang.String className)
Transform a class name by stripping its package name.- Parameters:
className
- a class name- Returns:
- the transformed class name
-
isUnlikelyToBeRenamed
public static boolean isUnlikelyToBeRenamed(java.lang.String pkg)
Return true if classes in the given package is unlikely to be renamed: e.g., because they are part of a public API.- Parameters:
pkg
- the package name- Returns:
- true if classes in the package is unlikely to be renamed
-
transformMethodSignature
public static java.lang.String transformMethodSignature(java.lang.String signature)
Transform a method signature to allow it to be compared even if any of its parameter types are moved to another package.- Parameters:
signature
- a method signature- Returns:
- the transformed signature
-
transformSignature
public static java.lang.String transformSignature(java.lang.String signature)
Transform a field or method parameter signature to allow it to be compared even if it is moved to another package.- Parameters:
signature
- the signature- Returns:
- the transformed signature
-
similarity
public static double similarity(ClassFeatureSet a, ClassFeatureSet b)
-
similarTo
public boolean similarTo(ClassFeatureSet other)
-
main
public static void main(java.lang.String[] args) throws java.lang.Exception
- Throws:
java.lang.Exception
-
writeXML
public void writeXML(XMLOutput xmlOutput) throws java.io.IOException
Description copied from interface:XMLWriteable
Write this object to given XMLOutput.- Specified by:
writeXML
in interfaceXMLWriteable
- Parameters:
xmlOutput
- the XMLOutput for the document- Throws:
java.io.IOException
-
-