[JSR308] Some general questions

Federico Mancini mancini.federico at gmail.com
Tue Jan 27 03:42:32 EST 2009


Hi,
I finally managed to get my checker to work.
After I spent quite some time  trying to write my own AnnotatedFactory
without success, I found out, reading the TreeAnnotator.java code,
that the annotation @ImplicitFor is indeed powerful enough to handle
regular expressions.
Was this a new feature added in the last release? If so, thanks a lot,
it made my life much easier! (5 minutes instead of a few days to get
the checker to work :-) ).

Federico

2009/1/14 Mahmood Ali <mahmood at mit.edu>:
> 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