[Bug] Duplicated class simple name in import section when use inline class qualified name
- Dominant language
- Java
- Stars
- 2k
- Forks
- 392
- Avg merge
- 11h 24m
- Merged PRs (30d)
- 36
Description
**Describe the bug**
When source code use inline qualified name in a class, and two of them have the same simple name, the classes imported will be conflict.
**To Reproduce**
Input:
```java
String code1 = "package io.example.pack1;\n" +
"import io.example.pack2.Class1;\n" +
" public class Example{\n" +
" void add(Class1 value){\n" +
" io.example.pack4.Class1 class1 = null;\n" +
" io.example.pack.Class1 class2 = null;\n" +
" }\n" +
" }\n";
CtClass class1 = Launcher.parseClass(code1);
System.out.println(class1.toStringWithImports());
```
Output:
```java
package io.example.pack1;
import io.example.pack.Class1;
import io.example.pack2.Class1;
import io.example.pack3.Class1;
import io.example.pack4.Class1;
public class Example {
void add(Class1 value) {
Class1 class1 = null;
Class1 class2 = null;
}
}
```
Test case pull request: https://github.com/INRIA/spoon/pull/4785
This problem doesn't only happen when parsing class, but also happened in the output file. You can check it in the test case in the pull request.
**Operating system, JDK and Spoon version used**
* OS: MacOS
* JDK: Java 11
* Spoon version: 10.1.1
Contributor guide
Research direction
Reproduce the example with Launcher.parseClass and inspect the output from CtClass.toStringWithImports. Review the test case in pull request #4785, including its output-file coverage. Done means the generated imports and references remain unambiguous when qualified names share the same simple class name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100