Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Can't create CtPackage which the parent package name equals child package name #4764

Closed
treenwang opened this issue Jun 26, 2022 · 1 comment · Fixed by #4770
Closed
Assignees
Labels

Comments

@treenwang
Copy link
Contributor

Describe the bug
When use PackageFactory to create package. If the parent package name equals the child package name. Only one level of package will be created.

To Reproduce

Processing with Spoon:

    @Test
    void testCreatePackage(){
        CtClass<?> dClass = Launcher.parseClass("class A{}");
        CtPackage ctPackage1 = dClass.getFactory().Package().getOrCreate("duplicated.non_duplicated");
        Assertions.assertEquals("duplicated.non_duplicated", ctPackage1.getQualifiedName());//successful
        CtPackage ctPackage2 = dClass.getFactory().Package().getOrCreate("duplicated.duplicated");
        Assertions.assertEquals("duplicated.duplicated", ctPackage2.getQualifiedName());//failed
        CtPackage ctPackage3 = dClass.getFactory().Package().getOrCreate("duplicated.duplicated.duplicated");
        Assertions.assertEquals("duplicated.duplicated.duplicated", ctPackage3.getQualifiedName());//failed
    }

Output:

expected: <duplicated.duplicated> but was: <duplicated>
Expected :duplicated.duplicated
Actual   :duplicated

Operating system, JDK and Spoon version used

  • OS: MacOS
  • JDK: Java 11
  • Spoon version: 10.1.1
@SirYwell SirYwell added the bug label Jun 26, 2022
@slarse
Copy link
Collaborator

slarse commented Jun 27, 2022

@treenwang Thanks for the bug report, I think I have a fix for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants