Search in sources :

Example 1 with UsageWarning

use of org.eclipse.ceylon.compiler.typechecker.analyzer.UsageWarning in project ceylon by eclipse.

the class PrintVisitor method print.

private void print(Node node) {
    print(node.getText());
    print(" [" + node.getNodeType() + "]");
    if (node.getToken() != null) {
        print(" (" + node.getLocation() + ")");
    }
    if (node instanceof Tree.Term) {
        Type type = ((Tree.Term) node).getTypeModel();
        if (type != null) {
            print(" : " + type.asString() + "");
        }
    }
    if (node instanceof Tree.ComprehensionClause) {
        Type type = ((Tree.ComprehensionClause) node).getTypeModel();
        if (type != null) {
            print(" : " + type.asString() + "");
        }
    }
    if (node instanceof Tree.Type) {
        Type type = ((Tree.Type) node).getTypeModel();
        if (type != null) {
            print(" : " + type.asString() + "");
        }
    }
    if (node instanceof Tree.TypeArguments) {
        List<Type> types = ((Tree.TypeArguments) node).getTypeModels();
        if (types != null && !types.isEmpty()) {
            print(" : <");
            int i = 0;
            for (Type pt : types) {
                if (pt != null) {
                    print(pt.asString());
                }
                if (++i != types.size()) {
                    print(", ");
                }
            }
            print(">");
        }
    }
    if (node instanceof Tree.MemberOrTypeExpression) {
        Reference t = ((Tree.MemberOrTypeExpression) node).getTarget();
        Declaration d = ((Tree.MemberOrTypeExpression) node).getDeclaration();
        if (t != null) {
            print(" : " + t.asString() + "");
        }
        if (d != null) {
            print(" : " + d);
        }
    }
    if (node instanceof Tree.Outer) {
        Declaration d = ((Tree.Outer) node).getDeclarationModel();
        if (d != null) {
            print(" : " + d);
        }
    }
    if (node instanceof Tree.SelfExpression) {
        Declaration d = ((Tree.SelfExpression) node).getDeclarationModel();
        if (d != null) {
            print(" : " + d);
        }
    }
    if (node instanceof Tree.Declaration) {
        Declaration d = ((Tree.Declaration) node).getDeclarationModel();
        if (d != null) {
            if (d.isCaptured() || d.isJsCaptured()) {
                print("[captured]");
            }
            print(" : " + d);
            Declaration rd = d.getRefinedDeclaration();
            if (rd != null && !rd.equals(d)) {
                Declaration container = (Declaration) rd.getContainer();
                print(" (refines " + container.getName() + "." + rd.getName() + ")");
            }
        }
    }
    if (node instanceof Tree.SpecifierStatement) {
        Declaration d = ((Tree.SpecifierStatement) node).getDeclaration();
        if (d != null) {
            print(" : " + d);
        }
        if (((Tree.SpecifierStatement) node).getRefinement()) {
            Declaration rd = d.getRefinedDeclaration();
            if (rd != null && !rd.equals(d)) {
                Declaration container = (Declaration) rd.getContainer();
                print(" (refines " + container.getName() + "." + rd.getName() + ")");
            }
        }
    }
    if (node instanceof Tree.SimpleType) {
        Declaration d = ((Tree.SimpleType) node).getDeclarationModel();
        if (d != null) {
            print(" : " + d);
        }
    }
    if (node instanceof Tree.ImportMemberOrType) {
        Declaration d = ((Tree.ImportMemberOrType) node).getDeclarationModel();
        if (d != null) {
            print(" : " + d);
        }
    }
    if (node instanceof Tree.Return) {
        Declaration d = ((Tree.Return) node).getDeclaration();
        if (d != null) {
            print(" : " + d);
        }
    }
    if (node instanceof Tree.PositionalArgument) {
        Parameter p = ((Tree.PositionalArgument) node).getParameter();
        if (p != null) {
            print(" : " + p);
        }
    }
    if (node instanceof Tree.NamedArgument) {
        Parameter p = ((Tree.NamedArgument) node).getParameter();
        if (p != null) {
            print(" : " + p);
        }
    }
    if (node instanceof Tree.SequencedArgument) {
        Parameter p = ((Tree.SequencedArgument) node).getParameter();
        if (p != null) {
            print(" : " + p);
        }
    }
    if (!node.getErrors().isEmpty()) {
        String icon = " [!]";
        for (Message e : node.getErrors()) {
            if (!(e instanceof UsageWarning)) {
                icon = " [X]";
            }
        }
        print(icon + node.getErrors());
    }
}
Also used : Message(org.eclipse.ceylon.compiler.typechecker.tree.Message) Reference(org.eclipse.ceylon.model.typechecker.model.Reference) Type(org.eclipse.ceylon.model.typechecker.model.Type) UsageWarning(org.eclipse.ceylon.compiler.typechecker.analyzer.UsageWarning) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 2 with UsageWarning

use of org.eclipse.ceylon.compiler.typechecker.analyzer.UsageWarning in project ceylon by eclipse.

the class ErrorCollectingVisitor method printErrors.

public int printErrors(Writer out, DiagnosticListener diagnosticListener, boolean printWarnings, boolean printCount) throws IOException {
    int warnings = 0;
    int count = 0;
    List<PositionedMessage> errors = (!recogErrors.isEmpty()) ? recogErrors : analErrors;
    for (PositionedMessage pm : errors) {
        Message err = pm.message;
        if (err instanceof UsageWarning) {
            if (!printWarnings || ((UsageWarning) err).isSuppressed()) {
                continue;
            }
        }
        Node node = TreeUtil.getIdentifyingNode(pm.node);
        int line = err.getLine();
        int position = -1;
        if (err instanceof AnalysisMessage) {
            if (node != null && node.getToken() != null)
                position = node.getToken().getCharPositionInLine();
        } else if (err instanceof RecognitionError) {
            position = ((RecognitionError) err).getCharacterInLine();
        }
        String fileName = (node.getUnit() != null) ? node.getUnit().getFullPath() : "unknown";
        out.write(OSUtil.color(fileName, OSUtil.Color.blue));
        out.write(":");
        out.write(String.format("%d", line));
        out.write(": ");
        if (err instanceof UsageWarning) {
            out.write(OSUtil.color("warning", OSUtil.Color.yellow));
            warnings++;
        } else {
            out.write(OSUtil.color("error", OSUtil.Color.red));
            count++;
        }
        out.write(": ");
        out.write(err.getMessage());
        out.write(System.lineSeparator());
        String ln = getErrorSourceLine(pm);
        if (ln != null) {
            out.write(ln);
            out.write(System.lineSeparator());
            out.write(getErrorMarkerLine(position));
            out.write(System.lineSeparator());
        }
        if (diagnosticListener != null) {
            File file = null;
            boolean warning = err instanceof UsageWarning;
            if (node.getUnit() != null && node.getUnit().getFullPath() != null)
                file = new File(node.getUnit().getFullPath()).getAbsoluteFile();
            if (position != -1)
                // make it 1-based
                position++;
            if (warning)
                diagnosticListener.warning(file, line, position, err.getMessage());
            else
                diagnosticListener.error(file, line, position, err.getMessage());
        }
    }
    if (printCount) {
        if (count > 0)
            out.write(String.format("%d %s%n", count, count == 1 ? "error" : "errors"));
        if (warnings > 0)
            out.write(String.format("%d %s%n", warnings, warnings == 1 ? "warning" : "warnings"));
    }
    out.flush();
    return count;
}
Also used : UsageWarning(org.eclipse.ceylon.compiler.typechecker.analyzer.UsageWarning) AnalysisMessage(org.eclipse.ceylon.compiler.typechecker.tree.AnalysisMessage) Message(org.eclipse.ceylon.compiler.typechecker.tree.Message) RecognitionError(org.eclipse.ceylon.compiler.typechecker.parser.RecognitionError) Node(org.eclipse.ceylon.compiler.typechecker.tree.Node) AnalysisMessage(org.eclipse.ceylon.compiler.typechecker.tree.AnalysisMessage) VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) File(java.io.File)

Example 3 with UsageWarning

use of org.eclipse.ceylon.compiler.typechecker.analyzer.UsageWarning in project ceylon by eclipse.

the class WarningSuppressionVisitor method visitAny.

public void visitAny(Node that) {
    Iterator<Message> errorIter = that.getErrors().iterator();
    while (errorIter.hasNext()) {
        Message error = errorIter.next();
        if (error instanceof UsageWarning) {
            UsageWarning warning = (UsageWarning) error;
            E warningName = parseName(warning.getWarningName());
            if (warningName == null) {
                continue;
            }
            Integer numSuppressed = counts.get(warningName);
            if (suppressed.get(warningName) != null) {
                warning.setSuppressed(true);
                counts.put(warningName, numSuppressed.intValue() + 1);
            }
        }
    }
    super.visitAny(that);
}
Also used : UsageWarning(org.eclipse.ceylon.compiler.typechecker.analyzer.UsageWarning) Message(org.eclipse.ceylon.compiler.typechecker.tree.Message)

Aggregations

UsageWarning (org.eclipse.ceylon.compiler.typechecker.analyzer.UsageWarning)3 Message (org.eclipse.ceylon.compiler.typechecker.tree.Message)3 File (java.io.File)1 VirtualFile (org.eclipse.ceylon.compiler.typechecker.io.VirtualFile)1 RecognitionError (org.eclipse.ceylon.compiler.typechecker.parser.RecognitionError)1 AnalysisMessage (org.eclipse.ceylon.compiler.typechecker.tree.AnalysisMessage)1 Node (org.eclipse.ceylon.compiler.typechecker.tree.Node)1 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)1 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)1 Reference (org.eclipse.ceylon.model.typechecker.model.Reference)1 Type (org.eclipse.ceylon.model.typechecker.model.Type)1