| Summary: | [formatter] Header comment formatting for package-info.java occurs even when "Format header comment" is unchecked | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Phillip Webb <pwebb> |
| Component: | Core | Assignee: | Mateusz Matela <mateusz.matela> |
| Status: | VERIFIED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | b.muskalla, jarthana, mateusz.matela |
| Version: | 4.5.1 | ||
| Target Milestone: | 4.5.2 | ||
| Hardware: | PC | ||
| OS: | Mac OS X | ||
| See Also: |
https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=4a2995e55bb490ddda70decb3fa4c48aaec59c94 https://bugs.eclipse.org/bugs/show_bug.cgi?id=113946 https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=R4_5_maintenance&id=e8fd769578cd972bf3c36ecf3c3e1fe0e8276dde |
||
| Whiteboard: | |||
|
Description
Phillip Webb
I think the root cause of this one is that `tokenManager.setHeaderEndIndex()` is never called for `package-info.java` files. Looking at `DefaultCodeFormatter.findHeader()` the existing implementation has the following logic: > List<TypeDeclaration> types = ((CompilationUnit) this.astRoot).types(); > if (!types.isEmpty()) { > int headerEndIndex = this.tokenManager.firstIndexIn(types.get(0), -1); > this.tokenManager.setHeaderEndIndex(headerEndIndex); > } With a package-info file the `types` collection is empty. Changing the code to this: > private void findHeader() { > if (this.astRoot instanceof CompilationUnit) { > CompilationUnit compilationUnit = (CompilationUnit) this.astRoot; > List<TypeDeclaration> types = compilationUnit.types(); > ASTNode node = (types.isEmpty() ? compilationUnit.getPackage() : types.get(0)); > if (node != null) { > int headerEndIndex = this.tokenManager.firstIndexIn(node, -1); > this.tokenManager.setHeaderEndIndex(headerEndIndex); > } > } > } Seems to solve the issue. Thanks Phillip! Fixed with http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=4a2995e55bb490ddda70decb3fa4c48aaec59c94 Keeping the bug open for eventual backport to 4.5.2. There's a regression fix (respecting the "Format header comment" setting), but also a fix for an older bug 113946 (differentiating between header comments and package javadoc). We'd love to see this backported as it makes it really hard to create package-info files consistently (and we love them for the null-support). Verified for 4.6 M3 using I20151026-2000 build Backported to 4.5.2 with http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=R4_5_maintenance&id=e8fd769578cd972bf3c36ecf3c3e1fe0e8276dde Verified for 4.5.2 with build M20160113-1000 |