[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-dev] Constructor Join Point and Super() constructor
|
> what exactly I want is to call the
> constructor of Superclass class before the constuctor
> of Tester class.
As I said, what you're asking specifically is not possible
because of the special semantics of super() in a
constructor.
When you are interposing a new parent, you can use after
advice to do initialization in the parent after the child
instance has initialized:
after() returning (SuperClass me) :
call((!SuperClass && SuperClass+).new(..)) {
me.init("hello");
}
That means using a method to do some superclass
initialization after the subclass constructor has run.
You can't do this before the subclass constructor runs
because there is no target object for a constructor
execution.
Hope this helps -
Wes
On Thu, 1 Sep 2005 12:44:02 +0100 (BST)
nathar shah <shah123khan@xxxxxxxxx> wrote:
> Erm..There is a problem with your suggested approach.
>
> Let put the scenario clearer..
> I am the programmer for a class named Superclass
> and I need to weave the bytecode Testear class writen
> by someone that i dont know.
>
> I am modifying the Tester class
> relationship(structure) through :-
> > declare parents: Tester extends Superclass;
> This construct is part of my Test aspect construct
> shown earlier. Assuming that the programmer does not
> have access to the source code and he/she can only
> modify (or weave) the bytecode of Tester class, it is
> not possible for the programmer to know constructors
> of Tester class.
>
> It is also not possible for me to override (by using
> around() advice) the constructors of Tester class
> because it may cause problems as I dont know what
> initialisation they are doing in the constructor. The
> least that i could do is just weave each constructor
> in Tester (I have only shown 1 constructor in my
> previous email, but now assume that there are many
> constructors in Tester class) with super(*,*) keyword
> so that a specific constructor of Superclass class can
> be invoked
>
> Your approach only allows another constructor of
> Tester class to be called instead the default Tester
> constructor. But, what exactly I want is to call the
> constructor of Superclass class before the constuctor
> of Tester class.
>
> How would this be possible?
>
> Regards,
> Shah
>
>
>
> --- Wes Isberg <wes@xxxxxxxxxxxxxx> wrote:
>
> > aack!
> >
> > > void around(): cons(){
> > > super(a, b);
> >
> > super(..) should never be available in advice.
> > That I think is a compiler bug.
> >
> > wrt calling super, does it work to declare the
> > constructor?
> >
> > Target.new() {
> > super("hello");
> > ...
> > }
> >
> > (If the default constructor is already declared,
> > then you
> > can't do that.)
> >
> > Another approach is to replace the calls:
> >
> > Target around() : call(Target.new()) {
> > return new Target("hello");
> > }
> >
> > You might combine this with the inter-type
> > declaration of
> > the constructor.
> >
> > Since super(..) is a special form in Java, that's
> > pretty
> > much all you can do in AspectJ.
> >
> > Wes
> >
> > On Thu, 1 Sep 2005 00:33:37 +0100 (BST)
> > nathar shah <shah123khan@xxxxxxxxx> wrote:
> > > Hi,
> > >
> > > I am looking at ways of developing an aspect which
> > > will call super() in the constructor so that its
> > super
> > > constructor can be called. For example if I have
> > class
> > > such as
> > >
> > > public class Tester{
> > > public Tester(){
> > > }
> > > }
> > >
> > > Currently implicit super() constructor is called
> > > automatically. But I want an aspect which will
> > call
> > > explicit super() constructor with some
> > arguments.The
> > > class structure of Tester will be modified using
> > > declare parents. I have developed an aspect such
> > as
> > > follows but facing problem when it is weaved
> > saying
> > > "super constructor call must be the first
> > statement in
> > > the constructor"
> > >
> > > aspect Test{
> > > declare parents: Tester extends Superclass;
> > >
> > > ClassA a = new ClassA();
> > > ClassB b = new ClassB();
> > >
> > > pointcut cons(): preinitialization(Tester.new());
> > >
> > > void around(): cons(){
> > > super(a, b);
> > > proceed();
> > > }
> > > }
> > >
> > > Note: I need the aspect to modify the Tester class
> > > structurally by extending Superclass class. Thus,
> > I
> > > need to call Super() constructor with some
> > arguments
> > > before the constructor of Tester is executed.
> > >
> > > This is a simple simulation of the problem I am
> > facing
> > > in my application development. Could anyone there
> > help
> > > me?
> > >
> > >
> > >
> > >
> > >
> > >
> >
>
___________________________________________________________
> > >
> > > How much free photo storage do you get? Store your
> > > holiday
> > > snaps for FREE with Yahoo! Photos
> > > http://uk.photos.yahoo.com
> > > _______________________________________________
> > > aspectj-dev mailing list
> > > aspectj-dev@xxxxxxxxxxx
> > >
> > https://dev.eclipse.org/mailman/listinfo/aspectj-dev
> >
> > _______________________________________________
> > aspectj-dev mailing list
> > aspectj-dev@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/aspectj-dev
> >
>
>
>
>
>
>
>
___________________________________________________________
>
> To help you stay safe and secure online, we've developed
> the all new Yahoo! Security Centre.
> http://uk.security.yahoo.com
> _______________________________________________
> aspectj-dev mailing list
> aspectj-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-dev