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

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

Introduction

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

Prototype

Signature getSignature();

Source Link

Document

getStaticPart().getSignature() returns the same object

Usage

From source file:eu.crisis_economics.abm.aspects.DataCollection.java

License:Open Source License

@AfterReturning(pointcut = "(addObject() || removeObject()) && dataReporterCode() && this(reporter) && args(.., arg)", returning = "result")
public void catchCollectionModification(JoinPoint jp, JoinPoint.EnclosingStaticPart enc, Object arg,
        Object reporter, Object result) {
    DataCollection aspectOf = Aspects.aspectOf(DataCollection.class);
    Object targetCollection = jp.getTarget();
    Class<?> dataReporterClass = enc.getSignature().getDeclaringType();
    Field[] dataReporterFields = dataReporterClass.getDeclaredFields();
    Collect.ChangeType changeType = jp.getSignature().getName().startsWith("add") ? ChangeType.COLLECTION_ADD
            : ChangeType.COLLECTION_REMOVE;

    if (jp.getSignature().getName().startsWith("remove") && !(result instanceof Boolean)) {
        arg = result;/*w  ww  .j  ava  2s  .c  o m*/
    }

    try {
        for (Field field : dataReporterFields) {
            field.setAccessible(true);
            if (field.get(reporter) == targetCollection) {
                Report newsAnnotation = field.getAnnotation(Report.class);
                if (newsAnnotation != null) {
                    if (newsAnnotation.interval() == 0) {
                        Set<Object> set = aspectOf.collectors.get(newsAnnotation.value());
                        if (set != null) {
                            for (Object collector : set) {
                                handleData(newsAnnotation.value(), arg, collector, reporter, changeType);
                            }
                        }
                    }
                }
            }
        }
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}