Learning javac's APIs

There are three APIs of javac:
  • JSR 199 - Java Compiler API. This API can be used to embed java compiler in your program. If you want to see a simple example, you may look at JSR-223 script engine for Java. This code uses JSR 199 to compile Java code from strings and readers into memory byte buffer and load it immediately to execute.
  • JSR 269: Pluggable Annotation Processing API. This API can be used to write your own annotation processors. For a simple example, you may want to look at this file in your JDK 6: $JDK/sample/javac/processing/src/CheckNameProcessor.java. This sample checks naming conventions of the compiled class (such as class name should start with upper case).
  • The Tree API - this API is in "com.sun.source.util" and "com.sun.source.tree" packages. If you want to access abstract syntax trees (read-only) of Java programs, you can use this API [start by casting JavaCompier.getTask() method's return value to JavacTask)
Comments:

Post a Comment:
Comments are closed for this entry.
About

sundararajan

Search

Archives
« July 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today
Bookmarks
Links

No bookmarks in folder

Blogroll

No bookmarks in folder

News

No bookmarks in folder