I'm trying to access the name of a parameter using aspectJ, but I always get arg0 instead of the real name. I found that I should activate java debugging options with -g parameter at AspectJ JoinPoint question but that doesn't work for me...
This is my java code:
private Set<Collection<String>> s;
private Collection<String> c;
public HashCodeProperty() {
s = new HashSet<Collection<String>>();
c = new ArrayList<String>();
}
/**
* method that satisfy property
*/
public void satisfy() {
c.add("this is ok");
s.add(c);
System.out.println("Collection is in Set: " + s.contains(c));
}
/**
* method that violate the property
*/
public void violate() {
c.add("this is ok");
s.add(c);
c.add("don't do this");
System.out.println("Collection is in Set: " +s.contains(c));
}
This is my AspectJ code:
pointcut addElementsToHashCodeSet() : call (* Set.add(..));
declare warning: addElementsToHashCodeSet(): "pointcut: addElementsToHashCode()";
after(): addElementsToHashCodeSet() {
monitorHashCode.addElementsToHashCode((MethodSignature)thisJoinPoint.getSignature());
public void addElementsToHashCode(MethodSignature methodSignature) {
System.out.println("\naddElementsToHashCode.");
// We need to access to real PARAMETER NAME
// Then we will concatenate with method and full class name
String firstParameterName = methodSignature.getParameterNames()[0];
// Add firstParameterName to an array that will contain all
// the name of the collections inserted into the HasSet
System.out.println("\nfirstParameterName: "+firstParameterName);
}
Current output:
firstParameterName: arg0
What I need to have as output:
firstParameterName: c
I have this two options:
What else do I have to activate?
Thank you very much !