Bug 105771 - Non-void aspect methods have void return type
Summary: Non-void aspect methods have void return type
Status: RESOLVED DUPLICATE of bug 89795
Alias: None
Product: AspectJ
Classification: Tools
Component: Compiler (show other bugs)
Version: DEVELOPMENT   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P2 normal (vote)
Target Milestone: 1.5.0RC1   Edit
Assignee: Andrew Clement CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-02 06:47 EDT by Chris Burnley CLA
Modified: 2005-11-03 06:47 EST (History)
0 users

See Also:


Attachments
Screenshot of bug (75.45 KB, image/png)
2005-08-02 11:27 EDT, Chris Burnley CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Burnley CLA 2005-08-02 06:47:45 EDT
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
Comment 1 Chris Burnley CLA 2005-08-02 11:27:24 EDT
Created attachment 25559 [details]
Screenshot of bug
Comment 2 Sian January CLA 2005-08-04 04:21:21 EDT
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 ***
Comment 3 Sian January CLA 2005-08-04 05:18:47 EDT
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
Comment 4 Sian January CLA 2005-08-04 05:20:11 EDT
Transferring to the compiler
Comment 5 olivier CLA 2005-09-16 05:45:55 EDT
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
  
Comment 6 Adrian Colyer CLA 2005-10-28 08:40:19 EDT
for investigation
Comment 7 Andrew Clement CLA 2005-11-01 12:38:39 EST
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()?
Comment 8 Chris Burnley CLA 2005-11-01 14:51:26 EST
It still isn't working for me. This is with the latest development build.
Comment 9 Chris Burnley CLA 2005-11-01 14:54:21 EST
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.
Comment 10 Andrew Clement CLA 2005-11-01 15:33:27 EST
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)
Comment 11 Chris Burnley CLA 2005-11-01 15:36:42 EST
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.
Comment 12 Andrew Clement CLA 2005-11-01 15:42:01 EST
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 ;)
Comment 13 Andrew Clement CLA 2005-11-02 05:39:10 EST
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).
Comment 14 Andrew Clement CLA 2005-11-03 06:47:05 EST
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 ***