Announcement Announcement Module
Collapse
No announcement yet.
Load-Time Weaving aspect complexities Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Load-Time Weaving aspect complexities

    Hi,

    I'm trying to write an aspect whose pointcut detects a method call m on class A (so A.m()), but I want to specify what class the caller is. Does aspectjweaver and the aop.xml file allow me to specify things such as this, target, and within for a particular pointcut? If so, can someone please show me how?

    Thank you,
    Jeff

  • #2
    The following link seem to have an answer
    http://www.eclipse.org/aspectj/doc/n...iguration.html
    Let us know if you still having an issue

    Comment


    • #3
      I had actually seen that link before, but that seems to show how to set includes and excludes for all aspects. I was just trying for a single aspect.

      I basically wanted to try to do something like this:

      Code:
                <aspectj>
                  <aspects>
                    <!-- define a concrete aspect inline -->
                    <concrete-aspect name="com.xyz.tracing.MyTracing"
                                     extends="tracing.AbstractTracing">
                      <pointcut name="tracingScope" expression="call(* MyClass.myMethod(..))"/>
                    </concrete-aspect>
                  </aspects>
      
                  <weaver options="-verbose">
                    <include within="javax.*"/>
                  </weaver>
      
                </aspectj>
      As it is, this would make sure com.xyz.tracing.MyTracing would be executed on any call to MyClass.myMethod(), but I would also like it to only be executed when the "this" object (i.e. the caller) is of type MyCaller. So it would be 2 expressions combined into 1. Is that possible?

      Thanks,
      Jeff

      Comment


      • #4
        Something like this should work
        Code:
         <aspectj>
                    <aspects>
                      <!-- define a concrete aspect inline -->
                      <concrete-aspect name="com.xyz.tracing.MyTracing"
                                       extends="tracing.AbstractTracing">
                        <pointcut name="tracingScope(MyCaller mc)" expression="call(* MyClass.myMethod(..)) && this(mc)"/>
                      </concrete-aspect>
                    </aspects>
        
                    <weaver options="-verbose">
                      <include within="javax.*"/>
                    </weaver>
        
        </aspectj>
        Let me know

        Comment


        • #5
          Oleg, thanks. That wasn't exactly the right syntax for the aop.xml file, but it got me close enough to find the right syntax. Appreciate it.

          Comment


          • #6
            Cool!

            Could you please post the right syntax so others can benefit?

            Comment


            • #7
              Sure, I'd be happy to.

              Code:
               <aspectj>
                          <aspects>
                            <!-- define a concrete aspect inline -->
                            <concrete-aspect name="com.xyz.tracing.MyTracing"
                                             extends="tracing.AbstractTracing">
                              <pointcut name="tracingScope" expression="call(* MyClass.myMethod(..)) AND this(fully.qualifier.package.MyCaller)"/>
                            </concrete-aspect>
                          </aspects>
              
                          <weaver options="-verbose">
                            <include within="javax.*"/>
                          </weaver>
              
              </aspectj>

              Comment

              Working...
              X