Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ajdt-dev] documentation for @DeclareParents

I think the problem comes from the way you declared the FeelingImpl: it must be static class. Otherwise in order to create an instance there is a need for an enclosing type instance (I think this is the message refering to).

hth,

./alex
--
.w( the_mindstorm )p.

#: Oliver Böhm changed the world a bit at a time by saying on  10/28/2005 10:48 PM :#
short addition to my mail before: without "static" it also doesn't
compile - I get the error message "@DeclareParents: can only be used on
a public static field whose type is an interface" - so the documentation
seems to be correct.

But with "static" I get "No enclosing instance..." as error message :-(

Any remarks?
Oliver


Oliver Böhm wrote:
Hello,

as mentioned here on the list the @DeclareParents syntax changed a
little bit but is implemented now (when I remember right). Today I
checked the documentation in CVS and found the following comment in
ataspectj.xml:

// here is the actual ITD syntax when using @AspectJ
// public static is mandatory
// the field type must be the introduced interface. It can't be a class.
@DeclareParents("org.xzy..*")
public static Moody introduced = new MoodyImpl();

But when I tried it with my example and the newest build
(1.5.0.200510241400) I get the error message
"No enclosing instance of type GefuehlsAspekt is accessible. Must
qualify the allocation with an enclosing instance of type GefuehlsAspekt
(e.g. x.new A() where x is an instance of GefuehlsAspekt)."
(you'll find the GefuehlsAspekt at the end of this mail)
I think the "static" is wrong here - without it, it seems to compile. So
here my questions, before I dig deeper into the problem:

1) is the documentation wrong here?

2) will @DeclareParents work without the "static"?

regards
Oliver



For completness here my example aspect, which is very similar to the
Mood example in the documentation:

public class GefuehlsAspekt {

    public interface Feeling {
        String getSense();
    }

    public class FeelingImpl implements Feeling {
        private String sense = "I feel good";

        public String getSense() {
            return sense;
        }
    }

    @DeclareParents("verwaltung.Person")
    public static Feeling introduced = new FeelingImpl();

    @After("execution(* *.*(..)) && this(f) && !within(GefuehlsAspekt)")
    public void howdoyoufeeltoday(Feeling f) {
        System.out.println(f.getSense());
    }

}






Back to the top