[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.tools.jdt] Re: Annotations in Eclipse (Europa)
|
"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.
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).
> 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.
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.