Note that there are some explanatory texts on larger screens.

plurals
  1. POPointcut matching methods with annotated parameters
    primarykey
    data
    text
    <p>I need to create an aspect with a pointcut matching a method if:</p> <ol> <li>it is annoted with MyAnnotationForMethod</li> <li>One of its parameters (can have many) is annotated with @MyAnnotationForParam (but can have other annotations as well).</li> </ol> <p>The aspect class look like this</p> <pre><code>@Pointcut("execution(@MyAnnotationForMethod * *(..,@aspects.MyAnnotationForParam Object, ..)) &amp;&amp; args(obj)") void myPointcut(JoinPoint thisJoinPoint, Object obj) { } @Before("myPointcut(thisJoinPoint , obj)") public void doStuffOnParam(JoinPoint thisJoinPoint, Object obj) { LOGGER.info("doStuffOnParam :"+obj); } </code></pre> <p>The annoted method</p> <pre><code>@MyAnnotationForMethod public string theMethod(String a, @MyAnnotationForParam @OtherAnnotation Object obj, Object b){ LOGGER.info(a+obj+b); } </code></pre> <p>With eclipse -> warnings : On the poincut : </p> <pre><code>Multiple markers at this line - no match for this type name: MyAnnotationForMethod [Xlint:invalidAbsoluteTypeName] - no match for this type name: aspects.MyAnnotationForParam On the before : advice defined in xxx.xxx.xxx.xxx.MyAspect has not been applied [Xlint:adviceDidNotMatch] </code></pre> <p>Using last aspectJ plugin from <a href="http://download.eclipse.org/tools/ajdt/35/update" rel="noreferrer">http://download.eclipse.org/tools/ajdt/35/update</a></p> <p>With maven command line using aspectj 1.6.9 </p> <pre><code>[WARNING] no match for this type name: MyAnnotationForMethod [Xlint:invalidAbsoluteTypeName] [WARNING] no match for this type name: aspects.MyAnnotationForParam [Xlint:invalidAbsoluteTypeName] [WARNING] advice defined in xxx.xxx.xxx.xxx.MyAspect has not been applied [Xlint:adviceDidNotMatch] </code></pre> <p>The annotations :</p> <pre><code>package com.xxx.xxx.annotation; // standard imports stripped @Documented @Target( { FIELD, CONSTRUCTOR, PARAMETER }) @Retention(RUNTIME) public @interface @MyAnnotationForParam {} </code></pre> <p>and </p> <pre><code>package com.xxx.xxx.annotation; // standard imports stripped @Target(METHOD) @Retention(RUNTIME) @Documented public @interface MyAnnotationForMethod {} </code></pre> <p>And of course it doesn' work properly.</p> <p>Can you tell me what is wrong ?</p> <p>thx.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload