我正在尝试使用 aspectJ 访问参数的名称,但我总是得到arg0而不是真实名称。我发现我应该在AspectJ JoinPoint 问题中使用 -g 参数激活 java 调试选项,但这对我不起作用......
这是我的java代码:
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));
}
这是我的 AspectJ 代码:
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);
}
电流输出:
第一个参数名称:arg0
我需要作为输出:
第一个参数名称:c
我有这两个选择:
我还需要激活什么?
非常感谢 !