Example usage for org.objectweb.asm Opcodes ACC_FINAL

List of usage examples for org.objectweb.asm Opcodes ACC_FINAL

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes ACC_FINAL.

Prototype

int ACC_FINAL

To view the source code for org.objectweb.asm Opcodes ACC_FINAL.

Click Source Link

Usage

From source file:org.evosuite.runtime.instrumentation.CreateClassResetClassAdapter.java

License:Open Source License

/** {@inheritDoc} */
@Override//from   w  w w  . j av  a2 s . c  o  m
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {

    if (name.equals("serialVersionUID")) {
        definesUid = true;
        // We must not remove final from serialVersionUID or else the
        // class cannot be serialised and de-serialised any more
        return super.visitField(access, name, desc, signature, value);
    }

    if (hasStaticModifier(access)) {
        StaticField staticField = new StaticField();
        staticField.name = name;
        staticField.desc = desc;
        staticField.value = value;
        static_fields.add(staticField);
    }

    if (!isEnum && !isInterface && removeFinalModifierOnStaticFields) {
        int newAccess = access & (~Opcodes.ACC_FINAL);
        if (newAccess != access) {
            // this means that the field was modified
            modifiedStaticFields.add(name);
        }
        return super.visitField(newAccess, name, desc, signature, value);
    } else {
        if (hasFinalModifier(access))
            finalFields.add(name);

        return super.visitField(access, name, desc, signature, value);
    }
}

From source file:org.evosuite.runtime.instrumentation.CreateClassResetClassAdapter.java

License:Open Source License

/**
 * Returns true iif the access modifiers has a final modifier
 * /*from   www  .  ja va  2 s . c  o m*/
 * @param access
 * @return
 */
private boolean hasFinalModifier(int access) {
    return (access & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL;
}

From source file:org.evosuite.runtime.instrumentation.CreateClassResetClassAdapter.java

License:Open Source License

@Deprecated
// This method is a code clone from MethodCallReplacementClassAdapter
private void createSerialisableUID() {
    // Only add this for serialisable classes
    if (serialUID < 0)
        return;//from www  . jav  a  2  s. c om
    /*
     * If the class is serializable, then adding a hashCode will change the
     * serialVersionUID if it is not defined in the class. Hence, if it is
     * not defined, we have to define it to avoid problems in serialising
     * the class.
     */
    logger.info("Adding serialId to class " + className);
    visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, "serialVersionUID", "J", null,
            serialUID);
}

From source file:org.evosuite.runtime.instrumentation.MethodCallReplacementClassAdapter.java

License:Open Source License

@Override
public void visitEnd() {
    if (canChangeSignature && !definesHashCode && !isInterface && RuntimeSettings.mockJVMNonDeterminism) {

        logger.info("No hashCode defined for: " + className + ", superclass = " + superClassName);

        if (superClassName.equals("java.lang.Object")) { //TODO: why only if superclass is Object??? unclear
            Method hashCodeMethod = Method.getMethod("int hashCode()");
            GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, hashCodeMethod, null, null, this);
            mg.loadThis();// w w  w.j  a va2 s. co m
            mg.visitAnnotation(Type.getDescriptor(EvoSuiteExclude.class), true);
            mg.invokeStatic(Type.getType(org.evosuite.runtime.System.class),
                    Method.getMethod("int identityHashCode(Object)"));
            mg.returnValue();
            mg.endMethod();
        }

    }

    /*
     * If the class is serializable, then doing any change (adding hashCode, static reset, etc)
     * will change the serialVersionUID if it is not defined in the class.
     * Hence, if it is not defined, we have to define it to
     * avoid problems in serialising the class, as reading Master will not do instrumentation.
     * The serialVersionUID HAS to be the same as the un-instrumented class
     */
    if (!definesUid && !isInterface && RuntimeSettings.applyUIDTransformation) {
        ClassLoader threadCL = Thread.currentThread().getContextClassLoader();
        try {
            ClassLoader evoCL = MethodCallReplacementClassAdapter.class.getClassLoader();
            Thread.currentThread().setContextClassLoader(evoCL);

            Class<?> clazz = Class.forName(className.replace('/', '.'), false, evoCL);

            if (Serializable.class.isAssignableFrom(clazz)) {
                ObjectStreamClass c = ObjectStreamClass.lookup(clazz);
                long serialID = c.getSerialVersionUID();
                logger.info("Adding serialId to class " + className);
                visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL, "serialVersionUID",
                        "J", null, serialID);
            }
        } catch (ClassNotFoundException e) {
            logger.warn("Failed to add serialId to class " + className + ": " + e.getMessage());
        } catch (NoClassDefFoundError e) {
            logger.warn("Failed to add serialId to class " + className + ": " + e.getMessage());

        } finally {
            Thread.currentThread().setContextClassLoader(threadCL);
        }
    }

    super.visitEnd();
}

From source file:org.evosuite.runtime.instrumentation.RemoveFinalClassAdapter.java

License:Open Source License

/**
 * Remove "final" accessor from class definition
 *//*from   w ww. j a  v a2  s . c o m*/
@Override
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {
    if ((access & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL) {
        finalClasses.add(name.replace('/', '.'));
    }
    super.visit(version, access & ~Opcodes.ACC_FINAL, name, signature, superName, interfaces);
}

From source file:org.evosuite.runtime.instrumentation.RemoveFinalClassAdapter.java

License:Open Source License

/**
 * Remove "final" accessor from inner class definition
 *///  w  ww.j  a  v a  2  s  . co  m
@Override
public void visitInnerClass(String name, String outerName, String innerName, int access) {
    if ((access & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL) {
        finalClasses.add(name.replace('/', '.'));
    }
    super.visitInnerClass(name, outerName, innerName, access & ~Opcodes.ACC_FINAL);
}

From source file:org.evosuite.runtime.instrumentation.RemoveFinalClassAdapter.java

License:Open Source License

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
    return super.visitMethod(access & ~Opcodes.ACC_FINAL, name, desc, signature, exceptions);
}

From source file:org.evosuite.seeding.PrimitiveClassAdapter.java

License:Open Source License

/** {@inheritDoc} */
@Override//from w w w .  j av  a 2s . c o  m
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {

    // We don't use serial numbers because they can be very long and are not used in any branches
    if (!"serialVersionUID".equals(name)) {
        if (DependencyAnalysis.isTargetClassName(className)) {
            poolManager.addSUTConstant(value);
            poolManager.addSUTConstant(Type.getType(desc));
        } else {
            poolManager.addNonSUTConstant(value);
        }
        if (isEnum) {
            // static final values in enums are likely enum values
            if ((access & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL
                    && (access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC) {
                if (DependencyAnalysis.isTargetClassName(className)) {
                    poolManager.addSUTConstant(name);
                } else {
                    poolManager.addNonSUTConstant(name);
                }
            }
        }
        // primitive_pool.add(value);
    }
    return super.visitField(access, name, desc, signature, value);
}

From source file:org.evosuite.symbolic.instrument.AccessFlags.java

License:Open Source License

static boolean isFinal(int access) {
    return is(access, Opcodes.ACC_FINAL);
}

From source file:org.formulacompiler.compiler.internal.bytecode.ArrayAccessorCompiler.java

License:Open Source License

private ArrayAccessorCompiler(SectionCompiler _section, String _name, ExpressionNodeForArrayReference _node,
        String _elementDescriptor) {
    super(_section, Opcodes.ACC_FINAL, _name, "()[" + _elementDescriptor);
    this.arrayNode = _node;
    this.arrayDescriptor = "[" + _elementDescriptor;
    this.elementDescriptor = _elementDescriptor;
}