Skip to content

Commit b289f84

Browse files
committed
Handle Markdown in EnumDeclaration
This commit fixes the IOBE on formatting Markdown in Enum declaration part Fixes : #5032
1 parent 4ea0cd7 commit b289f84

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16554,4 +16554,21 @@ record X<T>(T value) {
1655416554
""";
1655516555
formatSource(input, expected);
1655616556
}
16557+
16558+
public void testEnumJavaDocBreak() throws JavaModelException {
16559+
setComplianceLevel(CompilerOptions.VERSION_23);
16560+
String input = """
16561+
public enum TestEnum {
16562+
/// A
16563+
A;
16564+
}
16565+
""";
16566+
String expected = """
16567+
public enum TestEnum {
16568+
/// A
16569+
A;
16570+
}
16571+
""";
16572+
formatSource(input, expected);
16573+
}
1655716574
}

org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/LineBreaksPreparator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2014, 2025 Mateusz Matela and others.
2+
* Copyright (c) 2014, 2026 Mateusz Matela and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -163,8 +163,7 @@ public boolean visit(EnumDeclaration node) {
163163

164164
for (int i = 0; i < enumConstants.size(); i++) {
165165
EnumConstantDeclaration declaration = enumConstants.get(i);
166-
if (declaration.getJavadoc() != null)
167-
this.tm.firstTokenIn(declaration, TokenNameCOMMENT_JAVADOC).breakBefore();
166+
this.tm.firstTokenIn(declaration.getJavadoc(), ANY).breakBefore();
168167
if (declaration.getAnonymousClassDeclaration() != null && i < enumConstants.size() - 1)
169168
this.tm.firstTokenAfter(declaration, TokenNameCOMMA).breakAfter();
170169
}

0 commit comments

Comments
 (0)