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

[dom binding] JEP 409 - sealed modifiers and permitted types not accessible through ITypeBinding #3178

Open
subyssurendran666 opened this issue Oct 28, 2024 · 1 comment
Assignees

Comments

@subyssurendran666
Copy link
Contributor

code trying to access the sealed modifiers through ITypeBinding interface

The 'sealed' and 'non-sealed' modifiers are visible and accessible through the AST, but not when trying to get the same information with the associated type binding.

Also, permitted types are not available from ITypeBinding (while they are part of 'org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding').

Reproducer

ASTParser astParser = ASTParser.newParser(AST.JLS17);
    Map<String, String> options = new HashMap<>();
    options.put(JavaCore.COMPILER_COMPLIANCE, "17");
    options.put(JavaCore.COMPILER_SOURCE, "17");

    options.put(JavaCore.COMPILER_PB_ENABLE_PREVIEW_FEATURES, "enabled");

    astParser.setCompilerOptions(options);
    astParser.setEnvironment(new String[] {}, new String[] {}, new String[] {}, true);
    astParser.setUnitName("Example.java");
    astParser.setResolveBindings(true);
    astParser.setBindingsRecovery(true);

    String source =
      "sealed class A permits B, C {}\n"
      + "final class B extends A {}\n"
      + "non-sealed class C extends A {}";
    astParser.setSource(source.toCharArray());

    CompilationUnit compilationUnit = (CompilationUnit) astParser.createAST(null);
    TypeDeclaration a = (TypeDeclaration) compilationUnit.types().get(0);

    if (!Modifier.isSealed(a.getModifiers())) {
      throw new AssertionError("Modifier is not present in AST");
    }

    if (a.permittedTypes().size() != 2) {
      throw new AssertionError("permitted types are not present in AST");
    }

    ITypeBinding aBinding = a.resolveBinding();
    if (!Modifier.isSealed(aBinding.getModifiers())) {
      // permitted types not even available through the ITypeBinding interface
      throw new AssertionError("'sealed' modifier is not set in binding");
    }

Ref: https://bugs.eclipse.org/bugs/show_bug.cgi?id=578061

@jarthana
Copy link
Member

@subyssurendran666 please take this forward.

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

No branches or pull requests

2 participants