私は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);
}
現在の出力:
firstParameterName:arg0
出力として必要なもの:
firstParameterName:c
私にはこの2つのオプションがあります:
他に何をアクティブ化する必要がありますか?
どうもありがとうございます !