Skip to content
Permalink
Browse files

Merge branch 'findbugs' into spotbugs

 Conflicts:
	src/main/java/com/mebigfatguy/fbcontrib/collect/CollectStatistics.java
  • Loading branch information...
mebigfatguy committed Mar 13, 2019
2 parents 41f4734 + 1b9b8d0 commit 07b1509f0a0bd8c700adbb3d1e064a076b249bb8
@@ -66,11 +66,13 @@
// @formatter:on
);

private BugReporter bugReporter;
private int numMethodCalls;
private boolean modifiesState;
private boolean classHasAnnotation;
private OpcodeStack stack;
private Map<QMethod, Set<CalledMethod>> selfCallTree;
private Set<QMethod> constrainingMethods;
private QMethod curMethod;

/**
@@ -83,6 +85,7 @@
@SuppressWarnings("PMD.UnusedFormalParameter")
public CollectStatistics(BugReporter bugReporter) {
Statistics.getStatistics().clear();
this.bugReporter = bugReporter;
}

/**
@@ -95,6 +98,7 @@ public CollectStatistics(BugReporter bugReporter) {
public void visitClassContext(ClassContext classContext) {
try {
JavaClass cls = classContext.getJavaClass();
constrainingMethods = buildConstrainingMethods(cls);
AnnotationEntry[] annotations = cls.getAnnotationEntries();
classHasAnnotation = !CollectionUtils.isEmpty(annotations);
stack = new OpcodeStack();
@@ -107,6 +111,7 @@ public void visitClassContext(ClassContext classContext) {
stack = null;
selfCallTree = null;
curMethod = null;
constrainingMethods = null;
}
}

@@ -120,6 +125,7 @@ public void visitAnnotation(Annotations annotations) {
}
}


@Override
public void visitCode(Code obj) {

@@ -136,8 +142,15 @@ public void visitCode(Code obj) {
String clsName = getClassName();
Method method = getMethod();
int accessFlags = method.getAccessFlags();

boolean isDerived = false;
if (!constrainingMethods.isEmpty()) {
QMethod qm = new QMethod(method.getName(), method.getSignature());
isDerived = constrainingMethods.contains(qm);
}

MethodInfo mi = Statistics.getStatistics().addMethodStatistics(clsName, getMethodName(), getMethodSig(), accessFlags, code.length,
numMethodCalls);
numMethodCalls, isDerived);
if ((clsName.indexOf(Values.INNER_CLASS_SEPARATOR) >= 0) || ((accessFlags & (Const.ACC_ABSTRACT | Const.ACC_INTERFACE | Const.ACC_ANNOTATION)) != 0)) {
mi.addCallingAccess(Const.ACC_PUBLIC);
} else if ((accessFlags & Const.ACC_PRIVATE) == 0) {
@@ -264,6 +277,31 @@ private boolean isAssociationedWithAnnotations(Method m) {

return !CollectionUtils.isEmpty(m.getAnnotationEntries());
}

private Set<QMethod> buildConstrainingMethods(JavaClass cls) {

Set<QMethod> constraints = new HashSet<>();
try {
for (JavaClass inf : cls.getInterfaces()) {
for (Method m : inf.getMethods()) {
constraints.add(new QMethod(m.getName(), m.getSignature()));
}
}

for (JavaClass parent : cls.getSuperClasses()) {
if (!Values.DOTTED_JAVA_LANG_OBJECT.equals(parent.getClassName())) {
for (Method m : parent.getMethods()) {
constraints.add(new QMethod(m.getName(), m.getSignature()));
}
constraints.addAll(buildConstrainingMethods(parent));
}
}
} catch (ClassNotFoundException e) {
bugReporter.reportMissingClass(e);
}

return constraints;
}

/**
* represents a method that is called, and whether it is in the super class
@@ -53,7 +53,7 @@ public void clear() {
methodStatistics.clear();
}

public MethodInfo addMethodStatistics(String className, String methodName, String signature, int access, int numBytes, int numMethodCalls) {
public MethodInfo addMethodStatistics(String className, String methodName, String signature, int access, int numBytes, int numMethodCalls, boolean isDerived) {
FQMethod key = new FQMethod(className, methodName, signature);
MethodInfo mi = methodStatistics.get(key);
if (mi == null) {
@@ -64,6 +64,7 @@ public MethodInfo addMethodStatistics(String className, String methodName, Strin
mi.setNumBytes(numBytes);
mi.setNumMethodCalls(numMethodCalls);
mi.setDeclaredAccess(access);
mi.setDerived(isDerived);
return mi;
}

@@ -383,6 +383,7 @@ public void sawOpcode(int seen) {
case Const.GETFIELD: {
userValue = storeToUserValue.get(getNameConstantOperand());
}
break;

}
} finally {

0 comments on commit 07b1509

Please sign in to comment.
You can’t perform that action at this time.