Search in sources :

Example 1 with SyntaxErrorMessage

use of org.eclipse.xtext.nodemodel.SyntaxErrorMessage in project xtext-xtend by eclipse.

the class RichStringFormatter method _hasSyntaxError.

protected boolean _hasSyntaxError(final NodeEObjectRegion region) {
    final BidiTreeIterator<INode> i = region.getNode().getAsTreeIterable().iterator();
    while (i.hasNext()) {
        SyntaxErrorMessage _syntaxErrorMessage = i.next().getSyntaxErrorMessage();
        boolean _tripleNotEquals = (_syntaxErrorMessage != null);
        if (_tripleNotEquals) {
            return true;
        }
    }
    return false;
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) SyntaxErrorMessage(org.eclipse.xtext.nodemodel.SyntaxErrorMessage)

Example 2 with SyntaxErrorMessage

use of org.eclipse.xtext.nodemodel.SyntaxErrorMessage in project xtext-core by eclipse.

the class FormatterTestHelper method assertNoSyntaxErrors.

protected void assertNoSyntaxErrors(XtextResource resource) {
    Iterable<INode> syntaxErrors = resource.getParseResult().getSyntaxErrors();
    if (!Iterables.isEmpty(syntaxErrors)) {
        StringBuilder builder = new StringBuilder();
        builder.append("This document can't be formatted because of syntax errors:\n");
        for (INode node : syntaxErrors) {
            SyntaxErrorMessage msg = node.getSyntaxErrorMessage();
            builder.append(String.format("Line %02d: %s\n", node.getTotalStartLine(), msg.getMessage()));
        }
        fail(builder, resource.getParseResult().getRootNode().getText());
    }
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) SyntaxErrorMessage(org.eclipse.xtext.nodemodel.SyntaxErrorMessage)

Example 3 with SyntaxErrorMessage

use of org.eclipse.xtext.nodemodel.SyntaxErrorMessage in project xtext-core by eclipse.

the class SerializationUtilTest method testSyntaxErrorMessage.

@Test
public void testSyntaxErrorMessage() throws IOException {
    final String message = "hi";
    String[] issueCodes = { null, "issue" };
    String[][] issueDatas = { null, { null }, { "issue data" } };
    for (String[] issueData : issueDatas) {
        for (String issueCode : issueCodes) {
            SyntaxErrorMessage sem = new SyntaxErrorMessage(message, issueCode, issueData);
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            DataOutputStream dout = new DataOutputStream(out);
            SerializationUtil.writeSyntaxErrorMessage(dout, null, sem);
            dout.close();
            byte[] array = out.toByteArray();
            ByteArrayInputStream in = new ByteArrayInputStream(array);
            DataInputStream din = new DataInputStream(in);
            SyntaxErrorMessage sem2 = SerializationUtil.readSyntaxErrorMessage(din, null);
            assertEquals(sem, sem2);
        }
    }
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    DataOutputStream dout = new DataOutputStream(out);
    SerializationUtil.writeSyntaxErrorMessage(dout, null, null);
    dout.close();
    byte[] array = out.toByteArray();
    ByteArrayInputStream in = new ByteArrayInputStream(array);
    DataInputStream din = new DataInputStream(in);
    SyntaxErrorMessage readMessage = SerializationUtil.readSyntaxErrorMessage(din, null);
    assertNull(readMessage);
}
Also used : SyntaxErrorMessage(org.eclipse.xtext.nodemodel.SyntaxErrorMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Example 4 with SyntaxErrorMessage

use of org.eclipse.xtext.nodemodel.SyntaxErrorMessage in project xtext-core by eclipse.

the class SerializationUtil method readSyntaxErrorMessage.

public static SyntaxErrorMessage readSyntaxErrorMessage(DataInputStream in, DeserializationConversionContext context) throws IOException {
    boolean isNull = in.readBoolean();
    if (isNull)
        return null;
    String message = SerializationUtil.readString(in);
    String issueCode = SerializationUtil.readString(in);
    String[] issueData = SerializationUtil.readStringArray(in);
    SyntaxErrorMessage result = new SyntaxErrorMessage(message, issueCode, issueData);
    return result;
}
Also used : SyntaxErrorMessage(org.eclipse.xtext.nodemodel.SyntaxErrorMessage)

Example 5 with SyntaxErrorMessage

use of org.eclipse.xtext.nodemodel.SyntaxErrorMessage in project xtext-core by eclipse.

the class NodeModelUtils method compactDump.

private static void compactDump(INode node, boolean showHidden, String prefix, Appendable result) throws IOException {
    if (!showHidden && node instanceof ILeafNode && ((ILeafNode) node).isHidden())
        return;
    if (prefix.length() != 0) {
        result.append("\n");
        result.append(prefix);
    }
    if (node instanceof ICompositeNode) {
        if (node.getGrammarElement() != null)
            result.append(new GrammarElementTitleSwitch().showAssignments().doSwitch(node.getGrammarElement()));
        else
            result.append("(unknown)");
        String newPrefix = prefix + "  ";
        result.append(" {");
        BidiIterator<INode> children = ((ICompositeNode) node).getChildren().iterator();
        while (children.hasNext()) {
            INode child = children.next();
            compactDump(child, showHidden, newPrefix, result);
        }
        result.append("\n");
        result.append(prefix);
        result.append("}");
        SyntaxErrorMessage error = node.getSyntaxErrorMessage();
        if (error != null)
            result.append(" SyntaxError: [" + error.getIssueCode() + "] " + error.getMessage());
    } else if (node instanceof ILeafNode) {
        if (((ILeafNode) node).isHidden())
            result.append("hidden ");
        if (node.getGrammarElement() != null)
            result.append(new GrammarElementTitleSwitch().showAssignments().doSwitch(node.getGrammarElement()));
        else
            result.append("(unknown)");
        result.append(" => '");
        result.append(node.getText());
        result.append("'");
        SyntaxErrorMessage error = node.getSyntaxErrorMessage();
        if (error != null)
            result.append(" SyntaxError: [" + error.getIssueCode() + "] " + error.getMessage());
    } else if (node == null) {
        result.append("(null)");
    } else {
        result.append("unknown type ");
        result.append(node.getClass().getName());
    }
}
Also used : GrammarElementTitleSwitch(org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch) INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) SyntaxErrorMessage(org.eclipse.xtext.nodemodel.SyntaxErrorMessage) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode)

Aggregations

SyntaxErrorMessage (org.eclipse.xtext.nodemodel.SyntaxErrorMessage)7 INode (org.eclipse.xtext.nodemodel.INode)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 CommonToken (org.antlr.runtime.CommonToken)1 GrammarElementTitleSwitch (org.eclipse.xtext.grammaranalysis.impl.GrammarElementTitleSwitch)1 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)1 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)1 Test (org.junit.Test)1