[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools.jdt] Re: Annotations in Eclipse (Europa)

Walter Harley wrote:

> "David Goodenough" <david.goodenough@xxxxxxxxxxxxx> wrote in message
> news:fbr3fu$ai3$1@xxxxxxxxxxxxxxxxxxxx
>>> But I think you may have gotten off on the wrong foot here, by putting
>>> your
>>> processors, annotations, and annotated code all in the same project.  If
>>> I
>>> correctly understand what you mean, that will not, in general, work.
>>
>> Well if I read the Sun Javac documentation right this is allowed.  I am
>> not writing general purpose annotations, but ones specific to this
>> project so putting them in the project makes a whole heap of sense.
>>
>> In fact the default for javac is to look in the source tree and the
>> classpath for the processors if you do not specify -processpath.
> 
> javac will look for processor classes on the classpath, yes.  If it will
> look for processor source code, and compile it in time to use the
> processor on the rest of the source code that it's compiling, then that is
> news to me.
> 
> That is, if you had a project containing FooAnnotation.java,
> FooProcessor.java, and AnnotatedWithFoo.java, I don't believe that you
> could
> say "javac *.java" and have your annotations get processed.  Is that what
> you're saying?  On the other hand, you could certainly rig up an ant
> script to do it in the right sequence, I guess.
I will give it a try.  But certainly javac will read processors from -cp
which logically includes what has been compiled.  Given the rounds and that
it is quite possible to have annotations in generated code I do not see
why it should not be capable of going from source.  The only thing that 
might be a problem would be if you started with an empty bin (i.e. output)
directory which would not have a META-INF/services directory in it.  With
Ant it would be easy to set up to copy that first - I will try it.
> 
> In general I would seek to strongly discourage you from combining these
> things into the same project.  The processor is part of the compiler, in
> many important senses (for instance, it runs in the VM of the compiler).
> 
What I have done in the interim is to create a JAR from the annotations
and tell Eclipse to use that - it seems to work.
> 
>> My problem is that the annotation creates the class to which it is
>> applied,
>> and so the editor complains about errors until the class is created. 
>> What I am trying to do is create a data binding annotation for Swing
>> objects. So
>> for instance I have one for Combo boxes which create a ComboBoxModel
>> class which pulled a particular bean property as the dropdown content:-
>>
>> MyBean[]myBeanArray;
>> @ComboBinding(dataClass="MyBean",column="property")
>> MyComboModel model = new MyComboModel(myBeanArray);
>>
>> where MyComboModel is a class that is build by the annotation processor.
>> So the Eclipse editor flags the last line as having errors (the type does
>> not exist) until the build has been done.
> 
> Yeah, we talk about that design pattern a bit in our tutorial.  I'll let
> you read the tutorial and then ask questions, but for now suffice it to
> say if you can do it some other way (e.g. with an interface and factory
> method) you might have more satisfactory results.
Now that I have everything working it seems to work after I have got through
the basic bootstrap of creating the first instance of the target class.
> 
> You can make it work the way you want it to, if you turn on reconcile-time
> type generation.  Reconcile-time type generation is only supported for the
> Java 5 interface, not for the Java 6 interface.  Frankly I'm pushing to
> keep
> it that way.  Reconcile-time type generation was a bad experiment, in my
> personal opinion.  The compiler's type model is a fairly heavyweight
> object; by generating types at reconcile time, we're asking that model to
> revise itself on every keystroke (imagine, for instance, that you're
> editing the annotation parameters, causing the name or content of a
> generated type to
> change).  There is just no way to make that perform speedily enough to
> satisfy the user of the IDE.
I suppose that all that is needed is to run it the first time it is met, 
almost on the off chance that it might create the classes.  Alternatively
it could be a Quick Fix option - that way you are running it manually
and only when it is really needed.

David