Example usage for org.aspectj.lang.reflect MethodSignature getMethod

List of usage examples for org.aspectj.lang.reflect MethodSignature getMethod

Introduction

In this page you can find the example usage for org.aspectj.lang.reflect MethodSignature getMethod.

Prototype

Method getMethod();

Source Link

Usage

From source file:com.github.tddts.jet.util.SpringUtil.java

License:Apache License

public static Method getMethod(JoinPoint joinPoint) throws NoSuchMethodException {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Method method = signature.getMethod();

    if (method.getDeclaringClass().isInterface()) {
        method = joinPoint.getTarget().getClass().getDeclaredMethod(joinPoint.getSignature().getName(),
                method.getParameterTypes());
    }/*from   w ww  .  j a  v  a 2s.co m*/

    return method;
}

From source file:com.github.wnameless.nullproof.aspectj.AbstractNullProofAspect.java

License:Apache License

@Before("publicMethodOfRejectNullAnnotatedClassWithoutAcceptNull()")
public void rejectNullForPublicMethods(JoinPoint jointPoint) {
    MethodSignature sig = (MethodSignature) jointPoint.getSignature();
    NullBlocker.blockNulls(sig.getMethod(), jointPoint.getArgs());
}

From source file:com.github.woozoo73.ht.callback.StatisticsRecorder.java

License:Apache License

@Override
public void after(Invocation invocation) {
    if (invocation == null) {
        return;/* w  w  w.  j a v  a2s .com*/
    }

    JoinPoint joinPoint = invocation.getJoinPoint();
    if (joinPoint == null) {
        return;
    }

    Signature signature = joinPoint.getSignature();
    if (signature == null) {
        return;
    }

    if (!(signature instanceof MethodSignature)) {
        return;
    }

    MethodSignature methodSignature = (MethodSignature) signature;
    Method method = methodSignature.getMethod();

    record(method, invocation);
}

From source file:com.google.android.marvin.utils.TraceAspect.java

License:Apache License

private void log(ProceedingJoinPoint joinPoint, long elapsedMillis) {
    if (elapsedMillis >= LATENCY_THRESHOLD_MS) {
        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
        String className = methodSignature.getMethod().getDeclaringClass().getCanonicalName();
        String methodName = methodSignature.getName();
        LogUtils.log(className, Log.DEBUG, "%s %s.%s -->%dms",
                Strings.repeat("  ", callLevel > 0 ? callLevel : 0), className, methodName, elapsedMillis);
    }/*from www .  j a  v a 2 s . c  om*/
}

From source file:com.heliumv.annotation.BaseAspect.java

License:Open Source License

/**
 * Methode suchen. Sowohl im Interface als auch in der Klasse
 * @param pjp/*from   w w w .jav  a 2s .  c  om*/
 * @return
 * @throws Throwable
 */
public Method getMethodFrom(JoinPoint pjp) throws Throwable {
    MethodSignature methodSig = getMethodSignatureFrom(pjp);
    Method method = methodSig.getMethod();
    if (method.getDeclaringClass().isInterface()) {
        String methodName = pjp.getSignature().getName();
        method = pjp.getTarget().getClass().getDeclaredMethod(methodName, method.getParameterTypes());
    }

    return method;
}

From source file:com.heliumv.annotation.HvCallrateAspect.java

License:Open Source License

@Before("anyPublicOperation() && inHeliumv() && processHvCallTracerPointcut()")
public void processAttribute(JoinPoint pjp) throws Throwable {
    MethodSignature methodSig = getMethodSignatureFrom(pjp);
    Method method = getMethodFrom(pjp);
    HvCallrate theModul = (HvCallrate) method.getAnnotation(HvCallrate.class);
    if (theModul == null)
        return;/*from w  ww  .j av  a 2 s .co m*/

    log.debug("'" + theModul.maxCalls() + "' maxCalls and '" + theModul.durationMs() + "' duration<");
    callTracer.trace(theModul, methodSig.getMethod());
}

From source file:com.heliumv.annotation.HvFlrMapperAspect.java

License:Open Source License

@Before("anyPublicOperation() && inHeliumv() && @annotation(com.heliumv.annotation.HvFlrMapper)")
public void processAttribute(JoinPoint pjp) throws Throwable {
    // Class clazz = pjp.getSignature().getDeclaringType() ;
    // List<HvJudge> attributesList = new ArrayList<HvJudge>() ;
    ///*from   w  w w  . jav a  2  s. c o m*/
    // System.out.println("In declaring clazz " + clazz.getName() +
    // " inspecting annotations...") ;

    MethodSignature methodSig = (MethodSignature) pjp.getSignature();
    // methodSig.getMethod().getAnnotations() ;
    // System.out.println("In method signature: " +
    // methodSig.getMethod().getAnnotations().length + "<") ;

    HvFlrMapper theModul = (HvFlrMapper) methodSig.getMethod().getAnnotation(HvFlrMapper.class);
    if (theModul == null)
        return;

    System.out.println("Having the HvFlrMapper Annotation with name '" + theModul.flrName() + "<");
    //      if (!judgeCall.hatRecht(theModul.recht())) {
    //         throw new EJBExceptionLP(
    //               EJBExceptionLP.FEHLER_UNZUREICHENDE_RECHTE, methodSig
    //                     .getMethod().getName() + ":" + theModul.recht());
    //      }
    //      System.out.println("judge allowed: '" + theModul.recht() + "'");
}

From source file:com.heliumv.annotation.HvJudgeAspect.java

License:Open Source License

@Before("anyPublicOperation() && inHeliumv() && @annotation(com.heliumv.annotation.HvJudge)")
public void processAttribute(JoinPoint pjp) throws Throwable {
    //      Class clazz = pjp.getSignature().getDeclaringType() ;
    //      List<HvJudge> attributesList = new ArrayList<HvJudge>() ;
    //   //from  w  ww .j  a v  a  2s.c  om
    //      System.out.println("In declaring clazz " + clazz.getName() + " inspecting annotations...") ;

    MethodSignature methodSig = getMethodSignatureFrom(pjp);
    Method method = getMethodFrom(pjp);
    HvJudge theModul = (HvJudge) method.getAnnotation(HvJudge.class);
    if (theModul == null)
        return;

    //      System.out.println("Having the HvJudge Annotation with name |'" + theModul.recht() + "'|" +
    //            StringUtils.join(theModul.rechtOder(), "|") + "<") ;
    log.debug("Having the HvJudge Annotation with name |'" + theModul.recht() + "'|"
            + StringUtils.join(theModul.rechtOder(), "|") + "<");

    if (theModul.recht().length() > 0) {
        if (!judgeCall.hatRecht(theModul.recht())) {
            log.info("judge disallowed: '" + theModul.recht() + "' for '" + methodSig.getMethod().getName()
                    + "'");
            throw new EJBExceptionLP(EJBExceptionLP.FEHLER_UNZUREICHENDE_RECHTE,
                    methodSig.getMethod().getName() + ":" + theModul.recht());
        }

        //         System.out.println("judge allowed: '" + theModul.recht() + "'") ;
        log.debug("judge allowed: '" + theModul.recht() + "'");
        return;
    }

    if (theModul.rechtOder().length > 0) {
        for (String recht : theModul.rechtOder()) {
            if (judgeCall.hatRecht(recht)) {
                log.debug("judge allowed: '" + recht + "'");
                //               System.out.println("judge allowed: '" + recht + "'") ;
                return;
            }
        }

        log.info("judge disallowed: '" + Arrays.toString(theModul.rechtOder()) + "' for '"
                + methodSig.getMethod().getName() + "'");
        throw new EJBExceptionLP(EJBExceptionLP.FEHLER_UNZUREICHENDE_RECHTE,
                methodSig.getMethod().getName() + ":" + Arrays.toString(theModul.rechtOder()));
    }
}

From source file:com.heliumv.annotation.HvModulAspect.java

License:Open Source License

@Before("anyPublicOperation() && inHeliumv() && @annotation(com.heliumv.annotation.HvModul)")
public void processAttribute(JoinPoint pjp) throws Throwable {
    //      Class clazz = pjp.getSignature().getDeclaringType() ;
    //      List<HvJudge> attributesList = new ArrayList<HvJudge>() ;
    //   //w  w  w.j a v  a  2  s.c  om
    //      System.out.println("In declaring clazz " + clazz.getName() + " inspecting annotations...") ;

    MethodSignature methodSig = getMethodSignatureFrom(pjp);
    Method method = getMethodFrom(pjp);
    HvModul theModul = (HvModul) method.getAnnotation(HvModul.class);
    if (theModul == null)
        return;

    //      methodSig.getMethod().getAnnotations() ;
    //      System.out.println("In method signature: " + methodSig.getMethod().getAnnotations().length + "<") ;

    System.out.println("Having the HvModul Annotation with name '" + theModul.modul() + "' <"
            + methodSig.getMethod().getName() + ":" + theModul.modul() + ">");
    if (!mandantCall.hasNamedModul(theModul.modul())) {
        throw new EJBExceptionLP(EJBExceptionLP.FEHLER_UNZUREICHENDE_RECHTE,
                methodSig.getMethod().getName() + ":" + theModul.modul());
    }
    System.out.println("modul allowed: '" + theModul.modul() + "'");
}

From source file:com.helpinput.profaop.AspectProfiler.java

License:Apache License

@Around("notSelf() && notProfiler() && notAspectJ() && allMethods()")
public Object exeAround(ProceedingJoinPoint joinPoint) throws Throwable {
    MethodSignature signature = (MethodSignature) joinPoint.getSignature();
    Monitor.startMonitor(signature.getMethod());
    Throwable error = null;/*from www .j  a va 2 s  .c om*/
    try {
        Object result = joinPoint.proceed();
        return result;
    } catch (Throwable e) {
        error = e;
        throw error;
    } finally {
        Monitor.stopMonitor(error);
    }
}