Example usage for org.objectweb.asm Opcodes ACC_ABSTRACT

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

Introduction

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

Prototype

int ACC_ABSTRACT

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

Click Source Link

Usage

From source file:org.eclipse.pde.api.tools.internal.model.ApiMethod.java

License:Open Source License

@Override
public boolean isDefaultMethod() {
    return ((IApiType) getParent()).isInterface() && (getModifiers() & Opcodes.ACC_ABSTRACT) == 0;
}

From source file:org.eclipse.sisu.scanners.QualifiedTypeVisitor.java

License:Open Source License

@Override
public void visit(final int version, final int access, final String name, final String signature,
        final String superName, final String[] interfaces) {
    if ((access & (Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT | Opcodes.ACC_SYNTHETIC)) == 0) {
        clazzName = name; // concrete type
    }//from ww  w  .  ja  va 2  s. com
}

From source file:org.evosuite.continuous.project.ProjectGraph.java

License:Open Source License

/**
 * Is the given class name representing an abstract class in the SUT?
 * @param className//w ww.  jav a  2  s .c  om
 * @return
 * @throws IllegalArgumentException
 */
public boolean isAbstract(String className) throws IllegalArgumentException {
    checkClass(className);
    ClassNode node = getClassNode(className);
    return (node.access & Opcodes.ACC_ABSTRACT) == Opcodes.ACC_ABSTRACT;
}

From source file:org.evosuite.graphs.cfg.CFGMethodAdapter.java

License:Open Source License

/** {@inheritDoc} */
@Override//from w  ww.j a  va 2  s . c o  m
public void visitEnd() {
    logger.debug("Creating CFG of " + className + "." + methodName);
    boolean isExcludedMethod = excludeMethod || EXCLUDE.contains(methodName);
    boolean isMainMethod = plain_name.equals("main") && Modifier.isStatic(access);

    List<MethodInstrumentation> instrumentations = new ArrayList<MethodInstrumentation>();
    if (DependencyAnalysis.shouldInstrument(className, methodName)) {
        if (ArrayUtil.contains(Properties.CRITERION, Criterion.DEFUSE)
                || ArrayUtil.contains(Properties.CRITERION, Criterion.ALLDEFS)) {
            instrumentations.add(new BranchInstrumentation());
            instrumentations.add(new DefUseInstrumentation());
        } else if (ArrayUtil.contains(Properties.CRITERION, Criterion.MUTATION)
                || ArrayUtil.contains(Properties.CRITERION, Criterion.WEAKMUTATION)
                || ArrayUtil.contains(Properties.CRITERION, Criterion.ONLYMUTATION)
                || ArrayUtil.contains(Properties.CRITERION, Criterion.STRONGMUTATION)) {
            instrumentations.add(new BranchInstrumentation());
            instrumentations.add(new MutationInstrumentation());
        } else {
            instrumentations.add(new BranchInstrumentation());
        }
    } else {
        //instrumentations.add(new BranchInstrumentation());
    }

    boolean executeOnMain = false;
    boolean executeOnExcluded = false;

    for (MethodInstrumentation instrumentation : instrumentations) {
        executeOnMain = executeOnMain || instrumentation.executeOnMainMethod();
        executeOnExcluded = executeOnExcluded || instrumentation.executeOnExcludedMethods();
    }

    // super.visitEnd();
    // Generate CFG of method
    MethodNode mn = (AnnotatedMethodNode) mv;

    boolean checkForMain = false;
    if (Properties.CONSIDER_MAIN_METHODS) {
        checkForMain = true;
    } else {
        checkForMain = !isMainMethod || executeOnMain;
    }

    // Only instrument if the method is (not main and not excluded) or (the
    // MethodInstrumentation wants it anyway)
    if (checkForMain && (!isExcludedMethod || executeOnExcluded) && (access & Opcodes.ACC_ABSTRACT) == 0
            && (access & Opcodes.ACC_NATIVE) == 0) {

        logger.info("Analyzing method " + methodName + " in class " + className);

        // MethodNode mn = new CFGMethodNode((MethodNode)mv);
        // System.out.println("Generating CFG for "+ className+"."+mn.name +
        // " ("+mn.desc +")");

        BytecodeAnalyzer bytecodeAnalyzer = new BytecodeAnalyzer();
        logger.info("Generating CFG for method " + methodName);

        try {

            bytecodeAnalyzer.analyze(classLoader, className, methodName, mn);
            logger.trace("Method graph for " + className + "." + methodName + " contains "
                    + bytecodeAnalyzer.retrieveCFGGenerator().getRawGraph().vertexSet().size() + " nodes for "
                    + bytecodeAnalyzer.getFrames().length + " instructions");
            // compute Raw and ActualCFG and put both into GraphPool
            bytecodeAnalyzer.retrieveCFGGenerator().registerCFGs();
            logger.info("Created CFG for method " + methodName);

            if (DependencyAnalysis.shouldInstrument(className, methodName)) {
                if (!methods.get(classLoader).containsKey(className))
                    methods.get(classLoader).put(className, new HashSet<String>());

                // add the actual instrumentation
                logger.info("Instrumenting method " + methodName + " in class " + className);
                for (MethodInstrumentation instrumentation : instrumentations)
                    instrumentation.analyze(classLoader, mn, className, methodName, access);

                handleBranchlessMethods();
                String id = className + "." + methodName;
                if (isUsable()) {
                    methods.get(classLoader).get(className).add(id);
                    logger.debug("Counting: " + id);
                }
            }
        } catch (AnalyzerException e) {
            logger.error("Analyzer exception while analyzing " + className + "." + methodName + ": " + e);
            e.printStackTrace();
        }

    } else {
        logger.debug("NOT Creating CFG of " + className + "." + methodName + ": " + checkForMain + ", "
                + ((!isExcludedMethod || executeOnExcluded)) + ", " + ((access & Opcodes.ACC_ABSTRACT) == 0)
                + ", " + ((access & Opcodes.ACC_NATIVE) == 0));
        super.visitEnd();
    }
    mn.accept(next);
}

From source file:org.evosuite.instrumentation.BooleanTestabilityTransformation.java

License:Open Source License

/**
 * Apply testability transformation to an individual method
 * //from   www.  java 2s  .c  o  m
 * @param mn
 */
private void transformMethod(MethodNode mn) {
    logger.info("Transforming method {}{}", mn.name, mn.desc);

    //currentCFG = GraphPool.getActualCFG(className, mn.name + mn.desc);

    // TODO: Skipping interfaces for now, but will need to handle Booleans in interfaces!
    if ((mn.access & Opcodes.ACC_ABSTRACT) == Opcodes.ACC_ABSTRACT)
        return;

    String origDesc = getOriginalDesc(className, mn.name, mn.desc);
    logger.info("Analyzing {} for TT, signature {}/{}", mn.name, origDesc, mn.desc);
    try {
        Analyzer a = new Analyzer(
                new BooleanValueInterpreter(origDesc, (mn.access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC));
        a.analyze(className, mn);
        currentFrames = a.getFrames();
    } catch (Exception e) {
        logger.info("1. Error during analysis: {}", e);
        //e.printStackTrace();
        // TODO: Handle error
    }
    generateCDG(mn);
    currentMethodNode = mn;
    // First expand ifs without else/*
    new ImplicitElseTransformer(this).transform(mn);
    try {
        Analyzer a = new Analyzer(
                new BooleanValueInterpreter(origDesc, (mn.access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC));
        a.analyze(className, mn);
        currentFrames = a.getFrames();
    } catch (Exception e) {
        logger.info("2. Error during analysis: {}", e);
        //e.printStackTrace();
        // TODO: Handle error
    }

    //      BytecodeInstructionPool.reRegisterMethodNode(mn, className, mn.name + mn.desc);
    // Replace all bitwise operators
    logger.info("Transforming Boolean bitwise operators");
    new BitwiseOperatorTransformer(this).transform(mn);

    // Transform IFEQ/IFNE to IFLE/IFGT
    logger.info("Transforming Boolean IFs");
    new BooleanIfTransformer(this).transform(mn);

    // Insert call to BooleanHelper.get after ICONST_0/1 or Boolean fields
    logger.info("Transforming Boolean definitions");
    new BooleanDefinitionTransformer(this).transform(mn);

    // Replace all instanceof comparisons
    logger.info("Transforming instanceof");
    new InstanceOfTransformer().transform(mn);

    // Replace all calls to methods/fields returning booleans
    new BooleanCallsTransformer(this).transform(mn);

    // Transform all flag based comparisons
    logger.info("Transforming Boolean distances");
    new BooleanDistanceTransformer(this).transform(mn);
    mn.maxStack += 3;

    // Replace all boolean arrays
    new BooleanArrayTransformer().transform(mn);

    new BooleanArrayIndexTransformer(getArrayFrames(mn)).transform(mn);

    // Replace all boolean return values
    logger.info("Transforming Boolean return values");
    new BooleanReturnTransformer(this).transform(mn);

    //      GraphPool.clear(className, mn.name + mn.desc);
    //      BytecodeInstructionPool.clear(className, mn.name + mn.desc);
    //      BranchPool.clear(className, mn.name + mn.desc);

    // Actually this should be done automatically by the ClassWriter...
    // +2 because we might do a DUP2
    mn.maxStack += 1;
}

From source file:org.evosuite.instrumentation.PurityAnalysisClassVisitor.java

License:Open Source License

/** {@inheritDoc} */
@Override// w ww.j  ava  2 s.co m
public MethodVisitor visitMethod(int methodAccess, String name, String descriptor, String signature,
        String[] exceptions) {

    if (visitingInterface == true) {
        purityAnalyzer.addInterfaceMethod(className.replace('/', '.'), name, descriptor);
    } else {
        purityAnalyzer.addMethod(className.replace('/', '.'), name, descriptor);
        if ((methodAccess & Opcodes.ACC_ABSTRACT) != Opcodes.ACC_ABSTRACT) {
            purityAnalyzer.addMethodWithBody(className.replace('/', '.'), name, descriptor);
        } else {
            // The declaration of this method is abstract. So 
            // there is no method body for this method in this class
        }
    }

    MethodVisitor mv = super.visitMethod(methodAccess, name, descriptor, signature, exceptions);
    PurityAnalysisMethodVisitor purityAnalysisMethodVisitor = new PurityAnalysisMethodVisitor(className, name,
            descriptor, mv, purityAnalyzer);
    MethodEntry methodEntry = new MethodEntry(className, name, descriptor);
    this.method_adapters.put(methodEntry, purityAnalysisMethodVisitor);
    return purityAnalysisMethodVisitor;
}

From source file:org.evosuite.instrumentation.testability.BooleanTestabilityTransformation.java

License:Open Source License

/**
 * Apply testability transformation to an individual method
 * /*  w  w w . j a v  a2s.c o m*/
 * @param mn
 */
private void transformMethod(MethodNode mn) {
    logger.info("Transforming method " + mn.name + mn.desc);

    //currentCFG = GraphPool.getActualCFG(className, mn.name + mn.desc);

    // TODO: Skipping interfaces for now, but will need to handle Booleans in interfaces!
    if ((mn.access & Opcodes.ACC_ABSTRACT) == Opcodes.ACC_ABSTRACT)
        return;

    String origDesc = getOriginalDesc(className, mn.name, mn.desc);
    logger.info("Analyzing " + mn.name + " for TT, signature " + origDesc + "/" + mn.desc);
    try {
        Analyzer a = new Analyzer(
                new BooleanValueInterpreter(origDesc, (mn.access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC));
        a.analyze(className, mn);
        currentFrames = a.getFrames();
    } catch (Exception e) {
        logger.info("1. Error during analysis: " + e);
        //e.printStackTrace();
        // TODO: Handle error
    }
    generateCDG(mn);
    currentMethodNode = mn;
    // First expand ifs without else/*
    new ImplicitElseTransformer(this).transform(mn);
    try {
        Analyzer a = new Analyzer(
                new BooleanValueInterpreter(origDesc, (mn.access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC));
        a.analyze(className, mn);
        currentFrames = a.getFrames();
    } catch (Exception e) {
        logger.info("2. Error during analysis: " + e);
        //e.printStackTrace();
        // TODO: Handle error
    }

    //      BytecodeInstructionPool.reRegisterMethodNode(mn, className, mn.name + mn.desc);
    // Replace all bitwise operators
    logger.info("Transforming Boolean bitwise operators");
    new BitwiseOperatorTransformer(this).transform(mn);

    // Transform IFEQ/IFNE to IFLE/IFGT
    logger.info("Transforming Boolean IFs");
    new BooleanIfTransformer(this).transform(mn);

    // Insert call to BooleanHelper.get after ICONST_0/1 or Boolean fields
    logger.info("Transforming Boolean definitions");
    new BooleanDefinitionTransformer(this).transform(mn);

    // Replace all instanceof comparisons
    logger.info("Transforming instanceof");
    new InstanceOfTransformer().transform(mn);

    // Replace all calls to methods/fields returning booleans
    new BooleanCallsTransformer(this).transform(mn);

    // Transform all flag based comparisons
    logger.info("Transforming Boolean distances");
    new BooleanDistanceTransformer(this).transform(mn);
    mn.maxStack += 3;

    // Replace all boolean arrays
    new BooleanArrayTransformer().transform(mn);

    new BooleanArrayIndexTransformer(getArrayFrames(mn)).transform(mn);

    // Replace all boolean return values
    logger.info("Transforming Boolean return values");
    new BooleanReturnTransformer(this).transform(mn);

    //      GraphPool.clear(className, mn.name + mn.desc);
    //      BytecodeInstructionPool.clear(className, mn.name + mn.desc);
    //      BranchPool.clear(className, mn.name + mn.desc);

    // Actually this should be done automatically by the ClassWriter...
    // +2 because we might do a DUP2
    mn.maxStack += 1;
}

From source file:org.evosuite.junit.DetermineSUT.java

License:Open Source License

@SuppressWarnings("unchecked")
private boolean isJUnitTest(ClassNode cn) throws IOException {
    // We do not consider abstract classes
    if ((cn.access & Opcodes.ACC_ABSTRACT) == Opcodes.ACC_ABSTRACT)
        return false;

    if (hasJUnitSuperclass(cn))
        return true;

    List<MethodNode> methods = cn.methods;
    for (MethodNode mn : methods) {
        List<AnnotationNode> annotations = mn.visibleAnnotations;
        if (annotations != null) {
            for (AnnotationNode an : annotations) {
                if (an.desc.equals("Lorg/junit/Test;")
                        || an.desc.equals("L" + PackageInfo.getNameWithSlash(EvoSuiteTest.class) + ";"))
                    return true;
            }/* w  ww . j av a2s. com*/
        }
    }

    return false;
}

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

License:Open Source License

/**
 * If we want to have the calltree also for the superclasses, we need to
 * determine which methods are callable//from   ww  w  .  j  a  va  2s . c o  m
 * 
 * @param callTree
 * @param targetClass
 */
@SuppressWarnings("unchecked")
public void handleSuperClasses(ClassNode targetClass) {
    String superClassName = targetClass.superName;
    if (superClassName == null || superClassName.isEmpty())
        return;

    if (superClassName.equals("java/lang/Object"))
        return;

    logger.debug("Getting casts for superclass: " + superClassName);
    ClassNode superClass = DependencyAnalysis.getClassNode(superClassName);
    List<MethodNode> methods = superClass.methods;
    for (MethodNode mn : methods) {
        logger.debug("Method: " + mn.name);

        // Do not check super-constructors
        if (mn.name.equals("<init>"))
            continue;
        if (mn.name.equals("<clinit>"))
            continue;

        // Skip abstract etc
        if ((mn.access & Opcodes.ACC_ABSTRACT) == Opcodes.ACC_ABSTRACT)
            continue;

        // Do not handle classes if they are overridden by the subclass
        if ((mn.access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC) {
            handleMethodNode(superClass, mn, 0);
        }
    }
    handleSuperClasses(superClass);

}

From source file:org.evosuite.setup.callgraph.CallGraphGenerator.java

License:Open Source License

/**
 * If we want to have the calltree also for the superclasses, we need to
 * determine which methods are callable// www.java  2  s.c  o m
 * 
 * @param callGraph
 * @param targetClass
 */
@SuppressWarnings("unchecked")
private static void handleSuperClasses(CallGraph callGraph, ClassNode targetClass) {
    String superClassName = targetClass.superName;
    if (superClassName == null || superClassName.isEmpty())
        return;

    if (superClassName.equals("java/lang/Object"))
        return;

    logger.debug("Creating calltree for superclass: " + superClassName);
    ClassNode superClass = DependencyAnalysis.getClassNode(superClassName);
    List<MethodNode> methods = superClass.methods;
    for (MethodNode mn : methods) {
        logger.debug("Method: " + mn.name);

        // Do not check super-constructors
        if (mn.name.equals("<init>"))
            continue;
        if (mn.name.equals("<clinit>"))
            continue;

        // Skip abstract etc
        if ((mn.access & Opcodes.ACC_ABSTRACT) == Opcodes.ACC_ABSTRACT)
            continue;

        // Do not handle classes if they are overridden by the subclass
        if ((mn.access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC) {
            if (!isOverridden(mn.name + mn.desc)) {
                handleMethodNode(callGraph, superClass, mn, 0);
            }
        }
    }
    handleSuperClasses(callGraph, superClass);
}