import edu.umd.cs.findbugs.ba.XMethod; //導入方法依賴的package包/類
@Override
public void sawOpcode(int seen) {
if (getMethodName().equals("") && 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 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("") && getNameConstantOperand().equals("")) {
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(""))
fieldSummary.addWrittenOutsideOfConstructor(fieldOperand);
}
} else if (seen == PUTSTATIC && !getMethodName().equals(""))
fieldSummary.addWrittenOutsideOfConstructor(fieldOperand);
OpcodeStack.Item top = stack.getStackItem(0);
fieldSummary.mergeSummary(fieldOperand, top);
}
}