Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] getting varargs to work in args and advise

Hello,

I was trying out the varargs feature in aspectJ but cannot get it to work
unfortunately. I read through
http://www.eclipse.org/aspectj//doc/next/adk15notebook/varargs-in-pcds.html
and a few posts but tried to test the example but cannot get it to work. I'm
not getting syntax errors but nothing is getting. I have pasted my simple
code here. Please help me identify where I am going wrong.

Class I am trying to advise:

package arvind.AspectJTest;

import java.util.ArrayList;

public class myTestClass {
	String strFld = "InitVal";

	public String getStrFld() {
		return strFld;
	}

	public void setStrFld(String inStr) {
		strFld = inStr;
	}

	public void setStrFld(String inStr, String inStr2) {
		strFld = inStr + inStr2;
	}

	public void setStrFld(String inStr, int myInt) {
		strFld = inStr+","+Integer.toString(myInt);		
	}

	public void setStrFld(String someStr, int dividend, int divisor) {
		strFld = someStr + "," + ((float)dividend/divisor);
	}

	public static void main(String[] args) {
		myTestClass d = new myTestClass();
		System.out.println("Initially, StrFld is  " + d.getStrFld() + ". Calling
string,string");		
		d.setStrFld(args[0],args[1]);
		System.out.println("Secondly, StrFld is  " + d.getStrFld()+ ". Calling
string,int");
		d.setStrFld(args[0],Integer.parseInt(args[1]));
		System.out.println("Thirdly, StrFld is  " + d.getStrFld()+ ". Calling
string,int,int");
		d.setStrFld(args[0],Integer.parseInt(args[1]),Integer.parseInt(args[2]));
		System.out.println("Finally, StrFld is  " + d.getStrFld());
	}
};

Aspects that I am using for advice:
1.) InittAspect.java:

package arvind.AspectJTest;

abstract aspect InitAspect{	
	pointcut PCpart1(): !within(arvind.*) && within(arvind.AspectJTest.*);
	pointcut PCpart2(): !within(InitAspect);
	pointcut catchClasses(): PCpart1() && PCpart2();}
}

2.) testProceed.java:

package arvind.AspectJTest;

aspect testProceed extends InitAspect{
	pointcut catchAllMethods(String myStr, int[] restOfArgs): catchClasses()&& 
		call(* myTestClass.setStrFld(String,int...)) && 
		within(myTestClass) && args(myStr,restOfArgs);

	Object around(String myStr, int[] restOfArgs):catchAllMethods(myStr,
restOfArgs) {
	
System.out.println("------------------------------------------------------------------");
		System.out.println(thisJoinPoint);
		
		System.out.println("around Advice: before proceed: ");
		System.out.println("First string argument is " + myStr + ". Executing the
method now...");
		Object result = proceed(myStr,restOfArgs);
		System.out.println("Result is " + result);
		
		System.out.println("around Advice: After proceed: ");
	
System.out.println("------------------------------------------------------------------");
		return result;
	}
}

When I try to compile them using ajc as follows, I get no weave info:
C:\arvind\AspectJTest>ajc -showWeaveInfo -outjar aspectjar.jar -outxml
InitAspect.java testProceed.ja
va myTestClass.java

C:\arvind\AspectJTest>

My classpath and path are correct.

Please tell me where I am making mistakes. Also, eventually I would like to
able to use args(String, Object+...) in the pointcut but i don't know if its
possible. I read through the following code and got the impression that what
i am trying to do should work now but I there is no weaving going on. Please
help. 

Thanks.
-Arvind 

http://old.nabble.com/Matching-varargs-with-subtypes%3A-call%28*-*.*%28Object%2B...%29%29-td22076248.html#a22076248
-- 
View this message in context: http://old.nabble.com/getting-varargs-to-work-in-args-and-advise-tp27984480p27984480.html
Sent from the AspectJ - users mailing list archive at Nabble.com.



Back to the top