Package org.eclipse.steady.java.monitor
Class ClassVisitor
- java.lang.Object
-
- org.eclipse.steady.java.monitor.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 Summary
Constructors Constructor Description ClassVisitor(javassist.CtClass _c)Constructor for ClassVisitor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBooleanMember(String _field_name, boolean _value, boolean _final)addBooleanMember.voidaddIntMember(String _field_name, boolean _final)addIntMember.voidfinalizeInstrumentation()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).org.eclipse.steady.shared.json.model.ApplicationgetAppContext()Getter for the fieldappContext.StringgetArchiveDigest()getArchiveDigest.byte[]getBytecode()Returns the byte code of the visited class.Set<ConstructId>getConstructs()Returns a set with theConstructIds 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).javassist.CtClassgetCtClass()getCtClass.JavaIdgetJavaId()Getter for the fieldjavaId.StringgetOriginalArchiveDigest()Getter for the fieldoriginalArchiveDigest.StringgetQname()Getter for the fieldqname.StringgetUniqueMemberName(String _prefix, String _construct_name, boolean _random_part)Generates a name for a class member.booleanisInstrumented()isInstrumented.static StringprettyPrint(String _src)prettyPrint.static StringremovePackageContext(String _string)removePackageContext.static StringremoveParameterQualification(String _string)Removes package information (if any) from method and constructor parameters.voidsetAppContext(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).voidsetOriginalArchiveDigest(String _sha1)If called, the given SHA1 digest will be included in the instrumented code (as literal argument in the callback).Set<ConstructId>visitConstructors(boolean _instrument)visitConstructors.Set<ConstructId>visitMethods(boolean _instrument)visitMethods.
-
-
-
Method Detail
-
getConstructs
public Set<ConstructId> getConstructs()
Returns a set with theConstructIds 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
Setobject.
-
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
Setobject. - Throws:
javassist.CannotCompileException- if any.
-
visitConstructors
public Set<ConstructId> visitConstructors(boolean _instrument) throws javassist.CannotCompileException
visitConstructors.
- Parameters:
_instrument- a boolean.- Returns:
- a
Setobject. - 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- aStringobject.
-
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- aApplicationobject.
-
finalizeInstrumentation
public void finalizeInstrumentation() throws javassist.CannotCompileException, IOExceptionAdds 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- aStringobject._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- aStringobject._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.
-
removeParameterQualification
public static String removeParameterQualification(String _string)
Removes package information (if any) from method and constructor parameters. Previously, a string tokenizer split the givenStringat every comma, which led to problems in case of Map parameters (e.g., Map<String,Object>). The current implementation uses the regular expressionQUALIFIED_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.
-
getCtClass
public javassist.CtClass getCtClass()
getCtClass.
- Returns:
- a
CtClassobject.
-
getAppContext
public org.eclipse.steady.shared.json.model.Application getAppContext()
Getter for the field
appContext.- Returns:
- a
Applicationobject.
-
getOriginalArchiveDigest
public String getOriginalArchiveDigest()
Getter for the field
originalArchiveDigest.- Returns:
- a
Stringobject.
-
-