|
24 | 24 | import org.eclipse.jdt.core.dom.ASTNode;
|
25 | 25 | import org.eclipse.jdt.core.dom.ASTParser;
|
26 | 26 | import org.eclipse.jdt.core.dom.ASTVisitor;
|
| 27 | +import org.eclipse.jdt.core.dom.IMethodBinding; |
27 | 28 | import org.eclipse.jdt.core.dom.ITypeBinding;
|
28 | 29 | import org.eclipse.jdt.core.dom.MethodInvocation;
|
29 | 30 | import org.eclipse.jdt.core.dom.SimpleName;
|
@@ -91,15 +92,25 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
|
91 | 92 |
|
92 | 93 | @Override
|
93 | 94 | public boolean visit(MethodInvocation node) {
|
94 |
| - ITypeBinding declaringClass = node.resolveMethodBinding() |
95 |
| - .getDeclaringClass().getErasure(); |
| 95 | + IMethodBinding binding = node.resolveMethodBinding(); |
96 | 96 |
|
97 |
| - if (declaringClass.getPackage().getName().startsWith("java.util.stream")) { |
98 |
| - String declaringClassName = declaringClass.getQualifiedName(); |
99 |
| - SimpleName methodName = node.getName(); |
100 |
| - String qualfiedMethodName = declaringClassName + "." + methodName; |
| 97 | + if (binding != null) { |
| 98 | + ITypeBinding declaringClass = binding.getDeclaringClass(); |
101 | 99 |
|
102 |
| - calledMethodNameToCount.merge(qualfiedMethodName, 1, Integer::sum); |
| 100 | + if (declaringClass != null) { |
| 101 | + declaringClass = declaringClass.getErasure(); |
| 102 | + |
| 103 | + if (declaringClass.getPackage().getName() |
| 104 | + .startsWith("java.util.stream")) { |
| 105 | + String declaringClassName = declaringClass.getQualifiedName(); |
| 106 | + SimpleName methodName = node.getName(); |
| 107 | + String qualfiedMethodName = declaringClassName + "." |
| 108 | + + methodName; |
| 109 | + |
| 110 | + calledMethodNameToCount.merge(qualfiedMethodName, 1, |
| 111 | + Integer::sum); |
| 112 | + } |
| 113 | + } |
103 | 114 | }
|
104 | 115 | return super.visit(node);
|
105 | 116 | }
|
|
0 commit comments