Class ClassVisitor


  • public class ClassVisitor
    extends Object
    Identifies all methods and constructors in a given Java class (using Javassist). Can inject instrumentation code into constructors and methods in order to collect trace information during application tests.
    • Constructor Detail

      • ClassVisitor

        public ClassVisitor​(javassist.CtClass _c)

        Constructor for ClassVisitor.

        Parameters:
        _c - a CtClass object.
    • Method Detail

      • getConstructs

        public Set<ConstructId> getConstructs()
        Returns a set with the ConstructIds of all constructs contained in the given Java class, i.e., all methods, all constructors, the class or enumeration and the package (unless it is the default package, i.e., no package).
        Returns:
        a Set object.
      • isInstrumented

        public boolean isInstrumented()

        isInstrumented.

        Returns:
        a boolean.
      • visitMethods

        public Set<ConstructId> visitMethods​(boolean _instrument)
                                      throws javassist.CannotCompileException

        visitMethods.

        Parameters:
        _instrument - a boolean.
        Returns:
        a Set object.
        Throws:
        javassist.CannotCompileException - if any.
      • visitConstructors

        public Set<ConstructId> visitConstructors​(boolean _instrument)
                                           throws javassist.CannotCompileException

        visitConstructors.

        Parameters:
        _instrument - a boolean.
        Returns:
        a Set object.
        Throws:
        javassist.CannotCompileException - if any.
      • setOriginalArchiveDigest

        public void setOriginalArchiveDigest​(String _sha1)
        If called, the given SHA1 digest will be included in the instrumented code (as literal argument in the callback). Like this, the digest of the original JAR is preserved even if the instrumented class is written back to the archive. This method must be called prior to the invocation of visitMethods and visitConstructors, as the instrumentation code varies depending on whether the digest is known or not.
        Parameters:
        _sha1 - a String object.
      • setAppContext

        public void setAppContext​(org.eclipse.steady.shared.json.model.Application _ctx)
        If called, the application context (Maven groupId, artifactId and version) will be included in the instrumented code (as literal argument in the callback). Like this, the trace collector already knows the application context and does not need to determine it itself. * This method must be called prior to the invocation of visitMethods and visitConstructors, as the instrumentation code varies depending on whether the app context is known or not.
        Parameters:
        _ctx - a Application object.
      • finalizeInstrumentation

        public void finalizeInstrumentation()
                                     throws javassist.CannotCompileException,
                                            IOException
        Adds one additional member to the class: A boolean to indicate that the class has been instrumented (so that later processes and threads do not need to do it again).
        Throws:
        javassist.CannotCompileException - if any.
        IOException - if any.
      • getBytecode

        public byte[] getBytecode()
        Returns the byte code of the visited class.
        Returns:
        the byte code of the visited class
      • addBooleanMember

        public void addBooleanMember​(String _field_name,
                                     boolean _value,
                                     boolean _final)
                              throws javassist.CannotCompileException

        addBooleanMember.

        Parameters:
        _field_name - a String object.
        _value - a boolean.
        _final - a boolean.
        Throws:
        javassist.CannotCompileException - if any.
      • addIntMember

        public void addIntMember​(String _field_name,
                                 boolean _final)
                          throws javassist.CannotCompileException

        addIntMember.

        Parameters:
        _field_name - a String object.
        _final - a boolean.
        Throws:
        javassist.CannotCompileException - if any.
      • getUniqueMemberName

        public String getUniqueMemberName​(String _prefix,
                                          String _construct_name,
                                          boolean _random_part)
        Generates a name for a class member.
        Parameters:
        _prefix - a String object.
        _construct_name - a String object.
        _random_part - a boolean.
        Returns:
        a String object.
      • removeParameterQualification

        public static String removeParameterQualification​(String _string)
        Removes package information (if any) from method and constructor parameters. Previously, a string tokenizer split the given String at every comma, which led to problems in case of Map parameters (e.g., Map<String,Object>). The current implementation uses the regular expression QUALIFIED_TYPE_PATTERN.
        Parameters:
        _string - a String with qualified parameter types
        Returns:
        a a String where the package info of qualified parameter types has been removed
      • removePackageContext

        public static String removePackageContext​(String _string)

        removePackageContext.

        Parameters:
        _string - a String object.
        Returns:
        a String object.
      • getJavaId

        public JavaId getJavaId()

        Getter for the field javaId.

        Returns:
        a JavaId object.
      • getCtClass

        public javassist.CtClass getCtClass()

        getCtClass.

        Returns:
        a CtClass object.
      • getArchiveDigest

        public String getArchiveDigest()

        getArchiveDigest.

        Returns:
        a String object.
      • getAppContext

        public org.eclipse.steady.shared.json.model.Application getAppContext()

        Getter for the field appContext.

        Returns:
        a Application object.
      • getQname

        public String getQname()

        Getter for the field qname.

        Returns:
        a String object.
      • getOriginalArchiveDigest

        public String getOriginalArchiveDigest()

        Getter for the field originalArchiveDigest.

        Returns:
        a String object.
      • prettyPrint

        public static final String prettyPrint​(String _src)

        prettyPrint.

        Parameters:
        _src - a String object.
        Returns:
        a String object.