Search in sources :

Example 1 with NoInstrument

use of org.fakereplace.util.NoInstrument in project fakereplace by fakereplace.

the class Transformer method transform.

public boolean transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, ClassFile file, Set<Class<?>> classesToRetransform, ChangedClassImpl changedClass, Set<MethodInfo> modifiedMethods) throws IllegalClassFormatException, BadBytecode, DuplicateMemberException {
    boolean modified = false;
    if (classBeingRedefined != null) {
        ClassDataStore.instance().markClassReplaced(classBeingRedefined);
    }
    // java/io namespace except for java/lang/reflect/Proxy
    if (BuiltinClassData.skipInstrumentation(className)) {
        if (classBeingRedefined != null && manipulator.transformClass(file, loader, false, modifiedMethods)) {
            modified = true;
        }
        return modified;
    }
    if (classBeingRedefined == null) {
        AnnotationsAttribute at = (AnnotationsAttribute) file.getAttribute(AnnotationsAttribute.invisibleTag);
        if (at != null) {
            // NoInstrument is used for testing or by integration modules
            Object an = at.getAnnotation(NoInstrument.class.getName());
            if (an != null) {
                return modified;
            }
        }
    }
    final boolean replaceable = Fakereplace.isClassReplaceable(className, loader);
    if (manipulator.transformClass(file, loader, replaceable, modifiedMethods)) {
        modified = true;
    }
    if (replaceable) {
        if ((AccessFlag.ENUM & file.getAccessFlags()) == 0 && (AccessFlag.ANNOTATION & file.getAccessFlags()) == 0) {
            modified = true;
            watcher.addClassFile(className, loader);
            if (file.isInterface()) {
                addAbstractMethodForInstrumentation(file);
            } else {
                addMethodForInstrumentation(file);
                addConstructorForInstrumentation(file);
                addStaticConstructorForInstrumentation(file);
            }
        }
        if (classBeingRedefined == null) {
            BaseClassData baseData = new BaseClassData(file, loader, replaceable);
            ClassDataStore.instance().saveClassData(loader, baseData.getInternalName(), baseData);
        }
    }
    // file.getSuperclass(), classfileBuffer);
    return modified;
}
Also used : NoInstrument(org.fakereplace.util.NoInstrument) BaseClassData(org.fakereplace.data.BaseClassData) AnnotationsAttribute(javassist.bytecode.AnnotationsAttribute)

Aggregations

AnnotationsAttribute (javassist.bytecode.AnnotationsAttribute)1 BaseClassData (org.fakereplace.data.BaseClassData)1 NoInstrument (org.fakereplace.util.NoInstrument)1