mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 14:17:48 +00:00
Fixed issue 284 now also for java7, introduced more stubbing
This commit is contained in:
1 parent
70f778daa5
commit
a9f334fde9
13 files changed
+151
-10
No files matched your search
@@ -131,8 +131,12 @@ the common tasks and can be called on to run the main aspects of all the sub-scr
|
||||
anymore until you 'ant clean'. That's very much not desired, so we kill the processor, which stops lombok from running.
|
||||
We re-create the file at the end of this target. -->
|
||||
<delete file="build/lombok/META-INF/services/javax.annotation.processing.Processor" quiet="true" />
|
||||
<ivy:compile destdir="build/stubsstubs" source="1.5" target="1.5" includeantruntime="false">
|
||||
<src path="src/stubsstubs" />
|
||||
</ivy:compile>
|
||||
<ivy:compile destdir="build/stubs" source="1.5" target="1.5" includeantruntime="false">
|
||||
<src path="src/stubs" />
|
||||
<classpath location="build/stubsstubs" />
|
||||
</ivy:compile>
|
||||
|
||||
<ivy:compile destdir="build/lombok" source="1.5" target="1.5" includeantruntime="false">
|
||||
|
||||
@@ -358,8 +358,9 @@ public class Delombok {
|
||||
options.put("compilePolicy", "attr");
|
||||
|
||||
|
||||
registerCommentsCollectingScannerFactory(context);
|
||||
JavaCompiler compiler = new JavaCompiler(context);
|
||||
|
||||
|
||||
Map<JCCompilationUnit, com.sun.tools.javac.util.List<Comment>> commentsMap = new IdentityHashMap<JCCompilationUnit, com.sun.tools.javac.util.List<Comment>>();
|
||||
setInCompiler(compiler, context, commentsMap);
|
||||
|
||||
@@ -369,7 +370,6 @@ public class Delombok {
|
||||
List<JCCompilationUnit> roots = new ArrayList<JCCompilationUnit>();
|
||||
Map<JCCompilationUnit, File> baseMap = new IdentityHashMap<JCCompilationUnit, File>();
|
||||
|
||||
registerCommentsCollectingScannerFactory(context);
|
||||
|
||||
compiler.initProcessAnnotations(Collections.singleton(new lombok.javac.apt.Processor()));
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.sun.tools.javac.parser;
|
||||
|
||||
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
|
||||
|
||||
public class EndPosParser {
|
||||
public EndPosParser(Parser.Factory fac, Lexer S, boolean keepDocComments) {
|
||||
}
|
||||
|
||||
public EndPosParser(ParserFactory fac, Lexer S, boolean keepDocComments, boolean keepLineMap) {
|
||||
}
|
||||
|
||||
public JCCompilationUnit compilationUnit() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public JCCompilationUnit parseCompilationUnit() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.sun.tools.javac.parser;
|
||||
|
||||
public interface Lexer {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.sun.tools.javac.parser;
|
||||
|
||||
import com.sun.tools.javac.util.Context;
|
||||
|
||||
public class ParserFactory {
|
||||
public static Context.Key<ParserFactory> parserFactoryKey;
|
||||
|
||||
public ParserFactory(Context context) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import java.nio.CharBuffer;
|
||||
|
||||
import com.sun.tools.javac.util.Context;
|
||||
|
||||
public class Scanner {
|
||||
public class Scanner implements Lexer {
|
||||
protected Scanner(Factory fac, CharBuffer buffer) {
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,10 @@ public class ScannerFactory {
|
||||
protected ScannerFactory(Context c) {
|
||||
}
|
||||
|
||||
public static ScannerFactory instance(Context c) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Scanner newScanner(CharSequence input, boolean keepDocComments) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.sun.tools.javac.parser;
|
||||
|
||||
public class Parser {
|
||||
public static class Factory {}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.sun.tools.javac.tree;
|
||||
|
||||
public class JCTree {
|
||||
public static class JCCompilationUnit extends JCTree {}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import lombok.javac.Comment;
|
||||
|
||||
import com.sun.tools.javac.parser.EndPosParser;
|
||||
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.List;
|
||||
|
||||
@@ -13,12 +14,11 @@ class CommentCollectingParser extends EndPosParser {
|
||||
|
||||
private final Map<JCCompilationUnit, List<Comment>> commentsMap;
|
||||
private final Lexer lexer;
|
||||
|
||||
protected CommentCollectingParser(Factory fac, Lexer S, boolean keepDocComments, Map<JCCompilationUnit, List<Comment>> commentsMap) {
|
||||
|
||||
protected CommentCollectingParser(Parser.Factory fac, Lexer S, boolean keepDocComments, Map<JCCompilationUnit, List<Comment>> commentsMap) {
|
||||
super(fac, S, keepDocComments);
|
||||
lexer = S;
|
||||
this.commentsMap = commentsMap;
|
||||
|
||||
}
|
||||
|
||||
@Override public JCCompilationUnit compilationUnit() {
|
||||
|
||||
@@ -13,9 +13,8 @@ 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<Comment>> commentsMap;
|
||||
|
||||
|
||||
static Context.Key<Parser.Factory> key() {
|
||||
return parserFactoryKey;
|
||||
}
|
||||
@@ -26,7 +25,11 @@ public class CommentCollectingParserFactory extends Parser.Factory {
|
||||
}
|
||||
|
||||
@Override public Parser newParser(Lexer S, boolean keepDocComments, boolean genEndPos) {
|
||||
return new CommentCollectingParser(this, S, keepDocComments, commentsMap);
|
||||
Object x = new CommentCollectingParser(this, S, keepDocComments, commentsMap);
|
||||
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<Comment>> commentsMap) {
|
||||
@@ -38,6 +41,6 @@ public class CommentCollectingParserFactory extends Parser.Factory {
|
||||
field.set(compiler, new CommentCollectingParserFactory(context, commentsMap));
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Could not set comment sensitive parser in the compiler", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package lombok.javac.java7;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.javac.Comment;
|
||||
|
||||
import com.sun.tools.javac.parser.EndPosParser;
|
||||
import com.sun.tools.javac.parser.Lexer;
|
||||
import com.sun.tools.javac.parser.ParserFactory;
|
||||
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
|
||||
import com.sun.tools.javac.util.List;
|
||||
|
||||
class CommentCollectingParser extends EndPosParser {
|
||||
|
||||
private final Map<JCCompilationUnit, List<Comment>> commentsMap;
|
||||
private final Lexer lexer;
|
||||
|
||||
protected CommentCollectingParser(ParserFactory fac, Lexer S,
|
||||
boolean keepDocComments, boolean keepLineMap, Map<JCCompilationUnit, List<Comment>> commentsMap) {
|
||||
super(fac, S, keepDocComments, keepLineMap);
|
||||
lexer = S;
|
||||
this.commentsMap = commentsMap;
|
||||
}
|
||||
|
||||
public JCCompilationUnit parseCompilationUnit() {
|
||||
JCCompilationUnit result = super.parseCompilationUnit();
|
||||
if (lexer instanceof CommentCollectingScanner) {
|
||||
List<Comment> comments = ((CommentCollectingScanner)lexer).getComments();
|
||||
commentsMap.put(result, comments);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package lombok.javac.java7;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.javac.Comment;
|
||||
|
||||
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;
|
||||
import com.sun.tools.javac.util.List;
|
||||
|
||||
public class CommentCollectingParserFactory extends ParserFactory {
|
||||
private final Map<JCCompilationUnit, List<Comment>> commentsMap;
|
||||
private final Context context;
|
||||
|
||||
static Context.Key<ParserFactory> key() {
|
||||
return parserFactoryKey;
|
||||
}
|
||||
|
||||
protected CommentCollectingParserFactory(Context context, Map<JCCompilationUnit, List<Comment>> commentsMap) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
this.commentsMap = commentsMap;
|
||||
}
|
||||
|
||||
public Parser newParser(CharSequence input, boolean keepDocComments, boolean keepEndPos, boolean keepLineMap) {
|
||||
ScannerFactory scannerFactory = ScannerFactory.instance(context);
|
||||
Lexer lexer = scannerFactory.newScanner(input, keepDocComments);
|
||||
Object x = new CommentCollectingParser(this, lexer, keepDocComments, keepLineMap, commentsMap);
|
||||
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<Comment>> commentsMap) {
|
||||
context.put(CommentCollectingParserFactory.key(), (ParserFactory)null);
|
||||
Field field;
|
||||
try {
|
||||
field = JavaCompiler.class.getDeclaredField("parserFactory");
|
||||
field.setAccessible(true);
|
||||
field.set(compiler, new CommentCollectingParserFactory(context, commentsMap));
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("Could not set comment sensitive parser in the compiler", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user