Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Aspect Annotation Around Advice to Hide Values

Something like this:

pointcut methodOfInterest(MyAnnotation anno,Object instance):
execution(@MyAnnotation * get*(..)) && @annotation(anno) &&
this(instance);

Object around(MyAnnotation anno,Object instance):
methodOfInterest(anno, instance) {
  Field f = instance.getClass().getDeclaredField(anno.property);
  // f.setAccessible(true)
  Object value = f.get(instance);
  if (value==376.125) {
    return proceed();
  } else {
    return null;
  }
}

If you know the Object is of a specific type (or limited set of types,
or you can use a common supertype), you can perhaps lose the
reflection.

cheers
Andy

On 13 April 2011 17:13, CRANFORD, CHRIS <Chris.Cranford@xxxxxxxxxx> wrote:
> I need to annotate a property on a class or it's "getter" method like
> the following:
>
> @MyAnnotation(property="myField")
> public Double getPrice() {
>  return price;
> }
>
> The goal of the annotation is to perform an around advice where it
> inspects myField's value on the annotated method's class or property's
> class checks whether the value of myField is a specific value and if so;
> it returns the value from proceed() otherwise it is to default to
> returning null instead.
>
> Can someone show me how to accomplish this or is this not possible?
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top