eclipse-jdt / eclipse-jdt/eclipse.jdt.core
Formatter Ignores insert_space_before_opening_paren_in_enum_constant for Custom Annotations on Enum Constants
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 47
Description
The Eclipse Java formatter in version 2024-12 (4.34.0) fails to insert a space before the opening parenthesis in enum constant arguments when the constant is annotated with a custom (user-defined) annotation.
This contradicts the formatter setting org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant = insert, which works correctly for non-annotated constants and built-in annotations like @Deprecated.
**Steps to Reproduce**
Use Eclipse 2024-12 (4.34.0), Build ID: 20241128-0757.
Define a custom annotation:
```
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target(ElementType.FIELD)
@interface SimpleAnnotation {
String value();
}
```
Create an enum with mixed annotations:
```
enum TestEnum {
@SimpleAnnotation("test")
SIMPLE_VALUE(1),
@Deprecated
VALUE(1),
NO_ANNOTATION(2);
}
```
Apply a formatter profile with:
```
```
Format the code (Ctrl+Shift+F).
**Expected Behavior**
Based on the formatter settings, all enum constants should have a space before the opening parenthesis:
```
enum TestEnum {
@SimpleAnnotation("test")
SIMPLE_VALUE ( 1 ),
@Deprecated
VALUE ( 1 ),
NO_ANNOTATION ( 2 );
}
```
**Actual Behavior**
The space is omitted for the custom annotation:
```
enum TestEnum {
@SimpleAnnotation("test")
SIMPLE_VALUE(1),
@Deprecated
VALUE ( 1 ),
NO_ANNOTATION ( 2 );
}
```
**Environment**
- Eclipse Version: 2024-12 (4.34.0)
- Build ID: 20241128-0757
- Java Version: Java21
**Additional Details**
The issue is specific to custom annotations. Built-in annotations like @Deprecated work as expected.
Tested with a more complex custom annotation (@SimpleAnnotation with multiple parameters), yielding the same result.
**Steps Tried**
Confirmed the active profile includes insert_space_before_opening_paren_in_enum_constant = insert.
Tested with a fresh profile containing only enum-related settings—same outcome.
Workaround: Using @formatter:off and @formatter:on tags preserves manual spacing.
**Impact**
This inconsistency breaks formatting conventions for projects relying on custom annotations with enum constants, requiring manual intervention or disabling the formatter for affected lines.
**Suggested Fix**
Investigate why the formatter skips the spacing rule for custom annotations on enum constants. It may involve the JDT parser or formatter logic treating custom-annotated constants differently from built-in ones.
Contributor guide
Assessment
This issue has not been assessed yet.