Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] initializaton's definition


Rice,

The aspect should match each constructor so you may be experiencing a problem with incremental compilation in Eclipse. Try cleaning the project and see if you get advice markers.

WRT your question do you only want to advise StudyType, in which case you can simply add  "&& within(StudyType)" to your advise or do you want to ensure the registration only occurs once per object construction in which case try:

    after(as.classifier.Type type) returning():
            typeConstruction() && target(type)
            {
            Class declaringType = thisJoinPoint.getSignature().getDeclaringType();
            Class actualType = type.getClass();
            if (declaringType == actualType) {
                System.err.println("Aspect.afterReturning() " + thisJoinPoint);
//          xs.school.Types.getInstance().register(type);
            }

which is to say only call register() when the join point i.e. advised constructor, is declared by the current object.

Matthew Webster
AOSD Project
Java Technology Centre, MP146
IBM Hursley Park, Winchester,  SO21 2JN, England
Telephone: +44 196 2816139 (external) 246139 (internal)
Email: Matthew Webster/UK/IBM @ IBMGB, matthew_webster@xxxxxxxxxx
http://w3.hursley.ibm.com/~websterm/



"Rice Yeh" <riceyeh@xxxxxxxxx>
Sent by: aspectj-users-bounces@xxxxxxxxxxx

01/09/2006 14:43

Please respond to
aspectj-users@xxxxxxxxxxx

To
aspectj-users@xxxxxxxxxxx
cc
Subject
[aspectj-users] initializaton's definition





Hi,
 I have a aspect like the following:

   pointcut typeConstruction():
       initialization(as.classifier.Type+.new(..));
   
   after(as.classifier.Type type) returning():
           typeConstruction() && target(type) {
       xs.school.Types.getInstance().register(type);
   }

I find that the advice is executed twice for a subclass (StudyType) of as.classifier.Type. I traced my constructor call stack like the following: (StudyType inherits from AccountabilityType, which inherits from RelationType, which implements Type).

   private StudyType(String name, StudyType parent, boolean isAbstract) {
       super(name, parent, isAbstract);
   }  --> advice is executed here

   public AccountabilityType(String name, AccountabilityType parent, boolean isAbstract) {
       super(name, parent, isAbstract);
   }  --> advice is NOT executed here

   public RelationType(String name, RelationType parent, boolean isAbstract) {
       super(name, parent, isAbstract);
       if (this instanceof AggregationType)
           setValidator( CyclicValidator.getInstance());        
   }  -- > advice is executed here

Should not the join point for the constructor RelationType be adviced? I want just want the advice is executed on the join point for StudyType constructor. What should I do?

Thanks,
Rice

_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top