Package edu.umd.cs.findbugs

Examples of edu.umd.cs.findbugs.ClassAnnotation


        }
        if (equalsObjectIsAbstract) {
            // no errors reported
        } else if (!hasHashCode && (hasEqualsObject || hasEqualsSelf)) {
            EqualsKindSummary.KindOfEquals equalsKind = AnalysisContext.currentAnalysisContext().getEqualsKindSummary()
                    .get(new ClassAnnotation(obj.getClassName()));
            if (equalsKind == EqualsKindSummary.KindOfEquals.ALWAYS_FALSE) {
                return;
            }
            if (usesDefaultHashCode) {
                int priority = HIGH_PRIORITY;
View Full Code Here


                if (AnalysisContext.currentAnalysisContext().isApplicationClass(getThisClass())) {
                    bugReporter
                    .reportBug(new BugInstance(this, "EQ_UNUSUAL", Priorities.NORMAL_PRIORITY).addClassAndMethod(this));
                }
            }
            ClassAnnotation classAnnotation = new ClassAnnotation(getDottedClassName());
            equalsKindSummary.put(classAnnotation, kind);

            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);
                    }
                } catch (ClassNotFoundException e) {
                    assert true;
                }

            }

            String superClassName = getSuperclassName().replace('/', '.');
            if (!superClassName.equals("java.lang.Object")) {
                parentMap.put(classAnnotation, new ClassAnnotation(superClassName));
            }
            equalsMethod.put(classAnnotation, getMethodDescriptor());

        }
        bugAccumulator.reportAccumulatedBugs();
View Full Code Here

    public void report() {

        if (false) {
            Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2();
            for (Map.Entry<ClassDescriptor, Set<ClassDescriptor>> e : classesWithGetClassBasedEquals.entrySet()) {
                ClassAnnotation parentClass = ClassAnnotation.fromClassDescriptor(e.getKey());
                XClass xParent = AnalysisContext.currentXFactory().getXClass(e.getKey());
                if (xParent == null) {
                    continue;
                }
                EqualsKindSummary.KindOfEquals parentKind = equalsKindSummary.get(parentClass);
                for (ClassDescriptor child : e.getValue()) {
                    if (child.equals(e.getKey())) {
                        continue;
                    }
                    XClass xChild = AnalysisContext.currentXFactory().getXClass(child);
                    if (xChild == null) {
                        continue;
                    }
                    ClassAnnotation childClass = ClassAnnotation.fromClassDescriptor(child);
                    EqualsKindSummary.KindOfEquals childKind = equalsKindSummary.get(childClass);
                    int fieldsOfInterest = 0;
                    for (XField f : xChild.getXFields()) {
                        if (!f.isStatic() && !f.isSynthetic()) {
                            fieldsOfInterest++;
                        }
                    }
                    int grandchildren = -1;
                    try {

                        grandchildren = subtypes2.getSubtypes(child).size();
                    } catch (ClassNotFoundException e1) {
                        assert true;
                    }
                    System.out.println(parentKind + " " + childKind + " " + parentClass + " " + childClass + " "
                            + fieldsOfInterest + " " + grandchildren);
                    try {
                        if (grandchildren >= 2) {
                            for (ClassDescriptor g : subtypes2.getSubtypes(child)) {
                                if (!g.equals(child)) {
                                    System.out.println("  " + g);
                                }
                            }
                        }
                    } catch (ClassNotFoundException e1) {
                        assert true;
                    }

                }

            }
            int overridden = 0, total = 0;
            for (Map.Entry<ClassDescriptor, Set<ClassDescriptor>> e : classesWithInstanceOfBasedEquals.entrySet()) {
                ClassAnnotation parentClass = ClassAnnotation.fromClassDescriptor(e.getKey());
                XClass xParent = AnalysisContext.currentXFactory().getXClass(e.getKey());
                if (xParent == null) {
                    continue;
                }
                EqualsKindSummary.KindOfEquals parentKind = equalsKindSummary.get(parentClass);
                boolean isOverridden = false;
                for (ClassDescriptor child : e.getValue()) {
                    if (child.equals(e.getKey())) {
                        continue;
                    }
                    XClass xChild = AnalysisContext.currentXFactory().getXClass(child);
                    if (xChild == null) {
                        continue;
                    }
                    ClassAnnotation childClass = ClassAnnotation.fromClassDescriptor(child);
                    EqualsKindSummary.KindOfEquals childKind = equalsKindSummary.get(childClass);
                    if (childKind != null) {
                        isOverridden = true;
                    }
                }
                total++;
                if (isOverridden) {
                    overridden++;
                }
                System.out.println("IS_OVERRIDDEN: " + e.getKey().getClassName());
            }
            System.out.println("Instance of equals: " + total + " subclassed, " + overridden + " overrridden");
            for (Map.Entry<EqualsKindSummary.KindOfEquals, Integer> e : count.entrySet()) {
                System.out.println(e);
            }

        }

        for (Map.Entry<ClassAnnotation, ClassAnnotation> e : parentMap.entrySet()) {
            ClassAnnotation childClass = e.getKey();
            EqualsKindSummary.KindOfEquals childKind = equalsKindSummary.get(childClass);
            ClassAnnotation parentClass = e.getValue();
            EqualsKindSummary.KindOfEquals parentKind = equalsKindSummary.get(parentClass);

            if (childKind == EqualsKindSummary.KindOfEquals.INSTANCE_OF_EQUALS
                    && parentKind == EqualsKindSummary.KindOfEquals.INSTANCE_OF_EQUALS) {
                bugReporter.reportBug(new BugInstance(this, "EQ_OVERRIDING_EQUALS_NOT_SYMMETRIC", NORMAL_PRIORITY)
View Full Code Here

        }
        if (check.isEmpty()) {
            return;
        }

        ClassAnnotation c = bugInstance.getPrimaryClass();
        @DottedClassName
        String packageName = c.getPackageName();

        while (true) {
            if (check.contains(packageName)) {
                getDelegate().reportBug(bugInstance);
                return;
View Full Code Here

                    } else {
                        //                        newlyDeadBugs++;

                        BugInstance newBug = (BugInstance) bug.clone();

                        ClassAnnotation classBugFoundIn = bug.getPrimaryClass();
                        String className = classBugFoundIn.getClassName();
                        String sourceFile = classBugFoundIn.getSourceFileName();
                        boolean fixed = sourceFile != null && analyzedSourceFiles.contains(sourceFile)
                                || newCollection.getProjectStats().getClassStats(className) != null;
                        if (fixed) {
                            if (!copyDeadBugs) {
                                continue;
                            }
                            newBug.setRemovedByChangeOfPersistingClass(true);
                            newBug.setLastVersion(lastSequence);
                        } else {
                            //                            deadBugInDeadCode++;
                            if (!incrementalAnalysis) {
                                newBug.setLastVersion(lastSequence);
                            }
                        }

                        if (newBug.isDead() && newBug.getFirstVersion() > newBug.getLastVersion()) {
                            throw new IllegalStateException("Illegal Version range: " + newBug.getFirstVersion() + ".."
                                    + newBug.getLastVersion());
                        }
                        resultCollection.add(newBug, false);
                    }
                }
            }
        }
        // Copy matched bugs
        for (BugInstance bug : newCollection.getCollection()) {
            BugInstance newBug = (BugInstance) bug.clone();
            if (mapFromNewToOldBug.containsKey(bug)) {
                BugInstance origWarning = mapFromNewToOldBug.get(bug);

                mergeBugHistory(origWarning, newBug);
                // handle getAnnotationText()/setAnnotationText() and
                // designation key
                BugDesignation designation = newBug.getUserDesignation();
                if (designation != null) {
                    designation.merge(origWarning.getUserDesignation());
                }
                else {
                    newBug.setUserDesignation(origWarning.getUserDesignation()); // clone??
                }

                //                persistantBugs++;
            } else {
                newBug.setFirstVersion(lastSequence + 1);
                //                addedBugs++;

                ClassAnnotation classBugFoundIn = bug.getPrimaryClass();

                String className = classBugFoundIn.getClassName();
                if (origCollection.getProjectStats().getClassStats(className) != null) {
                    newBug.setIntroducedByChangeOfExistingClass(true);
                    // System.out.println("added bug to existing code " +
                    // newBug.getUniqueId() + " : " + newBug.getAbbrev() + " in
                    // " + classBugFoundIn);
View Full Code Here

                        warningsByField.put(fieldDescriptor, warnings);
                    }
                    warnings.add(warning);
                }

                ClassAnnotation clazz = warning.getPrimaryClass();
                if (clazz != null) {
                    ClassDescriptor classDesc = clazz.getClassDescriptor();
                    if(field != null && classDesc.equals(field.getClassDescriptor())) {
                        continue;
                    }
                    if (method != null && classDesc.equals(method.getClassDescriptor())) {
                        continue;
View Full Code Here

        }
    }

    private void suppressWarning(int parameter, String pattern) {
        String className = getDottedClassName();
        ClassAnnotation clazz = new ClassAnnotation(className);
        suppressionMatcher.addSuppressor(new ParameterWarningSuppressor(pattern, clazz, MethodAnnotation.fromVisitedMethod(this),
                parameter));

    }
View Full Code Here

    }

    private void suppressWarning(String pattern) {
        String className = getDottedClassName();
        ClassAnnotation clazz = new ClassAnnotation(className);
        if (className.endsWith(".package-info")) {
            suppressionMatcher.addPackageSuppressor(new PackageWarningSuppressor(pattern, getPackageName().replace('/', '.')));
        } else if (visitingMethod()) {
            suppressionMatcher
            .addSuppressor(new MethodWarningSuppressor(pattern, clazz, MethodAnnotation.fromVisitedMethod(this)));
View Full Code Here

    Component bugSummaryComponent(BugAnnotation value, BugInstance bug) {
        JLabel label = new JLabel();
        label.setFont(label.getFont().deriveFont(Driver.getFontSize()));
        label.setFont(label.getFont().deriveFont(Font.PLAIN));
        label.setForeground(Color.BLACK);
        ClassAnnotation primaryClass = bug.getPrimaryClass();

        String sourceCodeLabel = L10N.getLocalString("summary.source_code", "source code.");
        String summaryLine = L10N.getLocalString("summary.line", "Line");
        String summaryLines = L10N.getLocalString("summary.lines", "Lines");
        String clickToGoToText = L10N.getLocalString("tooltip.click_to_go_to", "Click to go to");
View Full Code Here

    }

    private String printSummary(BugInstance... bugs) {
        for (BugInstance bug : bugs) {
            bugCollection.add(bug);
            ClassAnnotation cls = bug.getPrimaryClass();
            projectStats.addClass(cls.getClassName(), cls.getSourceFileName(), false, 100);
        }

        cloud.printCloudSummary(new PrintWriter(summary), Arrays.asList(bugs), new String[0]);
        return trimWhitespace(summary.toString());
    }
View Full Code Here

TOP

Related Classes of edu.umd.cs.findbugs.ClassAnnotation

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.