[Bug]: InvocationFilter not filtering all instances of reference
- Dominant language
- Java
- Stars
- 2k
- Forks
- 392
- Avg merge
- 11h 24m
- Merged PRs (30d)
- 36
Description
### Describe the bug
I am trying to list all method invocations for Deprecated methods, using InvocationFilter. It seems it fails to identify invocations in example that I have listed.
init method in the code to be analyzed makes a call to service.voteInMovie(...) method which I have marked as deprecated. My spoon InvocationFilter is not able to detect this invocation.
### Source code you are trying to analyze/transform
```Java
public void init() {
get("/movie/:title", (req, res) -> gson.toJson(service.findMovie(URLDecoder.decode(req.params("title"), StandardCharsets.UTF_8))));
post("/movie/vote/:title", (req, res) -> {
Integer updates = service.voteInMovie(URLDecoder.decode(req.params("title"), StandardCharsets.UTF_8));
return gson.toJson( Map.of("updated", updates));
});
get("/search", (req, res) -> gson.toJson(service.search(req.queryParams("q"))));
get("/graph", (req, res) -> {
int limit = req.queryParams("limit") != null ? Integer.parseInt(req.queryParams("limit")) : 100;
return gson.toJson(service.graph(limit));
});
}
```
### Source code for your Spoon processing
```Java
public static void filterClassMethodReferences(CtModel ctModel) {
List allMethods = ctModel.getElements(new TypeFilter<>(CtMethod.class));
System.out.println("ALl methods count"+ allMethods.stream().count());
for(CtMethod myMethod : allMethods) {
// System.out.println("name "+myMethod);
if(myMethod.getAnnotation(Deprecated.class) != null ) {
System.out.println(myMethod.getSimpleName());
CtExecutableReference reference = myMethod.getReference();
System.out.println(myMethod.getType());
List> invocations = ctModel.getElements(new InvocationFilter(reference));
System.out.println("Method name "+myMethod.getSimpleName() + " Method references "+invocations.size());
invocations.forEach(t -> System.out.println(t.getExecutable().getDeclaringType()));
}
}
}
```
### Actual output
```Java
Inside launcher
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
ALl methods count18
findMovie
java.util.Map
Method name findMovie Method references 0
voteInMovie
java.lang.Integer
Method name voteInMovie Method references 0
graph
java.util.Map
Method name graph Method references 0
```
### Expected output
```Java
Inside launcher
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
ALl methods count18
findMovie
java.util.Map
Method name findMovie Method references 1
voteInMovie
java.lang.Integer
Method name voteInMovie Method references 1
graph
java.util.Map
Method name graph Method references 1
```
### Spoon Version
10.4.1
### JVM Version
Zulu 11
### What operating system are you using?
Windows 10 64bit
Contributor guide
Assessment
This issue has not been assessed yet.