Package edu.umd.cs.findbugs.util
Class ClassName
java.lang.Object
edu.umd.cs.findbugs.util.ClassName
Utility methods for working with class names.
- Author:
- David Hovemeyer
-
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).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) static boolean
isValidBaseTypeFieldDescriptor
(String className) Determines whether a class name is a valid array field descriptor as per JVMS (Java SE 8 Edition) 4.3.2static boolean
isValidClassName
(String className) Return whether or not the given class name is valid.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
-
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-null
and non-empty.- Returns:
true
ifclassName
is 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) -
toSlashedClassName
-