You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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");
}
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
Ref: https://bugs.eclipse.org/bugs/show_bug.cgi?id=578061
The text was updated successfully, but these errors were encountered: