bineanzhou / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Public methods matcher #244

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
From: Pierre Monestie <pmonestie@gmail.com>
Subject: Re: BytecodeGen

Reading the doc, you guys specify that this will only work if the methods
intercepted are public. I would suggest, for Guice, to provide a Method
interceptor matcher that matches only public methods so that people don't
make the mistake intercpeting package-private methods....

Something like:
public static Matcher<AnnotatedElement>
publicMethodAnnotatedWith(final Class<? extends Annotation>
annotationType) {
               return new AnnotatedWithType(annotationType){
                       public boolean matches(AnnotatedElement element) {
                               boolean v=
element.getAnnotation(annotationType) != null;
                               if (!v)return v;
                               if (!(element instanceof Method)){
                                       return false;
                               }else{
                                       Method method=(Method)element;

v=Modifier.isPublic(method.getModifiers());
                                       if (!v){
                                               log.error("Method is not
public, will not intercept");
                                       }
                                       return v;
                               }

                       }
               };
       }

Original issue reported on code.google.com by limpbizkit on 9 Sep 2008 at 8:42

GoogleCodeExporter commented 9 years ago
Maybe automatically decorate all method matchers with code like that?

Original comment by robbie.v...@gmail.com on 27 Dec 2008 at 1:03

GoogleCodeExporter commented 9 years ago
I opened issue 291, which would add some diagnostic information about the 
interceptors in play. With that it 
should be straightforward to write a tool to find missing/broken/unanticipated 
interceptions...

Original comment by limpbizkit on 27 Dec 2008 at 3:07