Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Enum Value matching facility

Hi,
        Ths issues was resolved in the bugzilla. I asked about that because I needed this code. This is working now.

public interface StateTransition {

StateTransition activate();

StateTransition deActivate();

}
  
public enum AStateTransition implements StateTransition{

ACTIVATE(new Activation()),

DEACTIVATE(new DeActivation());

private final StateTransition stateTransition;

private AStateTransition(StateTransition stateTransition) {
    this.stateTransition = stateTransition;
}

@Override
public StateTransition activate() {
    return stateTransition.activate();
}

@Override
public StateTransition deActivate() {
    return stateTransition.deActivate();
}
}

public class Activation implements StateTransition {

public StateTransition activate() {
    return AStateTransition.ACTIVATE;
}

@Override
public StateTransition deActivate() {
    return AStateTransition.DEACTIVATE;
}
}

public class DeActivation implements StateTransition {

public StateTransition deActivate() {
    return AStateTransition.DEACTIVATE;
}

@Override
public StateTransition activate() {
    return AStateTransition.ACTIVATE;
}
}

 @Aspect()


 public class StateChangeAspect {

    //Could be more generic so that all implemented methods
    //are covered
    @Pointcut("execution(* AStateTransition.activate()) && target(stateTransition) && if()")

    public static boolean stateChangePointcut( AStateTransition stateTransition ){
        return AStateTransition.ACTIVATE == stateTransition;
    }

    @Before("stateChangePointcut(stateTransition)")
    public void test1( AStateTransition stateTransition ) {
        System.out.println( " aspect  " );
    }

    @Before("stateChangePointcut(stateTransition)")
    public void test1(JoinPoint joinPoint, AStateTransition stateTransition) {
      System.out.println(joinPoint + " -> " + stateTransition);
    }

}

Thanks,
Mohan

On Wed, Oct 21, 2020 at 9:10 PM Andy Clement <andrew.clement@xxxxxxxxx> wrote:
Hey,

It is quite an old issue. I thought I'd done something around enum matching but I can't find it - I think maybe it was just in the context of enums used in annotation values. Re-reading the issue now I don't see exactly what it is asking for "Enum code requires Enum value JoinPoints." - if it is enum specific joinpoints, I am super nervous about adding new joinpoints because suddenly they will start affecting all existing code that was using wildcards.  If you just want to guard on joinpoints related to enum related operations there are type category patterns in https://www.eclipse.org/aspectj/doc/released/README-169.html

Is it asking for static matching (vs runtime/dynamic matching) in join points related to enums, that feels like it could be done without new join points, just needs some improvements in the matching algorithm to recognize enums in use.

cheers,
Andy

On Wed, 21 Oct 2020 at 07:12, Mohan Radhakrishnan <radhakrishnan.mohan@xxxxxxxxx> wrote:
Hi,

This was a very old request I raised. I think the comment there means this is already implemented.

But AJDT doesn't apply the pointcut. Was this implemented ?

Thanks,
Mohan
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/aspectj-users
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/aspectj-users

Back to the top