use of com.sun.tools.javac.util.DiagnosticSource in project ceylon-compiler by ceylon.
the class CeylonLog method report.
@Override
public void report(JCDiagnostic diagnostic) {
String messageKey = diagnostic.getCode();
if (messageKey != null) {
if (messageKey.startsWith("compiler.err.ceylon.codegen.exception")) {
numCeylonCodegenException++;
} else if (messageKey.startsWith("compiler.err.ceylon.codegen.erroneous")) {
numCeylonCodegenErroneous++;
} else if (messageKey.startsWith("compiler.err.ceylon")) {
numCeylonAnalysisErrors++;
} else if (sourceLanguage.isCeylon()) {
numCeylonCodegenGarbage++;
} else {
numNonCeylonErrors++;
}
} else if (sourceLanguage.isCeylon()) {
numCeylonCodegenGarbage++;
} else {
numNonCeylonErrors++;
}
DiagnosticSource source = diagnostic.getDiagnosticSource();
if (source != null) {
JavaFileObject file = source.getFile();
if (file instanceof CeylonFileObject && diagnostic.getType() == DiagnosticType.ERROR) {
((CeylonFileObject) file).addError(diagnostic);
}
}
super.report(diagnostic);
}
use of com.sun.tools.javac.util.DiagnosticSource in project error-prone by google.
the class ErrorProneError method formatMessage.
private static String formatMessage(String checkName, JavaFileObject file, DiagnosticPosition pos, Throwable cause) {
DiagnosticSource source = new DiagnosticSource(file, /*log=*/
null);
int column = source.getColumnNumber(pos.getStartPosition(), /*expandTabs=*/
true);
int line = source.getLineNumber(pos.getStartPosition());
String snippet = source.getLine(pos.getStartPosition());
StringBuilder sb = new StringBuilder();
sb.append(String.format("\n%s:%d: %s: An exception was thrown by Error Prone: %s\n", source.getFile().getName(), line, checkName, cause.getMessage()));
sb.append(snippet).append('\n');
if (column > 0) {
sb.append(Strings.repeat(" ", column - 1));
}
sb.append("^\n");
return sb.toString();
}
use of com.sun.tools.javac.util.DiagnosticSource in project ceylon-compiler by ceylon.
the class StatementTransformer method getSourceCode.
/**
* Gets the source code corresponding to the given node
*/
private String getSourceCode(Node node) {
StringBuilder sb = new StringBuilder();
DiagnosticSource source = new DiagnosticSource(gen().getFileObject(), Log.instance(gen().getContext()));
int startLine = node.getToken().getLine();
int endLine = node.getEndToken().getLine();
for (int lineNumber = startLine; lineNumber <= endLine; lineNumber++) {
int startPos = gen().getMap().getPosition(lineNumber, 1);
String line = source.getLine(startPos);
if (lineNumber == endLine) {
line = line.substring(0, node.getEndToken().getCharPositionInLine() + node.getEndToken().getText().length());
}
if (lineNumber == startLine) {
line = line.substring(node.getToken().getCharPositionInLine());
}
sb.append(line).append("\n");
}
return sb.substring(0, sb.length() - 1);
}
Aggregations