diff options
Diffstat (limited to 'src/main/java/org/javacs/Warning.java')
-rw-r--r-- | src/main/java/org/javacs/Warning.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/main/java/org/javacs/Warning.java b/src/main/java/org/javacs/Warning.java new file mode 100644 index 0000000..a173d40 --- /dev/null +++ b/src/main/java/org/javacs/Warning.java @@ -0,0 +1,70 @@ +package org.javacs; + +import com.sun.source.tree.LineMap; +import com.sun.source.util.*; +import java.util.Locale; +import javax.tools.*; +import javax.tools.JavaFileObject; + +class Warning implements Diagnostic<JavaFileObject> { + + private final JavaFileObject source; + private final LineMap lines; + private final long start, end; + private final String code, message; + + Warning(JavacTask task, TreePath path, String code, String message) { + this.source = path.getCompilationUnit().getSourceFile(); + this.lines = path.getCompilationUnit().getLineMap(); + var pos = Trees.instance(task).getSourcePositions(); + this.start = pos.getStartPosition(path.getCompilationUnit(), path.getLeaf()); + this.end = pos.getEndPosition(path.getCompilationUnit(), path.getLeaf()); + this.code = code; + this.message = message; + } + + @Override + public Kind getKind() { + return Kind.WARNING; + } + + @Override + public JavaFileObject getSource() { + return source; + } + + @Override + public long getPosition() { + return start; + } + + @Override + public long getStartPosition() { + return start; + } + + @Override + public long getEndPosition() { + return end; + } + + @Override + public long getLineNumber() { + return lines.getLineNumber(start); + } + + @Override + public long getColumnNumber() { + return lines.getColumnNumber(start); + } + + @Override + public String getCode() { + return code; + } + + @Override + public String getMessage(Locale locale) { + return message; + } +} |