Package edu.umd.cs.findbugs.classfile

Examples of edu.umd.cs.findbugs.classfile.ClassDescriptor


            @Override
            public void visitInnerClass(String name, String outerName, String innerName, int access) {
                if (name.equals(slashedClassName) && outerName != null) {
                    if (cBuilder instanceof ClassInfo.Builder) {
                        ClassDescriptor outerClassDescriptor = DescriptorFactory.createClassDescriptor(outerName);
                        ((ClassInfo.Builder) cBuilder).setImmediateEnclosingClass(outerClassDescriptor);
                        ((ClassInfo.Builder) cBuilder).setAccessFlags(access);
                    }

                }

            }

            @Override
            public MethodVisitor visitMethod(final int access, final String methodName, final String methodDesc,
                    String signature, String[] exceptions) {
                if (cBuilder instanceof ClassInfo.Builder) {
                    final MethodInfo.Builder mBuilder = new MethodInfo.Builder(slashedClassName, methodName, methodDesc, access);
                    mBuilder.setSourceSignature(signature);
                    mBuilder.setThrownExceptions(exceptions);
                    if ((access & Opcodes.ACC_SYNCHRONIZED) != 0) {
                        mBuilder.setUsesConcurrency();
                    }

                    return new ClassParserMethodVisitor(calledClassSet, mBuilder, methodName, access, methodDesc, cBuilder);

                }
                return null;
            }

            @Override
            public void visitOuterClass(String owner, String name, String desc) {

            }

            @Override
            public void visitSource(String arg0, String arg1) {
                if (cBuilder instanceof ClassInfo.Builder) {
                    ((ClassInfo.Builder) cBuilder).setSource(arg0);
                }

            }
        }, ClassReader.SKIP_FRAMES);
        HashSet<ClassDescriptor> referencedClassSet = new HashSet<ClassDescriptor>();

        // collect class references

        int constantPoolCount = classReader.readUnsignedShort(8);
        int offset = 10;
        char[] buf = new char[1024];
        // System.out.println("constant pool count: " + constantPoolCount);
        for (int count = 1; count < constantPoolCount; count++) {
            int tag = classReader.readByte(offset);

            int size;
            switch (tag) {
            case Constants.CONSTANT_Methodref:
            case Constants.CONSTANT_InterfaceMethodref:
            case Constants.CONSTANT_Fieldref:
            case Constants.CONSTANT_Integer:
            case Constants.CONSTANT_Float:
            case Constants.CONSTANT_NameAndType:
            case Constants.CONSTANT_InvokeDynamic:
                size = 5;
                break;
            case Constants.CONSTANT_Long:
            case Constants.CONSTANT_Double:
                size = 9;
                count++;
                break;
            case Constants.CONSTANT_Utf8:
                size = 3 + classReader.readUnsignedShort(offset + 1);
                break;
            case Constants.CONSTANT_Class:
                @SlashedClassName
                String className = classReader.readUTF8(offset + 1, buf);
                if (className.indexOf('[') >= 0) {
                    ClassParser.extractReferencedClassesFromSignature(referencedClassSet, className);
                } else if (ClassName.isValidClassName(className)) {
                    ClassDescriptor classDescriptor = DescriptorFactory.instance().getClassDescriptor(className);
                    referencedClassSet.add(classDescriptor);
                }
                size = 3;
                break;
            case Constants.CONSTANT_String:
View Full Code Here


                return;
            }
            if (ClassParserUsingASM.this.slashedClassName.equals(owner)) {
                return;
            }
            ClassDescriptor classDescriptor = DescriptorFactory.instance().getClassDescriptor(owner);
            calledClassSet.add(classDescriptor);

        }
View Full Code Here

    private static ClassDescriptor singleThreadedServlet = DescriptorFactory
            .createClassDescriptor("javax/servlet/SingleThreadModel");

    public static boolean isServletField(XField field) {
        ClassDescriptor classDescriptor = field.getClassDescriptor();

        try {
            Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2();
            if (subtypes2.isSubtype(classDescriptor, servlet) && !subtypes2.isSubtype(classDescriptor, singleThreadedServlet)) {
                return true;
            }
        } catch (ClassNotFoundException e) {
            assert true;
        }
        if (classDescriptor.getClassName().endsWith("Servlet")) {
            return true;
        }
        return false;
    }
View Full Code Here

                // True if variable is itself declared as a Map
                if ("java.util.Map".equals(d.getDottedClassName())) {
                    return true;
                }
                XClass classNameAndInfo = Global.getAnalysisCache().getClassAnalysis(XClass.class, d);
                ClassDescriptor is[] = classNameAndInfo.getInterfaceDescriptorList();
                d = classNameAndInfo.getSuperclassDescriptor();
                for (ClassDescriptor i : is) {
                    if ("java.util.Map".equals(i.getDottedClassName())) {
                        return true;
                    }
View Full Code Here

    @Override
    public void visit(JavaClass obj) {
        isTigerOrHigher = obj.getMajor() >= MAJOR_1_5;
        try {
            Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2();
            ClassDescriptor me = getClassDescriptor();
            if (subtypes2.isSubtype(me, MAP_ENTRY) && subtypes2.isSubtype(me, ITERATOR)) {
                bugReporter.reportBug(new BugInstance(this, "PZ_DONT_REUSE_ENTRY_OBJECTS_IN_ITERATORS", NORMAL_PRIORITY)
                .addClass(this).addString("shouldn't reuse Iterator as a Map.Entry"));
            }
        } catch (ClassNotFoundException e) {
View Full Code Here


        if (seen == INVOKEVIRTUAL && getNameConstantOperand().equals("ordinal") && getSigConstantOperand().equals("()I")) {
            XClass c = getXClassOperand();
            if (c != null) {
                ClassDescriptor superclassDescriptor = c.getSuperclassDescriptor();
                if (superclassDescriptor != null && superclassDescriptor.getClassName().equals("java/lang/Enum")) {
                    enumType = c;
                }
                if (DEBUG) {
                    System.out.println("Saw " + enumType + ".ordinal()");
                }
View Full Code Here

    private boolean isStaticOnlyClass(XClass xClass)  {

        if (xClass.getInterfaceDescriptorList().length > 0) {
            return false;
        }
        ClassDescriptor superclassDescriptor = xClass.getSuperclassDescriptor();
        if (superclassDescriptor == null) {
            return false;
        }
        String superClassName = superclassDescriptor.getClassName();
        if (!superClassName.equals("java/lang/Object")) {
            return false;
        }
        int staticCount = 0;
View Full Code Here

                        .addValueSource(arguments[e.getArgIndex()], getMethod(), getPC()).addSourceLine(this));
                    } else {
                        String aSig = e.getArgumentSignature();
                        char conversion = e.getConversion();
                        if ((conversion == 't' || conversion == 'T') && aSig.charAt(0) == 'L') {
                            ClassDescriptor argDescriptor = DescriptorFactory.createClassDescriptorFromFieldSignature(aSig);
                            assert argDescriptor != null : "sig started with L, should get descriptor";
                            String arg = argDescriptor.toDottedClassName();
                            try {
                                if (Hierarchy.isSubtype(arg,  java.util.Date.class.getName())
                                        || Hierarchy.isSubtype(arg,  java.util.Calendar.class.getName())) {
                                    return;
                                }
View Full Code Here

        }

        // GUI types should not be accessed from multiple threads

        if (signature.charAt(0) == 'L') {
            ClassDescriptor fieldType = DescriptorFactory.createClassDescriptorFromFieldSignature(signature);

            while (fieldType != null) {
                XClass fieldClass;
                try {
                    fieldClass = Global.getAnalysisCache().getClassAnalysis(XClass.class, fieldType);
View Full Code Here

            count(kind);
            if (kind == EqualsKindSummary.KindOfEquals.GETCLASS_GOOD_EQUALS
                    || kind == EqualsKindSummary.KindOfEquals.ABSTRACT_GETCLASS_GOOD_EQUALS
                    || kind == EqualsKindSummary.KindOfEquals.GETCLASS_BAD_EQUALS) {

                ClassDescriptor classDescriptor = getClassDescriptor();
                try {
                    Set<ClassDescriptor> subtypes = AnalysisContext.currentAnalysisContext().getSubtypes2()
                            .getSubtypes(classDescriptor);
                    if (subtypes.size() > 1) {
                        classesWithGetClassBasedEquals.put(classDescriptor, subtypes);
                    }
                } catch (ClassNotFoundException e) {
                    assert true;
                }

            }
            if (kind == EqualsKindSummary.KindOfEquals.INSTANCE_OF_EQUALS
                    || kind == EqualsKindSummary.KindOfEquals.ABSTRACT_INSTANCE_OF) {

                ClassDescriptor classDescriptor = getClassDescriptor();
                try {
                    Set<ClassDescriptor> subtypes = AnalysisContext.currentAnalysisContext().getSubtypes2()
                            .getSubtypes(classDescriptor);
                    if (subtypes.size() > 1) {
                        classesWithInstanceOfBasedEquals.put(classDescriptor, subtypes);
View Full Code Here

TOP

Related Classes of edu.umd.cs.findbugs.classfile.ClassDescriptor

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.