Package edu.umd.cs.findbugs.util
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 void
assertIsDotted
(String className) static void
assertIsSlashed
(String className) static String
extractClassName
(String originalName) Extract a slashed classname from a JVM classname or signature.static String
extractPackageName
(String className) extract the package name from a dotted class name.static String
extractPackagePrefix
(String packageName, int count) static String
extractSimpleName
(String className) static String
fromFieldSignature
(String signature) Converts from signature to slashed class name (e.g., from Ljava/lang/String; to java/lang/String).static String
fromFieldSignatureToDottedClassName
(String signature) Converts from signature to dotted class name (e.g., from Ljava/lang/String; to java.lang.String).private static boolean
fuzzyMatch
(String className, String searchString) Perform a fuzzy matching, by comparing the Levenshtein distance of the simple class name and the search string.static String
getPrimitiveType
(String cls) static boolean
isAnonymous
(String className) Does a class name appear to designate an anonymous class? Only the name is analyzed.static boolean
isLocalOrAnonymous
(String className) Does a class name appear to designate an anonymous or local (defined inside method) class? Only the name is analyzed.static boolean
isMathClass
(String className) private static boolean
isValidArrayFieldDescriptor
(String className) Determines whether a class name is a valid array field descriptor as per JVMS (Java SE 8 Edition) 4.3.2private static boolean
isValidBaseTypeFieldDescriptor
(String className) private static boolean
isValidBinaryClassName
(String className) private static boolean
isValidClassFieldDescriptor
(String className) static boolean
isValidClassName
(String className) Return whether or not the given class name is valid.private static boolean
isValidDottedClassName
(String className) static boolean
matchedPrefixes
(String[] classSearchStrings, String className) static String
toDottedClassName
(String className) Convert class name to dotted format.static String
toSignature
(String className) static String
toSlashedClassName
(Class<?> class1) static String
toSlashedClassName
(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-null
and non-empty.- Returns:
true
ifclassName
is a valid array field descriptor as per JVMS 4.3.2, otherwisefalse
- Throws:
IndexOutOfBoundsException
- ifclassName
is empty.NullPointerException
- ifclassName
isnull
.
-
isValidClassFieldDescriptor
-
isValidBaseTypeFieldDescriptor
-
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
-