Skip to content

[Bug] Erroenous AST for type in a Jigsaw module #4746

@Auties00

Description

@Auties00

Describe the bug
In short, calling CtElement

#getParent(P) using as a parameter CtModule.class always returns the unnamed module even when using types such as String that are definitely in a valid jigsaw module. You can find an example below and various snippets I tried.

To Reproduce

Input:

public class TestInput {
    private static final String ABC = String.valueOf("");
}

Processing with Spoon:

public class FieldTransformer extends AbstractProcessor<CtField<?>> {
    @Override
    public boolean isToBeProcessed(CtField<?> element) {
        return true;
    }

    @Override
    public void process(CtField<?> element) {
        if (element.getAssignment() == null) {
            return;
        }

        element.getParent(CtModule.class); // Unnamed module 
        element.getType().getParent(CtModule.class); // Unnamed module 
        element.getType().getPackage().getParent(CtModule.class); // Unnamed module 
    }
}
  • OS: Windows 11
  • JDK: openjdk version "16" 2021-03-16
  • Spoon version: 10.2.0-beta-10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions