eclipse-jdt / eclipse-jdt/eclipse.jdt.core

[24] CompilationUnit does not contains modifier for the ImplicitTypeDeclaration

Open
#3,696 2 comments 0 reactions 1 assignee Claimed by @subyssurendran666 View on GitHub
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 10h
Merged PRs (30d)
49

Description

ref: https://openjdk.org/jeps/495
JLS Changes : https://cr.openjdk.org/~gbierman/jep495/jep495-20241101/specs/simple-source-files-instance-main-methods-jls.html#jls-8.1.8

Summery
The `CompilationUnit.types` of `ImplicitTypeDeclaration` does not contain modifier. In light of JEP-495, the `ImplicitTypeDeclaration` can have the `final` modifier. However, the modifier is accessible through `ITypeBinding`.

Reproducer
========

```
public void test001() throws CoreException {
ASTParser astParser = ASTParser.newParser(getAST24());
Map options = new HashMap<>();
options.put(JavaCore.COMPILER_COMPLIANCE, "24");
options.put(JavaCore.COMPILER_SOURCE, "24");

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

String source ="""
String greeting() {
return "Hello, World!";
}
void main() {
System.out.println(greeting());
}
""";

astParser.setSource(source.toCharArray());

CompilationUnit compilationUnit = (CompilationUnit) astParser.createAST(null);
ImplicitTypeDeclaration a = (ImplicitTypeDeclaration) compilationUnit.types().get(0);
assertTrue(Modifier.isFinal(a.getModifiers()));

ITypeBinding aBinding = a.resolveBinding();
assertTrue(Modifier.isFinal(aBinding.getModifiers()));
}
```

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.