Community
Participate
Working Groups
If I add a method to an aspect like this: public aspect Test { public String getValue(){ return "VALUE"; } } then when I try to invoke this method on the aspect instance, the method will be reported by the compiler and code completion to return void. public void testGetValue(){ // an error will be reported since the compiler thinks getValue is void String val = ((Test)Aspects.aspectOf(Test.class)).getValue(); } I'm using ajdt dev build on eclpse 3.1 rc (2?) (I20050617-1618): 1:44:51 AM AJDT Plugin Startup AJDT version: 1.2.1 for Eclipse 3.1 AspectJ Compiler version: DEVELOPMENT doneAutoOpenXRefView/Users/chris/Workspace = true org.aspectj.ajdt.core.compiler.BuildOptions.showweavemessages = true ajde.version.at.previous.startup = 1.5.0.20050721171410 neverRunMigrationWizard = true org.aspectj.ajdt.core.compiler.BuildOptions.incrementalMode = false
Created attachment 25559 [details] Screenshot of bug
Thank you for the detailed bug report. Unfortunately our code completion support is fairly limited. We already have a bug open to track this so I am closing this one as a duplicate. *** This bug has been marked as a duplicate of 74419 ***
Hi Chris - sorry about that, I misread your original report. This actually looks like a compiler issue. I don't believe the 'Aspects' feature is fully implemented yet, as it was designed for use with the @AspectJ syntax style. Since you are using the code style you should be able to do something like this to get the instance of the test aspect: boolean hasAspect = Test.hasAspect(); if(hasAspect) { Test testAspect = Test.aspectOf(); ... } The above works because the default model for aspect instantiation is as a singleton. Alternatively if you are using one of the per... instantiation models and want to find the aspect instance for a particular object (myObject) you would use: boolean hasAspect = Test.hasAspect(myObject); if(hasAspect) { Test testAspect = Test.aspectOf(myObject); ... } Please see the AspectJ Programming Guide for more information: http://www.eclipse.org/aspectj/doc/released/progguide/index.html
Transferring to the compiler
Hi, I got the same error when using inner-aspects. I add an aspect inside an exisiting class file, then I change to .aj file extension. Now all the non-void methods of the class are showed as having void return type in the Outliner. This error have no effects on compilation and my application runs OK. The boring point is that when accesing to these methods from standard java classes they are also shown as having void return type. An inline error is shown when accesing the return object of these methods - complaining about the misused of the void return object - BUT the class is not showed as containing an error (neither in class name tab nor in package explorer) I am working on MAC OS (tiger) , jdk 1.5, eclipse 3.1 and AJDT 1.3.0.20050915173842
for investigation
I'm having trouble working out exactly what might be failing here. I went back to the first comment in the bug report - I created: public aspect Test { public String getValue(){ return "VALUE"; } } then I created a method: public void testGetValue(){ // an error will be reported since the compiler thinks getValue is void String val = ((Test)Aspects.aspectOf(Test.class)).getValue(); } And everything worked fine, once I'd imported org.aspectj.lang.Aspects. Have we accidentally recently fixed this or is it still going wrong for you? I tried it with both the java and the aspectj editor and it was OK. === On comment #5, I'm a little confused, I can't see the return type of any method in my java editor outline - is that a Mac only feature? or something I need to configure? Was it the return type of the Aspects.aspectOf() problem that was an issue? or the return type of the method you called on the result returned from aspectOf()?
It still isn't working for me. This is with the latest development build.
Actually, it seems as though this isn't reported as a compile error, but is reported in the editor as an error. Not sure if it ever was compile error.
Is it only reported as an error in the editor if you have the file in question open with the java editor? Or does it also happen for the aj editor? (If you close the file, you can do 'Open with' from the context menu to choose which you want)
Interstingly it is only reported as an error in the Java editor. In the AspectJ editor it is fine, though I notice that the context menu still shows the return type as void.
I need to check with Sian, but I think that may be a known problem with eager parsing in the Java editor. thanks for responding to my ramblings so quickly ;)
Ok. spoken to Sian - the remaining issue is that if you refer to something in an aspect from a java file (like you are by referring to getValue() in the aspect type Test) then you have to use the AspectJ editor to avoid any bogus eager parsing errors. See bug 89795. (Because the java editor can't see the method in the aspect properly with its eager parsing).
The editor problem is logged in AJDT, currently we recommend using the AJ editor for any source code in an AJ project, but we have bug 93772 to recognize that the AJ editor isn't as capable as the Java editor in some areas (yet). Effectively this is another scenario related to 89795, so i'll mark it as a dup of that. *** This bug has been marked as a duplicate of 89795 ***