diff options
Diffstat (limited to 'src/utils/lombok/javac')
7 files changed, 34 insertions, 63 deletions
diff --git a/src/utils/lombok/javac/CommentCatcher.java b/src/utils/lombok/javac/CommentCatcher.java index ff6be7a2..c32da68b 100644 --- a/src/utils/lombok/javac/CommentCatcher.java +++ b/src/utils/lombok/javac/CommentCatcher.java @@ -25,7 +25,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.Collections; import java.util.List; -import lombok.core.ReferenceFieldAugment; +import lombok.core.FieldAugment; import com.sun.tools.javac.main.JavaCompiler; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; @@ -33,24 +33,22 @@ import com.sun.tools.javac.util.Context; public class CommentCatcher { private final JavaCompiler compiler; - private final ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField; + public static final FieldAugment<JCCompilationUnit, List<CommentInfo>> JCCompilationUnit_comments = FieldAugment.augment(JCCompilationUnit.class, List.class, "lombok$comments"); public static CommentCatcher create(Context context) { registerCommentsCollectingScannerFactory(context); JavaCompiler compiler = new JavaCompiler(context); - ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> comments = ReferenceFieldAugment.augment(JCCompilationUnit.class, List.class, "lombok$comments"); - setInCompiler(compiler, context, comments); + setInCompiler(compiler, context); compiler.keepComments = true; compiler.genEndPos = true; - return new CommentCatcher(compiler, comments); + return new CommentCatcher(compiler); } - private CommentCatcher(JavaCompiler compiler, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { + private CommentCatcher(JavaCompiler compiler) { this.compiler = compiler; - this.commentsField = commentsField; } public JavaCompiler getCompiler() { @@ -59,14 +57,14 @@ public class CommentCatcher { public void setComments(JCCompilationUnit ast, List<CommentInfo> comments) { if (comments != null) { - commentsField.set(ast, comments); + JCCompilationUnit_comments.set(ast, comments); } else { - commentsField.clear(ast); + JCCompilationUnit_comments.clear(ast); } } public List<CommentInfo> getComments(JCCompilationUnit ast) { - List<CommentInfo> list = commentsField.get(ast); + List<CommentInfo> list = JCCompilationUnit_comments.get(ast); return list == null ? Collections.<CommentInfo>emptyList() : list; } @@ -89,7 +87,7 @@ public class CommentCatcher { } } - private static void setInCompiler(JavaCompiler compiler, Context context, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { + private static void setInCompiler(JavaCompiler compiler, Context context) { try { Class<?> parserFactory; int javaCompilerVersion = Javac.getJavaCompilerVersion(); @@ -100,7 +98,7 @@ public class CommentCatcher { } else { parserFactory = Class.forName("lombok.javac.java8.CommentCollectingParserFactory"); } - parserFactory.getMethod("setInCompiler", JavaCompiler.class, Context.class, ReferenceFieldAugment.class).invoke(null, compiler, context, commentsField); + parserFactory.getMethod("setInCompiler", JavaCompiler.class, Context.class).invoke(null, compiler, context); } catch (InvocationTargetException e) { throw Javac.sneakyThrow(e.getCause()); } catch (Exception e) { diff --git a/src/utils/lombok/javac/java6/CommentCollectingParser.java b/src/utils/lombok/javac/java6/CommentCollectingParser.java index 215bf5b6..d5d3c256 100644 --- a/src/utils/lombok/javac/java6/CommentCollectingParser.java +++ b/src/utils/lombok/javac/java6/CommentCollectingParser.java @@ -21,7 +21,7 @@ */ package lombok.javac.java6; -import lombok.core.ReferenceFieldAugment; +import static lombok.javac.CommentCatcher.JCCompilationUnit_comments; import lombok.javac.CommentInfo; import com.sun.tools.javac.parser.EndPosParser; @@ -31,21 +31,18 @@ import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.util.List; class CommentCollectingParser extends EndPosParser { - - private final ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField; private final Lexer lexer; - protected CommentCollectingParser(Parser.Factory fac, Lexer S, boolean keepDocComments, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { + protected CommentCollectingParser(Parser.Factory fac, Lexer S, boolean keepDocComments) { super(fac, S, keepDocComments); lexer = S; - this.commentsField = commentsField; } @Override public JCCompilationUnit compilationUnit() { JCCompilationUnit result = super.compilationUnit(); if (lexer instanceof CommentCollectingScanner) { List<CommentInfo> comments = ((CommentCollectingScanner)lexer).getComments(); - commentsField.set(result, comments); + JCCompilationUnit_comments.set(result, comments); } return result; } diff --git a/src/utils/lombok/javac/java6/CommentCollectingParserFactory.java b/src/utils/lombok/javac/java6/CommentCollectingParserFactory.java index 124a05f7..0cf8fdcd 100644 --- a/src/utils/lombok/javac/java6/CommentCollectingParserFactory.java +++ b/src/utils/lombok/javac/java6/CommentCollectingParserFactory.java @@ -23,43 +23,35 @@ package lombok.javac.java6; import java.lang.reflect.Field; -import lombok.core.ReferenceFieldAugment; -import lombok.javac.CommentInfo; - import com.sun.tools.javac.main.JavaCompiler; import com.sun.tools.javac.parser.Lexer; import com.sun.tools.javac.parser.Parser; -import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.util.List; public class CommentCollectingParserFactory extends Parser.Factory { - private final ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField; - static Context.Key<Parser.Factory> key() { return parserFactoryKey; } - protected CommentCollectingParserFactory(Context context, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { + protected CommentCollectingParserFactory(Context context) { super(context); - this.commentsField = commentsField; } @Override public Parser newParser(Lexer S, boolean keepDocComments, boolean genEndPos) { - Object x = new CommentCollectingParser(this, S, true, commentsField); + Object x = new CommentCollectingParser(this, S, true); return (Parser) x; // CCP is based on a stub which extends nothing, but at runtime the stub is replaced with either //javac6's EndPosParser which extends Parser, or javac7's EndPosParser which implements Parser. //Either way this will work out. } - public static void setInCompiler(JavaCompiler compiler, Context context, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { + public static void setInCompiler(JavaCompiler compiler, Context context) { context.put(CommentCollectingParserFactory.key(), (Parser.Factory)null); Field field; try { field = JavaCompiler.class.getDeclaredField("parserFactory"); field.setAccessible(true); - field.set(compiler, new CommentCollectingParserFactory(context, commentsField)); + field.set(compiler, new CommentCollectingParserFactory(context)); } catch (Exception e) { throw new IllegalStateException("Could not set comment sensitive parser in the compiler", e); } diff --git a/src/utils/lombok/javac/java7/CommentCollectingParser.java b/src/utils/lombok/javac/java7/CommentCollectingParser.java index 27d731ba..de93e5b4 100644 --- a/src/utils/lombok/javac/java7/CommentCollectingParser.java +++ b/src/utils/lombok/javac/java7/CommentCollectingParser.java @@ -21,9 +21,10 @@ */ package lombok.javac.java7; +import static lombok.javac.CommentCatcher.JCCompilationUnit_comments; + import java.util.List; -import lombok.core.ReferenceFieldAugment; import lombok.javac.CommentInfo; import com.sun.tools.javac.parser.EndPosParser; @@ -32,21 +33,19 @@ import com.sun.tools.javac.parser.ParserFactory; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; class CommentCollectingParser extends EndPosParser { - private final ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField; private final Lexer lexer; protected CommentCollectingParser(ParserFactory fac, Lexer S, - boolean keepDocComments, boolean keepLineMap, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { + boolean keepDocComments, boolean keepLineMap) { super(fac, S, keepDocComments, keepLineMap); lexer = S; - this.commentsField = commentsField; } public JCCompilationUnit parseCompilationUnit() { JCCompilationUnit result = super.parseCompilationUnit(); if (lexer instanceof CommentCollectingScanner) { List<CommentInfo> comments = ((CommentCollectingScanner)lexer).getComments(); - commentsField.set(result, comments); + JCCompilationUnit_comments.set(result, comments); } return result; } diff --git a/src/utils/lombok/javac/java7/CommentCollectingParserFactory.java b/src/utils/lombok/javac/java7/CommentCollectingParserFactory.java index dba5a0fa..ffd68f55 100644 --- a/src/utils/lombok/javac/java7/CommentCollectingParserFactory.java +++ b/src/utils/lombok/javac/java7/CommentCollectingParserFactory.java @@ -22,50 +22,43 @@ package lombok.javac.java7; import java.lang.reflect.Field; -import java.util.List; - -import lombok.core.ReferenceFieldAugment; -import lombok.javac.CommentInfo; import com.sun.tools.javac.main.JavaCompiler; import com.sun.tools.javac.parser.Lexer; import com.sun.tools.javac.parser.Parser; import com.sun.tools.javac.parser.ParserFactory; import com.sun.tools.javac.parser.ScannerFactory; -import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.util.Context; public class CommentCollectingParserFactory extends ParserFactory { - private final ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField; private final Context context; static Context.Key<ParserFactory> key() { return parserFactoryKey; } - protected CommentCollectingParserFactory(Context context, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { + protected CommentCollectingParserFactory(Context context) { super(context); this.context = context; - this.commentsField = commentsField; } public Parser newParser(CharSequence input, boolean keepDocComments, boolean keepEndPos, boolean keepLineMap) { ScannerFactory scannerFactory = ScannerFactory.instance(context); Lexer lexer = scannerFactory.newScanner(input, true); - Object x = new CommentCollectingParser(this, lexer, true, keepLineMap, commentsField); + Object x = new CommentCollectingParser(this, lexer, true, keepLineMap); return (Parser) x; // CCP is based on a stub which extends nothing, but at runtime the stub is replaced with either //javac6's EndPosParser which extends Parser, or javac7's EndPosParser which implements Parser. //Either way this will work out. } - public static void setInCompiler(JavaCompiler compiler, Context context, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { + public static void setInCompiler(JavaCompiler compiler, Context context) { context.put(CommentCollectingParserFactory.key(), (ParserFactory)null); Field field; try { field = JavaCompiler.class.getDeclaredField("parserFactory"); field.setAccessible(true); - field.set(compiler, new CommentCollectingParserFactory(context, commentsField)); + field.set(compiler, new CommentCollectingParserFactory(context)); } catch (Exception e) { throw new IllegalStateException("Could not set comment sensitive parser in the compiler", e); } diff --git a/src/utils/lombok/javac/java8/CommentCollectingParser.java b/src/utils/lombok/javac/java8/CommentCollectingParser.java index 9a05267c..b49312cb 100644 --- a/src/utils/lombok/javac/java8/CommentCollectingParser.java +++ b/src/utils/lombok/javac/java8/CommentCollectingParser.java @@ -21,9 +21,10 @@ */ package lombok.javac.java8; +import static lombok.javac.CommentCatcher.JCCompilationUnit_comments; + import java.util.List; -import lombok.core.ReferenceFieldAugment; import lombok.javac.CommentInfo; import com.sun.tools.javac.parser.JavacParser; @@ -32,21 +33,19 @@ import com.sun.tools.javac.parser.ParserFactory; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; class CommentCollectingParser extends JavacParser { - private final ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField; private final Lexer lexer; protected CommentCollectingParser(ParserFactory fac, Lexer S, - boolean keepDocComments, boolean keepLineMap, boolean keepEndPositions, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { + boolean keepDocComments, boolean keepLineMap, boolean keepEndPositions) { super(fac, S, keepDocComments, keepLineMap, keepEndPositions); lexer = S; - this.commentsField = commentsField; } public JCCompilationUnit parseCompilationUnit() { JCCompilationUnit result = super.parseCompilationUnit(); if (lexer instanceof CommentCollectingScanner) { List<CommentInfo> comments = ((CommentCollectingScanner)lexer).getComments(); - commentsField.set(result, comments); + JCCompilationUnit_comments.set(result, comments); } return result; } diff --git a/src/utils/lombok/javac/java8/CommentCollectingParserFactory.java b/src/utils/lombok/javac/java8/CommentCollectingParserFactory.java index 5bed46fc..45f865ad 100644 --- a/src/utils/lombok/javac/java8/CommentCollectingParserFactory.java +++ b/src/utils/lombok/javac/java8/CommentCollectingParserFactory.java @@ -22,50 +22,43 @@ package lombok.javac.java8; import java.lang.reflect.Field; -import java.util.List; - -import lombok.core.ReferenceFieldAugment; -import lombok.javac.CommentInfo; import com.sun.tools.javac.main.JavaCompiler; import com.sun.tools.javac.parser.JavacParser; import com.sun.tools.javac.parser.Lexer; import com.sun.tools.javac.parser.ParserFactory; import com.sun.tools.javac.parser.ScannerFactory; -import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.util.Context; public class CommentCollectingParserFactory extends ParserFactory { - private final ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField; private final Context context; static Context.Key<ParserFactory> key() { return parserFactoryKey; } - protected CommentCollectingParserFactory(Context context, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { + protected CommentCollectingParserFactory(Context context) { super(context); this.context = context; - this.commentsField = commentsField; } public JavacParser newParser(CharSequence input, boolean keepDocComments, boolean keepEndPos, boolean keepLineMap) { ScannerFactory scannerFactory = ScannerFactory.instance(context); Lexer lexer = scannerFactory.newScanner(input, true); - Object x = new CommentCollectingParser(this, lexer, true, keepLineMap, keepEndPos, commentsField); + Object x = new CommentCollectingParser(this, lexer, true, keepLineMap, keepEndPos); return (JavacParser) x; // CCP is based on a stub which extends nothing, but at runtime the stub is replaced with either //javac6's EndPosParser which extends Parser, or javac8's JavacParser which implements Parser. //Either way this will work out. } - public static void setInCompiler(JavaCompiler compiler, Context context, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { - context.put(CommentCollectingParserFactory.key(), (ParserFactory)null); + public static void setInCompiler(JavaCompiler compiler, Context context) { + context.put(CommentCollectingParserFactory.key(), (ParserFactory) null); Field field; try { field = JavaCompiler.class.getDeclaredField("parserFactory"); field.setAccessible(true); - field.set(compiler, new CommentCollectingParserFactory(context, commentsField)); + field.set(compiler, new CommentCollectingParserFactory(context)); } catch (Exception e) { throw new IllegalStateException("Could not set comment sensitive parser in the compiler", e); } |