mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-16 06:14:36 +00:00
Added support for setting up an alternative diagnostics listener
This commit is contained in:
1 parent
b6d468144d
commit
58f5f68f05
2 files changed
+16
-1
No files matched your search
@@ -30,6 +30,7 @@ import javax.annotation.processing.Messager;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.AnnotationValue;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.tools.DiagnosticListener;
|
||||
import javax.tools.JavaFileObject;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
|
||||
@@ -46,6 +47,7 @@ import com.sun.tools.javac.util.Options;
|
||||
public class CommentPreservingParser {
|
||||
private final String encoding;
|
||||
private boolean deleteLombokAnnotations = false;
|
||||
private DiagnosticListener<JavaFileObject> diagnostics = null;
|
||||
|
||||
public CommentPreservingParser() {
|
||||
this("utf-8");
|
||||
@@ -56,7 +58,11 @@ public class CommentPreservingParser {
|
||||
}
|
||||
|
||||
public void setDeleteLombokAnnotations(boolean deleteLombokAnnotations) {
|
||||
this.deleteLombokAnnotations = deleteLombokAnnotations;
|
||||
this.deleteLombokAnnotations = deleteLombokAnnotations;
|
||||
}
|
||||
|
||||
public void setDiagnosticsListener(DiagnosticListener<JavaFileObject> diagnostics) {
|
||||
this.diagnostics = diagnostics;
|
||||
}
|
||||
|
||||
public ParseResult parse(JavaFileObject source, boolean forceProcessing) throws IOException {
|
||||
@@ -72,6 +78,8 @@ public class CommentPreservingParser {
|
||||
|
||||
Options.instance(context).put(OptionName.ENCODING, encoding);
|
||||
|
||||
if (diagnostics != null) context.put(DiagnosticListener.class, diagnostics);
|
||||
|
||||
CommentCollectingScanner.Factory.preRegister(context);
|
||||
|
||||
JavaCompiler compiler = new JavaCompiler(context) {
|
||||
@@ -80,6 +88,7 @@ public class CommentPreservingParser {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
compiler.genEndPos = true;
|
||||
|
||||
Comments comments = new Comments();
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.nio.charset.UnsupportedCharsetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.tools.DiagnosticListener;
|
||||
import javax.tools.JavaFileObject;
|
||||
|
||||
import lombok.delombok.CommentPreservingParser.ParseResult;
|
||||
@@ -170,6 +171,11 @@ public class Delombok {
|
||||
charset = Charset.forName(charsetName);
|
||||
}
|
||||
|
||||
|
||||
public void setDiagnosticsListener(DiagnosticListener<JavaFileObject> diagnostics) {
|
||||
parser.setDiagnosticsListener(diagnostics);
|
||||
}
|
||||
|
||||
public void setForceProcess(boolean force) {
|
||||
this.force = force;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user