Project: JDT
Bug 196200 [jsr269] Need annotation bindings even when code contains errors
Reported: 2007-07-11 14:06:55 | Status: verified fixed

The JSR-269 spec, very unfortunately, requires certain information to be available to annotation processors even when the code being compiled contains semantic errors such as missing types. Here's the relevant text from the javax.lang.model.element package javadoc: "During annotation processing, operating on incomplete or erroneous programs is necessary; however, there are fewer guarantees about the nature of the resulting model. If the source code is not syntactically well-formed, a model may or may not be provided as a quality of implementation issue. If a program is syntactically valid but erroneous in some other fashion, the returned model must have no less information than if all the method bodies in the program were replaced by "throw new RuntimeException();". If a program refers to a missing type XYZ, the returned model must contain no less information than if the declaration of type XYZ were assumed to be "class XYZ {}", "interface XYZ {}", "enum XYZ {}", or "@interface XYZ {}". If a program refers to a missing type XYZ<K1, ... ,Kn>, the returned model must contain no less information than if the declaration of XYZ were assumed to be "class XYZ<T1, ... ,Tn> {}" or "interface XYZ<T1, ... ,Tn> {}" Note that this spec is ambiguous, is probably not perfectly implementable even in principle, and does not provide any real benefit to users; however, it is unlikely that we can get Sun to substantially change it. The 6.0 javac compiler does implement the described functionality. To implement this in Eclipse, I think we need annotation bindings (of some sort) to be available in the compiler even when the annotated types are unresolved. I don't know if this is possible or practical, but this bug report can serve as a discussion forum. I have added a test case, org.eclipse.jdt.compiler.apt.tests.NegativeTests, that demonstrates the problem. The test case currently fails (and therefore is not part of the TestAll suite).

Files changed in fix:
org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/error_out/A_test801.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractMethodWorkSpace/ExtractMethodTests/error_out/A_test802.java org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/ui/tests/quickfix/UnresolvedTypesQuickFixTest.java