[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.technology.ajdt] Method with Aspect getting called twice

Hi,

I built a small application with one aspect . The code for the Aspect is :

@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD })
public @interface Validate {

}


@Aspect public class ValidationAspect {

   @Before("@annotation(com.Validate)")
   public void invokeMethod(final JoinPoint joinPoint)
       throws Throwable {
   	System.out.println("Aspect Called");
   }
}


I applied this aspect on a class :


package com;

public class Address {
	
	private String city;

	@Validate
	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}
	
}


And I used a test class to invoke Address.getCity()

class Main {
     public static void main(String[] args) {
		Address a =new Address();
		a.getCity();
     }
}


Now when a.getCity() is called , the Aspect is invoked twice . My Eclipse project is AspectJ enabled and when I look at the class of Main.java it looks like this:


   Address a = new Address();
   Address localAddress1 = a;
   JoinPoint localJoinPoint2 = Factory.makeJP(ajc$tjp_1, null, localAddress1);
   ValidationAspect.aspectOf().invokeMethod(localJoinPoint2);
   localAddress1.getCity();

This is why it is getting invoked twice . Why so ?