[JSR308] Some general questions
Federico Mancini
mancini.federico at gmail.com
Wed Jan 14 08:34:40 EST 2009
Hi again,
I have been reading the sections you suggested, and also found the
thesis of Matthew Papi, which was very helpful.
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?
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?
Thanks again for the all the help!
Federico
2009/1/9 Mahmood Ali <mahmood at mit.edu>:
> Greetings Federico,
>
>> 3) Is it possible to define a new type by the kind of values that are
>> valid for that type? For example the type @Date that defines all strings
>> that matches the regular expression "[1-31]/[1-12]/[2000-2010]".
>> If so, how to extend the basic checker for this type?
>
> Yes. Please read sections 7 and 9 of the Checkers manual.
>
> Here is a summary of those sections related to the example you provided:
>
> Summary of section 7:
> When using the basic checker, you simply need to declare the annotations:
> @TypeQualifier
> @SubtypeOf(Unqualified.class)
> public @interface Date { }
> And have the basic checker enforce the semantics of the basic type system
> (checks assignments and pseudo-assignments only).
>
> Such checker doesn't verify that a string literal in the code is indeed of a
> Date format. This makes either need to cast such string literals to @Date
> String type (which is an unsafe cast), or have a format verifier method that
> ensures the string is a Date string at run-time.
>
> Summary of Section 9:
> Because of the limitation mentioned earlier, you can build a more powerful
> checker that implicitly add @Date qualifier to the types of string literals
> that match the specified format.
>
> With this more powerful checker, you may still need to have a method that
> verifies the string Date format for strings that are inputs from the user or
> from configuration files.
More information about the JSR308
mailing list