use of lombok.core.DiagnosticsReceiver in project lombok by rzwitserloot.
the class LombokProcessor method placePostCompileAndDontMakeForceRoundDummiesHook.
private void placePostCompileAndDontMakeForceRoundDummiesHook() {
stopJavacProcessingEnvironmentFromClosingOurClassloader();
forceMultipleRoundsInNetBeansEditor();
Context context = processingEnv.getContext();
disablePartialReparseInNetBeansEditor(context);
try {
Method keyMethod = Context.class.getDeclaredMethod("key", Class.class);
keyMethod.setAccessible(true);
Object key = keyMethod.invoke(context, JavaFileManager.class);
Field htField = Context.class.getDeclaredField("ht");
htField.setAccessible(true);
@SuppressWarnings("unchecked") Map<Object, Object> ht = (Map<Object, Object>) htField.get(context);
final JavaFileManager originalFiler = (JavaFileManager) ht.get(key);
if (!(originalFiler instanceof InterceptingJavaFileManager)) {
final Messager messager = processingEnv.getMessager();
DiagnosticsReceiver receiver = new MessagerDiagnosticsReceiver(messager);
JavaFileManager newFiler = new InterceptingJavaFileManager(originalFiler, receiver);
ht.put(key, newFiler);
Field filerFileManagerField = JavacFiler.class.getDeclaredField("fileManager");
filerFileManagerField.setAccessible(true);
filerFileManagerField.set(processingEnv.getFiler(), newFiler);
}
} catch (Exception e) {
throw Lombok.sneakyThrow(e);
}
}
use of lombok.core.DiagnosticsReceiver in project lombok by rzwitserloot.
the class TestPostCompiler method testPostCompiler.
@Test
public void testPostCompiler() throws IOException {
byte[] compiled = TestClassFileMetaData.compile(new File("test/bytecode/resource/PostCompileSneaky.java"));
DiagnosticsReceiver receiver = new DiagnosticsReceiver() {
@Override
public void addWarning(String message) {
fail("Warning during post compilation processing of a sneakyThrow call: " + message);
}
@Override
public void addError(String message) {
fail("Error during post compilation processing of a sneakyThrow call: " + message);
}
};
assertTrue("Before post compilation, expected lombok.Lombok.sneakyThrow() call in compiled code, but it's not there", new ClassFileMetaData(compiled).usesMethod("lombok/Lombok", "sneakyThrow"));
byte[] transformed = PostCompiler.applyTransformations(compiled, "PostCompileSneaky.java", receiver);
assertNotSame("Post-compiler did not do anything; we expected it to remove a Lombok.sneakyThrow() call.", compiled, transformed);
assertTrue("After removing a sneakyThrow the classfile got... bigger (or stayed equal in size). Huh?", transformed.length < compiled.length);
}
Aggregations