[Bug]: Different methods with same name are merged into one method
- Dominant language
- Java
- Stars
- 2k
- Forks
- 392
- Avg merge
- 11h 24m
- Merged PRs (30d)
- 36
Description
### Describe the bug
I use `spoon.refactoring.MethodInvocationSearch` to get the invocation relationship of methods, and different methods with same name are merged into one when i use `getInvocationsOfMethod` to retrieve the result. The demo is shown as below.
### Source code you are trying to analyze/transform
```Java
public class Test {
public void test2() {
test3();
Test2.test3();
Child.test3();
}
public static void test3() {
}
public void test4() {
}
private static class Child {
public static void test3() {
}
}
}
```
### Source code for your Spoon processing
```Java
@Slf4j
@RunWith(SpringRunner.class)
public class TestMethodLines {
@Test
public void test() throws URISyntaxException {
final Launcher spoon = initSpoon();
MethodInvocationSearch processor = new MethodInvocationSearch();
CtModel model = spoon.getModel();
model.getElements(new TypeFilter<>(CtExecutable.class)).forEach(processor::scan);
MethodCallGraph methodCallGraph = MethodGraphUtils.buildMethodCallGraph(processor.getInvocationsOfMethod());
Collection allMethods = methodCallGraph.getAllMethods();
for (MethodCallGraph.MethodNode methodNode : allMethods) {
Collection callerMethods = methodNode.getCallerMethods();
if (CollectionUtils.size(callerMethods) != 0) {
String join = JOINER
.join(Collections2.transform(callerMethods, new Function() {
@Override public Object apply(MethodCallGraph.MethodNode input) {
return input.getMethod().getMethodName();
}
}));
System.out.println(methodNode.getMethod().getMethodName() + " is called by " +join);
}
}
}
private Launcher initSpoon() throws URISyntaxException {
String path = Test1.class.getResource("/" + "Test.java").toURI().getPath();
final String[] arg = {
"-i", path,
"-o", "target/spooned/"
};
final Launcher launcher = new Launcher();
launcher.setArgs(arg);
launcher.run();
return launcher;
}
}
```
### Actual output
```Java
test3 is called by test2
```
### Expected output
```Java
rathen than showing only one single method "test3 is called by test2" ,three different methods of "test3" are called by test2
```
### Spoon Version
tried with 9.1.0 and 10.1.1
### JVM Version
11
### What operating system are you using?
tried both on Linux and Windows
Contributor guide
Assessment
This issue has not been assessed yet.