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


Java LocalVariableAnnotation类代码示例

本文整理汇总了Java中edu.umd.cs.findbugs.LocalVariableAnnotation的典型用法代码示例。如果您正苦于以下问题:Java LocalVariableAnnotation类的具体用法?Java LocalVariableAnnotation怎么用?Java LocalVariableAnnotation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: reportNullDeref

import edu.umd.cs.findbugs.LocalVariableAnnotation; //导入依赖的package包/类
private void reportNullDeref(WarningPropertySet<WarningProperty> propertySet, Location location, String type, int priority,
        BugAnnotation cause, @CheckForNull BugAnnotation variable) {

    BugInstance bugInstance = new BugInstance(this, type, priority).addClassAndMethod(classContext.getJavaClass(), method);
    bugInstance.add(cause);
    if (variable != null)
        bugInstance.add(variable);
    else
        bugInstance.add(new LocalVariableAnnotation("?", -1, -1));
    bugInstance.addSourceLine(classContext, method, location).describe("SOURCE_LINE_DEREF");

    if (FindBugsAnalysisFeatures.isRelaxedMode()) {
        WarningPropertyUtil.addPropertiesForDataMining(propertySet, classContext, method, location);
    }
    addPropertiesForDereferenceLocations(propertySet, Collections.singleton(location));

    propertySet.decorateBugInstance(bugInstance);

    bugReporter.reportBug(bugInstance);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:21,代码来源:NoiseNullDeref.java

示例2: reportPossibleBug

import edu.umd.cs.findbugs.LocalVariableAnnotation; //导入依赖的package包/类
void reportPossibleBug(BugInstance bug) {
    int catchSize = Util.getSizeOfSurroundingTryBlock(getConstantPool(), getCode(), "java/io/EOFException", getPC());
    if (catchSize < Integer.MAX_VALUE)
        bug.lowerPriorityALot();
    else {
        catchSize = Util.getSizeOfSurroundingTryBlock(getConstantPool(), getCode(), "java/lang/NoSuchElementException",
                getPC());
        if (catchSize < Integer.MAX_VALUE)
            bug.lowerPriorityALot();
        else {
            LocalVariableAnnotation lv = bug.getPrimaryLocalVariableAnnotation();
            if (lv == null && getMethodName().equals("run"))
                bug.lowerPriority();
        }
    }
    bugReporter.reportBug(bug);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:18,代码来源:InfiniteLoop.java

示例3: reportNullDeref

import edu.umd.cs.findbugs.LocalVariableAnnotation; //导入依赖的package包/类
private void reportNullDeref(WarningPropertySet<WarningProperty> propertySet, Location location, String type, int priority,
        @CheckForNull
        BugAnnotation variable) {

    BugInstance bugInstance = new BugInstance(this, type, priority).addClassAndMethod(classContext.getJavaClass(), method);
    if (variable != null)
        bugInstance.add(variable);
    else
        bugInstance.add(new LocalVariableAnnotation("?", -1, -1));
    bugInstance.addSourceLine(classContext, method, location).describe("SOURCE_LINE_DEREF");

    if (FindBugsAnalysisFeatures.isRelaxedMode()) {
        WarningPropertyUtil.addPropertiesForDataMining(propertySet, classContext, method, location);
    }
    addPropertiesForDereferenceLocations(propertySet, Collections.singleton(location), false);

    propertySet.decorateBugInstance(bugInstance);

    bugReporter.reportBug(bugInstance);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:21,代码来源:FindNullDeref.java

示例4: findLocalAnnotationFromValueNumber

import edu.umd.cs.findbugs.LocalVariableAnnotation; //导入依赖的package包/类
public static LocalVariableAnnotation findLocalAnnotationFromValueNumber(Method method, Location location,
        ValueNumber valueNumber, ValueNumberFrame vnaFrame) {

    if (vnaFrame == null || vnaFrame.isBottom() || vnaFrame.isTop())
        return null;

    LocalVariableAnnotation localAnnotation = null;
    for (int i = 0; i < vnaFrame.getNumLocals(); i++) {
        if (valueNumber.equals(vnaFrame.getValue(i))) {
            InstructionHandle handle = location.getHandle();
            InstructionHandle prev = handle.getPrev();
            if (prev == null) 
                continue;
            int position1 = prev.getPosition();
            int position2 = handle.getPosition();
            localAnnotation = LocalVariableAnnotation.getLocalVariableAnnotation(method, i, position1, position2);
            if (localAnnotation != null)
                return localAnnotation;
        }
    }
    return null;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:23,代码来源:ValueNumberSourceInfo.java

示例5: reportVacuousBitOperation

import edu.umd.cs.findbugs.LocalVariableAnnotation; //导入依赖的package包/类
/**
 * @param seen
 * @param item
 */
private void reportVacuousBitOperation(int seen, OpcodeStack.Item item) {
    if (item.getConstant() == null)
        accumulator
                .accumulateBug(
                        new BugInstance(this, "INT_VACUOUS_BIT_OPERATION", NORMAL_PRIORITY)
                                .addClassAndMethod(this)
                                .addString(OPCODE_NAMES[seen])
                                .addOptionalAnnotation(
                                        LocalVariableAnnotation.getLocalVariableAnnotation(getMethod(), item, getPC())), this);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:15,代码来源:DumbMethods.java

示例6: visit

import edu.umd.cs.findbugs.LocalVariableAnnotation; //导入依赖的package包/类
@Override
public void visit(LocalVariable obj) {
    if (isReservedName(obj.getName())) {
        LocalVariableAnnotation var = new LocalVariableAnnotation(obj.getName(), obj.getIndex(), obj.getStartPC());
        SourceLineAnnotation source = SourceLineAnnotation.fromVisitedInstruction(getClassContext(), this, obj.getStartPC());
        BugInstance bug = new BugInstance(this, "NM_FUTURE_KEYWORD_USED_AS_IDENTIFIER", NORMAL_PRIORITY)
                .addClassAndMethod(this).add(var).add(source);
        bugReporter.reportBug(bug);
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:11,代码来源:DontUseEnum.java

示例7: visitClassContext

import edu.umd.cs.findbugs.LocalVariableAnnotation; //导入依赖的package包/类
public void visitClassContext(ClassContext classContext) {

        JavaClass jclass = classContext.getJavaClass();

        for (Method method : jclass.getMethods()) {
            XMethod xmethod = XFactory.createXMethod(classContext.getJavaClass(), method);
            ParameterProperty nonnullParameters = AnalysisContext.currentAnalysisContext().getUnconditionalDerefParamDatabase()
                    .getProperty(xmethod.getMethodDescriptor());
            if (nonnullParameters != null) {
                for (int p : nonnullParameters.iterable()) {
                    TypeQualifierAnnotation directTypeQualifierAnnotation = TypeQualifierApplications
                            .getDirectTypeQualifierAnnotation(xmethod, p, nonnullTypeQualifierValue);
                    if (directTypeQualifierAnnotation != null && directTypeQualifierAnnotation.when == When.UNKNOWN) {
                        //
                        // The LocalVariableAnnotation is constructed using the
                        // local variable
                        // number of the parameter, not the parameter number.
                        //
                        int paramLocal = xmethod.isStatic() ? p : p + 1;

                        reporter.reportBug(new BugInstance(this, "NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE",
                                NORMAL_PRIORITY).addClassAndMethod(jclass, method).add(
                                LocalVariableAnnotation.getParameterLocalVariableAnnotation(method, paramLocal)));

                    }

                }
            }
        }

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

示例8: checkForSelfOperation

import edu.umd.cs.findbugs.LocalVariableAnnotation; //导入依赖的package包/类
private void checkForSelfOperation(int opCode, String op) {
    {

        OpcodeStack.Item item0 = stack.getStackItem(0);
        OpcodeStack.Item item1 = stack.getStackItem(1);

        if (item0.getSignature().equals("D") || item0.getSignature().equals("F"))
            return;
        if (item1.getSignature().equals("D") || item1.getSignature().equals("F"))
            return;

        XField field0 = item0.getXField();
        XField field1 = item1.getXField();
        int fr0 = item0.getFieldLoadedFromRegister();
        int fr1 = item1.getFieldLoadedFromRegister();
        if (field0 != null && field0.equals(field1) && fr0 != -1 && fr0 == fr1)
            bugAccumulator.accumulateBug(new BugInstance(this, "SA_FIELD_SELF_" + op, NORMAL_PRIORITY)
                    .addClassAndMethod(this).addField(field0), this);

        else if (opCode == IXOR && item0.equals(item1)) {
            LocalVariableAnnotation localVariableAnnotation = LocalVariableAnnotation.getLocalVariableAnnotation(this, item0);
            if (localVariableAnnotation != null)
                bugAccumulator.accumulateBug(
                        new BugInstance(this, "SA_LOCAL_SELF_" + op, HIGH_PRIORITY).addClassAndMethod(this).add(
                                localVariableAnnotation), this);
        } else if (opCode == ISUB && registerLoadCount >= 2) { // let
                                                               // FindSelfComparison2
                                                               // report
                                                               // this; more
                                                               // accurate
            bugAccumulator.accumulateBug(
                    new BugInstance(this, "SA_LOCAL_SELF_" + op, (opCode == ISUB || opCode == LSUB
                            || opCode == INVOKEINTERFACE || opCode == INVOKEVIRTUAL) ? NORMAL_PRIORITY : HIGH_PRIORITY)
                            .addClassAndMethod(this).add(
                                    LocalVariableAnnotation.getLocalVariableAnnotation(getMethod(), whichRegister, getPC(),
                                            getPC() - 1)), this);
        }
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:40,代码来源:FindSelfComparison.java

示例9: findAnnotationFromValueNumber

import edu.umd.cs.findbugs.LocalVariableAnnotation; //导入依赖的package包/类
/**
 * @param method
 * @param location
 * @param valueNumber
 * @param vnaFrame
 * @param partialRole
 *            TODO
 * @return the annotation
 */
public static @CheckForNull
BugAnnotation findAnnotationFromValueNumber(Method method, Location location, ValueNumber valueNumber,
        ValueNumberFrame vnaFrame, @CheckForNull String partialRole) {
    if (location.getHandle().getInstruction() instanceof ACONST_NULL) {
        StringAnnotation nullConstant = new StringAnnotation("null");
        nullConstant.setDescription(StringAnnotation.STRING_NONSTRING_CONSTANT_ROLE);
        return nullConstant;
    }
    LocalVariableAnnotation ann = ValueNumberSourceInfo.findLocalAnnotationFromValueNumber(method, location, valueNumber,
            vnaFrame);
    if (ann != null && partialRole != null)
        ann.setDescription("LOCAL_VARIABLE_" + partialRole);

    if (ann != null && ann.isSignificant()) {
        return ann;
    }
    FieldAnnotation field = ValueNumberSourceInfo.findFieldAnnotationFromValueNumber(method, location, valueNumber, vnaFrame);
    if (field != null) {
        if (partialRole != null)
            field.setDescription("FIELD_" + partialRole);

        return field;
    }
    if (ann != null)
        return ann;
    return null;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:37,代码来源:ValueNumberSourceInfo.java

示例10: match

import edu.umd.cs.findbugs.LocalVariableAnnotation; //导入依赖的package包/类
public boolean match(BugInstance bugInstance) {
    LocalVariableAnnotation localAnnotation = bugInstance.getPrimaryLocalVariableAnnotation();
    if (localAnnotation == null) {
        return false;
    }
    if (!name.match(localAnnotation.getName())) {
        return false;
    }
    return true;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:11,代码来源:LocalMatcher.java

示例11: sawOpcode

import edu.umd.cs.findbugs.LocalVariableAnnotation; //导入依赖的package包/类
@Override
public void sawOpcode(int seen) {
    if (!inConstructor)
        return;
    if (uninitializedFieldReadAndCheckedForNonnull != null) {
        if (seen == NEW && getClassConstantOperand().endsWith("Exception"))
            uninitializedFieldReadAndCheckedForNonnull.raisePriority();
        uninitializedFieldReadAndCheckedForNonnull = null;
    }

    if (seen == ALOAD_0) {
        thisOnTOS = true;
        return;
    }

    if (seen == PUTFIELD && getClassConstantOperand().equals(getClassName()))
        initializedFields.add(FieldAnnotation.fromReferencedField(this));

    else if (thisOnTOS && seen == GETFIELD && getClassConstantOperand().equals(getClassName())) {
        UnreadFieldsData unreadFields = AnalysisContext.currentAnalysisContext().getUnreadFieldsData();
        XField xField = XFactory.createReferencedXField(this);
        FieldAnnotation f = FieldAnnotation.fromReferencedField(this);
        int nextOpcode = 0xff & codeBytes[getPC() + 3];
        if (nextOpcode != POP && !initializedFields.contains(f) && declaredFields.contains(f) && !containerFields.contains(f)
                && !unreadFields.isContainerField(xField)) {
            // System.out.println("Next opcode: " +
            // OPCODE_NAMES[nextOpcode]);
            LocalVariableAnnotation possibleTarget = LocalVariableAnnotation.findMatchingIgnoredParameter(getClassContext(),
                    getMethod(), getNameConstantOperand(), xField.getSignature());
            if (possibleTarget == null)
                possibleTarget = LocalVariableAnnotation.findUniqueBestMatchingParameter(getClassContext(), getMethod(),
                        getNameConstantOperand(), getSigConstantOperand());
            int priority = unreadFields.getReadFields().contains(xField) ? NORMAL_PRIORITY : LOW_PRIORITY;
            boolean priorityLoweredBecauseOfIfNonnullTest = false;
            if (possibleTarget != null)
                priority--;
            else {
                FieldSummary fieldSummary = AnalysisContext.currentAnalysisContext().getFieldSummary();
                if (fieldSummary.callsOverriddenMethodsFromSuperConstructor(getClassDescriptor()))
                    priority++;
                else if (nextOpcode == IFNONNULL) {
                    priority++;
                    priorityLoweredBecauseOfIfNonnullTest = true;
                }
            }

            BugInstance bug = new BugInstance(this, "UR_UNINIT_READ", priority).addClassAndMethod(this).addField(f)
                    .addOptionalAnnotation(possibleTarget).addSourceLine(this);
            pendingBugs.add(bug);
            if (priorityLoweredBecauseOfIfNonnullTest) {
                uninitializedFieldReadAndCheckedForNonnull = bug;
            }
            initializedFields.add(f);
        }
    } else if ((seen == INVOKESPECIAL && !(getNameConstantOperand().equals("<init>") && !getClassConstantOperand().equals(
            getClassName())))
            || (seen == INVOKESTATIC && getNameConstantOperand().equals("doPrivileged") && getClassConstantOperand().equals(
                    "java/security/AccessController"))
            || (seen == INVOKEVIRTUAL && getClassConstantOperand().equals(getClassName()))
            || (seen == INVOKEVIRTUAL && getNameConstantOperand().equals("start"))) {

        inConstructor = false;
    }

    thisOnTOS = false;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:67,代码来源:FindUninitializedGet.java

示例12: sawOpcode

import edu.umd.cs.findbugs.LocalVariableAnnotation; //导入依赖的package包/类
@Override
    public void sawOpcode(int seen) {
//        System.out.printf("%5d %12s %s%n", getPC(), OPCODE_NAMES[seen],stack);
        if (seen == PUTFIELD) {
            OpcodeStack.Item top = stack.getStackItem(0);
            OpcodeStack.Item next = stack.getStackItem(1);

            XField f = top.getXField();
            int registerNumber = next.getRegisterNumber();
            if (f != null && f.equals(getXFieldOperand()) && registerNumber >= 0
                    && registerNumber == top.getFieldLoadedFromRegister()) {
                int priority = NORMAL_PRIORITY;

                LocalVariableAnnotation possibleMatch = LocalVariableAnnotation.findMatchingIgnoredParameter(getClassContext(),
                        getMethod(), getNameConstantOperand(), getSigConstantOperand());
                if (possibleMatch != null)
                    priority--;
                else 
                    possibleMatch = LocalVariableAnnotation.findUniqueBestMatchingParameter(getClassContext(), getMethod(),
                            getNameConstantOperand(), getSigConstantOperand());
                if (possibleMatch == null) {
                    String signature = stack.getLVValue(registerNumber).getSignature();
                    for (int i = 0; i < stack.getNumLocalValues(); i++)
                        if (i != register) {
                            Item lvValue = stack.getLVValue(i);
                            if (lvValue != null && lvValue.getSignature().equals(signature)) {
                                priority--;
                                break;
                            }
                        }
                }

                bugReporter.reportBug(new BugInstance(this, "SA_FIELD_SELF_ASSIGNMENT", priority).addClassAndMethod(this)
                        .addReferencedField(this).addOptionalAnnotation(possibleMatch).addSourceLine(this));

            }
        }
        switch (state) {
        case 0:
            if (seen == DUP)
                state = 6;
            break;
        case 6:
            if (isRegisterStore()) {
                state = 7;
                register = getRegisterOperand();
            } else
                state = 0;
            break;
        case 7:
            if (isRegisterStore() && register == getRegisterOperand()) {
                bugReporter.reportBug(new BugInstance(this, "SA_LOCAL_DOUBLE_ASSIGNMENT", NORMAL_PRIORITY)
                        .addClassAndMethod(this)
                        .add(LocalVariableAnnotation.getLocalVariableAnnotation(getMethod(), register, getPC(), getPC() - 1))
                        .addSourceLine(this));
            }
            state = 0;
            break;
        }

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

示例13: sawOpcode

import edu.umd.cs.findbugs.LocalVariableAnnotation; //导入依赖的package包/类
@Override
public void sawOpcode(int seen) {
    if (seen == GOTO) {
        previousGotoTarget = getBranchTarget();
        gotoCount++;
        if (previousGotoTarget < getPC())
            previousLoadOf = -1;
    } else {
        if (isRegisterLoad())
            previousLoadOf = getRegisterOperand();
        else {
            if (isRegisterStore()) {
                if (previousLoadOf == getRegisterOperand() && gotoCount < 2 && getPC() != previousGotoTarget) {
                    int priority = NORMAL_PRIORITY;
                    String methodName = getMethodName();
                    if (methodName.equals("<init>") || methodName.startsWith("set") && getCode().getCode().length <= 5
                            || !previousStores.get(getRegisterOperand()))
                        priority = HIGH_PRIORITY;
                    previousStores.set(getRegisterOperand());
                    XClass c = getXClass();
                    LocalVariableAnnotation local = LocalVariableAnnotation.getLocalVariableAnnotation(getMethod(),
                            getRegisterOperand(), getPC(), getPC());
                    if (local.getName().equals("?")) {
                        priority++;
                    } else
                        for (XField f : c.getXFields()) {
                            if (f.getName().equals(local.getName()) && (f.isStatic() || !getMethod().isStatic())) {
                                bugReporter.reportBug(new BugInstance(this, "SA_LOCAL_SELF_ASSIGNMENT_INSTEAD_OF_FIELD",
                                        priority).addClassAndMethod(this).add(local).addField(f)
                                        .describe(FieldAnnotation.DID_YOU_MEAN_ROLE).addSourceLine(this));
                                return;

                            }
                        }

                    bugReporter.reportBug(new BugInstance(this, "SA_LOCAL_SELF_ASSIGNMENT", priority).addClassAndMethod(this)
                            .add(local).addSourceLine(this));
                } else
                    previousStores.set(getRegisterOperand());
            }

            previousLoadOf = -1;
            gotoCount = 0;
        }
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:47,代码来源:FindLocalSelfAssignment2.java

示例14: emitDataflowWarning

import edu.umd.cs.findbugs.LocalVariableAnnotation; //导入依赖的package包/类
private void emitDataflowWarning(XMethod xMethod, TypeQualifierValue typeQualifierValue,
        TypeQualifierValueSet forwardsFact, TypeQualifierValueSet backwardsFact, ValueNumber vn, FlowValue forward,
        FlowValue backward, Location locationToReport, @CheckForNull Location locationWhereDoomedValueIsObserved, ValueNumberFrame vnaFrame)
        throws CheckedAnalysisException {
    String bugType;
    if (typeQualifierValue.isStrictQualifier() && forward == FlowValue.UNKNOWN)
        bugType = "TQ_UNKNOWN_VALUE_USED_WHERE_ALWAYS_STRICTLY_REQUIRED";
    else if (backward == FlowValue.NEVER)
        bugType = "TQ_ALWAYS_VALUE_USED_WHERE_NEVER_REQUIRED";
    else
        bugType = "TQ_NEVER_VALUE_USED_WHERE_ALWAYS_REQUIRED";

    // Issue warning
    BugInstance warning = new BugInstance(this, bugType, Priorities.NORMAL_PRIORITY).addClassAndMethod(xMethod);
    annotateWarningWithTypeQualifier(warning, typeQualifierValue);

    Set<? extends SourceSinkInfo> sourceSet = (forward == FlowValue.ALWAYS) ? forwardsFact.getWhereAlways(vn) : forwardsFact
            .getWhereNever(vn);
    for (SourceSinkInfo source : sourceSet) {
        annotateWarningWithSourceSinkInfo(warning, xMethod, vn, source);
    }
    Set<? extends SourceSinkInfo> sinkSet = (backward == FlowValue.ALWAYS) ? backwardsFact.getWhereAlways(vn) : backwardsFact
            .getWhereNever(vn);

    Location sinkLocation = getSinkLocation(sinkSet);
    if (sinkLocation == null) {
        AnalysisContext.logError("Unable to compute sink location for " + xMethod);
        return;
    }

    // Hopefully we can find the conflicted value in a local variable
    if (locationWhereDoomedValueIsObserved != null) {
        Method method = Global.getAnalysisCache().getMethodAnalysis(Method.class, xMethod.getMethodDescriptor());

        LocalVariableAnnotation localVariable = ValueNumberSourceInfo.findLocalAnnotationFromValueNumber(method,
                locationWhereDoomedValueIsObserved, vn, vnaFrame);
        if (localVariable != null && !localVariable.equals(warning.getPrimaryLocalVariableAnnotation())) {
            localVariable.setDescription(localVariable.isSignificant() ? "LOCAL_VARIABLE_VALUE_DOOMED_NAMED"
                    : "LOCAL_VARIABLE_VALUE_DOOMED");
            warning.add(localVariable);

        }
        if (!sinkLocation.equals(locationToReport)) {
            // Report where we observed the value.
            // Note that for conflicts detected on control edges,
            // we REPORT the edge source location
            // rather than the target location, even though it is the
            // target location where the conflict is detected.
            // The only reason to use a different reporting location
            // is to produce a more informative report for the user,
            // since the edge source is where the branch is found.
            SourceLineAnnotation observedLocation = SourceLineAnnotation.fromVisitedInstruction(xMethod.getMethodDescriptor(),
                    locationToReport);
            observedLocation.setDescription("SOURCE_LINE_VALUE_DOOMED");
            warning.add(observedLocation);
        }
    }

    // Add value sinks
    for (SourceSinkInfo sink : sinkSet) {
        annotateWarningWithSourceSinkInfo(warning, xMethod, vn, sink);
    }

    bugReporter.reportBug(warning);
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:66,代码来源:CheckTypeQualifiers.java

示例15: annotateWarningWithSourceSinkInfo

import edu.umd.cs.findbugs.LocalVariableAnnotation; //导入依赖的package包/类
private void annotateWarningWithSourceSinkInfo(BugInstance warning, XMethod xMethod, ValueNumber vn,
        SourceSinkInfo sourceSinkInfo) {
    MethodDescriptor methodDescriptor = xMethod.getMethodDescriptor();
    switch (sourceSinkInfo.getType()) {
    case PARAMETER:
        try {
            Method method = Global.getAnalysisCache().getMethodAnalysis(Method.class, methodDescriptor);
            LocalVariableAnnotation lva = LocalVariableAnnotation.getParameterLocalVariableAnnotation(method,
                    sourceSinkInfo.getLocal());
            lva.setDescription(lva.isSignificant() ? "LOCAL_VARIABLE_PARAMETER_VALUE_SOURCE_NAMED"
                    : "LOCAL_VARIABLE_PARAMETER_VALUE_SOURCE");
            warning.add(lva);
        } catch (CheckedAnalysisException e) {
            warning.addSourceLine(methodDescriptor, sourceSinkInfo.getLocation()).describe("SOURCE_LINE_VALUE_SOURCE");
        }
        break;

    case CONSTANT_VALUE:
        Object constantValue = sourceSinkInfo.getConstantValue();
        if (constantValue instanceof String) {
            warning.addString((String) constantValue).describe(StringAnnotation.STRING_CONSTANT_ROLE);
        } else if (constantValue instanceof Integer) {
            warning.addInt((Integer) constantValue).describe(IntAnnotation.INT_VALUE);
        } else if (constantValue == null)
            warning.addString("null").describe(StringAnnotation.STRING_NONSTRING_CONSTANT_ROLE);
        else
            warning.addString(constantValue.toString()).describe(StringAnnotation.STRING_NONSTRING_CONSTANT_ROLE);
        break;

    case RETURN_VALUE_OF_CALLED_METHOD:
    case FIELD_LOAD:
        warning.addSourceLine(methodDescriptor, sourceSinkInfo.getLocation()).describe("SOURCE_LINE_VALUE_SOURCE");
        break;

    case ARGUMENT_TO_CALLED_METHOD:
    case RETURN_VALUE:
    case FIELD_STORE:
        warning.addSourceLine(methodDescriptor, sourceSinkInfo.getLocation());
        return;

    default:
        throw new IllegalStateException();
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:45,代码来源:CheckTypeQualifiers.java


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