Example usage for org.aspectj.lang JoinPoint.StaticPart getSignature

List of usage examples for org.aspectj.lang JoinPoint.StaticPart getSignature

Introduction

In this page you can find the example usage for org.aspectj.lang JoinPoint.StaticPart getSignature.

Prototype

Signature getSignature();

Source Link

Document

getStaticPart().getSignature() returns the same object

Usage

From source file:ajia.tracing.TransactionTraceAspect.java

License:Apache License

@AfterReturning(value = "ajia.transaction.TransactionPointcuts.transactionEnd(txStatus)")
public void traceEnd(JoinPoint.StaticPart tjpsp, TransactionStatus txStatus) {
    NDC.pop();/*from   w w w  .j  a v a2s .  c  o m*/
    logger.log(Level.INFO, "Ending transaction " + tjpsp.getSignature().getName());
}

From source file:ajia.tracing.TransactionTraceAspect.java

License:Apache License

@Before("ajia.jpa.JPAPointcuts.entityManagerExecution() " + "&& !ajia.core.JavaPointcuts.objectExecution() "
        + "&& this(entityManager)")
public void traceEntityManager(JoinPoint.StaticPart tjpsp, EntityManager entityManager) {
    logger.log(Level.INFO, "EntityManager [" + tjpsp.getSignature().toShortString() + " on "
            + System.identityHashCode(entityManager) + "]");
}

From source file:ajia.util.JoinPointUtil.java

License:Apache License

public static void rethrow(JoinPoint.StaticPart jp, Throwable ex) {
    Signature signature = jp.getSignature();
    if (!(signature instanceof CodeSignature)) {
        throw new IncompatibleRethrownException();
    }/*  ww w .j a  v a2  s.c  o m*/

    boolean mayThrow = false;
    if (ex instanceof RuntimeException) {
        mayThrow = true;
    } else {
        CodeSignature codeSignature = (CodeSignature) signature;
        for (Class exceptionType : codeSignature.getExceptionTypes()) {
            if (exceptionType.isAssignableFrom(ex.getClass())) {
                mayThrow = true;
                break;
            }
        }
    }

    if (!mayThrow) {
        throw new IncompatibleRethrownException();
    }

    try {
        synchronized (CheckedExceptionThrower.class) {
            CheckedExceptionThrower.exception = ex;
            CheckedExceptionThrower.class.newInstance();
        }
    } catch (InstantiationException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.qmetry.qaf.automation.step.JavaStepReporter.java

License:Open Source License

@Around("execution(@QAFTestStep * *.*(..))")
public Object javaTestStep(ProceedingJoinPoint jp, JoinPoint.StaticPart thisJoinPointStaticPart)
        throws Throwable {
    JavaStep testStep = null;/*from   w  ww  .java 2  s .  c  om*/
    Signature sig = null;

    try {
        sig = thisJoinPointStaticPart.getSignature();
        if ((sig instanceof MethodSignature)
                && TestBaseProvider.instance().get().getContext().getBoolean(JavaStep.ATTACH_LISTENER, true)) {
            // this must be a call or execution join point
            Method method = ((MethodSignature) sig).getMethod();

            testStep = new MockJavaStep(method, jp);
            if (null != jp.getArgs()) {
                testStep.setActualArgs(jp.getArgs());
            }
        }
    } catch (Exception e) {
        // ignore it...
    }

    if (ConfigurationManager.getBundle().getBoolean("method.recording.mode", false)) {
        ConfigurationManager.getBundle().setProperty("method.param.names",
                ((MethodSignature) sig).getParameterNames());
        return null;
    } else {
        // unblock for sub-steps
        TestBaseProvider.instance().get().getContext().setProperty(JavaStep.ATTACH_LISTENER, true);
        if (null != testStep) {
            try {
                return testStep.execute();
            } catch (JPThrowable e) {
                throw e.getCause();
            }
        } else {

            // this call is from text client (bdd/kwd/excel)
            testStep = (JavaStep) TestBaseProvider.instance().get().getContext()
                    .getProperty("current.teststep");
            testStep.setFileName(jp.getSourceLocation().getFileName());
            testStep.setLineNumber(jp.getSourceLocation().getLine());
            testStep.signature = jp.getSignature().toLongString();

            return jp.proceed();

        }

    }

}

From source file:kieker.monitoring.probe.aspectj.flow.construction.AbstractAspect.java

License:Apache License

/**
 * This is an advice which will be used after the construction of an object.
 *
 * @param thisObject/*  w w  w . j a v a 2  s. co  m*/
 * @param jp
 *            The static information about this joint point.
 */
// HINT: This may be logged multiple times due to super constructor calls...
@AfterReturning("monitoredConstructor() && this(thisObject) && notWithinKieker()")
public void afterConstruction(final Object thisObject, final JoinPoint.StaticPart jp) {
    if (!CTRLINST.isMonitoringEnabled()) {
        return;
    }
    final Signature signature = jp.getSignature();
    if (!CTRLINST.isProbeActivated(this.signatureToLongString(signature))) {
        return;
    }
    // common fields
    TraceMetadata trace = TRACEREGISTRY.getTrace();
    final boolean newTrace = trace == null;
    if (newTrace) {
        trace = TRACEREGISTRY.registerTrace();
        CTRLINST.newMonitoringRecord(trace);
    }
    final ConstructionEvent crecord = new ConstructionEvent(TIME.getTime(), trace.getTraceId(),
            trace.getNextOrderId(), signature.getDeclaringTypeName(), System.identityHashCode(thisObject));
    CTRLINST.newMonitoringRecord(crecord);
}

From source file:net.sf.oval.guard.ParameterNameResolverAspectJImpl.java

License:Open Source License

private void determineParamterNames(final Class<?> clazz)
        throws IllegalArgumentException, IllegalAccessException {
    assert clazz != null;

    for (final Field field : clazz.getDeclaredFields()) {
        // search for static fields of type JoinPoint.StaticPart
        if (ReflectionUtils.isStatic(field) && field.getType() == JoinPoint.StaticPart.class) {
            // access the StaticPart object
            field.setAccessible(true);/*from  ww  w  .j  a  v  a  2 s.  com*/
            final JoinPoint.StaticPart staticPart = (JoinPoint.StaticPart) field.get(null);
            if (staticPart == null) {
                break;
            }

            if (staticPart.getSignature() instanceof ConstructorSignature) {
                final ConstructorSignature sig = (ConstructorSignature) staticPart.getSignature();
                final String[] parameterNames = sig.getParameterNames();

                final Constructor<?> constr = sig.getConstructor();

                if (parameterNames.length > 0) {
                    parameterNamesCache.put(constr, parameterNames);
                }
            } else if (staticPart.getSignature() instanceof MethodSignature) {
                final MethodSignature sig = (MethodSignature) staticPart.getSignature();
                final String[] parameterNames = sig.getParameterNames();

                final Method method = sig.getMethod();

                if (parameterNames.length > 0) {
                    parameterNamesCache.put(method, parameterNames);
                }
            }
        }
    }
}

From source file:org.cooperari.core.CYieldPointImpl.java

License:Apache License

@SuppressWarnings("javadoc")
private static String deriveSignature(JoinPoint.StaticPart jpsp) {
    String kind = jpsp.getKind(); // note that String is internalized
    if (kind == JoinPoint.SYNCHRONIZATION_LOCK) {
        return MONITOR_ENTER_SIGNATURE;
    }/*from   w w  w .j  a  v  a  2 s  . co  m*/
    if (kind == JoinPoint.SYNCHRONIZATION_UNLOCK) {
        return MONITOR_EXIT_SIGNATURE;
    }
    String s = jpsp.getSignature().toString();
    s = s.substring(s.indexOf(' ') + 1);
    s = s.replace("java.lang.", "").replace('$', '.');
    if (kind == JoinPoint.METHOD_CALL) {
        return s;
    }
    return kind + '(' + s + ')';
}

From source file:org.failearly.ajunit.AjUnitAspectTest.java

License:Open Source License

private static JoinPoint.StaticPart joinpoint() throws NoSuchMethodException {
    final JoinPoint.StaticPart joinPointStaticPart = Mockito.mock(JoinPoint.StaticPart.class);
    Mockito.when(joinPointStaticPart.getKind()).thenReturn(JoinPoint.METHOD_EXECUTION);
    final MethodSignature methodSignature = getMethodSignature();
    Mockito.when(joinPointStaticPart.getSignature()).thenReturn(methodSignature);
    return joinPointStaticPart;
}

From source file:org.failearly.ajunit.aspect.AjJoinpointCollector.java

License:Open Source License

private void validateResult(JoinPoint.StaticPart joinPoint, List<AjJoinPoint> joinPoints) {
    final int numAssociatedJoinPoints = joinPoints.size();
    AjAssert.assertCondition(numAssociatedJoinPoints > 0, MessageBuilders
            .message("Assertion failed: No associated ajUnit join point found for AspectJ join point")
            .arg(joinPoint).line("Please add").arg(joinPoint.getSignature().getDeclaringTypeName())
            .part("to Test Fixtures.").line("Or the join point type").arg(joinPoint.getKind())
            .part("is not yet supported: Propose a feature request to https://github.com/loddar/ajunit/issues."));
    AjAssert.assertCondition(numAssociatedJoinPoints == 1, MessageBuilders
            .message("Assertion failed: Exactly one join point expected, got").arg(numAssociatedJoinPoints));

}

From source file:org.failearly.ajunit.internal.universe.matcher.AjJoinPointMatcherBase.java

License:Open Source License

@Override
public final boolean match(JoinPoint.StaticPart thisJoinPointStaticPart,
        JoinPoint.StaticPart thisEnclosingJoinPointStaticPart, AjJoinPoint ajUnitJoinPoint) {
    AjAssert.state(joinPointType.isSameKind(thisJoinPointStaticPart), "Expect same join point type.");
    // TODO: It could depend on the join point type which of these join points will be used.
    return isSameJoinPointType(ajUnitJoinPoint)
            && doMatchSignature(castSignature(thisJoinPointStaticPart.getSignature()), ajUnitJoinPoint);
}