当前位置: 首页>>代码示例>>Java>>正文


Java SourceLineAnnotation.getStartLine方法代码示例

本文整理汇总了Java中edu.umd.cs.findbugs.SourceLineAnnotation.getStartLine方法的典型用法代码示例。如果您正苦于以下问题:Java SourceLineAnnotation.getStartLine方法的具体用法?Java SourceLineAnnotation.getStartLine怎么用?Java SourceLineAnnotation.getStartLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.umd.cs.findbugs.SourceLineAnnotation的用法示例。


在下文中一共展示了SourceLineAnnotation.getStartLine方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: foundSwitchNoDefault

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
private void foundSwitchNoDefault(SourceLineAnnotation s) {
    LineNumberTable table = getCode().getLineNumberTable();

    if (table != null) {
        int startLine = s.getStartLine();
        int prev = Integer.MIN_VALUE;
        for (LineNumber ln : table.getLineNumberTable()) {
            int thisLineNumber = ln.getLineNumber();
            if (thisLineNumber < startLine && thisLineNumber > prev && ln.getStartPC() < s.getStartBytecode())
                prev = thisLineNumber;
        }
        int diff = startLine - prev;
        if (diff > 5)
            return;

        bugAccumulator.accumulateBug(new BugInstance(this, "SF_SWITCH_NO_DEFAULT", NORMAL_PRIORITY).addClassAndMethod(this),
                s);
    }

}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:21,代码来源:SwitchFallthrough.java

示例2: getSourceLink

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
@SuppressWarnings("boxing")
public @CheckForNull URL getSourceLink(BugInstance b) {
    if (sourceFileLinkPattern == null)
        return null;

    SourceLineAnnotation src = b.getPrimarySourceLineAnnotation();
    String fileName = src.getSourcePath();
    int startLine = src.getStartLine();
    int endLine = src.getEndLine();
    java.util.regex.Matcher m = sourceFileLinkPattern.matcher(fileName);
    boolean isMatch = m.matches();
    if (isMatch)
        try {
            URL link;
            if (startLine > 0)
                link = new URL(String.format(sourceFileLinkFormatWithLine, m.group(1),
                        startLine, startLine - 10, endLine));
            else
                link = new URL(String.format(sourceFileLinkFormat, m.group(1)));
            return link;
        } catch (Exception e) {
            AnalysisContext.logError("Error generating source link for " + src, e);
        }

    return null;

}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:28,代码来源:AbstractCloud.java

示例3: run

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
public void run() {
    frame.getSourceCodeTextPane().setEditorKit(src.getEditorKit());
    StyledDocument document = src.getDocument();
    frame.getSourceCodeTextPane().setDocument(document);
    String sourceFile = mySourceLine.getSourceFile();
    if (sourceFile == null || sourceFile.equals("<Unknown>")) {
        sourceFile = mySourceLine.getSimpleClassName();
    }
    int startLine = mySourceLine.getStartLine();
    int endLine = mySourceLine.getEndLine();
    frame.setSourceTab(sourceFile + " in " + mySourceLine.getPackageName(), myBug);

    int originLine = (startLine + endLine) / 2;
    LinkedList<Integer> otherLines = new LinkedList<Integer>();
    // 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);
            }
        }
    }
               
    if (startLine >= 0 && endLine >= 0)
        frame.getSourceCodeTextPane().scrollLinesToVisible(startLine, endLine, otherLines);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:35,代码来源:SourceCodeDisplay.java

示例4: highlight

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
/**
 * @param src
 * @param sourceAnnotation
 */
private void highlight(JavaSourceDocument src, SourceLineAnnotation sourceAnnotation, Color color) {

    int startLine = sourceAnnotation.getStartLine();
    if (startLine == -1)
        return;
    String sourceFile = sourceAnnotation.getSourcePath();
    String sourceFile2 = src.getSourceFile().getFullFileName();
    if (!java.io.File.separator.equals(String.valueOf(SourceLineAnnotation.CANONICAL_PACKAGE_SEPARATOR))) {
        sourceFile2 = sourceFile2.replace(java.io.File.separatorChar, SourceLineAnnotation.CANONICAL_PACKAGE_SEPARATOR);
    }
    if (!sourceFile2.endsWith(sourceFile))
        return;
    src.getHighlightInformation().setHighlight(startLine, sourceAnnotation.getEndLine(), color);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:19,代码来源:SourceCodeDisplay.java

示例5: findEnclosingMethod

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
public static MethodDeclaration findEnclosingMethod(CompilationUnit workingUnit,
        SourceLineAnnotation primarySourceLineAnnotation) {

    MethodFinder mf = new MethodFinder(workingUnit, primarySourceLineAnnotation.getStartLine());
    workingUnit.accept(mf);

    return mf.enclosingMethod;
}
 
开发者ID:kjlubick,项目名称:fb-contrib-eclipse-quick-fixes,代码行数:9,代码来源:TraversalUtil.java

示例6: generateBugInstance

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
/**
 * Uses immutable values, updated priority and added lines for reporting
 * 
 * @param taintedInsideMethod true if not influenced by method arguments
 * @return new bug instance filled with information
 */
public BugInstance generateBugInstance(boolean taintedInsideMethod) {
    BugInstance bug = new BugInstance(detector, bugType, originalPriority);
    bug.addClassAndMethod(classContext.getJavaClass(), method);
    bug.addSourceLine(SourceLineAnnotation.fromVisitedInstruction(classContext, method, instructionHandle));
    addMessage(bug, "Sink method", sinkMethod);

    for(TaintLocation source : unknownSources) {
        addMessage(bug, "Unknown source", source.getTaintSource());
        //md.getSlashedClassName() + "." + md.getName() + md.getSignature());
    }

    addMessage(bug, "Sink method", sinkMethod);
    if (sinkPriority != UNKNOWN_SINK_PRIORITY) {
        // higher priority is represented by lower integer
        if (sinkPriority < originalPriority) {
            bug.setPriority(sinkPriority);
            addMessage(bug, "Method usage", "with tainted arguments detected");
        } else if (sinkPriority > originalPriority) {
            bug.setPriority(Priorities.LOW_PRIORITY);
            addMessage(bug, "Method usage", "detected only with safe arguments");
        }
    } else if (!taintedInsideMethod) {
        addMessage(bug, "Method usage", "not detected");
    }
    Collections.sort(lines);
    SourceLineAnnotation annotation = null;
    for (Iterator<SourceLineAnnotation> it = lines.iterator(); it.hasNext();) {
        SourceLineAnnotation prev = annotation;
        annotation = it.next();
        if (prev != null && prev.getClassName().equals(annotation.getClassName())
                && prev.getStartLine() == annotation.getStartLine()) {
            // keep only one annotation per line
            it.remove();
        }
    }
    for (SourceLineAnnotation sourceLine : lines) {
        bug.addSourceLine(sourceLine);
    }
    return bug;
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:47,代码来源:InjectionSink.java

示例7: checkForSelfOperation

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
/**
 * @param classContext
 *            TODO
 * @param location
 * @param method
 *            TODO
 * @param methodGen
 *            TODO
 * @param sourceFile
 *            TODO
 * @param string
 * @throws DataflowAnalysisException
 */
private void checkForSelfOperation(ClassContext classContext, Location location, ValueNumberDataflow valueNumberDataflow,
        String op, Method method, MethodGen methodGen, String sourceFile) throws DataflowAnalysisException {
    ValueNumberFrame frame = valueNumberDataflow.getFactAtLocation(location);
    if (!frame.isValid())
        return;
    Instruction ins = location.getHandle().getInstruction();
    int opcode = ins.getOpcode();
    int offset = 1;
    if (opcode == LCMP || opcode == LXOR || opcode == LAND || opcode == LOR || opcode == LSUB)
        offset = 2;
    ValueNumber v0 = frame.getStackValue(0);
    ValueNumber v1 = frame.getStackValue(offset);
    if (!v1.equals(v0))
        return;
    if (v0.hasFlag(ValueNumber.CONSTANT_CLASS_OBJECT) || v0.hasFlag(ValueNumber.CONSTANT_VALUE))
        return;

    int priority = HIGH_PRIORITY;
    if (opcode == ISUB || opcode == LSUB || opcode == INVOKEINTERFACE || opcode == INVOKEVIRTUAL)
        priority = NORMAL_PRIORITY;
    XField field = ValueNumberSourceInfo.findXFieldFromValueNumber(method, location, v0, frame);
    BugAnnotation annotation;
    String prefix;
    if (field != null) {
        if (field.isVolatile())
            return;
        if (true)
            return; // don't report these; too many false positives
        annotation = FieldAnnotation.fromXField(field);
        prefix = "SA_FIELD_SELF_";
    } else {
        annotation = ValueNumberSourceInfo.findLocalAnnotationFromValueNumber(method, location, v0, frame);
        prefix = "SA_LOCAL_SELF_";
        if (opcode == ISUB)
            return; // only report this if simple detector reports it
    }
    if (annotation == null)
        return;
    SourceLineAnnotation sourceLine = SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen, sourceFile,
            location.getHandle());
    int line = sourceLine.getStartLine();
    BitSet occursMultipleTimes = classContext.linesMentionedMultipleTimes(method);
    if (line > 0 && occursMultipleTimes.get(line))
        return;
    BugInstance bug = new BugInstance(this, prefix + op, priority).addClassAndMethod(methodGen, sourceFile).add(annotation)
            .addSourceLine(classContext, methodGen, sourceFile, location.getHandle());
    bugReporter.reportBug(bug);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:62,代码来源:FindSelfComparison2.java

示例8: sawOpcode

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
@Override
public void sawOpcode(int seen) {
    if (isRegisterStore() || isReturn(seen) || isSwitch(seen) || seen == INVOKEINTERFACE || seen == INVOKESPECIAL
            || seen == INVOKESTATIC || seen == INVOKEVIRTUAL || seen == PUTFIELD || seen == PUTSTATIC) {
        reset();
    } else if (stack.getStackDepth() == 0) {
        check: if (emptyStackLocations.size() > 1) {
            int first = emptyStackLocations.get(emptyStackLocations.size() - 2);
            int second = emptyStackLocations.get(emptyStackLocations.size() - 1);
            int third = getPC();
            if (third - second == second - first) {
                int endOfFirstSegment = prevOpcodeLocations.get(emptyStackLocations.size() - 1);
                int endOfSecondSegment = oldPC;
                int opcodeAtEndOfFirst = getCodeByte(endOfFirstSegment);
                int opcodeAtEndOfSecond = getCodeByte(endOfSecondSegment);

                if (!isBranch(opcodeAtEndOfFirst) || !isBranch(opcodeAtEndOfSecond)) {
                    break check;
                }
                if (opcodeAtEndOfFirst == Opcodes.GOTO || opcodeAtEndOfSecond == Opcodes.GOTO) {
                    break check;
                }
                if (opcodeAtEndOfFirst != opcodeAtEndOfSecond
                        && !areOppositeBranches(opcodeAtEndOfFirst, opcodeAtEndOfSecond)) {
                    break check;
                }

                byte[] code = getCode().getCode();
                if (first == endOfFirstSegment) {
                    break check;
                }
                for (int i = first; i < endOfFirstSegment; i++) {
                    if (code[i] != code[i - first + second]) {
                        break check;
                    }
                }
                if (false) {
                    System.out.println(getFullyQualifiedMethodName());
                    System.out.println(first + " ... " + endOfFirstSegment + " : " + OPCODE_NAMES[opcodeAtEndOfFirst]);
                    System.out.println(second + " ... " + endOfSecondSegment + " : " + OPCODE_NAMES[opcodeAtEndOfSecond]);
                }
                SourceLineAnnotation firstSourceLine = SourceLineAnnotation.fromVisitedInstructionRange(getClassContext(),
                        this, first, endOfFirstSegment - 1);
                SourceLineAnnotation secondSourceLine = SourceLineAnnotation.fromVisitedInstructionRange(getClassContext(),
                        this, second, endOfSecondSegment - 1);

                int priority = HIGH_PRIORITY;
                if (firstSourceLine.getStartLine() == -1 || firstSourceLine.getStartLine() != secondSourceLine.getEndLine()) {
                    priority++;
                }
                if (stack.isJumpTarget(second)) {
                    priority++;
                }
                Integer firstTarget = branchTargets.get(endOfFirstSegment);
                Integer secondTarget = branchTargets.get(endOfSecondSegment);
                if (firstTarget == null || secondTarget == null) {
                    break check;
                }
                if (firstTarget.equals(secondTarget) && opcodeAtEndOfFirst == opcodeAtEndOfSecond
                        || firstTarget.intValue() == getPC()) {
                    // identical checks;
                } else {
                    // opposite checks
                    priority += 2;
                }

                BugInstance bug = new BugInstance(this, "RpC_REPEATED_CONDITIONAL_TEST", priority).addClassAndMethod(this)
                        .add(firstSourceLine).add(secondSourceLine);
                bugReporter.reportBug(bug);
            }
        }
        emptyStackLocations.add(getPC());
        prevOpcodeLocations.add(oldPC);

    }
    oldPC = getPC();
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:78,代码来源:RepeatedConditionals.java

示例9: checkForSelfOperation

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
/**
 * @param classContext
 *            TODO
 * @param location
 * @param method
 *            TODO
 * @param methodGen
 *            TODO
 * @param sourceFile
 *            TODO
 * @param string
 * @throws DataflowAnalysisException
 */
private void checkForSelfOperation(ClassContext classContext, Location location, ValueNumberDataflow valueNumberDataflow,
        String op, Method method, MethodGen methodGen, String sourceFile) throws DataflowAnalysisException {
    ValueNumberFrame frame = valueNumberDataflow.getFactAtLocation(location);
    if (!frame.isValid())
        return;
    Instruction ins = location.getHandle().getInstruction();
    int opcode = ins.getOpcode();
    int offset = 1;
    if (opcode == LCMP || opcode == LXOR || opcode == LAND || opcode == LOR || opcode == LSUB)
        offset = 2;
    ValueNumber v0 = frame.getStackValue(0);
    ValueNumber v1 = frame.getStackValue(offset);
    if (!v1.equals(v0))
        return;
    if (v0.hasFlag(ValueNumber.CONSTANT_CLASS_OBJECT) || v0.hasFlag(ValueNumber.CONSTANT_VALUE))
        return;

    int priority = HIGH_PRIORITY;
    if (opcode == ISUB || opcode == LSUB || opcode == INVOKEINTERFACE || opcode == INVOKEVIRTUAL)
        priority = NORMAL_PRIORITY;
    XField field = ValueNumberSourceInfo.findXFieldFromValueNumber(method, location, v0, frame);
    BugAnnotation annotation;
    String prefix;
    if (field != null) {
        if (field.isVolatile())
            return;
        if (true)
            return; // don't report these; too many false positives
        annotation = FieldAnnotation.fromXField(field);
        prefix = "SA_FIELD_SELF_";
    } else {
        annotation = ValueNumberSourceInfo.findLocalAnnotationFromValueNumber(method, location, v0, frame);
        prefix = "SA_LOCAL_SELF_";
        if (opcode == ISUB)
            return; // only report this if simple detector reports it
    }
    if (annotation == null)
        return;
    SourceLineAnnotation sourceLine = SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen, sourceFile,
            location.getHandle());
    int line = sourceLine.getStartLine();
    BitSet occursMultipleTimes = classContext.linesMentionedMultipleTimes(method);
    if (line > 0 && occursMultipleTimes.get(line))
        return;
    BugInstance bug = new BugInstance(this, prefix + op, priority).addClassAndMethod(methodGen, sourceFile);
    if (ins instanceof InvokeInstruction)
        bug.addCalledMethod(classContext.getConstantPoolGen(), (InvokeInstruction) ins);

    bug.add(annotation)
            .addSourceLine(classContext, methodGen, sourceFile, location.getHandle());
    bugReporter.reportBug(bug);
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:66,代码来源:FindSelfComparison2.java

示例10: hasLineInfo

import edu.umd.cs.findbugs.SourceLineAnnotation; //导入方法依赖的package包/类
private static boolean hasLineInfo(SourceLineAnnotation annotation) {
    return annotation != null && annotation.getStartLine() > 0;
}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:4,代码来源:MarkerUtil.java


注:本文中的edu.umd.cs.findbugs.SourceLineAnnotation.getStartLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。