Package edu.umd.cs.findbugs

Examples of edu.umd.cs.findbugs.SourceLineAnnotation


                }
                sizes.put(path, size + cStat.size());
            }
        }
        for (BugInstance bug : bugs.getCollection()) {
            SourceLineAnnotation source = bug.getPrimarySourceLineAnnotation();

            String packagePath = source.getPackageName().replace('.', '/');
            String key;
            if (packagePath.length() == 0) {
                key = source.getSourceFile();
            } else {
                key = packagePath + "/" + source.getSourceFile();
            }
            StringBuilder buf = hashes.get(key);
            if (buf == null) {
                buf = new StringBuilder();
                hashes.put(key, buf);
            }
            buf.append(bug.getInstanceKey()).append("-").append(source.getStartLine()).append(".")
            .append(source.getStartBytecode()).append(" ");
            Integer count = counts.get(key);
            if (count == null) {
                counts.put(key, 1);
            } else {
                counts.put(key, 1 + count);
View Full Code Here


                assert false;
                Debug.println(e1);
                continue;
            }
            BugInstance myBug = display.bug;
            SourceLineAnnotation mySourceLine = display.source;

            if (myBug == null || mySourceLine == null) {
                frame.clearSourcePane();
                continue;
            }

            try {
                JavaSourceDocument src = getDocument(mySourceLine);
                this.myDocument = src;
                src.getHighlightInformation().clear();
                String primaryKind = mySourceLine.getDescription();
                // Display myBug and mySourceLine
                for (Iterator<BugAnnotation> i = myBug.annotationIterator(); i.hasNext();) {
                    BugAnnotation annotation = i.next();
                    if (annotation instanceof SourceLineAnnotation) {
                        SourceLineAnnotation sourceAnnotation = (SourceLineAnnotation) annotation;
                        if (sourceAnnotation == mySourceLine) {
                            continue;
                        }
                        if (sourceAnnotation.getDescription().equals(primaryKind)) {
                            highlight(src, sourceAnnotation, MAIN_HIGHLIGHT_MORE);
                        } else {
                            highlight(src, sourceAnnotation, ALTERNATIVE_HIGHLIGHT);
                        }
                    }
View Full Code Here

            // show(frame.getSourceCodeTextPane(), document,
            // thisSource);
            for (Iterator<BugAnnotation> i = myBug.annotationIterator(); i.hasNext();) {
                BugAnnotation annotation = i.next();
                if (annotation instanceof SourceLineAnnotation) {
                    SourceLineAnnotation sourceAnnotation = (SourceLineAnnotation) annotation;
                    if (sourceAnnotation != mySourceLine) {
                        // show(frame.getSourceCodeTextPane(),
                        // document, sourceAnnotation);
                        int otherLine = sourceAnnotation.getStartLine();
                        if (otherLine > originLine) {
                            otherLine = sourceAnnotation.getEndLine();
                        }
                        otherLines.add(otherLine);
                    }
                }
            }
View Full Code Here

                BugInstance bugTwo = two.getBug();
                result = bugOne.getPrimaryClass().getClassName().compareTo(bugTwo.getPrimaryClass().getClassName());
                if (result != 0) {
                    return result;
                }
                SourceLineAnnotation oneSource = bugOne.getPrimarySourceLineAnnotation();
                SourceLineAnnotation twoSource = bugTwo.getPrimarySourceLineAnnotation();
                result = oneSource.getClassName().compareTo(twoSource.getClassName());
                if (result != 0) {
                    return result;
                }
                result = compare(oneSource.getStartLine(), twoSource.getStartLine());
                if (result != 0) {
                    return result;
                }
                result = compare(oneSource.getEndLine(), twoSource.getEndLine());
                if (result != 0) {
                    return result;
                }
                result = compare(oneSource.getStartBytecode(), twoSource.getStartBytecode());
                if (result != 0) {
                    return result;
                }
                result = compare(oneSource.getEndBytecode(), twoSource.getEndBytecode());
                return result;

            }
        };
        Collections.sort(mainList, comparator);
View Full Code Here

            String methodSig = inv.getSignature(cpg);
            if ( methodName.equals("assertSame") && methodSig.equals("(Ljava/lang/Object;Ljava/lang/Object;)V")) {
                checkRefComparison(location, jclass, method, methodGen, visitor, typeDataflow, stringComparisonList,
                        refComparisonList);
            } else if ( methodName.equals("assertFalse") && methodSig.equals("(Z)V")) {
                SourceLineAnnotation lastLocation = bugAccumulator.getLastBugLocation();
                InstructionHandle prevHandle = location.getHandle().getPrev();
                if (lastLocation != null && prevHandle != null && lastLocation.getEndBytecode() == prevHandle.getPosition()){
                    bugAccumulator.forgetLastBug();
                    if (DEBUG) {
                        System.out.println("Forgetting last bug due to call to " + className +"." + methodName);
                    }
                }
View Full Code Here

        }

        String sourceFile = jclass.getSourceFileName();
        BugInstance instance = new BugInstance(this, bugPattern, BASE_ES_PRIORITY).addClassAndMethod(methodGen, sourceFile)
                .addType("Ljava/lang/String;").describe(TypeAnnotation.FOUND_ROLE).addSomeSourceForTopTwoStackValues(classContext, method, location);
        SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen,
                sourceFile, location.getHandle());

        WarningWithProperties warn = new WarningWithProperties(instance, propertySet, sourceLineAnnotation, location);
        stringComparisonList.add(warn);
    }
View Full Code Here

        if (xf != null) {
            instance.addField(xf).describe(FieldAnnotation.LOADED_FROM_ROLE);
        } else {
            instance.addSomeSourceForTopTwoStackValues(classContext, method, location);
        }
        SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen,
                sourceFile, location.getHandle());

        refComparisonList.add(new WarningWithProperties(instance, new WarningPropertySet<WarningProperty>(),
                sourceLineAnnotation, location));
    }
View Full Code Here

            OpcodeStack.Item value = e.getValue();
            if (value.isNull() || value.hasConstantValue(0)) {
                priority++;
            }

            SourceLineAnnotation fieldSetAt = SourceLineAnnotation.fromVisitedInstruction(getThisClass(), upcallMethod, pc);

            BugInstance bug = new BugInstance(this, "UR_UNINIT_READ_CALLED_FROM_SUPER_CONSTRUCTOR", priority).addClassAndMethod(
                    this).addField(f);
            bug.addMethod(p.method).describe(MethodAnnotation.METHOD_SUPERCLASS_CONSTRUCTOR)
            .addSourceLine(p.getSourceLineAnnotation()).describe(SourceLineAnnotation.ROLE_CALLED_FROM_SUPERCLASS_AT)
View Full Code Here

     * @return the IResource representing the Java class
     */
    private static @CheckForNull
    IJavaElement getJavaElement(BugInstance bug, IJavaProject project) throws JavaModelException {

        SourceLineAnnotation primarySourceLineAnnotation = bug.getPrimarySourceLineAnnotation();
        PackageMemberAnnotation packageAnnotation = null;
        String packageName = null;
        String qualifiedClassName = null;
        if (primarySourceLineAnnotation == null) {
            packageAnnotation = bug.getPrimaryClass();
            if (packageAnnotation != null) {
                packageName = packageAnnotation.getPackageName();
                qualifiedClassName = packageAnnotation.getClassName();
            }
        } else {
            packageName = primarySourceLineAnnotation.getPackageName();
            qualifiedClassName = primarySourceLineAnnotation.getClassName();
        }
        if (qualifiedClassName == null) {
            return null;
        }

        if (Reporter.DEBUG) {
            System.out.println("Looking up class: " + packageName + ", " + qualifiedClassName);
        }

        Matcher m = fullName.matcher(qualifiedClassName);
        IType type;
        String innerName = null;
        if (m.matches() && m.group(2).length() > 0) {

            String outerQualifiedClassName = m.group(1).replace('$', '.');
            innerName = m.group(2).substring(1);
            // second argument is required to find also secondary types
            type = project.findType(outerQualifiedClassName, (IProgressMonitor) null);

            /*
             * code below only points to the first line of inner class even if
             * this is not a class bug but field bug
             */
            if (type != null && !hasLineInfo(primarySourceLineAnnotation)) {
                completeInnerClassInfo(qualifiedClassName, innerName, type, bug);
            }
        } else {
            // second argument is required to find also secondary types
            type = project.findType(qualifiedClassName.replace('$', '.'), (IProgressMonitor) null);

            // for inner classes, some detectors does not properly report source
            // lines:
            // instead of reporting the first line of inner class, they report
            // first line of parent class
            // in this case we will try to fix this here and point to the right
            // start line
            if (type != null && type.isMember()) {
                if (!hasLineInfo(primarySourceLineAnnotation)) {
                    completeInnerClassInfo(qualifiedClassName, type.getElementName(), type, bug);
                }
            }
        }

        // reassign it as it may be changed for inner classes
        primarySourceLineAnnotation = bug.getPrimarySourceLineAnnotation();

        int startLine;
        /*
         * Eclipse can help us find the line number for fields => we trying to
         * add line info for fields here
         */
        if (primarySourceLineAnnotation != null) {
            startLine = primarySourceLineAnnotation.getStartLine();
            if (startLine <= 0 && bug.getPrimaryField() != null) {
                completeFieldInfo(qualifiedClassName, innerName, type, bug);
            }
        } else {
            if (bug.getPrimaryField() != null) {
View Full Code Here

            return;
        }
        int lineNbr = scanner.getLineNumber(sourceRange.getOffset());
        lineNbr = lineNbr <= 0 ? 1 : lineNbr;
        String sourceFileStr = getSourceFileHint(type, qualifiedClassName);
        field.setSourceLines(new SourceLineAnnotation(qualifiedClassName, sourceFileStr, lineNbr, lineNbr, 0, 0));
    }
View Full Code Here

TOP

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

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.