From leavens@cs.iastate.edu Sun Oct 27 18:32:50 2002 Date: Sun, 27 Oct 2002 18:19:16 -0600 (CST) From: Gary T. Leavens To: Becca Wemhoff Cc: George Ushakov , Gary Leavens Subject: Re: HW3 - 7 Becca, On Sun, 27 Oct 2002, Becca Wemhoff wrote: > For #7, we're supposed to "add another test method" to the *class* > aspectjhw.FibonacciTest. > > When I have something like this: > > > import aspectjhw.FibonacciTest; > > > > public aspect FibLargerTest extends FibonacciTest > > { > > I get the errors: > > > ./aspectjhw/FibLargerTest.java:17:1: aspectjhw.FibonacciTest() not found > > in aspectjhw.FibonacciTest > > { > > ^ > > ./aspectjhw/FibLargerTest.java:16:1: aspectjhw.FibonacciTest() not found > > in aspectjhw.FibonacciTest > > public aspect FibLargerTest extends FibonacciTest > > ^ > > The constructor for FibonacciTest has an argument; I *think* that's > why the problem is happening. > > I couldn't find any examples in the papers nor at the aspectj.org site > that have aspects extending *classes*, although they say that it can > be done. The only code example is of an aspect extending an abstract > aspect. > > I can simulate the behavior with an after aspect on the pointcut > execution(* aspectjhw.FibonacciTest.testFib()), but the question > reads like we should be using the extend... > > So, > (1) extend necessary for this question (after all, the advice gets > run...) or should we just use pointcuts like above? As you note, an aspect can only extend another (abstract) aspect. So first thing to do is take out the "extends" clause from your aspect FibLargerTest. You should just use a static introduction. This is a feature we haven't really discussed in class but it's listed in the AspectJ programmer's guide in the introduction under "static crosscutting" and summarized in appendix A, section 5 under "introductions". The introductions provide a way for an aspect to add a method to a class. > (2) even if not necessary, how do you extend an existing *class*? Either with a static introuction or a declare parents clause. Try it... > ---------------------------------------- > Also, even when I use import junit.framework.*, I still get an error > if I don't fully quantify the assertTrue: > > > ./aspectjhw/FibLargerTest.java:21:10: can't find any method > > with name: assertTrue > > assertTrue(Fibonacci.fib(30) > Fibonacci.fib(20)); > > But code like > junit.framework.TestCase.assertTrue(Fibonacci.fib(40) > Fibonacci.fib(30)); > works fine. > > Is this something I don't realize about Java? No something you don't realize about AspectJ. It works to fully qualify it, but what you really want is to use a static introduction, which will make it be as if your code was inside FibonacciTest, where it will work. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ----------------------------------------------------------- From leavens@cs.iastate.edu Mon Oct 28 14:55:45 2002 Date: Mon, 28 Oct 2002 14:54:48 -0600 (CST) From: Gary T. Leavens To: Becca Wemhoff Cc: George Ushakov , Gary Leavens Subject: Re: hw3-7 -- do we need to create another class? Becca, Sorry it's taken a while to answer this... On Mon, 28 Oct 2002, Becca Wemhoff wrote: > I had looked at the "declare parents" earlier (got it off the Quick > Reference and had found a powerpoint presentation on 2/6/2002 by > Zhenxiao Yang that had a 4-slide example on "introduction") and had > abandoned it because it was generating the same error that I emailed > to you. E.g. > declare parents: FibLargerTest implements FibonacciTest; > ^^^^^^^^^^^^^ > produced that same error about FibonacciTest() not found. > > Then, I looked at the 'Static Crosscutting' example and found that > I used the same name as the aspect and they didn't. Duh. Using > declare parents: FibLarger implements FibonacciTest; > ^^^^^^^^^ > worked like a charm! (And no pointcuts nor advice to define, either.) > > My question is: do I have somehow define FibLarger as a class somewhere > in this aspect? I'm thinking that since it's not defined, AspectJ > creates a default class and that's why everything works. I'm not sure about that. I would guess you have to define FibLarger as a class somewhere and this declaration would make it a subtype (if you change "implements" to "extends" as in your next email) of FibonacciTest. But the homework question is not about using "declare parents" or about adding a subclass of FibonacciTest. I wanted you to add a *method* testLargerArgs to the class FibonacciTest. Don't use declare parents but a static introduction. See my earlier email. You'll have to use something of the form FibonacciTest.testLargerArgs in an aspect to do it. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 ---------------------------------------------------------- From leavens@larch.cs.iastate.edu Tue Oct 29 16:57:49 2002 Date: Tue, 29 Oct 2002 15:37:48 -0600 (CST) From: Gary T. Leavens To: Computer Science 541 , George Ushakov , Satish Kumar Vemula , Tongjie Chen Subject: A few points from today's class Hi, I found by testing that "this" in advice does refer to the aspect instance, not the object being advised. Also that you can write (as I suspected) "public abstract pointcut" so that the "abstract doesn't have to come first. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 -------------------------------------------------------- From leavens@cs.iastate.edu Wed Oct 30 04:40:05 2002 Date: Wed, 30 Oct 2002 04:37:44 -0600 (CST) From: Gary T. Leavens To: Brian Patterson Cc: cs541s@cs.iastate.edu Subject: Re: Confused about what you're asking for HW4, #1 Brian, On Tue, 29 Oct 2002, Brian Patterson wrote: > Well, I've been trying to answer problem #1 and all I can come up with > is (a) below: > a. Easily, clearly, and modularly insert code to be done before, > after, or around another operation ... > > So, is (a) just too generic and I need to break it down or am I missing > the point of the problem? I think (a) is just too generic. I would like you to break it down a bit. Thinking about what these changes can accomplish (their purpose) should help. -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 --------------------------------------------- From leavens@cs.iastate.edu Wed Oct 30 10:34:46 2002 Date: Wed, 30 Oct 2002 10:33:13 -0600 (CST) From: Gary T. Leavens To: Becca Wemhoff Cc: cs541s@cs.iastate.edu Subject: Re: COMS 541: A few points from today's class Becca, On Wed, 30 Oct 2002, Becca Wemhoff wrote: > Yeah, I was expecting this when you consider that the method call > join point is not in the object as yet. > > So, how can we get access to the public (private?) variables of the > object being advised? Would we extend the class using static > crosscutting and access the variables from within that extended > method? That's why we have context-exposing join points of the form this(...) and target(...) so you can give a name to the this object at the join point itself. I admit it takes a bit of getting used to... -- Gary T. Leavens Department of Computer Science, Iowa State University 229 Atanasoff Hall, Ames, Iowa 50011-1041 USA http://www.cs.iastate.edu/~leavens phone: +1-515-294-1580 -----------------------------------------------------------------