Bug 211052 - Invalid error for declare @type when specifying enum value for annotation
Summary: Invalid error for declare @type when specifying enum value for annotation
Status: RESOLVED FIXED
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P2 major (vote)
Target Milestone: 1.5.4   Edit
Assignee: aspectj inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-27 06:52 EST by Andrew Clement CLA
Modified: 2007-12-04 03:42 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Clement CLA 2007-11-27 06:52:30 EST
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() {
  }
}
Comment 1 Andrew Clement CLA 2007-12-04 03:42:33 EST
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.



Comment 2 Andrew Clement CLA 2007-12-04 03:42:59 EST
fixes available