Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] classes and methodes name

Hello fairouz,

We use: StaticPart jps -  jps.getSignature().getName()

Example of logging, certainly not the better one but it might help.


@Aspect
public class LoggingControllerBehavior extends LoggingBaseBehavior {

@DeclareMixin("com.nested.crm.web.common.controller.BaseController")
public static Loggable createLoggerDelegate(Object o) {
        return new ServantLogger(o.getClass());
}

@Pointcut("execution(* com.nested.crm.web..*Controller*.do*(..))")
public void controllerLogger() {};

@Pointcut("execution(protected void com.nested.crm.web..BaseTabController.initialize(..)) && !within(com.nested.crm.web..BaseClientController)")
public void initializerLogger() {};

@Pointcut("execution(* com.nested.crm.web..*Controller.validate(..))")
public void validateLogger() {};


@Before(value = "controllerLogger() && this(log)")
public void loggerController(JoinPoint jp, JoinPoint.StaticPart jps, Loggable log) {
        if (log.getLog().isDebugEnabled() && jps != null) {
                final String args = buildParameters(jp.getArgs());
                log.getLog().debug(jps.getSignature().getName() + " - Entering..." + (args.isEmpty() ? "" : " - " + args));
                log.getLog().debug(jps.getSignature().getName() + " - Object dump - " + jp.getTarget());
                }
        }

@Before(value = "initializerLogger() && this(log) && target(controller)")
public void loggerInitializer(JoinPoint jp, JoinPoint.StaticPart jps, Loggable log, Object controller) {
        if (log.getLog().isDebugEnabled()) {
                if (controller.getClass().isAssignableFrom(BaseTabController.class)) {
                        if (!((BaseTabController)controller).getTabId().equals(jp.getArgs()[0])) {
                                log.getLog().debug(jps.getSignature().getName() + " - Entering initializer... - "  buildParameters(jp.getArgs()));
                        }
                } else {
                        log.getLog().debug(jps.getSignature().getName() + " - Entering initializer... - " + buildParameters(jp.getArgs()));
                }
        }
}


@Aspect
public abstract class LoggingBaseBehavior {

        protected String buildParameters(Object[] parameters) {
                if (parameters == null) {
                        return null;
                }

                StringBuilder sb = new StringBuilder();
                for (int i = 0; i< parameters.length; i++) {
                        sb.append("Param")
                          .append(i+1)
                          .append(" : ")
                          .append("'")
                          .append(parameters[i])
                          .append("'");
                        if (i+1 < parameters.length) { sb.append(" - "); }
                }
                return sb.toString();
        }

        /*
         * The interface and the implementation of Loggable class.
         */
        public interface Loggable {
                Logger getLog();
        };

        public static class ServantLogger implements Loggable {
                private transient Logger log = null;

                public ServantLogger(Class<? extends Object> clazz) {
                        this.log = LoggerFactory.getLogger(clazz);
                }

                @Override
                public Logger getLog() {
                        return log;
                }
        }
}





De :        fairouz <BendjamaFairouz_ilc@xxxxxxxx>
A :        aspectj-users@xxxxxxxxxxx,
Date :        2013-04-16 13:14
Objet :        [aspectj-users] classes and methodes name
Envoyé par :        aspectj-users-bounces@xxxxxxxxxxx




Hi,

I am still beginner in aop, and I want to know if there is a way to find the
name of all the classes and methods in a java project, and the callers of
each method;

thank you for help



--
View this message in context:
http://aspectj.2085585.n4.nabble.com/classes-and-methodes-name-tp4650877.html
Sent from the AspectJ - users mailing list archive at Nabble.com.
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top