[project lombok] Custom annotations with Lombok

1,052 views
Skip to first unread message

daver

unread,
May 10, 2010, 4:29:42 PM5/10/10
to Project Lombok
I was following this thread with great interest (from Franz):

http://groups.google.com/group/project-lombok/browse_thread/thread/3e47f43aec82a855

I took his code (thanks Franz for posting it...) and put it into a
test project, but I'm unable to get the helloField to show in my
code...I have the Eclipse and Javac implementations both compiling--
easy enough. When I copied the code, I did move them to separate
packages (for organization):

com.mypackage.annotation.Hello
com.mypackage.annotation.handler.HandleHello
com.mypackage.annotation.handler.eclipse.HandleHello

By doing this, did I hose something? I can't see how these hook into
Lombok as extensions. Do I have to build a custom lombok.jar to make
that happen? Or something else? Or both?

I'm digging to find something to start from here...Suggestions?

Thanks,
-Dave

--
You received this message because you are subscribed to the Google
Groups group for http://projectlombok.org/

To post to this group, send email to project...@googlegroups.com
To unsubscribe from this group, send email to
project-lombo...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/project-lombok?hl=en

Franz Allan Valencia See

unread,
May 11, 2010, 5:05:12 AM5/11/10
to project...@googlegroups.com
Good day,

I'd just like to correct my HandleHello.java for eclipse: The line with 'injectMethod(fieldNode, method);' should have been 'injectMethod(fieldNode.up(), method);' With that change, @HandleHello should now work properly in your eclipse.

What I did was I modified lombok's sources themselves. That's where I added @Hello and eclipse & javac HandleHello java files. 
( But do check if you can see your handlers in build/lombok/META-INF/services/lombok.eclipse.EclipseAnnotationHandler and in build/lombok/META-INF/services/lombok.javac.JavacAnnotationHandler ). 

I am not sure though if it would be possible to create a separate jar (i.e. lombok-hello-ext.jar) and have lombok pick that up at runtime. Maybe you can create your own lombok.eclipse.EclipseAnnotationHandler & lombok.javac.JavacAnnotationHandler files inside your new jar? ...I'm not sure. I haven't tested that yet.

Also, in case you're interested on how I used this new lombok annotation, I'm attaching the sample project that I used to test my @Hello (Note: this is a maven project).

Steps to test:
1.) Build lombok (with the @Hello and HandleHello java files).
2.) Install dist/lombok jar in your local repository (mvn install:install-file -DgroupId=org.projectlombok -DartifactId=lombok -Dversion=0.9.3-EDGE -Dpackaging=jar -Dfile=dist/lombok.jar)
3.) Untar lombok-sample.tar.gz

To test Javac HandleHello:
4.) Go to the directory where you exploded lombok-sample.tar.gz
5.) Run mvn clean test
* If @Hello worked, then you should see a Build Successful. If not, then you will see a compile error.

To test Eclipse HandleHello:
4.) Run the newly created dist/lombok.jar (and install this lombok to your eclipse)
5.) Run eclipse and import the exploded lombok-sample to your eclipse as an eclipse project
6.) Run AppTest
* If @Hello worked, then the tests should pass. If not, then you will most probably get an Eclipse error or a compile error.

Cheers
-- 
Franz Allan Valencia See | Java Software Engineer 
fran...@gmail.com
LinkedIn: http://www.linkedin.com/in/franzsee
Twitter: http://www.twitter.com/franz_see
lombok-sample.tar.gz

Roel Spilker

unread,
May 11, 2010, 5:51:47 AM5/11/10
to Project Lombok
You should be able to have your own jar file that contains the META-
INF/services/lombok.eclipse.EclipseAnnotationHandler and META-INF/
services/lombok.javac.JavacAnnotationHandler files containing just one
line: the fully qualified class name of the handler. Lombok uses the
Service Provider Interface API to discover the handlers on the
classpath.

Roel

On May 11, 11:05 am, Franz Allan Valencia See <franz....@gmail.com>
wrote:
> franz....@gmail.com
> LinkedIn:http://www.linkedin.com/in/franzsee
> Twitter:http://www.twitter.com/franz_see
>
>
>
> On Tue, May 11, 2010 at 4:29 AM, daver <rodenba...@gmail.com> wrote:
> > I was following this thread with great interest (from Franz):
>
> >http://groups.google.com/group/project-lombok/browse_thread/thread/3e...
>
> > I took his code (thanks Franz for posting it...) and put it into a
> > test project, but I'm unable to get the helloField to show in my
> > code...I have the Eclipse and Javac implementations both compiling--
> > easy enough.  When I copied the code, I did move them to separate
> > packages (for organization):
>
> > com.mypackage.annotation.Hello
> > com.mypackage.annotation.handler.HandleHello
> > com.mypackage.annotation.handler.eclipse.HandleHello
>
> > By doing this, did I hose something?  I can't see how these hook into
> > Lombok as extensions.  Do I have to build a custom lombok.jar to make
> > that happen?  Or something else?  Or both?
>
> > I'm digging to find something to start from here...Suggestions?
>
> > Thanks,
> > -Dave
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups group forhttp://projectlombok.org/
>
> > To post to this group, send email to project...@googlegroups.com
> > To unsubscribe from this group, send email to
> > project-lombo...@googlegroups.com<project-lombok%2Bunsu...@googlegroups.com>
> > For more options, visit this group at
> >http://groups.google.com/group/project-lombok?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups group forhttp://projectlombok.org/
>
> To post to this group, send email to project...@googlegroups.com
> To unsubscribe from this group, send email to
> project-lombo...@googlegroups.com
> For more options, visit this group athttp://groups.google.com/group/project-lombok?hl=en
>
>  lombok-sample.tar.gz
> 2KViewDownload

daver

unread,
May 11, 2010, 11:26:21 AM5/11/10
to Project Lombok
Thanks guys. I got mine working after getting the lombok project
compiling and shoe-horning it inside there. I'll break it out based
on the suggestions above.
Reply all
Reply to author
Forward
0 new messages