Note that there are some explanatory texts on larger screens.

plurals
  1. POAspectJ/Java instrumentation to intercept an annoted parameter call/usage
    text
    copied!<p>I would like to know how the doMonitorization method can be called when the param1 is used (param defined and used on the methods of the TestClassGeneralMeasuraments Class) which has the correct annotation that has a interception AspectJ definition as the bellow code shows.</p> <pre><code>package monitorization; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; @Aspect public class AspectJInterceptor { @Pointcut(value = "@annotation(monitorme)", argNames = "monitorme") public void monitorActivity(Monitorme monitorme) {} @After("monitorActivity(monitorme)") public void doMonitorization(JoinPoint jp, Monitorme monitorme) { MetricsDataStructure.staticInstance.addOperation(jp.getSignature().toLongString(), monitorme.value()); } } </code></pre> <p>/////////////////////////////////////////////////</p> <pre><code>package monitorization; import java.lang.annotation.Retention; import java.lang.annotation.Target; import java.lang.annotation.ElementType; import java.lang.annotation.RetentionPolicy; @Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) @Retention(RetentionPolicy.RUNTIME) public @interface Monitorme { int value(); } </code></pre> <p>/////////////////////////////////////////////////</p> <pre><code>package monitorization; public class TestClassGeneralMeasuraments{ @Monitorme(20) int field; @Monitorme(50) int field2; @Monitorme(5) public void simpleTestMethod(@Monitorme(10) String param1){ this.field = 1; this.field = 3; this.field = 4; param1 = ""; } @Monitorme(30) public void simpleTestMethod2(@Monitorme(10) String param1){ this.field2 = 1; this.field2 = 1; param1 = ""; } public static void main(final String[] args){ long intialTimeStamp = System.currentTimeMillis(); System.out.println("Starting up"); TestClassGeneralMeasuraments testObject = new TestClassGeneralMeasuraments(); for(long i=0; i&lt;50; i++) { testObject.simpleTestMethod("Hey"); testObject.simpleTestMethod("Hey"); testObject.simpleTestMethod2(""); } } } </code></pre>
 

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