本文整理汇总了Java中edu.umd.cs.findbugs.ba.CFG.blockIterator方法的典型用法代码示例。如果您正苦于以下问题:Java CFG.blockIterator方法的具体用法?Java CFG.blockIterator怎么用?Java CFG.blockIterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.umd.cs.findbugs.ba.CFG
的用法示例。
在下文中一共展示了CFG.blockIterator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scan
import edu.umd.cs.findbugs.ba.CFG; //导入方法依赖的package包/类
/**
* Scan a method for self call sites.
*
* @param node the CallGraphNode for the method to be scanned
*/
private void scan(CallGraphNode node) throws CFGBuilderException {
Method method = node.getMethod();
CFG cfg = classContext.getCFG(method);
if (method.isSynchronized())
hasSynchronization = true;
Iterator<BasicBlock> i = cfg.blockIterator();
while (i.hasNext()) {
BasicBlock block = i.next();
Iterator<InstructionHandle> j = block.instructionIterator();
while (j.hasNext()) {
InstructionHandle handle = j.next();
Instruction ins = handle.getInstruction();
if (ins instanceof InvokeInstruction) {
InvokeInstruction inv = (InvokeInstruction) ins;
Method called = isSelfCall(inv);
if (called != null) {
// Add edge to call graph
CallSite callSite = new CallSite(method, block, handle);
callGraph.createEdge(node, callGraph.getNodeForMethod(called), callSite);
// Add to called method set
calledMethodSet.add(called);
}
} else if (ins instanceof MONITORENTER || ins instanceof MONITOREXIT) {
hasSynchronization = true;
}
}
}
}
示例2: scan
import edu.umd.cs.findbugs.ba.CFG; //导入方法依赖的package包/类
/**
* Scan a method for self call sites.
*
* @param node
* the CallGraphNode for the method to be scanned
*/
private void scan(CallGraphNode node) throws CFGBuilderException {
Method method = node.getMethod();
CFG cfg = classContext.getCFG(method);
if (method.isSynchronized())
hasSynchronization = true;
Iterator<BasicBlock> i = cfg.blockIterator();
while (i.hasNext()) {
BasicBlock block = i.next();
Iterator<InstructionHandle> j = block.instructionIterator();
while (j.hasNext()) {
InstructionHandle handle = j.next();
Instruction ins = handle.getInstruction();
if (ins instanceof InvokeInstruction) {
InvokeInstruction inv = (InvokeInstruction) ins;
Method called = isSelfCall(inv);
if (called != null) {
// Add edge to call graph
CallSite callSite = new CallSite(method, block, handle);
callGraph.createEdge(node, callGraph.getNodeForMethod(called), callSite);
// Add to called method set
calledMethodSet.add(called);
}
} else if (ins instanceof MONITORENTER || ins instanceof MONITOREXIT) {
hasSynchronization = true;
}
}
}
}
示例3: visitMethod
import edu.umd.cs.findbugs.ba.CFG; //导入方法依赖的package包/类
@Override
public void visitMethod(Method method) {
try {
if (method.getCode() == null)
return;
CFG cfg = classContext.getCFG(method);
Iterator<BasicBlock> bbi = cfg.blockIterator();
while (bbi.hasNext()) {
BasicBlock bb = bbi.next();
int numOutgoing = cfg.getNumOutgoingEdges(bb);
if (numOutgoing == 2)
findIfElseDuplicates(cfg, method, bb);
else if (numOutgoing > 2)
findSwitchDuplicates(cfg, method, bb);
}
} catch (MethodUnprofitableException mue) {
if (SystemProperties.getBoolean("unprofitable.debug")) // otherwise
// don't
// report
bugReporter.logError("skipping unprofitable method in " + getClass().getName());
} catch (Exception e) {
bugReporter.logError("Failure examining basic blocks in Duplicate Branches detector", e);
}
if (pendingBugs.size() <= 2)
for (BugInstance b : pendingBugs)
bugReporter.reportBug(b);
pendingBugs.clear();
}
示例4: analyzeMethod
import edu.umd.cs.findbugs.ba.CFG; //导入方法依赖的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));
}
}
示例5: analyzeMethod
import edu.umd.cs.findbugs.ba.CFG; //导入方法依赖的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));
}
}