diff options
Diffstat (limited to 'src/utils/lombok/javac')
7 files changed, 56 insertions, 57 deletions
diff --git a/src/utils/lombok/javac/CommentCatcher.java b/src/utils/lombok/javac/CommentCatcher.java index 36d90e30..ff6be7a2 100644 --- a/src/utils/lombok/javac/CommentCatcher.java +++ b/src/utils/lombok/javac/CommentCatcher.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2013 The Project Lombok Authors. + * Copyright (C) 2011-2014 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,8 +24,8 @@ package lombok.javac; import java.lang.reflect.InvocationTargetException; import java.util.Collections; import java.util.List; -import java.util.Map; -import java.util.WeakHashMap; + +import lombok.core.ReferenceFieldAugment; import com.sun.tools.javac.main.JavaCompiler; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; @@ -33,24 +33,24 @@ import com.sun.tools.javac.util.Context; public class CommentCatcher { private final JavaCompiler compiler; - private final Map<JCCompilationUnit, List<CommentInfo>> commentsMap; + private final ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField; public static CommentCatcher create(Context context) { registerCommentsCollectingScannerFactory(context); JavaCompiler compiler = new JavaCompiler(context); - Map<JCCompilationUnit, List<CommentInfo>> commentsMap = new WeakHashMap<JCCompilationUnit, List<CommentInfo>>(); - setInCompiler(compiler, context, commentsMap); + ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> comments = ReferenceFieldAugment.augment(JCCompilationUnit.class, List.class, "lombok$comments"); + setInCompiler(compiler, context, comments); compiler.keepComments = true; compiler.genEndPos = true; - return new CommentCatcher(compiler, commentsMap); + return new CommentCatcher(compiler, comments); } - private CommentCatcher(JavaCompiler compiler, Map<JCCompilationUnit, List<CommentInfo>> commentsMap) { + private CommentCatcher(JavaCompiler compiler, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { this.compiler = compiler; - this.commentsMap = commentsMap; + this.commentsField = commentsField; } public JavaCompiler getCompiler() { @@ -59,14 +59,14 @@ public class CommentCatcher { public void setComments(JCCompilationUnit ast, List<CommentInfo> comments) { if (comments != null) { - commentsMap.put(ast, comments); + commentsField.set(ast, comments); } else { - commentsMap.remove(ast); + commentsField.clear(ast); } } public List<CommentInfo> getComments(JCCompilationUnit ast) { - List<CommentInfo> list = commentsMap.get(ast); + List<CommentInfo> list = commentsField.get(ast); return list == null ? Collections.<CommentInfo>emptyList() : list; } @@ -89,7 +89,7 @@ public class CommentCatcher { } } - private static void setInCompiler(JavaCompiler compiler, Context context, Map<JCCompilationUnit, List<CommentInfo>> commentsMap) { + private static void setInCompiler(JavaCompiler compiler, Context context, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { try { Class<?> parserFactory; int javaCompilerVersion = Javac.getJavaCompilerVersion(); @@ -100,7 +100,7 @@ public class CommentCatcher { } else { parserFactory = Class.forName("lombok.javac.java8.CommentCollectingParserFactory"); } - parserFactory.getMethod("setInCompiler", JavaCompiler.class, Context.class, Map.class).invoke(null, compiler, context, commentsMap); + parserFactory.getMethod("setInCompiler", JavaCompiler.class, Context.class, ReferenceFieldAugment.class).invoke(null, compiler, context, commentsField); } 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 30192b06..215bf5b6 100644 --- a/src/utils/lombok/javac/java6/CommentCollectingParser.java +++ b/src/utils/lombok/javac/java6/CommentCollectingParser.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Project Lombok Authors. + * Copyright (C) 2013-2014 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -21,8 +21,7 @@ */ package lombok.javac.java6; -import java.util.Map; - +import lombok.core.ReferenceFieldAugment; import lombok.javac.CommentInfo; import com.sun.tools.javac.parser.EndPosParser; @@ -33,20 +32,20 @@ import com.sun.tools.javac.util.List; class CommentCollectingParser extends EndPosParser { - private final Map<JCCompilationUnit, List<CommentInfo>> commentsMap; + private final ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField; private final Lexer lexer; - protected CommentCollectingParser(Parser.Factory fac, Lexer S, boolean keepDocComments, Map<JCCompilationUnit, List<CommentInfo>> commentsMap) { + protected CommentCollectingParser(Parser.Factory fac, Lexer S, boolean keepDocComments, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { super(fac, S, keepDocComments); lexer = S; - this.commentsMap = commentsMap; + this.commentsField = commentsField; } @Override public JCCompilationUnit compilationUnit() { JCCompilationUnit result = super.compilationUnit(); if (lexer instanceof CommentCollectingScanner) { List<CommentInfo> comments = ((CommentCollectingScanner)lexer).getComments(); - commentsMap.put(result, comments); + commentsField.set(result, comments); } return result; } diff --git a/src/utils/lombok/javac/java6/CommentCollectingParserFactory.java b/src/utils/lombok/javac/java6/CommentCollectingParserFactory.java index b250b898..124a05f7 100644 --- a/src/utils/lombok/javac/java6/CommentCollectingParserFactory.java +++ b/src/utils/lombok/javac/java6/CommentCollectingParserFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Project Lombok Authors. + * Copyright (C) 2013-2014 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -22,8 +22,8 @@ package lombok.javac.java6; import java.lang.reflect.Field; -import java.util.Map; +import lombok.core.ReferenceFieldAugment; import lombok.javac.CommentInfo; import com.sun.tools.javac.main.JavaCompiler; @@ -34,32 +34,32 @@ import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.List; public class CommentCollectingParserFactory extends Parser.Factory { - private final Map<JCCompilationUnit, List<CommentInfo>> commentsMap; + private final ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField; static Context.Key<Parser.Factory> key() { return parserFactoryKey; } - protected CommentCollectingParserFactory(Context context, Map<JCCompilationUnit, List<CommentInfo>> commentsMap) { + protected CommentCollectingParserFactory(Context context, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { super(context); - this.commentsMap = commentsMap; + this.commentsField = commentsField; } @Override public Parser newParser(Lexer S, boolean keepDocComments, boolean genEndPos) { - Object x = new CommentCollectingParser(this, S, true, commentsMap); + Object x = new CommentCollectingParser(this, S, true, commentsField); 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, Map<JCCompilationUnit, List<CommentInfo>> commentsMap) { + public static void setInCompiler(JavaCompiler compiler, Context context, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { context.put(CommentCollectingParserFactory.key(), (Parser.Factory)null); Field field; try { field = JavaCompiler.class.getDeclaredField("parserFactory"); field.setAccessible(true); - field.set(compiler, new CommentCollectingParserFactory(context, commentsMap)); + field.set(compiler, new CommentCollectingParserFactory(context, commentsField)); } 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 0e8a4ef6..27d731ba 100644 --- a/src/utils/lombok/javac/java7/CommentCollectingParser.java +++ b/src/utils/lombok/javac/java7/CommentCollectingParser.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Project Lombok Authors. + * Copyright (C) 2013-2014 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -22,8 +22,8 @@ package lombok.javac.java7; import java.util.List; -import java.util.Map; +import lombok.core.ReferenceFieldAugment; import lombok.javac.CommentInfo; import com.sun.tools.javac.parser.EndPosParser; @@ -32,21 +32,21 @@ import com.sun.tools.javac.parser.ParserFactory; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; class CommentCollectingParser extends EndPosParser { - private final Map<JCCompilationUnit, List<CommentInfo>> commentsMap; + private final ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField; private final Lexer lexer; protected CommentCollectingParser(ParserFactory fac, Lexer S, - boolean keepDocComments, boolean keepLineMap, Map<JCCompilationUnit, List<CommentInfo>> commentsMap) { + boolean keepDocComments, boolean keepLineMap, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { super(fac, S, keepDocComments, keepLineMap); lexer = S; - this.commentsMap = commentsMap; + this.commentsField = commentsField; } public JCCompilationUnit parseCompilationUnit() { JCCompilationUnit result = super.parseCompilationUnit(); if (lexer instanceof CommentCollectingScanner) { List<CommentInfo> comments = ((CommentCollectingScanner)lexer).getComments(); - commentsMap.put(result, comments); + commentsField.set(result, comments); } return result; } diff --git a/src/utils/lombok/javac/java7/CommentCollectingParserFactory.java b/src/utils/lombok/javac/java7/CommentCollectingParserFactory.java index ed8279df..dba5a0fa 100644 --- a/src/utils/lombok/javac/java7/CommentCollectingParserFactory.java +++ b/src/utils/lombok/javac/java7/CommentCollectingParserFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Project Lombok Authors. + * Copyright (C) 2013-2014 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,8 +23,8 @@ package lombok.javac.java7; import java.lang.reflect.Field; import java.util.List; -import java.util.Map; +import lombok.core.ReferenceFieldAugment; import lombok.javac.CommentInfo; import com.sun.tools.javac.main.JavaCompiler; @@ -36,36 +36,36 @@ import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.util.Context; public class CommentCollectingParserFactory extends ParserFactory { - private final Map<JCCompilationUnit, List<CommentInfo>> commentsMap; + private final ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField; private final Context context; static Context.Key<ParserFactory> key() { return parserFactoryKey; } - protected CommentCollectingParserFactory(Context context, Map<JCCompilationUnit, List<CommentInfo>> commentsMap) { + protected CommentCollectingParserFactory(Context context, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { super(context); this.context = context; - this.commentsMap = commentsMap; + 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, commentsMap); + Object x = new CommentCollectingParser(this, lexer, true, keepLineMap, commentsField); 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, Map<JCCompilationUnit, List<CommentInfo>> commentsMap) { + public static void setInCompiler(JavaCompiler compiler, Context context, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { context.put(CommentCollectingParserFactory.key(), (ParserFactory)null); Field field; try { field = JavaCompiler.class.getDeclaredField("parserFactory"); field.setAccessible(true); - field.set(compiler, new CommentCollectingParserFactory(context, commentsMap)); + field.set(compiler, new CommentCollectingParserFactory(context, commentsField)); } 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 e305e44f..9a05267c 100644 --- a/src/utils/lombok/javac/java8/CommentCollectingParser.java +++ b/src/utils/lombok/javac/java8/CommentCollectingParser.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Project Lombok Authors. + * Copyright (C) 2013-2014 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -22,8 +22,8 @@ package lombok.javac.java8; import java.util.List; -import java.util.Map; +import lombok.core.ReferenceFieldAugment; import lombok.javac.CommentInfo; import com.sun.tools.javac.parser.JavacParser; @@ -32,21 +32,21 @@ import com.sun.tools.javac.parser.ParserFactory; import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; class CommentCollectingParser extends JavacParser { - private final Map<JCCompilationUnit, List<CommentInfo>> commentsMap; + private final ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField; private final Lexer lexer; protected CommentCollectingParser(ParserFactory fac, Lexer S, - boolean keepDocComments, boolean keepLineMap, boolean keepEndPositions, Map<JCCompilationUnit, List<CommentInfo>> commentsMap) { + boolean keepDocComments, boolean keepLineMap, boolean keepEndPositions, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { super(fac, S, keepDocComments, keepLineMap, keepEndPositions); lexer = S; - this.commentsMap = commentsMap; + this.commentsField = commentsField; } public JCCompilationUnit parseCompilationUnit() { JCCompilationUnit result = super.parseCompilationUnit(); if (lexer instanceof CommentCollectingScanner) { List<CommentInfo> comments = ((CommentCollectingScanner)lexer).getComments(); - commentsMap.put(result, comments); + commentsField.set(result, comments); } return result; } diff --git a/src/utils/lombok/javac/java8/CommentCollectingParserFactory.java b/src/utils/lombok/javac/java8/CommentCollectingParserFactory.java index 6b5f9198..5bed46fc 100644 --- a/src/utils/lombok/javac/java8/CommentCollectingParserFactory.java +++ b/src/utils/lombok/javac/java8/CommentCollectingParserFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013 The Project Lombok Authors. + * Copyright (C) 2013-2014 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -23,8 +23,8 @@ package lombok.javac.java8; import java.lang.reflect.Field; import java.util.List; -import java.util.Map; +import lombok.core.ReferenceFieldAugment; import lombok.javac.CommentInfo; import com.sun.tools.javac.main.JavaCompiler; @@ -36,36 +36,36 @@ import com.sun.tools.javac.tree.JCTree.JCCompilationUnit; import com.sun.tools.javac.util.Context; public class CommentCollectingParserFactory extends ParserFactory { - private final Map<JCCompilationUnit, List<CommentInfo>> commentsMap; + private final ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField; private final Context context; static Context.Key<ParserFactory> key() { return parserFactoryKey; } - protected CommentCollectingParserFactory(Context context, Map<JCCompilationUnit, List<CommentInfo>> commentsMap) { + protected CommentCollectingParserFactory(Context context, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { super(context); this.context = context; - this.commentsMap = commentsMap; + 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, commentsMap); + Object x = new CommentCollectingParser(this, lexer, true, keepLineMap, keepEndPos, commentsField); 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, Map<JCCompilationUnit, List<CommentInfo>> commentsMap) { + public static void setInCompiler(JavaCompiler compiler, Context context, ReferenceFieldAugment<JCCompilationUnit, List<CommentInfo>> commentsField) { context.put(CommentCollectingParserFactory.key(), (ParserFactory)null); Field field; try { field = JavaCompiler.class.getDeclaredField("parserFactory"); field.setAccessible(true); - field.set(compiler, new CommentCollectingParserFactory(context, commentsMap)); + field.set(compiler, new CommentCollectingParserFactory(context, commentsField)); } catch (Exception e) { throw new IllegalStateException("Could not set comment sensitive parser in the compiler", e); } |