google / google/guice

Public methods matcher

Open
#244 2 comments 0 reactions 0 assignees View on GitHub
enhancement imported Priority-Low
Dominant language
Java
Stars
12.7k
Forks
1.7k
Avg merge
11m
Merged PRs (30d)
2

Description

_From [limpbizkit](https://code.google.com/u/limpbizkit/) on September 09, 2008 16:42:17_

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: http://code.google.com/p/google-guice/issues/detail?id=244_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.