2017-08-09 1 views
0

In meiner aktuellen Android-Anwendung arbeitet ich die Verwendung von @AspectJAndroid AspectJ @Around mit Methode args nicht

untersuche ich, „Capture“, um alle Hinrichtung zu Methoden, deren Unterschrift bin versucht, ähnelt: -

public void onMethodClicked(com.example.CustomType customType) {} 

ich habe nach dem POINTCUTS

1) Ignorieren meine Aspect Klasse:

@Pointcut("!within(com.example.aspect)") 
public void notAspect() { } 

2) Wählen Sie alle "Clicked" Methoden mit customType Argument

@Pointcut("execution(* com.example..*.*Clicked(com.example.CustomType)) && args(custom)";) 
public void customClicked(CustomType custom) { } 

3) Mein @Around: -

@Around("notAspect() && customClicked()") 
public Object selectedClicked(final ProceedingJoinPoint joinPoint, CustomType custom) throws Throwable { 
    Log.d(TAG, "Found a clicked method " + custom); 
    Object result = joinPoint.proceed(); 

    return result; 
} 

Wenn ich meine Applikation für Android bauen erhalte ich diese Meldungen

no match for this type name: CustomType [Xlint:invalidAbsoluteTypeName] 

bad parameter to pointcut reference 
formal unbound in pointcut 

no match for this type name: com.example.aspect [Xlint:invalidAbsoluteTypeName] 

the parameter custom is not bound in [all branches of] pointcut 
use of ProceedingJoinPoint is allowed only on around advice (arg 1 in (before(extraFlags: 2): (((!within(com.example.aspect+) && execution(* com.example..*.*Clicked(com.example.CustomType)) && args(custom)) && persingleton(com.example.aspect.TraceAspect))->void com.example.aspect.TraceAspect.selectedClicked(org.aspectj.lang.JoinPoint, com.example.CustomType))) 

Was habe ich falsch gemacht?

UPDATE

ich einer der Fehler behoben haben/Warnmeldungen durch die !within() Korrektur wie folgt: -

1) meine Aspect Klasse ignorieren:

@Pointcut("!within(com.example.aspect.TraceAspect)") 
public void notAspect() { } 

Antwort

2

Ich bin nicht sicher über Ihr Problem, aber Sie können versuchen, die POINTCUT wie folgt zu ändern.

@Pointcut("!within(com.example.aspect.TraceAspect)") 
public void notAspect() { } 

@Pointcut("execution(* com.example..*.*Clicked(com.example.CustomType))) 
public void customClicked() { } 

Schau, ich habe den args(custom) Teil hier entfernt, die innerhalb der @Around Anmerkung gehen. Und ja, natürlich habe ich das Funktionsparameterargument der customClicked Funktion und das Semikolon am Ende der Anweisung entfernt.

Schreiben Sie jetzt Ihre selectedClicked Funktion wie folgt, indem Sie die Argumente von hier übergeben.

@Around("notAspect() && customClicked() && args(custom)") 
public Object selectedClicked(final ProceedingJoinPoint joinPoint, CustomType custom) throws Throwable { 

    Log.d(TAG, "Found a clicked method " + custom); 
    Object result = joinPoint.proceed(); 

    return result; 
} 

Es sollte ohne Fehler funktionieren.

+1

nette arbeit! dies behob mein Problem, obwohl ich die "pointcut =" fronte um den Rat entfernen musste – Hector

+0

Gut zu wissen das half! :) –

Verwandte Themen