diff options
author | Reinier Zwitserloot <reinier@tipit.to> | 2009-06-16 03:04:46 +0200 |
---|---|---|
committer | Reinier Zwitserloot <reinier@tipit.to> | 2009-06-16 03:04:46 +0200 |
commit | f36be2eb01bcbff01a513d64bff2d1aba54460b1 (patch) | |
tree | 7d49ebe90cb836e054c35d2a4382be6b999ca452 /src/lombok/javac/apt/PKG.java | |
parent | d78a04d74886101c81de77659b067d16cb2d0de2 (diff) | |
download | lombok-f36be2eb01bcbff01a513d64bff2d1aba54460b1.tar.gz lombok-f36be2eb01bcbff01a513d64bff2d1aba54460b1.tar.bz2 lombok-f36be2eb01bcbff01a513d64bff2d1aba54460b1.zip |
Implemented a lot of stuff for javac, but we ran into 2 major issues still to be implemented:
1. The visit mode of a lombok handler (does not trigger off of annotations, instead sees every field, method, type, and statement), needs to be coded,
2. triggering off of annotations via APT's annotation handling system skips method-local classes. We'll need to recode this via an AST visitor like we need for issue #1
Other than that, triggering off of annotations works swimmingly!
Diffstat (limited to 'src/lombok/javac/apt/PKG.java')
-rw-r--r-- | src/lombok/javac/apt/PKG.java | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/lombok/javac/apt/PKG.java b/src/lombok/javac/apt/PKG.java new file mode 100644 index 00000000..2ecf1c7a --- /dev/null +++ b/src/lombok/javac/apt/PKG.java @@ -0,0 +1,56 @@ +package lombok.javac.apt; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import lombok.Lombok; + + +class PKG { + private PKG() {} + + static boolean isInstanceOf(Object o, String className) { + if ( o == null ) return false; + return isInstanceOf(o.getClass(), className); + } + + static boolean isInstanceOf(Class<?> c, String className) { + if ( c == Object.class || c == null ) return false; + + if ( c.getName().equals(className) ) return true; + + if ( isInstanceOf(c.getSuperclass(), className) ) return true; + for ( Class<?> iface : c.getInterfaces() ) { + if ( isInstanceOf(iface, className) ) return true; + } + + return false; + } + + static byte[] readResource(String name) { + return readResource(PKG.class.getClassLoader(), name); + } + + static byte[] readResource(ClassLoader loader, String name) { + InputStream in = loader.getResourceAsStream(name); + if ( in == null ) throw Lombok.sneakyThrow(new IOException("Not found: " + name)); + + try { + return readStream(in); + } catch (IOException e) { + throw Lombok.sneakyThrow(e); + } + } + + static byte[] readStream(InputStream in) throws IOException { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + byte[] b = new byte[65536]; + while ( true ) { + int r = in.read(b); + if ( r == -1 ) break; + if ( r > 0 ) baos.write(b, 0, r); + } + return baos.toByteArray(); + } +} |