Search in sources :

Example 1 with DiagnosticSource

use of org.eclipse.ceylon.langtools.tools.javac.util.DiagnosticSource in project ceylon by eclipse.

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);
}
Also used : JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) DiagnosticSource(org.eclipse.ceylon.langtools.tools.javac.util.DiagnosticSource) CeylonFileObject(org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject)

Example 2 with DiagnosticSource

use of org.eclipse.ceylon.langtools.tools.javac.util.DiagnosticSource in project ceylon by eclipse.

the class AssertionBuilder 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.gen().getFileObject(), Log.instance(gen.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);
}
Also used : DiagnosticSource(org.eclipse.ceylon.langtools.tools.javac.util.DiagnosticSource)

Aggregations

DiagnosticSource (org.eclipse.ceylon.langtools.tools.javac.util.DiagnosticSource)2 CeylonFileObject (org.eclipse.ceylon.compiler.java.codegen.CeylonFileObject)1 JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)1