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


Java Hierarchy2类代码示例

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


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

示例1: checkForWeirdEquals

import edu.umd.cs.findbugs.ba.Hierarchy2; //导入依赖的package包/类
/**
 * @param lhsSig
 * @param rhsSig
 * @param targets
 * @return
 */
private boolean checkForWeirdEquals(String lhsSig, String rhsSig, Set<XMethod> targets) {
    boolean allOk = false;
    try {
        ClassSummary classSummary = AnalysisContext.currentAnalysisContext().getClassSummary();

        ClassDescriptor expectedClassDescriptor = DescriptorFactory.createClassDescriptorFromSignature(lhsSig);
        ClassDescriptor actualClassDescriptor = DescriptorFactory.createClassDescriptorFromSignature(rhsSig);

        targets.addAll(Hierarchy2.resolveVirtualMethodCallTargets(expectedClassDescriptor, "equals", "(Ljava/lang/Object;)Z",
                false, false));
        allOk = targets.size() > 0;
        for (XMethod m2 : targets)
            if (!classSummary.mightBeEqualTo(m2.getClassDescriptor(), actualClassDescriptor))
                allOk = false;

    } catch (ClassNotFoundException e) {
        AnalysisContext.reportMissingClass(e);
    }
    return allOk;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:27,代码来源:FindRefComparison.java

示例2: killLoadsOfObjectsPassed

import edu.umd.cs.findbugs.ba.Hierarchy2; //导入依赖的package包/类
private void killLoadsOfObjectsPassed(InvokeInstruction ins) {
    try {

        XMethod called = Hierarchy2.findExactMethod(ins, methodGen.getConstantPool(), Hierarchy.ANY_METHOD);
        FieldSummary fieldSummary = AnalysisContext.currentAnalysisContext().getFieldSummary();
        Set<XField> touched = fieldSummary.getFieldsWritten(called);
        if (!touched.isEmpty()) {
            getFrame().killLoadsOf(touched);
        }


        int passed = getNumWordsConsumed(ins);
        ValueNumber[] arguments = allocateValueNumberArray(passed);
        getFrame().killLoadsWithSimilarName(ins.getClassName(cpg), ins.getMethodName(cpg));
        getFrame().getTopStackWords(arguments);
        for (ValueNumber v : arguments)
            getFrame().killAllLoadsOf(v);

    } catch (DataflowAnalysisException e) {
        AnalysisContext.logError("Error in killLoadsOfObjectsPassed", e);
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:23,代码来源:ValueNumberFrameModelingVisitor.java

示例3: getXMethodOperand

import edu.umd.cs.findbugs.ba.Hierarchy2; //导入依赖的package包/类
public @CheckForNull
XMethod getXMethodOperand() {
    if (getReferencedXClass() != null && referencedXMethod == null) {
        referencedXMethod = Hierarchy2.findInvocationLeastUpperBound(getReferencedXClass(), nameConstantOperand,
                sigConstantOperand, opcode == INVOKESTATIC, opcode == INVOKEINTERFACE);
    }

    return referencedXMethod;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:10,代码来源:DismantleBytecode.java

示例4: addEqualsMethodUsed

import edu.umd.cs.findbugs.ba.Hierarchy2; //导入依赖的package包/类
@Nonnull
public BugInstance addEqualsMethodUsed(ClassDescriptor expectedClass) {
    try {
        Set<XMethod> targets = Hierarchy2.resolveVirtualMethodCallTargets(expectedClass, "equals", "(Ljava/lang/Object;)Z",
                false, false);
        addEqualsMethodUsed(targets);

    } catch (ClassNotFoundException e) {
        AnalysisContext.reportMissingClass(e);
    }

    return this;
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:14,代码来源:BugInstance.java

示例5: sawOpcode

import edu.umd.cs.findbugs.ba.Hierarchy2; //导入依赖的package包/类
@Override
public void sawOpcode(int seen) {
    if (getMethodName().equals("<init>") && seen == INVOKEVIRTUAL) {
        XMethod m = getXMethodOperand();
        if (m != null && !m.isPrivate() && !m.isFinal()) {
            int args = PreorderVisitor.getNumberArguments(m.getSignature());
            OpcodeStack.Item item = stack.getStackItem(args);
            if (item.getRegisterNumber() == 0) {
                try {
                    Set<XMethod> targets = Hierarchy2.resolveVirtualMethodCallTargets(m, false, false);
                    Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2();

                    for (XMethod called : targets) {
                        if (!called.isAbstract() && !called.equals(m)
                                && subtypes2.isSubtype(called.getClassDescriptor(), getClassDescriptor()))
                            fieldSummary.setCalledFromSuperConstructor(new ProgramPoint(this), called);
                    }
                } catch (ClassNotFoundException e) {
                    AnalysisContext.reportMissingClass(e);
                }

            }

        }

    }

    if (seen == INVOKESPECIAL && getMethodName().equals("<init>") && getNameConstantOperand().equals("<init>")) {

        String classOperand = getClassConstantOperand();
        OpcodeStack.Item invokedOn = stack.getItemMethodInvokedOn(this);
        if (invokedOn.getRegisterNumber() == 0 && !classOperand.equals(getClassName())) {
            sawInitializeSuper = true;
            XMethod invoked = getXMethodOperand();
            if (invoked != null)
                fieldSummary.sawSuperCall(getXMethod(), invoked);
        }

    }

    if (seen == PUTFIELD || seen == PUTSTATIC) {
        XField fieldOperand = getXFieldOperand();
        if (fieldOperand == null)
            return;
        touched.add(fieldOperand);
        if (!fieldOperand.getClassDescriptor().getClassName().equals(getClassName()))
            fieldSummary.addWrittenOutsideOfConstructor(fieldOperand);
        else if (seen == PUTFIELD) {
            OpcodeStack.Item addr = stack.getStackItem(1);
            {
                if (addr.getRegisterNumber() != 0 || !getMethodName().equals("<init>"))
                    fieldSummary.addWrittenOutsideOfConstructor(fieldOperand);
            }
        } else if (seen == PUTSTATIC && !getMethodName().equals("<clinit>"))
            fieldSummary.addWrittenOutsideOfConstructor(fieldOperand);
        OpcodeStack.Item top = stack.getStackItem(0);
        fieldSummary.mergeSummary(fieldOperand, top);
    }

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

示例6: analyzeMethod

import edu.umd.cs.findbugs.ba.Hierarchy2; //导入依赖的package包/类
private void analyzeMethod(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException {
    if (method.isSynthetic() || (method.getAccessFlags() & Constants.ACC_BRIDGE) == Constants.ACC_BRIDGE)
        return;
    CFG cfg = classContext.getCFG(method);

    ConstantPoolGen cpg = classContext.getConstantPoolGen();
    TypeDataflow typeDataflow = classContext.getTypeDataflow(method);

    for (Iterator<BasicBlock> i = cfg.blockIterator(); i.hasNext();) {
        BasicBlock basicBlock = i.next();

        // Check if it's a method invocation.
        if (!basicBlock.isExceptionThrower())
            continue;
        InstructionHandle thrower = basicBlock.getExceptionThrower();
        Instruction ins = thrower.getInstruction();
        if (!(ins instanceof InvokeInstruction))
            continue;

        InvokeInstruction inv = (InvokeInstruction) ins;
        boolean foundThrower = false;
        boolean foundNonThrower = false;

        if (inv instanceof INVOKEINTERFACE)
            continue;

        String className = inv.getClassName(cpg);

        Location loc = new Location(thrower, basicBlock);
        TypeFrame typeFrame = typeDataflow.getFactAtLocation(loc);
        XMethod primaryXMethod = XFactory.createXMethod(inv, cpg);
        // if (primaryXMethod.isAbstract()) continue;
        Set<XMethod> targetSet = null;
        try {

            if (className.startsWith("["))
                continue;
            String methodSig = inv.getSignature(cpg);
            if (!methodSig.endsWith("V"))
                continue;

            targetSet = Hierarchy2.resolveMethodCallTargets(inv, typeFrame, cpg);

            for (XMethod xMethod : targetSet) {
                if (DEBUG)
                    System.out.println("\tFound " + xMethod);

                boolean isUnconditionalThrower = xMethod.isUnconditionalThrower() && !xMethod.isUnsupported()
                        && !xMethod.isSynthetic();
                if (isUnconditionalThrower) {
                    foundThrower = true;
                    if (DEBUG)
                        System.out.println("Found thrower");
                } else {
                    foundNonThrower = true;
                    if (DEBUG)
                        System.out.println("Found non thrower");
                }

            }
        } catch (ClassNotFoundException e) {
            analysisContext.getLookupFailureCallback().reportMissingClass(e);
        }
        boolean newResult = foundThrower && !foundNonThrower;
        if (newResult)
            bugReporter.reportBug(new BugInstance(this, "TESTING", Priorities.NORMAL_PRIORITY)
                    .addClassAndMethod(classContext.getJavaClass(), method)
                    .addString("Call to method that always throws Exception").addMethod(primaryXMethod)
                    .describe(MethodAnnotation.METHOD_CALLED).addSourceLine(classContext, method, loc));

    }

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

示例7: analyzeMethod

import edu.umd.cs.findbugs.ba.Hierarchy2; //导入依赖的package包/类
private void analyzeMethod(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException {
    if (BCELUtil.isSynthetic(method) || (method.getAccessFlags() & Constants.ACC_BRIDGE) == Constants.ACC_BRIDGE)
        return;
    CFG cfg = classContext.getCFG(method);

    ConstantPoolGen cpg = classContext.getConstantPoolGen();
    TypeDataflow typeDataflow = classContext.getTypeDataflow(method);

    for (Iterator<BasicBlock> i = cfg.blockIterator(); i.hasNext();) {
        BasicBlock basicBlock = i.next();

        // Check if it's a method invocation.
        if (!basicBlock.isExceptionThrower())
            continue;
        InstructionHandle thrower = basicBlock.getExceptionThrower();
        Instruction ins = thrower.getInstruction();
        if (!(ins instanceof InvokeInstruction))
            continue;

        InvokeInstruction inv = (InvokeInstruction) ins;
        boolean foundThrower = false;
        boolean foundNonThrower = false;

        if (inv instanceof INVOKEINTERFACE)
            continue;

        String className = inv.getClassName(cpg);

        Location loc = new Location(thrower, basicBlock);
        TypeFrame typeFrame = typeDataflow.getFactAtLocation(loc);
        XMethod primaryXMethod = XFactory.createXMethod(inv, cpg);
        // if (primaryXMethod.isAbstract()) continue;
        Set<XMethod> targetSet = null;
        try {

            if (className.startsWith("["))
                continue;
            String methodSig = inv.getSignature(cpg);
            if (!methodSig.endsWith("V"))
                continue;

            targetSet = Hierarchy2.resolveMethodCallTargets(inv, typeFrame, cpg);

            for (XMethod xMethod : targetSet) {
                if (DEBUG)
                    System.out.println("\tFound " + xMethod);

                boolean isUnconditionalThrower = xMethod.isUnconditionalThrower() && !xMethod.isUnsupported()
                        && !xMethod.isSynthetic();
                if (isUnconditionalThrower) {
                    foundThrower = true;
                    if (DEBUG)
                        System.out.println("Found thrower");
                } else {
                    foundNonThrower = true;
                    if (DEBUG)
                        System.out.println("Found non thrower");
                }

            }
        } catch (ClassNotFoundException e) {
            analysisContext.getLookupFailureCallback().reportMissingClass(e);
        }
        boolean newResult = foundThrower && !foundNonThrower;
        if (newResult)
            bugReporter.reportBug(new BugInstance(this, "TESTING", Priorities.NORMAL_PRIORITY)
                    .addClassAndMethod(classContext.getJavaClass(), method)
                    .addString("Call to method that always throws Exception").addMethod(primaryXMethod)
                    .describe(MethodAnnotation.METHOD_CALLED).addSourceLine(classContext, method, loc));

    }

}
 
开发者ID:OpenNTF,项目名称:FindBug-for-Domino-Designer,代码行数:74,代码来源:CallToUnconditionalThrower.java


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