Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Final Classes

Ron,

	I suppose I didn't explain myself quite well. You are absolutely right about 
what you've just said. Actually, what I was trying to do is something else: 
I'm trying to capture the class itself being final, not its constructor being 
final. The source code I have put here was just to simplify but I guess it 
wasn't well chosen. I would like to do something like the following:

// The following does not compile
pointcut finalClasses() : call(* (final *.*)(..)) 
&& !within(DetectFinalClassesAspect);

Is there a way to see if a class is declared as final?

Best regards,

	Paulo Zenida


Em Sexta, 23 de Dezembro de 2005 14:30, o Ronald R. DiFrango escreveu:
> Paulo,
>
> Just remove the final from your advice and you should be good to go.  At
> least I was.  Here is what it should look like:
>
>   pointcut finalClasses() : execution(*.new(..)) &&
> !within(DetectFinalClassesAspect);
>
> The reason this fails is that final as a modifier is not allowed on a
> constructor, therefore aspectj can not pick it up.
>
> Ron
>
> On 12/23/05, Paulo Alexandre Corigo Zenida <paulo.zenida@xxxxxxxx> wrote:
> > Good morning,
> >
> >        I was trying to capture calls to the constructores of a final
> > class with the
> > following example but I couldn't do so. Am I doing something wrong or
> > isn't
> > possible to capture final classes? In the case of not being possible to
> > capture final classes, could someone tell me why, please?
> >
> > Here's my final class:
> >
> > final public class FinalClass {
> >
> >        public void foo() {
> >                System.out.println("FinalClass.foo()");
> >        }
> > }
> >
> > The testing class, which simply creates an instance of my FinalClass
> > class and
> > executes its foo method:
> >
> > public class Test {
> >
> >        public static void main(String args[]) {
> >                FinalClass fc = new FinalClass();
> >                fc.foo();
> >        }
> > }
> >
> > And here's the Aspect I have created in order to capture calls for the
> > constructors of final classes:
> >
> > public aspect DetectFinalClassesAspect {
> >
> >        pointcut finalClasses() : execution(final *.new(..))
> > && !within(DetectFinalClassesAspect);
> >
> >        // This is not being applied to anything!!!
> >        before() : finalClasses() {
> >                System.out.println("Before final class: " +
> > thisJoinPointStaticPart);
> >        }
> > }
> >
> > Thanks in advance. Best regards,
> >
> >        Paulo Zenida
> > _______________________________________________
> > aspectj-users mailing list
> > aspectj-users@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users


Back to the top