Class DescriptorFactory


  • public class DescriptorFactory
    extends java.lang.Object
    Factory for creating ClassDescriptors, MethodDescriptors, and FieldDescriptors.
    Author:
    David Hovemeyer
    • Method Detail

      • canonicalizeString

        @Deprecated
        public static java.lang.String canonicalizeString​(@CheckForNull
                                                          java.lang.String s)
        Deprecated.
        this hack is needless for modern JVM, at least Java8
        This method was designed to canonicalize String to improve performance, but now GC cost is cheaper than calculation cost in application thread so removing this old optimization makes SpotBugs 16% faster.
        Returns:
        given string instance
      • instance

        public static DescriptorFactory instance()
        Get the singleton instance of the DescriptorFactory.
        Returns:
        the singleton instance of the DescriptorFactory
      • clearInstance

        public static void clearInstance()
      • getAllClassDescriptors

        public java.util.Collection<ClassDescriptor> getAllClassDescriptors()
      • purge

        public void purge​(java.util.Collection<ClassDescriptor> unusable)
      • getClassDescriptor

        @Nonnull
        public ClassDescriptor getClassDescriptor​(java.lang.Class<?> actualClass)
      • getClassDescriptor

        @Nonnull
        public ClassDescriptor getClassDescriptor​(@SlashedClassName
                                                  java.lang.String className)
        Get a ClassDescriptor for a class name in VM (slashed) format.
        Parameters:
        className - a class name in VM (slashed) format
        Returns:
        ClassDescriptor for that class
      • getClassDescriptorForDottedClassName

        public ClassDescriptor getClassDescriptorForDottedClassName​(@DottedClassName
                                                                    java.lang.String dottedClassName)
        Get a ClassDescriptor for a class name in dotted format.
        Parameters:
        dottedClassName - a class name in dotted format
        Returns:
        ClassDescriptor for that class
      • getMethodDescriptor

        public MethodDescriptor getMethodDescriptor​(org.apache.bcel.classfile.JavaClass jClass,
                                                    org.apache.bcel.classfile.Method method)
      • getMethodDescriptor

        public MethodDescriptor getMethodDescriptor​(@SlashedClassName
                                                    java.lang.String className,
                                                    java.lang.String name,
                                                    java.lang.String signature,
                                                    boolean isStatic)
        Get a MethodDescriptor.
        Parameters:
        className - name of the class containing the method, in VM format (e.g., "java/lang/String")
        name - name of the method
        signature - signature of the method
        isStatic - true if method is static, false otherwise
        Returns:
        MethodDescriptor
      • profile

        public void profile()
      • getFieldDescriptor

        public FieldDescriptor getFieldDescriptor​(@SlashedClassName
                                                  java.lang.String className,
                                                  java.lang.String name,
                                                  java.lang.String signature,
                                                  boolean isStatic)
        Get a FieldDescriptor.
        Parameters:
        className - the name of the class the field belongs to, in VM format (e.g., "java/lang/String")
        name - the name of the field
        signature - the field signature (type)
        isStatic - true if field is static, false if not
        Returns:
        FieldDescriptor
      • getClassDescriptor

        public static ClassDescriptor getClassDescriptor​(org.apache.bcel.generic.ObjectType type)
        Get a ClassDescriptor for the class described by given ObjectType object.
        Parameters:
        type - an ObjectType
        Returns:
        a ClassDescriptor for the class described by the ObjectType
      • createClassDescriptor

        public static ClassDescriptor createClassDescriptor​(org.apache.bcel.classfile.JavaClass c)
      • createClassDescriptorFromResourceName

        public static ClassDescriptor createClassDescriptorFromResourceName​(java.lang.String resourceName)
        Create a class descriptor from a resource name.
        Parameters:
        resourceName - the resource name
        Returns:
        the class descriptor
      • createClassDescriptorFromFieldSignature

        @CheckForNull
        public static ClassDescriptor createClassDescriptorFromFieldSignature​(java.lang.String signature)
        Create a class descriptor from a field signature
      • isClassResource

        public static boolean isClassResource​(java.lang.String resourceName)
        Determine whether or not the given resource name refers to a class.
        Parameters:
        resourceName - the resource name
        Returns:
        true if the resource is a class, false otherwise
      • isModuleInfo

        public static boolean isModuleInfo​(java.lang.String resourceName)
        Determine whether or not the given resource name refers to a module-info class.
        Parameters:
        resourceName - the resource name
        Returns:
        true if the resource is a module-info class, false otherwise
      • createClassDescriptorFromSignature

        public static ClassDescriptor createClassDescriptorFromSignature​(java.lang.String signature)
      • createClassOrObjectDescriptorFromSignature

        public static ClassDescriptor createClassOrObjectDescriptorFromSignature​(java.lang.String signature)
      • createClassDescriptor

        public static ClassDescriptor createClassDescriptor​(java.lang.Class<?> aClass)
      • createClassDescriptor

        public static ClassDescriptor[] createClassDescriptor​(java.lang.String[] classNames)
      • createClassDescriptorFromDottedClassName

        public static ClassDescriptor createClassDescriptorFromDottedClassName​(java.lang.String dottedClassName)