• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Custom Java Compiler Constraints

 
Ranch Hand
Posts: 171
Spring Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I'm very eager to know about custom constraints can be added in default java compiler I wanna implement a functionality only when java program has my own annotations, so the compiler has to read my annotations and it should implement the what I wanted. Is it possible? (Like this I wanna to check my own exceptions etc.) Thanks in advance.
 
Sheriff
Posts: 21758
102
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will need to write your own compiler (possibly using the source of another compiler to start with) for that to work.
 
Saloon Keeper
Posts: 5561
143
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you provide more detail about what you intend to do? From your description it's not clear to me that the compiler has to do that, and not the runtime.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure because I've never used it myself, but maybe you can use the apt tool that's included with the JDK to do what you want.

Annotations are not really meant for extending the Java language in the way that you seem to want to do. Using the reflection API, you can find out if classes, methods etc. have annotations on them. Most libraries or frameworks that use annotations use the reflection API to read information about the annotations.
 
Ranch Foreman
Posts: 3264
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jesper de Jong wrote:Annotations are not really meant for extending the Java language in the way that you seem to want to do.


That's true, as far as the original intent of Sun et al is concerned. However, others have indeed used annotations much as the original poster describes. Check out Project Lombok for example. It might be worthwhile to study just how that's been implemented; I suspect it uses apt internally, as Jesper recommends.
 
Kumaravadivel Subramani
Ranch Hand
Posts: 171
Spring Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks All to shared the ideas.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!