aboutsummaryrefslogtreecommitdiff
path: root/src/java/lombok
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@tipit.to>2009-06-09 18:27:10 +0200
committerReinier Zwitserloot <reinier@tipit.to>2009-06-09 18:27:10 +0200
commit41fb7cba62b543243c784757d1af4e05824ddc4e (patch)
treeb910a78f31576d08f7a95440edb8f630cf4164eb /src/java/lombok
parent525211b872b982b880aa2bed5e263ec582593f0d (diff)
downloadlombok-41fb7cba62b543243c784757d1af4e05824ddc4e.tar.gz
lombok-41fb7cba62b543243c784757d1af4e05824ddc4e.tar.bz2
lombok-41fb7cba62b543243c784757d1af4e05824ddc4e.zip
Many changes:
- Split off the actual agent work into a separate src package in preparation for creating separate jars. Involved a lot of renaming - Renamed TransformCompilationUnitDeclaration to TransformEclipseAST, as this class will also be transforming e.g. MethodDeclaration objects. - Expanded the patching to also patch in transform calls when the parser fills in the Statement array for existing constructors, methods, and initializers. - Redesigned the ClassLoaderWorkaround class quite a bit. - Positioning should not work correctly ('jump to method' should jump to the getter annotation). (Apparently, Clinit objects are always fully parsed in the original run, so no need to patch anything there).
Diffstat (limited to 'src/java/lombok')
-rw-r--r--src/java/lombok/ClassLoaderWorkaround.java74
1 files changed, 0 insertions, 74 deletions
diff --git a/src/java/lombok/ClassLoaderWorkaround.java b/src/java/lombok/ClassLoaderWorkaround.java
deleted file mode 100644
index c533424d..00000000
--- a/src/java/lombok/ClassLoaderWorkaround.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package java.lombok;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Method;
-
-/**
- * Allows you to load a class off of any place that is injected into a class loader (which doesn't know how to load the class you're injecting).
- *
- * Example: Injecting lombok's Eclipse Parser patching code into eclipse's OSGi BundleLoader.
- *
- * @author rzwitserloot
- */
-public class ClassLoaderWorkaround {
- private static boolean initialized;
- private static Method m;
-
- public static void transformCompilationUnitDeclaration(Object cud) throws Exception {
- if ( !initialized ) initialize(cud);
- if ( m == null ) throw new ClassNotFoundException("lombok.agent.eclipse.TransformCompilationUnitDeclaration");
- m.invoke(null, cud);
- }
-
- private static void initialize(Object cud) {
- final ClassLoader parent = cud.getClass().getClassLoader();
- ClassLoader loader = new ClassLoader() {
- @Override public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
- if ( name.startsWith("lombok.") ) {
- InputStream in = ClassLoader.getSystemClassLoader().getResourceAsStream(name.replace(".", "/") + ".class");
- ByteArrayOutputStream out = new ByteArrayOutputStream();
-
- byte[] b = new byte[65536];
- try {
- while ( true ) {
- int r = in.read(b);
- if ( r == -1 ) break;
- if ( r > 0 ) out.write(b, 0, r);
- }
-
- in.close();
- byte[] data = out.toByteArray();
- Class<?> result = defineClass(name, data, 0, data.length);
- if ( resolve ) resolveClass(result);
- return result;
- } catch ( IOException e ) {
- throw new ClassNotFoundException();
- }
- } else {
- try {
- Class<?> result = ClassLoader.getSystemClassLoader().loadClass(name);
- if ( resolve ) resolveClass(result);
- return result;
- } catch ( ClassNotFoundException e ) {
- Class<?> result = parent.loadClass(name);
- if ( resolve ) resolveClass(result);
- return result;
- }
- }
- }
- };
-
- try {
- Class<?> c = loader.loadClass("lombok.agent.eclipse.TransformCompilationUnitDeclaration");
- for ( Method m : c.getMethods() ) {
- if ( m.getName().equals("transform") ) {
- ClassLoaderWorkaround.m = m;
- break;
- }
- }
- } catch ( ClassNotFoundException ignore ) {}
- initialized = true;
- }
-}