Class ClassName
java.lang.Object
edu.umd.cs.findbugs.util.ClassName
Utility methods for working with class names.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertIsDotted(String className) static voidassertIsSlashed(String className) static StringextractClassName(String originalName) Extract a slashed classname from a JVM classname or signature.static StringextractPackageName(String className) extract the package name from a dotted class name.static StringextractPackagePrefix(String packageName, int count) static StringextractSimpleName(String className) static StringfromFieldSignature(String signature) Converts from signature to slashed class name (e.g., from Ljava/lang/String; to java/lang/String).static StringfromFieldSignatureToDottedClassName(String signature) Converts from signature to dotted class name (e.g., from Ljava/lang/String; to java.lang.String).private static booleanfuzzyMatch(String className, String searchString) Perform a fuzzy matching, by comparing the Levenshtein distance of the simple class name and the search string.static StringgetPrimitiveType(String cls) static booleanisAnonymous(String className) Does a class name appear to designate an anonymous class? Only the name is analyzed.static booleanisLocalOrAnonymous(String className) Does a class name appear to designate an anonymous or local (defined inside method) class? Only the name is analyzed.static booleanisMathClass(String className) private static booleanisValidArrayFieldDescriptor(String className) Determines whether a class name is a valid array field descriptor as per JVMS (Java SE 8 Edition) 4.3.2static booleanisValidBaseTypeFieldDescriptor(String className) Determines whether a class name is a valid array field descriptor as per JVMS (Java SE 8 Edition) 4.3.2private static booleanisValidBinaryClassName(String className) private static booleanisValidClassFieldDescriptor(String className) static booleanisValidClassName(String className) Return whether or not the given class name is valid.private static booleanisValidDottedClassName(String className) static booleanmatchedPrefixes(String[] classSearchStrings, String className) static StringtoDottedClassName(String className) Convert class name to dotted format.static StringtoSignature(String className) static StringtoSlashedClassName(Class<?> class1) static StringtoSlashedClassName(String className) Convert class name to slashed format.
-
Constructor Details
-
ClassName
public ClassName()
-
-
Method Details
-
isMathClass
-
assertIsDotted
-
assertIsSlashed
-
toSignature
-
getPrimitiveType
-
fromFieldSignature
Converts from signature to slashed class name (e.g., from Ljava/lang/String; to java/lang/String). Returns null if it is the signature for an array or primitive type. -
toSlashedClassName
@SlashedClassName public static String toSlashedClassName(@SlashedClassName(when=UNKNOWN) String className) Convert class name to slashed format. If the class name is already in slashed format, it is returned unmodified.- Parameters:
className- a class name- Returns:
- the same class name in slashed format
-
toDottedClassName
@DottedClassName public static String toDottedClassName(@SlashedClassName(when=UNKNOWN) String className) Convert class name to dotted format. If the class name is already in dotted format, it is returned unmodified.- Parameters:
className- a class name- Returns:
- the same class name in dotted format
-
fromFieldSignatureToDottedClassName
@DottedClassName @CheckForNull public static String fromFieldSignatureToDottedClassName(String signature) Converts from signature to dotted class name (e.g., from Ljava/lang/String; to java.lang.String). Returns null if it is the signature for an array or primitive type.- Parameters:
signature- a class signature- Returns:
- the class of the signature in dotted format
-
extractPackageName
extract the package name from a dotted class name. Package names are always in dotted format.- Parameters:
className- a dotted class name- Returns:
- the name of the package containing the class
-
extractSimpleName
-
isValidClassName
Return whether or not the given class name is valid.- Parameters:
className- a possible class name- Returns:
- true if it's a valid class name, false otherwise
-
isValidBinaryClassName
- See Also:
-
isValidDottedClassName
-
isValidArrayFieldDescriptor
Determines whether a class name is a valid array field descriptor as per JVMS (Java SE 8 Edition) 4.3.2- Parameters:
className- a class name to test for validity - must be non-nulland non-empty.- Returns:
trueifclassNameis a valid array field descriptor as per JVMS 4.3.2, otherwisefalse- Throws:
IndexOutOfBoundsException- ifclassNameis empty.NullPointerException- ifclassNameisnull.
-
isValidClassFieldDescriptor
-
isValidBaseTypeFieldDescriptor
Determines whether a class name is a valid array field descriptor as per JVMS (Java SE 8 Edition) 4.3.2- Parameters:
className- a class name to test for validity - must be non-nulland non-empty.- Returns:
trueifclassNameis a valid basetype field descriptor as per JVMS 4.3.2, otherwisefalse
-
isLocalOrAnonymous
Does a class name appear to designate an anonymous or local (defined inside method) class? Only the name is analyzed. No classes are loaded or looked up.- Parameters:
className- class name, slashed or dotted, fully qualified or unqualified- Returns:
- true if className is the name of an anonymous or local class
-
isAnonymous
Does a class name appear to designate an anonymous class? Only the name is analyzed. No classes are loaded or looked up.- Parameters:
className- class name, slashed or dotted, fully qualified or unqualified- Returns:
- true if className is the name of an anonymous class
-
extractClassName
Extract a slashed classname from a JVM classname or signature.- Parameters:
originalName- JVM classname or signature- Returns:
- a slashed classname
-
extractPackagePrefix
-
matchedPrefixes
public static boolean matchedPrefixes(String[] classSearchStrings, @DottedClassName String className) -
fuzzyMatch
Perform a fuzzy matching, by comparing the Levenshtein distance of the simple class name and the search string. A maximum distance of 3 is used. This means the searchString and the className may differ by 3 single-character edits (insertions, deletions or substitutions). This limit also speeds up the computation.For more information on the Levenshtein distance see Wikipedia and the Apache Commons Text JavaDoc.
- Parameters:
className- the full class namesearchString- the search string- Returns:
- true, if the strings are similar, false otherwise
-
toSlashedClassName
-