| Summary: | PackageBinding annotations not available | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Tom Ball <tball> | ||||
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> | ||||
| Status: | CLOSED WONTFIX | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | stephan.herrmann | ||||
| Version: | 4.5.1 | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Mac OS X | ||||||
| Whiteboard: | stalebug | ||||||
| Attachments: |
|
||||||
What is typeEqualsClass()? Does the package binding have any annotations or none at all? Do you by chance have a full JUnit ready for us to run? Sorry, typeEqualsClass checks for package names rather than comparing package bindings. But it can simply be replaced:
boolean hasAnnotation(IBinding binding, Class<?> annotationClass) {
for (IAnnotationBinding annotation : binding.getAnnotations()) {
throw new AssertionError("never happens");
}
return false;
}
The package binding has no annotations, whether package-info.java is on the source path, or package-info.class is on the class path.
Do you have a JUnit test example that takes multiple sources? I haven't written a test for JDT, but would be happy to do so.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie. |
Created attachment 258054 [details] Source for package-annotations bug. The attached zip contains an annotation (simplified version of javax.annotation.ParametersAreNonnullByDefault), package-info using that annotation, and a test file that has a method with a parameter. To check for "inherited" annotations by this, we have code similar to: boolean isNonNullParameter(IVariableBinding parameter) { if (hasAnnotation(parameter, ParametersAreNonnullByDefault.class)) { return true; } IPackageBinding pkg = parameter.getDeclaringMethod().getDeclaringClass().getPackage(); return hasAnnotation(pkg, ParametersAreNonnullByDefault.class); } boolean hasAnnotation(IBinding binding, Class<?> annotationClass) { for (IAnnotationBinding annotation : binding.getAnnotations()) { if (typeEqualsClass(annotation.getAnnotationType(), annotationClass)) { return annotation; } } return null; } The zipped classes fail to return true for the Test.test(s) parameter, because the package binding has no annotations. I've tried this with putting package-info.java on the sourcepath, as well as package-info.class on the classpath. Is there some workaround to get a package's annotations while working with one of its classes?