Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Simple question about Java, AspectJ, and Static type information

As far as I know, the thisJoinPointStaticPart requires reflect to create.

If you change the semantics of what you are trying to do slightly, and
your hierarchy is fixed, then you can do this all statically by using
execution instead of call.

Something like this:

aspect Aspect {
  enum Shapes { SHAPE, TRIANGLE, CIRCLE, ... }

  pointcut callToM() : call (public void m());

  // now specialize the pointcut for each member of the hierarchy
  before() : callToM() && within(Triangle) {
    delegate(TRIANGLE);
  }
  before() : callToM() && within(Shape) {
    delegate(SHAPE);
  }
  ...
}

2010/9/8 Henrique Rebêlo <hemr@xxxxxxxxxxx>:
> Any ideas? Comments?
>
> 2010/9/3 Henrique Rebêlo <hemr@xxxxxxxxxxx>
>>
>> Hi all,
>>
>>  Consider the following simple hierarchy:
>>
>> class Shape { public void m() {} }
>> class Triangle extends Shape { public void m() {} }
>>
>> along with the simple advice
>>
>> pointcut callMeth() : call (public void Shape.m());
>>
>> before
>>
>> (Shape s) : call(public void Shape.m()) && target(s){
>>
>> // advice body
>>
>> }
>>
>> Suppose that I have the following call
>>
>> Shape s = new Triangle();
>> s.m();
>>
>> I know that the above advice will affect this call, I want to know if
>> there is a way to get the static type information of the executing
>> object without using reflection. If I use
>>
>>
>> thisJoinPoint
>>
>> .getSignature().getDeclaringType().getName() // this returns type Shape
>> that is what I want
>>
>> I can access that information... but the use of the special variable
>> thisJoinPoint or thisJoinPointStaticPart refers to Java.lang.reflect... I
>> want this constraint because I need to apply such a strategy with Java ME
>> platform in which does not support reflection at all.
>>
>> I also tried inside the body of the advice
>>
>> s.getClass().getName(); // But this returns only the type of the executing
>> object which is Triangle in this case... I dont know how to access the name
>> of the static type of the object represented by s which is Shape.
>>
>> So, You guys (Java and Aspect experts), Do have any ideas on how I can get
>> this?
>>
>> Kind Regards,
>>
>> Henrique
>>
>> --
>>
>> ...............................................................................................................................
>> Henrique Rebelo
>> http://www.cin.ufpe.br/~hemr
>> Informatics Center, UFPE, Brazil
>
>
>
> --
> ...............................................................................................................................
> Henrique Rebelo
> http://www.cin.ufpe.br/~hemr
> Informatics Center, UFPE, Brazil
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>


Back to the top