Community
Participate
Working Groups
This bug was originally found by Charles Zhang and reported as an AJDT problem on our newsgroup. I think it's an AspectJ compiler problem, and so am reporducing it here. I am using AspectJ 1.1rc1 on Win2K. The problem first manifested using the Eclipse AJDT plugin. If you create a package called "aspect.test" and then create an aspect MyAspect in that package, you get an error 'Error Syntax error on token "aspect", "Identifier" expected' (the error is flagged on the bad package name). I assume this is because "aspect" is a keyword in AspectJ, so this is expected behaviour (ideally we could catch it when the package is created, but we'd have to write a specialised AspectJ New Package Wizard for that. Right now, Java keywords are caught by that wizard, so you can't create a new package called "class.foo", e.g.) The unusual behaviour is that this program, with aspect "MyAspect" in package "aspect.test", does compile using ajc from the command line, and runs. On the other hand, a class in a package called "class.foo" will not build with ajc (you get the error "identifier expected" on the "class.foo" name). This seems inconsistent (both between the behaviour of Java keywords versus AspectJ keywords, as well as between the ide versus the commandline). I would expect a similar "identifier expected" error when I try to use "apsect.foo" as an identifier.
Created attachment 4756 [details] Trivial aspect in a package that has the keyword "aspect" in its name.
This bug merits some more work to understand the details after the 1.1 release. In order to be compatible with existing Java code bases, we've tried to not add any new keywords to the AspectJ grammar. Instead, words like 'aspect' are treated as pseudo-keywords that are also allowed to be used in most identifier positions. This means that code which has a field called 'aspect' is legal, whereas code with a field called 'class' is not. We should probably look at the grammar more closely to understand any places where this liberalness breaks down and at least document that behavior. Ceratinly, having a top-level package named aspect is the kind of thing that might lead to trouble. However, we definitely want to support package names like 'com.parc.mycode.aspect' which are easier to imagine in large-scale existing code bases.
*** Bug 41785 has been marked as a duplicate of this bug. ***
Version: 1.6.5.200903301249 AspectJ version: 1.6.4.20090329215800 This is more curious than it seems... I just tried this. -- src/aspect/Aspect.aj package aspect; // after build, error marker here, and aspect is bold as keyword public aspect Aspect { } However, if I look in my bin directory I get: /bin - /aspect - /Aspect.class When I should see /bin - /aspect - /aspect/Aspect.class The package folder is created, but the generated class is not in it.