[JSR308] Can we agree on our goals? (annotations on blocks)
Eugene Kuleshov
eu at javatx.org
Thu Feb 1 18:21:13 EST 2007
Tom Ball wrote:
>> Tom, does block nodes [in javac AST] have information about type of
>> the parent, i.e. if/else/for/try/catch/etc ?
> No node has any knowledge of its parents, as javac's AST is a directed
> acyclic graph. I'm not sure parent information is useful anyway since
> loop statements don't necessarily have blocks -- they have child
> statements which may or may not be blocks.
>
> However, I was suggesting putting a block around the statement(s) to
> be annotated:
>
> @DoForever {
> for (;;) {
> ...
> }
> }
>
> No parent node knowledge is needed here, whereas it would be a serious
> compiler whack to support something like "for (;;) @DoForever { ...
> }". IMHO, I think the former is easier to read.
Yes, but "for (;;) @DoForever { ... }" meant postfix annotation linked
to the "for" not to the block. This is sensitive for tools like JML,
because they need to be able to restrict annotation on the loop only,
but in your suggestion nothing would stop user from doing something like
this:
@DoForever {
for (;;) {
...
}
doSomethingElse();
}
On the other hand the following code would be valid (restricting block
to not change instance state for this particular scope):
@Readonly {
doSomething();
doSomethingElse();
}
regards,
Eugene
More information about the JSR308
mailing list