All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.umd.cs.findbugs.classfile.engine.ClassParserUsingASM Maven / Gradle / Ivy

There is a newer version: 4.8.6
Show newest version
/*
 * FindBugs - Find Bugs in Java programs
 * Copyright (C) 2003-2008 University of Maryland
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package edu.umd.cs.findbugs.classfile.engine;

import java.util.BitSet;
import java.util.HashSet;
import java.util.TreeSet;

import javax.annotation.CheckForNull;

import org.apache.bcel.Const;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Handle;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.TypePath;
import org.objectweb.asm.TypeReference;

import edu.umd.cs.findbugs.ba.SignatureParser;
import edu.umd.cs.findbugs.classfile.ClassDescriptor;
import edu.umd.cs.findbugs.classfile.DescriptorFactory;
import edu.umd.cs.findbugs.classfile.ICodeBaseEntry;
import edu.umd.cs.findbugs.classfile.InvalidClassFileFormatException;
import edu.umd.cs.findbugs.classfile.analysis.AnnotationValue;
import edu.umd.cs.findbugs.classfile.analysis.ClassInfo;
import edu.umd.cs.findbugs.classfile.analysis.ClassInfo.Builder;
import edu.umd.cs.findbugs.classfile.analysis.ClassNameAndSuperclassInfo;
import edu.umd.cs.findbugs.classfile.analysis.FieldInfo;
import edu.umd.cs.findbugs.classfile.analysis.MethodInfo;
import edu.umd.cs.findbugs.classfile.engine.asm.FindBugsASM;
import edu.umd.cs.findbugs.internalAnnotations.SlashedClassName;
import edu.umd.cs.findbugs.util.ClassName;

/**
 * @author William Pugh
 */
public class ClassParserUsingASM implements ClassParserInterface {

    // static final boolean NO_SHIFT_INNER_CLASS_CTOR =
    // SystemProperties.getBoolean("classparser.noshift");

    private static final BitSet RETURN_OPCODE_SET = new BitSet();
    static {
        RETURN_OPCODE_SET.set(Opcodes.ARETURN);
        RETURN_OPCODE_SET.set(Opcodes.IRETURN);
        RETURN_OPCODE_SET.set(Opcodes.LRETURN);
        RETURN_OPCODE_SET.set(Opcodes.DRETURN);
        RETURN_OPCODE_SET.set(Opcodes.FRETURN);
        RETURN_OPCODE_SET.set(Opcodes.RETURN);
    }

    private final ClassReader classReader;

    private @SlashedClassName String slashedClassName;

    //    private final ClassDescriptor expectedClassDescriptor;

    private final ICodeBaseEntry codeBaseEntry;



    /**
     * @author pugh
     */
    private final class ClassParserMethodVisitor extends AbstractMethodVisitor {
        /**
         *
         */
        private final TreeSet calledClassSet;

        /**
         *
         */
        private final MethodInfo.Builder mBuilder;

        /**
         *
         */
        private final String methodName;

        /**
         *
         */
        private final int access;

        /**
         *
         */
        private final String methodDesc;

        /**
         *
         */
        private final ClassNameAndSuperclassInfo.Builder cBuilder;

        boolean sawReturn;

        boolean sawNormalThrow = false;

        boolean sawUnsupportedThrow = false;

        boolean sawSystemExit = false;

        boolean sawBranch = false;

        boolean sawBackBranch = false;

        int methodCallCount = 0;

        int fieldInstructionCount = 0;

        boolean sawStubThrow = false;

        boolean justSawInitializationOfUnsupportedOperationException;

        boolean isBridge;

        String bridgedMethodSignature;

        IdentityMethodState identityState =
                IdentityMethodState.INITIAL;

        ParameterLoadState parameterLoadState = ParameterLoadState.OTHER;

        int parameterForLoadState;

        StubState stubState = StubState.INITIAL;

        boolean isAccessMethod;

        String accessOwner, accessName, accessDesc;

        boolean accessForField;

        boolean accessIsStatic;

        HashSet




© 2015 - 2024 Weber Informatics LLC | Privacy Policy