Community
Participate
Working Groups
Reported on mailing list by Ashley Williams. Here is a test program aspect ConfigureTracing { declare @type : MyPojo : @Tracing(level = LoggingLevel.DEBUG); // compile error!!! declare @method : * MyPojo.calculate() : @TestAnnotation; } @interface Tracing { LoggingLevel level(); } @interface TestAnnotation {} class Level { Level(int i) {} public final static Level ALL = new Level(1); public final static Level DEBUG = new Level(2); public final static Level ERROR = new Level(3); public final static Level FATAL = new Level(4); public final static Level INFO = new Level(5); public final static Level OFF = new Level(6); public final static Level WARN = new Level(7); } enum LoggingLevel { ALL(Level.ALL), DEBUG(Level.DEBUG), ERROR(Level.ERROR), FATAL(Level.FATAL), INFO( Level.INFO), OFF(Level.OFF), WARN(Level.WARN); private final Level level; private LoggingLevel(Level level) { this.level = level; } public Level getLevel() { return level; } } class MyPojo { public static void calculate() { } }
The problem here is an attempted double resolution of the annotation by the compiler. The annotation is first resolved when processing the declare @type statement. It is then attached to the MyPojo type. We then encounter it again when processing the MyPojo type. The case statement in QualifiedNameReference.resolveType() initially worked out that LoggingLevel.DEBUG was a FieldBinding and set the flags appropriately - when we re-process the annotation the flags are still set to just Field (bit1) and so the case statements dont match and we drop through to the error case. There are two possible solutions: 1. Change the case statement to allow for just the field bit being set (replace case Binding.VARIABLE with both 'Binding.FIELD' 'Binding.LOCAL') 2. Don't go and re-resolve the type is we already know it. This is what I've implemented and it fixes this case. The change is in ASTNode.resolveAnnotations() which now checks the resolvedType before calling resolveType() The testcase above now passes. I'm also going to add some tests relating to declare @type and packages - where the target for the declare @ is in another package. 6 new tests added, that vary whether the annotation and the target type are imported or accessed through a fully qualified reference. All works fine. Fixes and tests all committed.
fixes available