Eclipse AJDT - Error message "This method must return a result of type int" on Java aspect class

572 Views Asked by At

I'm using AJDT (AspectJ Development Tools) Eclipse plugin.

I wrote the following advice:

package com.exemple.aop.aspect;

import com.exemple.aop.bean.impl.MyBeanImpl.Iface;



aspect MyAspect {
    
    // pointcut
    pointcut clientMethod(Iface p) : target(p) && call(String com.exemple.aop.bean.impl.MyBeanImpl$Client.doSomething());  
    
    // advice
    // **LINE JUST BELOW IS MARKED AS ERROR**
    after(Iface p) returning(Object x): clientMethod(p) {
        System.out.println("Returning from client method");
        System.out.println("Target: " + p);
        System.out.println("Return: " + x);
    }
}

I wrote a unit test that works: traces are visible in the console.

However, when opening the Java file with the AspectJ/Java editor, my Eclipse UI shows an error at line "after(Iface p) returning(Object x): clientMethod(p) {" It says:

Multiple markers at this line

  • This method must return a result of type int

  • 2 AspectJ markers at this line

Note that the project is not marked with the error flag in the "Project explorer" view.

Does any one know or as an idea why the Eclipse AJDT plugin shows the error "This method must return a result of type int"?

Thanks!

2

There are 2 best solutions below

2
On

There are a few possibilities. Most likely, you are trying to open an aspect file in a java editor.

0
On

Your aspect file was created as a Java Class (MyAspect.java). You have to create it as a Aspect (MyAspect.aj).

Just do it via New -> Other -> Aspect with the same content.

You should have AspectJ plugin for Eclipse (AJDT)

That's it