| Summary: | [1.5][formatter] Formatter unable to format due to AbortFormatting | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Philipe Mulet <philippe_mulet> | ||||
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> | ||||
| Status: | CLOSED DUPLICATE | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | frederic_fusier, mateusz.matela | ||||
| Version: | 3.4 | ||||||
| Target Milestone: | 4.5 | ||||||
| Hardware: | PC | ||||||
| OS: | Windows XP | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
Sounds like formatting of annotation is ok here.
The problem seems to originate from the CodeFormatterVisitor aborting the formating while scanning the following MethodDeclaration:
void foo() {
this.bar();
Zork2 z;
}
These are due to the sytanx errors which make the compiler gives up before having set the statements of method foo. So, as the method has no statement, the formatter expects to have a closing brace after the opening one, hence also gives up at this stage when encountering the token 'this'... So, close as WORKSFORME Reopen. There is no syntax error in this case. The only problem is that the anonymous type declaration doesn't get its method bodies parsed properly. The parser doesn't walk annotations to parse the method bodies. Annotations should be constant expressions. So technically speaking it is not possible to have an anonymous declaration as a annotation value. But syntactically it is possible to get it so we should support it inside the formatter which means we should parse these methods. Now in order to prevent the parser to slow down, we should set a bit on the method declaration if it has an annotation that contains method declarations. Whatever we do to reduce the impact on parsing, we still need to do more work in order to get the method bodies inside annotation when that case is clearly an error. So we need a "good" ast for the formatter to work, but it is pointless for the compiler as the code is invalid anyway. I would be tempted to close as WONTFIX, but I'll let you have a second look using the hack I made. Created attachment 150730 [details]
First draft
We might want to set a bit on the declaration that contains the annotations to indicate if one of its annotations contains a method body. This will still require several arrays traversals inside the parser.
The patch is not sufficient as it needs to recursively walk annotations as annotation member value pair can be annotations. I think the best approach is to close as WONTFIX. This is not critical enough and the code is incorrect anyway. On save, right errors are reported and once they are fixed, the code will format again. Philippe, do you really believe we should fix this issue ? This problem no longer occurs after formatter redesign. *** This bug has been marked as a duplicate of bug 303519 *** |
Build 3.4M3 I can't get the following code to be handled by the formatter: import java.io.Serializable; public final class X implements Serializable { class SMember extends String {} @Annot(value = new SMember()) void bar() {} @Annot(value = new X(){ ZorkAnonymous1 z; void foo() { this.bar(); Zork2 z; } }) void foo() {} } @interface Annot { String value(); }