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.evosuite.setup.CallTreeGenerator.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  w  ww.  jav  a2  s . c  om
 * 
 * @param callTree
 * @param targetClass
 */
@SuppressWarnings("unchecked")
private static void handleSuperClasses(CallTree callTree, 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(callTree, superClass, mn, 0);
            }
        }
    }
    handleSuperClasses(callTree, superClass);

}

From source file:org.evosuite.setup.GetStaticGraphGenerator.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 w ww .  j  av  a 2 s.co m*/
 * 
 * @param staticUsageTree
 * @param targetClass
 */
@SuppressWarnings("unchecked")
private static void handleSuperClasses(GetStaticGraph staticUsageTree, 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(staticUsageTree, superClass, mn, 0);
            }
        }
    }
    handleSuperClasses(staticUsageTree, superClass);

}

From source file:org.evosuite.setup.InheritanceTreeGenerator.java

License:Open Source License

@SuppressWarnings("unchecked")
private static void analyzeClassNode(InheritanceTree inheritanceTree, ClassNode cn, boolean onlyPublic) {

    logger.info("Analyzing class {}", cn.name);

    // Don't load classes already seen from a different CP entry
    if (inheritanceTree.hasClass(cn.name))
        return;//from w  ww.  java  2 s .  c o m

    if ((Opcodes.ACC_INTERFACE & cn.access) != Opcodes.ACC_INTERFACE) {
        for (Object m : cn.methods) {
            MethodNode mn = (MethodNode) m;
            inheritanceTree.addAnalyzedMethod(cn.name, mn.name, mn.desc);
        }
        if ((Opcodes.ACC_ABSTRACT & cn.access) == Opcodes.ACC_ABSTRACT) {
            inheritanceTree.registerAbstractClass(cn.name);
        }
    } else {
        inheritanceTree.registerInterface(cn.name);
    }
    if (onlyPublic) {
        if ((cn.access & Opcodes.ACC_PUBLIC) == 0) {
            return;
        }
        //      } else {
        //         if (!canUse(cn)) {
        //            logger.info("Cannot use "+cn.name);
        //            return;
        //         }
    }

    if (cn.superName != null)
        inheritanceTree.addSuperclass(cn.name, cn.superName, cn.access);

    List<String> interfaces = cn.interfaces;
    for (String interfaceName : interfaces) {
        inheritanceTree.addInterface(cn.name, interfaceName);
    }
}

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

License:Open Source License

static boolean isAbstract(int access) {
    return is(access, Opcodes.ACC_ABSTRACT);
}

From source file:org.evosuite.testcarver.instrument.TransformerUtil.java

License:Open Source License

public static boolean isAbstract(final int access) {
    return (access & Opcodes.ACC_ABSTRACT) != 0;
}

From source file:org.fehrman.jcm.find.Find.java

License:CDDL license

@SuppressWarnings("unchecked")
private String processMethod(MethodNode methodNode) throws Exception
//----------------------------------------------------------------
{
    StringBuilder methodDescription = new StringBuilder();
    String className = null;//w  w  w  .  j a v  a  2s  .c  o  m

    Type returnType = Type.getReturnType(methodNode.desc);
    Type[] argumentTypes = Type.getArgumentTypes(methodNode.desc);

    List<String> thrownInternalClassNames = methodNode.exceptions;

    _logger.entering(CLASS, Thread.currentThread().getStackTrace()[1].getMethodName());

    if ((methodNode.access & Opcodes.ACC_PUBLIC) != 0) {
        methodDescription.append("public ");
    }

    if ((methodNode.access & Opcodes.ACC_PRIVATE) != 0) {
        methodDescription.append("private ");
    }

    if ((methodNode.access & Opcodes.ACC_PROTECTED) != 0) {
        methodDescription.append("protected ");
    }

    if ((methodNode.access & Opcodes.ACC_STATIC) != 0) {
        methodDescription.append("static ");
    }

    if ((methodNode.access & Opcodes.ACC_ABSTRACT) != 0) {
        methodDescription.append("abstract ");
    }

    if ((methodNode.access & Opcodes.ACC_SYNCHRONIZED) != 0) {
        methodDescription.append("synchronized ");
    }

    className = returnType.getClassName();
    if (className != null && className.startsWith(JAVA_LANG)) {
        methodDescription.append(className.substring(JAVA_LANG.length()));
    } else {
        methodDescription.append(className);
    }

    methodDescription.append(" ");
    methodDescription.append(methodNode.name);

    methodDescription.append("(");
    for (int i = 0; i < argumentTypes.length; i++) {
        Type argumentType = argumentTypes[i];

        if (i > 0) {
            methodDescription.append(", ");
        }

        className = argumentType.getClassName();
        if (className != null && className.startsWith(JAVA_LANG)) {
            methodDescription.append(className.substring(JAVA_LANG.length()));
        } else {
            methodDescription.append(className);
        }
    }
    methodDescription.append(")");

    if (!thrownInternalClassNames.isEmpty()) {
        methodDescription.append(" throws ");
        int i = 0;
        for (String thrownInternalClassName : thrownInternalClassNames) {
            if (i > 0) {
                methodDescription.append(", ");
            }

            className = Type.getObjectType(thrownInternalClassName).getClassName();
            if (className != null && className.startsWith(JAVA_LANG)) {
                methodDescription.append(className.substring(JAVA_LANG.length()));
            } else {
                methodDescription.append(className);
            }
            i++;
        }
    }

    _logger.exiting(CLASS, Thread.currentThread().getStackTrace()[1].getMethodName());

    return methodDescription.toString();
}

From source file:org.freud.analysed.classbytecode.parser.asm.AsmClassByteCode.java

License:Apache License

@Override
public boolean isAbstract() {
    return isAccessModifier(Opcodes.ACC_ABSTRACT);
}

From source file:org.gradle.api.internal.tasks.testing.junit.JUnitTestClassDetecter.java

License:Apache License

/**
 * Visits the header of the class./*from  www .  j av a 2s .c  o m*/
 *
 * @param version the class version.
 * @param access the class's access flags (see {@link Opcodes}). This parameter also indicates if the class is
 * deprecated.
 * @param name the internal name of the class (see {@link org.objectweb.asm.Type#getInternalName()
 * getInternalName}).
 * @param signature the signature of this class. May be <tt>null</tt> if the class is not a generic one, and does
 * not extend or implement generic classes or interfaces.
 * @param superName the internal of name of the super class (see {@link org.objectweb.asm.Type#getInternalName()
 * getInternalName}). For interfaces, the super class is {@link Object}. May be <tt>null</tt>, but only for the
 * {@link Object} class.
 * @param interfaces the internal names of the class's interfaces (see {@link org.objectweb.asm.Type#getInternalName()
 * getInternalName}). May be <tt>null</tt>.
 */
public void visit(int version, int access, String name, String signature, String superName,
        String[] interfaces) {
    isAbstract = (access & Opcodes.ACC_ABSTRACT) != 0;

    this.className = name;
    this.superClassName = superName;
}

From source file:org.gradle.initialization.DefaultLegacyTypesSupport.java

License:Apache License

@Override
public byte[] generateSyntheticClass(String name) {
    ClassWriter visitor = new ClassWriter(0);
    visitor.visit(Opcodes.V1_7,/*  w  w  w. j a v a 2  s  .c  o  m*/
            Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_INTERFACE | Opcodes.ACC_ABSTRACT,
            name.replace('.', '/'), null, OBJECT_TYPE.getInternalName(), null);
    visitor.visitEnd();
    return visitor.toByteArray();
}

From source file:org.jacoco.core.internal.analysis.dua.ClassAnalyzer.java

License:Open Source License

/**
 * Visits the header of the class./*from   ww  w  . jav a  2 s . c om*/
 * 
 * @param classNode
 */
public void visit(final ClassNode classNode) {
    final String[] interfaces = classNode.interfaces.toArray(new String[classNode.interfaces.size()]);
    coverage = new DuaClassCoverage(stringPool.get(classNode.name), classid,
            stringPool.get(classNode.signature), stringPool.get(classNode.superName),
            stringPool.get(interfaces));

    int methodId = 0;
    for (final MethodNode method : methods) {
        // Does not instrument:
        // 1. Abstract methods
        if ((method.access & Opcodes.ACC_ABSTRACT) != 0) {
            continue;
        }
        // 2. Static class initialization
        if (method.name.equals("<clinit>")) {
            continue;
        }

        visitMethod(method, methodId++);
    }
}