Hi Andrew, thanks for your comments. The runtime option won't work since I am
trying to create a build time check to prevent developers from using non public
API methods. We actually have custom classloaders and LTW to prevent runtime
usage but the problem there is that we then have to rely on QA to find issues
since our development tests don't have that kind of coverage.
The other problem is that the concrete class often does not have the @PublicAPI
annotation. In many cases we only annotate interfaces. e.g.
interface Doer { public void doIt(); }
@PublicAPI interface IA extends Doer { public void doIt(); } // unnecessary
overriding but it happens. Can't change this.
class IA_Impl implements IA
I'll look into creating an enhancement.
Thanks very much,
Steve
--- On Tue, 6/23/09, Andrew Eisenberg <[email protected]> wrote:
> From: Andrew Eisenberg <[email protected]>
> Subject: Re: [aspectj-users] Joinpoint method signature matches superclass
> and not the referenced class
> To: [email protected]
> Date: Tuesday, June 23, 2009, 9:17 AM
> Hi Steve,
>
> The problem is that the signature at the C.doIt() method
> call matches *both* the method declaration on C and the
> method declaration on IC.
>
> http://www.eclipse.org/aspectj/doc/released/progguide/semantics-pointcuts.html#signatures
>
>
> So, the pointcut is behaving as spec-ed.
>
> Because of how method call signatures are matched, I do not
> think it is possible to do exactly what you want using
> declare warning only.
>
> However, you can try doing this using a before advice:
>
>
> before() : !...@target(PublicAPI) && (call(*
> (!...@publicapi *).*())) {
> throw new RuntimeException("Non public
> API usage");
> }
>
> Notice how this becomes a runtime test. This will look at
> the concrete type of the target at runtime and throw an
> exception if it does not have the annotation.
>
>
> eg-
>
> interface IC
> @PublicAPI class C implements IC
> class D extends C
>
> IC ic = new C();
> ic.doIt(); // OK! with gutter marker signifying
> runtime test
> ic = new D();
> ic.doIt(); // Exception!!! with gutter marker signifying
> runtime test
>
>
> This is the best I can do. Can anyone else do better?
>
> Feel free to raise an enhancement request for your
> particular situation.
>
>
> On Tue, Jun 23, 2009 at 8:01 AM,
> Steve reds <[email protected]>
> wrote:
>
>
>
> Hi Oliver, its not the constructor because if I have
> another class
>
>
>
> @PublicAPI
>
> class B
>
> {
>
> public void doIt() {
>
> }
>
> }
>
>
>
> and call
>
> new B().doIt();
>
>
>
> that does not give me a warning.
>
>
>
> I can even have
>
> @PublicAPI
>
> class B implements IB
>
> {
>
> public void doIt() {
>
> }
>
> }
>
>
>
> public interface IB
>
> {
>
> }
>
>
>
> and that does not give a warning.
>
>
>
> Thanks,
>
> Steve
>
>
>
> --- On Tue, 6/23/09, Oliver Böhm <[email protected]>
> wrote:
>
>
>
> > From: Oliver Böhm <[email protected]>
>
> > Subject: Re: [aspectj-users] Joinpoint method
> signature matches superclass and not the referenced class
>
> > To: [email protected]
>
> > Date: Tuesday, June 23, 2009, 7:09 AM
>
> > Hello Steve,
>
> >
>
> > I guess, it is the constructor call "new
> C()" who causes
>
> > the warning, because it has no annotation.
>
> >
>
> > rggards
>
> > Oliver
>
> >
>
> >
>
> >
>
> > Steve reds schrieb:
>
> > > Hi, I'm having trouble creating a method
> signature and
>
> > I wonder if it is FaD.
>
> > >
>
> > > I'm trying to create a pattern for
> 'declare warning'
>
> > that identifies all method calls to classes that do
> not have
>
> > the annotation - @PublicAPI. The annotation is on the
>
> > referenced class, not its methods.
>
> > >
>
> > > The pattern I am using is:
>
> > > declare warning : call(* (!...@publicapi *).*(..)) :
> "Non
>
> > public API usage";
>
> > >
>
> > > In the following case I don't expect a
> warning but one
>
> > is generated:
>
> > >
>
> > > public class Main
>
> > > {
>
> > > public static void
>
> > main(String[] args) {
>
> > > // Generates
>
> > warning even though C is @PublicAPI
>
> > > new C().doIt();
>
> > > }
>
> > > }
>
> > >
>
> > > @PublicAPI
>
> > > class C implements IC
>
> > > {
>
> > > public void doIt() {
>
> > > }
>
> > > }
>
> > >
>
> > > public interface IC
>
> > > {
>
> > > public void doIt();
>
> > > }
>
> > >
>
> > > Shouldn't the signature match doIt() in C and
> not the
>
> > one in IC since only C is referenced in Main?
>
> > >
>
> > > Thanks,
>
> > > Steve
>
> > >
>
> > >
>
> > >
>
> > _______________________________________________
>
> > > aspectj-users mailing list
>
> > > [email protected]
>
> > > https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
> >
>
> > -- Oliver Böhm
>
> > http://www.javatux.de
>
> > _______________________________________________
>
> > aspectj-users mailing list
>
> > [email protected]
>
> > https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
> >
>
>
>
>
>
>
>
> _______________________________________________
>
> aspectj-users mailing list
>
> [email protected]
>
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
>
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> aspectj-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users