Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.Code


        } else if (etaba != null || etabb != null) {
            return false;
        }
       
        // compare the exception handling details
        Code acode = a.getCode();
        Code bcode = b.getCode();
        CodeException[] acexs = acode.getExceptionTable();
        CodeException[] bcexs = bcode.getExceptionTable();
        if (acexs.length == bcexs.length) {
            for (int i = 0; i < acexs.length; i++) {
                CodeException acex = acexs[i];
                CodeException bcex = bcexs[i];
                if (acex.getCatchType() != bcex.getCatchType() ||
                    acex.getStartPC() != bcex.getStartPC() ||
                    acex.getEndPC() != bcex.getEndPC() ||
                    acex.getHandlerPC() != bcex.getHandlerPC()) {
                    return false;
                }
            }
        }
       
        // finally compare the actual byte codes
        return Arrays.equals(acode.getCode(), bcode.getCode());
    }
View Full Code Here


    public TypeAnalysis(Method method, MethodGen methodGen, CFG cfg, DepthFirstSearch dfs, TypeMerger typeMerger,
            TypeFrameModelingVisitor visitor, RepositoryLookupFailureCallback lookupFailureCallback,
            ExceptionSetFactory exceptionSetFactory) {
        super(dfs);
        this.method = method;
        Code code = method.getCode();
        if (code == null) {
            throw new IllegalArgumentException(method.getName() + " has no code");
        }
        for (Attribute a : code.getAttributes()) {
            if (a instanceof LocalVariableTypeTable) {
                visitor.setLocalTypeTable((LocalVariableTypeTable) a);
            }
        }
        this.methodGen = methodGen;
View Full Code Here

                    String methodName = method.getName();
                    if (!methodName.startsWith("access$")) {
                        continue;
                    }

                    Code code = method.getCode();
                    if (code == null) {
                        continue;
                    }

                    if (DEBUG) {
                        System.out.println("Analyzing " + className + "." + method.getName()
                                + " as an inner-class access method...");
                    }

                    byte[] instructionList = code.getCode();
                    String methodSig = method.getSignature();
                    InstructionCallback callback = new InstructionCallback(javaClass, methodName, methodSig, instructionList);
                    //                    try {
                    new BytecodeScanner().scan(instructionList, callback);
                    //                    } catch (LookupFailure lf) {
View Full Code Here

    public static SourceLineAnnotation forEntireMethod(JavaClass javaClass, @CheckForNull Method method) {
        String sourceFile = javaClass.getSourceFileName();
        if (method == null) {
            return createUnknown(javaClass.getClassName(), sourceFile);
        }
        Code code = method.getCode();
        LineNumberTable lineNumberTable = method.getLineNumberTable();
        if (code == null || lineNumberTable == null) {
            return createUnknown(javaClass.getClassName(), sourceFile);
        }

        return forEntireMethod(javaClass.getClassName(), sourceFile, lineNumberTable, code.getLength());
    }
View Full Code Here

        int endLine = lineNumberTable.getSourceLine(end.getPosition());
        return new SourceLineAnnotation(className, sourceFile, startLine, endLine, start.getPosition(), end.getPosition());
    }

    private static LineNumberTable getLineNumberTable(PreorderVisitor visitor) {
        Code code = visitor.getMethod().getCode();
        if (code == null) {
            return null;
        }
        return code.getLineNumberTable();
    }
View Full Code Here

        return false;
    }

    static SourceLineAnnotation getSourceAnnotationForMethod(String className, String methodName, String methodSig) {
        JavaClassAndMethod targetMethod = null;
        Code code = null;

        try {
            JavaClass targetClass = AnalysisContext.currentAnalysisContext().lookupClass(className);
            targetMethod = Hierarchy.findMethod(targetClass, methodName, methodSig);
            if (targetMethod != null) {
                Method method = targetMethod.getMethod();
                if (method != null) {
                    code = method.getCode();
                }
            }

        } catch (ClassNotFoundException e) {
            AnalysisContext.reportMissingClass(e);
        }
        SourceInfoMap sourceInfoMap = AnalysisContext.currentAnalysisContext().getSourceInfoMap();
        SourceInfoMap.SourceLineRange range = sourceInfoMap.getMethodLine(className, methodName, methodSig);

        if (range != null) {
            return new SourceLineAnnotation(className, AnalysisContext.currentAnalysisContext().lookupSourceFile(className),
                    range.getStart(), range.getEnd(), 0, code == null ? -1 : code.getLength());
        }

        if (sourceInfoMap.fallBackToClassfile() && targetMethod != null) {
            return forEntireMethod(targetMethod.getJavaClass(), targetMethod.getMethod());
        }
View Full Code Here

        int firstLine = Integer.MAX_VALUE;

        try {
            JavaClass targetClass = AnalysisContext.currentAnalysisContext().lookupClass(className);
            for (Method m : targetClass.getMethods()) {
                Code c = m.getCode();
                if (c != null) {
                    LineNumberTable table = c.getLineNumberTable();
                    if (table != null) {
                        for (LineNumber line : table.getLineNumberTable()) {
                            lastLine = Math.max(lastLine, line.getLineNumber());
                            firstLine = Math.min(firstLine, line.getLineNumber());
                        }
View Full Code Here

        // System.out.println(getFullyQualifiedMethodName());
        isPublicStaticVoidMain = method.isPublic() && method.isStatic() && getMethodName().equals("main")
                || cName.toLowerCase().indexOf("benchmark") >= 0;
                prevOpcodeWasReadLine = false;
                Code code = method.getCode();
                if (code != null) {
                    this.exceptionTable = code.getExceptionTable();
                }
                if (this.exceptionTable == null) {
                    this.exceptionTable = new CodeException[0];
                }
                primitiveObjCtorSeen = null;
View Full Code Here

        int position = location.getHandle().getPosition();

        if (calledMethod.getClassName().equals("java.lang.Integer")) {

            ConstantPool constantPool = classContext.getJavaClass().getConstantPool();
            Code code = method.getCode();

            int catchSize;

            catchSize = Util.getSizeOfSurroundingTryBlock(constantPool, code, "java/lang/NumberFormatException", position);
            if (catchSize < Integer.MAX_VALUE) {
View Full Code Here

     * .classfile.IAnalysisCache, java.lang.Object)
     */
    @Override
    public MethodBytecodeSet analyze(IAnalysisCache analysisCache, MethodDescriptor descriptor) throws CheckedAnalysisException {
        Method method = analysisCache.getMethodAnalysis(Method.class, descriptor);
        Code code = method.getCode();
        if (code == null) {
            return null;
        }

        byte[] instructionList = code.getCode();

        // Create callback
        UnpackedBytecodeCallback callback = new UnpackedBytecodeCallback(instructionList.length);

        // Scan the method.
View Full Code Here

TOP

Related Classes of org.apache.bcel.classfile.Code

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.