[JSR308] Some general questions

Mahmood Ali mahmood at MIT.EDU
Wed Jan 14 16:10:58 EST 2009


Greetings,

> I have been reading the sections you suggested, and also found the
> thesis of Matthew Papi, which was very helpful.
Very glad!

> Regarding the quoted text at the end of this email, I understand that
> I need to extend the checker
> by adding an @ImplicitFor annotation, where the argument is the set of
> strings which match my date format.
> I understand that it should be possible to pass string literals to
> the @ImplicitFor annotation,
> but can I pass a regular expression? If so, could you be so kind to
> show me an example?
>
@ImplicitFor is a declarative method for type introduction rules.  It  
is not expressive enough to handle regular expressions though.

One possible approach is to use a TreeAnnotator in your  
AnnotatedTypeFactory.  You can override  
AnnotatedTypeFactory.createTreeAnnotator (look at  
IGJAnnotatedTypeFactory for an example), like the following:

     @Override
     protected TreeAnnotator createTreeAnnotator(BaseTypeChecker  
checker) {
         return new TreeAnnotator(checker) {
             @Override
             public Void visitLiteral(LiteralTree node,  
AnnotatedTypeMirror p) {
                 if (node.getKind() == Tree.Kind.STRING_LITERAL) {
                     String str = (String)node.getValue();
                     if (str.matches(MY_REGEXP))
                         p.addAnnotation(DATE);
                 }
                 return super.visitLiteral(node, p);
             }
         };
     }

> Another thing that I was wondering, after trying Findbugs: can you
> give a whole project to the checker or only single java files? In
> the latter case, does the checker automatically check also the
> external classes or functions that are used in the file that is being
> checked?


The checkers operate as a compiler plug-in for the files being  
compiled.  They only verify the code being compiled, whether it's a  
one file, an entire project, or a sub-project.

For classes and functions that are not within the code being compiled,  
the checkers don't analyze the body of such classes, but they do check  
the uses of those functions/classes in source code.

Regards,
Mahmood




More information about the JSR308 mailing list