我試圖訪問使用aspectJ的參數的名稱,但我總是得到arg0而不是真實名稱。我發現,我應該激活與-g參數Java調試選項在AspectJ JoinPoint question但是,這並不爲我工作...如何在使用AspectJ的eclipse中啓用調試符號?
這是我的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);
}
電流輸出:
firstParameterName所示:arg0
我需要有作爲輸出什麼:
firstParameterName:C
我有這兩個選項:
我還需要激活什麼?
非常感謝!
謝謝您的幫助。我必須做的是:在方法** s.add(c)**內部**我需要訪問** c **變量名來保存它,並稍後在另一個Aspectj中監視它。 – 2013-03-25 16:43:19