From d330649b1567cb016d6cc0421959fbf6a90733f5 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Tue, 6 May 2014 18:45:09 +0200 Subject: more work on JDK8 support: val on generified lub types now works a little better. --- .../lombok/javac/Javac6BasedLombokOptions.java | 27 ++++++++++++++++++++-- src/core/lombok/javac/handlers/HandleVal.java | 2 +- 2 files changed, 26 insertions(+), 3 deletions(-) (limited to 'src/core/lombok') diff --git a/src/core/lombok/javac/Javac6BasedLombokOptions.java b/src/core/lombok/javac/Javac6BasedLombokOptions.java index 871e41c4..cefb89ff 100644 --- a/src/core/lombok/javac/Javac6BasedLombokOptions.java +++ b/src/core/lombok/javac/Javac6BasedLombokOptions.java @@ -21,11 +21,28 @@ */ package lombok.javac; -import com.sun.tools.javac.main.OptionName; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import lombok.Lombok; + import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Options; public class Javac6BasedLombokOptions extends LombokOptions { + private static final Method optionName_valueOf; + private static final Method options_put; + + static { + try { + Class optionNameClass = Class.forName("com.sun.tools.javac.main.OptionName"); + optionName_valueOf = optionNameClass.getMethod("valueOf", String.class); + options_put = Class.forName("com.sun.tools.javac.util.Options").getMethod("put", optionNameClass, String.class); + } catch (Exception e) { + throw new IllegalArgumentException("Can't initialize Javac6-based lombok options due to reflection issue.", e); + } + } + public static Javac6BasedLombokOptions replaceWithDelombokOptions(Context context) { Options options = Options.instance(context); context.put(optionsKey, (Options)null); @@ -39,6 +56,12 @@ public class Javac6BasedLombokOptions extends LombokOptions { } @Override public void putJavacOption(String optionName, String value) { - put(OptionName.valueOf(optionName), value); + try { + options_put.invoke(this, optionName_valueOf.invoke(null, optionName), value); + } catch (IllegalAccessException e) { + throw new IllegalArgumentException("Can't initialize Javac6-based lombok options due to reflection issue.", e); + } catch (InvocationTargetException e) { + throw Lombok.sneakyThrow(e.getCause()); + } } } diff --git a/src/core/lombok/javac/handlers/HandleVal.java b/src/core/lombok/javac/handlers/HandleVal.java index 75464195..eb3a2f46 100644 --- a/src/core/lombok/javac/handlers/HandleVal.java +++ b/src/core/lombok/javac/handlers/HandleVal.java @@ -91,7 +91,7 @@ public class HandleVal extends JavacASTAdapter { local.mods.annotations = local.mods.annotations == null ? List.of(valAnnotation) : local.mods.annotations.append(valAnnotation); } - local.vartype = JavacResolution.createJavaLangObject(localNode.getAst()); + local.vartype = localNode.getAst().getTreeMaker().Ident(localNode.getAst().toName("___Lombok_VAL_Attrib__")); Type type; try { -- cgit