Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Ok, I have another crazy scenario:

A question this long deserves a short answer: proceed.

I might add that this is very well documented -- it's even in the 2-page
"quick reference" for aspectj in the text associated with around().  Did you
RTFM?

Eric

-----Original Message-----
From: Anagnost, Ted (MED, GEMS-IT) [mailto:Theodore.Anagnost@xxxxxxxxxx]
Sent: Tuesday, July 01, 2003 3:38 PM
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] Ok, I have another crazy scenario:


This is a long but simple question, please bear with me:

public class A
{
	private B m_b;
	
	public void method()
	{
		m_b = new B( "Test" );
		m_b.method();
	}
}

public class B extends D
{
	public B(String string)
	{
	}

	public void method()
	{
	}
}

public class C extends D
{
	public C(String string)
	{
	}

	public void method()
	{
	}
}

My original question was:
Is it possible to change A so that when it tries to do this:

		m_b = new B( "Test" );
		m_b.method();		
		
it actually effectively does this:

		m_b = new C( "Test" );
		m_b.method(); // calls C's method()		

David Vollbracht (thanks!) gave this solution, which works:

aspect BToC
{
   declare parents: C extends B;

   /**
    * No-arg constructor for class B so Class C doesn't
    * need to be changed
    */
   public B.new()
   {
      this( "Dummy String" );
   }

   pointcut createB( String string ) :
      call( B.new( String ) ) && args( string );

   B around( String string ) : createB( string )
   {
      return new C( string );
   }
}

Here's the question (finally!).  Is there a way within the 'around' part
to still allow the 
creation of 'B' (see example above) and get access to that instance?
Something like this:

   B around( String string ) : createB( string )
   {
	B b = ...some way to get access to the originally intended
object instance B...

      return new C( string );
   }


Thanks for any help!

Ted

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top