[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:fbpt81$29d$1@xxxxxxxxxxxxxxxxxxxx
>>I am trying to use annotations in Eclipse, and I am stuck.
>>
>> I have a workplace with a project within which I have defined a couple
>> of annotation processors, the annotation classes, and some classes which
>> use the annotations.  I have made sure that I have started Eclipse with
>> a Version 6 JVM (a Sun one) and I have enabled annotation processing for
>> this project.  But nothing happens, and the processor is never invoked
>> (as far as I can tell - at least there are no errors and nothing gets
>> generated).
> 
> Heh.  I was just in the process of writing up an enhancement request for
> features to support this situation :-)
> 
> You're right, it can be quite hard to debug what's going on when
> processing isn't happening.
> 
> 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.

> 
> Think of the processors as being part of the compiler, not part of what is
> being compiled.  So you can't put the processor code in the same project
> as
> the code to be processed.  Typically if you are just using a readymade
> processor, it is in a plug-in or a jar file of its own; you would then
> refer to that in the Factory Path of the project containing the annotated
> code to be processed.

I am not using a readymade processor, I am writing my own.

> 
> If you are developing annotation processors, you would typically have one
> workspace (or at least a separate project) for your processors, and a
> separate workspace containing the projects with annotated code.
> 
> 
> 
>> I did come across a reference to having to enable something specific to
>> allow new classes to be generated while I am editing so that new classes
>> can be generated by annotations and then referenced in the class I am
>> editing, but I do not understand exactly what I am supposed to do to
>> enable
>> this.
> 
> I would avoid this for now.  Stick with generating types during *build*,
> which is the default.  The distinction is simply that if type generation
> during reconcile is enabled, then your annotation processors are able to
> generate types as you work in the editor, rather than only when you build.
> This is rarely necessary.
>

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.

> 
>> Does anyone have a worked example of writing an annotation processor in
>> Eclipse, and then using it - I guess I am missing some simple stage in
>> the process.
> 
> You can take a look at our EclipseCon 2007 presentation on writing
> processors at http://www.eclipsecon.org/2007/index.php?page=sub/&id=3618 .
> The presentation file there contains a PowerPoint presentation and some
> worked example code.

I will have a look and see if there are then any more questions that I have.

David
> 
> If you still have questions after looking at that I'd be delighted to
> help. Feel free to post more questions to this newsgroup.
> 
> Thanks,
>   -Walter Harley
>    JDT APT team