INRIA / INRIA/spoon

[Bug] Wrong package name when parsing class

Open
#4,786 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
2k
Forks
392
Avg merge
11h 24m
Merged PRs (30d)
36

Description

**Describe the bug**
When parsing a class which package is child of some classes which use inline qualified class name, those inline qualified classes' package name will be changed to the child package.

**To Reproduce**

Input:
```java
String code2 = "package io.example.pack1.pack2;\n" +
" public class Example{\n" +
" void add(io.example.pack1.Class1 value){\n" +
" }\n" +
" }\n";
CtClass class2 = Launcher.parseClass(code2);
System.out.println(class2.toStringWithImports());
```

Output:
```java
package io.example.pack1.pack2;
public class Example {
void add(Class1 value) {
}
}
```
Expected:
```java
package io.example.pack1.pack2;
import io.example.pack1.Class1;
import io.example.pack1.Class2;
public class Example {
void add(Class1 value) {
}
}
```
Test case pull request: https://github.com/INRIA/spoon/pull/4782

**Operating system, JDK and Spoon version used**

* OS: MacOS
* JDK: Java 11
* Spoon version: 10.1.1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.