Class Clazz


  • public class Clazz
    extends java.lang.Object
    • Field Detail

      • logger

        private static final org.slf4j.Logger logger
      • METHOD_DESCRIPTOR

        static java.util.regex.Pattern METHOD_DESCRIPTOR
      • HAS_ARGUMENT

        public static final java.util.EnumSet<Clazz.QUERY> HAS_ARGUMENT
      • ACC_PUBLIC

        static final int ACC_PUBLIC
          ACC_PUBLIC 0x0001 Declared public; may be accessed from outside its
         package. ACC_FINAL 0x0010 Declared final; no subclasses allowed.
         ACC_SUPER 0x0020 Treat superclass methods specially when invoked by the
         invokespecial instruction. ACC_INTERFACE 0x0200 Is an interface, not a
         class. ACC_ABSTRACT 0x0400 Declared abstract; may not be instantiated.
         
        See Also:
        Constant Field Values
      • NAME_COMPARATOR

        public static final java.util.Comparator<Clazz> NAME_COMPARATOR
      • hasRuntimeAnnotations

        boolean hasRuntimeAnnotations
      • hasClassAnnotations

        boolean hasClassAnnotations
      • hasDefaultConstructor

        boolean hasDefaultConstructor
      • depth

        int depth
      • pool

        java.lang.Object[] pool
      • intPool

        int[] intPool
      • path

        java.lang.String path
      • minor

        int minor
      • major

        int major
      • innerAccess

        int innerAccess
      • accessx

        int accessx
      • sourceFile

        java.lang.String sourceFile
      • forName

        int forName
      • class$

        int class$
      • deprecated

        boolean deprecated
      • classSignature

        java.lang.String classSignature
      • detectLdc

        private boolean detectLdc
      • defaults

        private java.util.Map<java.lang.String,​java.lang.Object> defaults
    • Constructor Detail

      • Clazz

        public Clazz​(Analyzer analyzer,
                     java.lang.String path,
                     Resource resource)
    • Method Detail

      • parseClassFile

        public java.util.Set<Descriptors.TypeRef> parseClassFile()
                                                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • parseClassFile

        public java.util.Set<Descriptors.TypeRef> parseClassFile​(java.io.InputStream in)
                                                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • parseClassFileData

        java.util.Set<Descriptors.TypeRef> parseClassFileData​(java.io.DataInput in)
                                                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • constantFloat

        private void constantFloat​(java.io.DataInput in,
                                   int poolIndex)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • constantInteger

        private void constantInteger​(java.io.DataInput in,
                                     int poolIndex)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • pool

        private void pool​(java.lang.Object[] pool,
                          int[] intPool)
      • nameAndType

        private void nameAndType​(java.io.DataInput in,
                                 int poolIndex,
                                 Clazz.CONSTANT tag)
                          throws java.io.IOException
        Parameters:
        in -
        poolIndex -
        tag -
        Throws:
        java.io.IOException
      • methodType

        private void methodType​(java.io.DataInput in,
                                int poolIndex,
                                Clazz.CONSTANT tag)
                         throws java.io.IOException
        Parameters:
        in -
        poolIndex -
        tag -
        Throws:
        java.io.IOException
      • methodHandle

        private void methodHandle​(java.io.DataInput in,
                                  int poolIndex,
                                  Clazz.CONSTANT tag)
                           throws java.io.IOException
        Parameters:
        in -
        poolIndex -
        tag -
        Throws:
        java.io.IOException
      • invokeDynamic

        private void invokeDynamic​(java.io.DataInput in,
                                   int poolIndex,
                                   Clazz.CONSTANT tag)
                            throws java.io.IOException
        Parameters:
        in -
        poolIndex -
        tag -
        Throws:
        java.io.IOException
      • ref

        private void ref​(java.io.DataInput in,
                         int poolIndex)
                  throws java.io.IOException
        Parameters:
        in -
        poolIndex -
        Throws:
        java.io.IOException
      • constantString

        private void constantString​(java.io.DataInput in,
                                    int poolIndex)
                             throws java.io.IOException
        Parameters:
        in -
        poolIndex -
        Throws:
        java.io.IOException
      • constantClass

        private void constantClass​(java.io.DataInput in,
                                   int poolIndex)
                            throws java.io.IOException
        Parameters:
        in -
        poolIndex -
        Throws:
        java.io.IOException
      • constantDouble

        private void constantDouble​(java.io.DataInput in,
                                    int poolIndex)
                             throws java.io.IOException
        Parameters:
        in -
        Throws:
        java.io.IOException
      • constantLong

        private void constantLong​(java.io.DataInput in,
                                  int poolIndex)
                           throws java.io.IOException
        Parameters:
        in -
        Throws:
        java.io.IOException
      • constantUtf8

        private void constantUtf8​(java.io.DataInput in,
                                  int poolIndex)
                           throws java.io.IOException
        Parameters:
        in -
        poolIndex -
        Throws:
        java.io.IOException
      • findMethodReference

        private int findMethodReference​(java.lang.String clazz,
                                        java.lang.String methodname,
                                        java.lang.String descriptor)
        Find a method reference in the pool that points to the given class, methodname and descriptor.
        Parameters:
        clazz -
        methodname -
        descriptor -
        Returns:
        index in constant pool
      • doAttributes

        private void doAttributes​(java.io.DataInput in,
                                  java.lang.annotation.ElementType member,
                                  boolean crawl,
                                  int access_flags)
                           throws java.lang.Exception
        Called for each attribute in the class, field, or method.
        Parameters:
        in - The stream
        access_flags -
        Throws:
        java.lang.Exception
      • doAttribute

        private void doAttribute​(java.io.DataInput in,
                                 java.lang.annotation.ElementType member,
                                 boolean crawl,
                                 int access_flags)
                          throws java.lang.Exception
        Process a single attribute, if not recognized, skip it.
        Parameters:
        in - the data stream
        access_flags -
        Throws:
        java.lang.Exception
      • doEnclosingMethod

        private void doEnclosingMethod​(java.io.DataInput in)
                                throws java.io.IOException
          EnclosingMethod_attribute { u2 attribute_name_index; u4
         attribute_length; u2 class_index u2 method_index; }
         
        Parameters:
        in -
        Throws:
        java.io.IOException
      • doInnerClasses

        private void doInnerClasses​(java.io.DataInput in)
                             throws java.lang.Exception
          InnerClasses_attribute { u2 attribute_name_index; u4
         attribute_length; u2 number_of_classes; { u2 inner_class_info_index; u2
         outer_class_info_index; u2 inner_name_index; u2 inner_class_access_flags;
         } classes[number_of_classes]; }
         
        Parameters:
        in -
        Throws:
        java.lang.Exception
      • doSignature

        void doSignature​(java.io.DataInput in,
                         java.lang.annotation.ElementType member,
                         int access_flags)
                  throws java.io.IOException
        Handle a signature
          Signature_attribute { u2 attribute_name_index;
         u4 attribute_length; u2 signature_index; }
         
        Parameters:
        member -
        access_flags -
        Throws:
        java.io.IOException
      • doConstantValue

        void doConstantValue​(java.io.DataInput in)
                      throws java.io.IOException
        Handle a constant value call the data collector with it
        Throws:
        java.io.IOException
      • doExceptions

        void doExceptions​(java.io.DataInput in,
                          int access_flags)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • doCode

        private void doCode​(java.io.DataInput in,
                            boolean crawl)
                     throws java.lang.Exception
          Code_attribute { u2 attribute_name_index; u4 attribute_length; u2
         max_stack; u2 max_locals; u4 code_length; u1 code[code_length]; u2
         exception_table_length; { u2 start_pc; u2 end_pc; u2 handler_pc; u2
         catch_type; } exception_table[exception_table_length]; u2
         attributes_count; attribute_info attributes[attributes_count]; }
         
        Parameters:
        in -
        pool -
        Throws:
        java.lang.Exception
      • crawl

        private void crawl​(byte[] code)
        We must find Class.forName references ...
        Parameters:
        code -
      • doSourceFile

        private void doSourceFile​(java.io.DataInput in)
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • doParameterAnnotations

        private void doParameterAnnotations​(java.io.DataInput in,
                                            java.lang.annotation.ElementType member,
                                            java.lang.annotation.RetentionPolicy policy,
                                            int access_flags)
                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • doTypeAnnotations

        private void doTypeAnnotations​(java.io.DataInput in,
                                       java.lang.annotation.ElementType member,
                                       java.lang.annotation.RetentionPolicy policy,
                                       int access_flags)
                                throws java.lang.Exception
        Throws:
        java.lang.Exception
      • doAnnotations

        private void doAnnotations​(java.io.DataInput in,
                                   java.lang.annotation.ElementType member,
                                   java.lang.annotation.RetentionPolicy policy,
                                   int access_flags)
                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • doAnnotation

        private Annotation doAnnotation​(java.io.DataInput in,
                                        java.lang.annotation.ElementType member,
                                        java.lang.annotation.RetentionPolicy policy,
                                        boolean collect,
                                        int access_flags)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • doElementValue

        private java.lang.Object doElementValue​(java.io.DataInput in,
                                                java.lang.annotation.ElementType member,
                                                java.lang.annotation.RetentionPolicy policy,
                                                boolean collect,
                                                int access_flags)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • doBootstrapMethods

        private void doBootstrapMethods​(java.io.DataInput in)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • doStackMapTable

        private void doStackMapTable​(java.io.DataInput in)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • verification_type_info

        private void verification_type_info​(java.io.DataInput in)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • referTo

        void referTo​(Descriptors.TypeRef typeRef,
                     int modifiers)
        Add a new package reference.
        Parameters:
        packageRef - A '.' delimited package name
      • referTo

        void referTo​(int index,
                     int modifiers)
      • parseDescriptor

        public void parseDescriptor​(java.lang.String descriptor,
                                    int modifiers)
        This method parses a descriptor and adds the package of the descriptor to the referenced packages. The syntax of the descriptor is:
         descriptor ::= ( '(' reference * ')' )? reference reference ::= 'L'
         classname ( '<' references '>' )? ';' | 'B' | 'Z' | ... | '+' | '-'
         | '['
         
        This methods uses heavy recursion to parse the descriptor and a roving pointer to limit the creation of string objects.
        Parameters:
        descriptor - The to be parsed descriptor
        modifiers -
      • parseReferences

        int parseReferences​(java.lang.String descriptor,
                            int rover,
                            char delimiter,
                            int modifiers)
        Parse a sequence of references. A sequence ends with a given character or when the string ends.
        Parameters:
        descriptor - The whole descriptor.
        rover - The index in the descriptor
        delimiter - The end character or 0
        Returns:
        the last index processed, one character after the delimeter
      • parseReference

        int parseReference​(java.lang.String descriptor,
                           int rover,
                           int modifiers)
        Parse a single reference. This can be a single character or an object reference when it starts with 'L'.
        Parameters:
        descriptor - The descriptor
        rover - The place to start
        Returns:
        The return index after the reference
      • parseFormalTypeParameters

        private int parseFormalTypeParameters​(java.lang.String descriptor,
                                              int index,
                                              int modifiers)
        FormalTypeParameters
        Parameters:
        descriptor -
        index -
      • getAbsolutePath

        public java.lang.String getAbsolutePath()
      • getSourceFile

        public java.lang.String getSourceFile()
      • reset

        public void reset()
        .class construct for different compilers sun 1.1 Detect static variable class$com$acme$MyClass 1.2 " 1.3 " 1.4 " 1.5 ldc_w (class) 1.6 " eclipse 1.1 class$0, ldc (string), invokestatic Class.forName 1.2 " 1.3 " 1.5 ldc (class) 1.6 " 1.5 and later is not an issue, sun pre 1.5 is easy to detect the static variable that decodes the class name. For eclipse, the class$0 gives away we have a reference encoded in a string. compilerversions/compilerversions.jar contains test versions of all versions/compilers.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getMethodDef

        void getMethodDef​(int access,
                          int methodRefPoolIndex)
        Called when crawling the byte code and a method reference is found
      • isPublic

        public boolean isPublic()
      • isProtected

        public boolean isProtected()
      • isEnum

        public boolean isEnum()
      • isSynthetic

        public boolean isSynthetic()
      • isModule

        public boolean isModule()
      • objectDescriptorToFQN

        public static java.lang.String objectDescriptorToFQN​(java.lang.String string)
      • unCamel

        public static java.lang.String unCamel​(java.lang.String id)
      • isInterface

        public boolean isInterface()
      • isAbstract

        public boolean isAbstract()
      • hasPublicNoArgsConstructor

        public boolean hasPublicNoArgsConstructor()
      • getAccess

        public int getAccess()
      • getMethodDef

        public Clazz.MethodDef getMethodDef​(int access,
                                            java.lang.String name,
                                            java.lang.String descriptor)
        To provide an enclosing instance
        Parameters:
        access -
        name -
        descriptor -
      • getFQN

        public java.lang.String getFQN()
      • setInnerAccess

        public void setInnerAccess​(int access)
      • isFinal

        public boolean isFinal()
      • setDeprecated

        public void setDeprecated​(boolean b)
      • isDeprecated

        public boolean isDeprecated()
      • isAnnotation

        public boolean isAnnotation()
      • classConstRef

        private void classConstRef​(int lastReference)
      • getClassSignature

        public java.lang.String getClassSignature()
      • getDefaults

        public java.util.Map<java.lang.String,​java.lang.Object> getDefaults()
                                                                           throws java.lang.Exception
        Throws:
        java.lang.Exception