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;
}
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());
}
}
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);
}
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;
}
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());
}
}
Aggregations