Java Code Examples for org.eclipse.xtext.nodemodel.INode#getSyntaxErrorMessage()

The following examples show how to use org.eclipse.xtext.nodemodel.INode#getSyntaxErrorMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PartialParsingHelper.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean isInvalidLastChildNode(ICompositeNode candidate, INode lastChild) {
	if (lastChild != null && lastChild.getSyntaxErrorMessage() != null) {
		EObject lastChildGrammarElement = lastChild.getGrammarElement();
		if (lastChildGrammarElement == null)
			return true;
		AbstractElement candidateElement = getCandidateElement(candidate.getGrammarElement());
		if (candidateElement != null) {
			if (isCalledBy(lastChildGrammarElement, candidateElement)) {
				while(candidate != null) {
					if (candidateElement != null && hasMandatoryFollowElements(candidateElement))
						return true;
					candidate = candidate.getParent();
					if (candidate != null)
						candidateElement = getCandidateElement(candidate.getGrammarElement());
				}
			}
			return true;
		}
	}
	return false;
}
 
Example 2
Source File: FixedPartialParsingHelper.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
protected boolean isInvalidLastChildNode(ICompositeNode candidate, final INode lastChild) {
  if (lastChild != null && lastChild.getSyntaxErrorMessage() != null) {
    EObject lastChildGrammarElement = lastChild.getGrammarElement();
    if (lastChildGrammarElement == null) {
      return true;
    }
    AbstractElement candidateElement = getCandidateElement(candidate.getGrammarElement());
    if (candidateElement != null) {
      if (isCalledBy(lastChildGrammarElement, candidateElement)) {
        while (candidate != null) {
          if (candidateElement != null && hasMandatoryFollowElements(candidateElement)) {
            return true;
          }
          candidate = candidate.getParent();
          if (candidate != null) {
            candidateElement = getCandidateElement(candidate.getGrammarElement());
          }
        }
      }
      return true;
    }
  }
  return false;
}
 
Example 3
Source File: UtilN4.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@code true} if the leaf node argument is an instance of {@link LeafNodeWithSyntaxError} and the issue code of
 * the syntax error message matches with any of the ignored syntax error issue codes argument. Otherwise, returns
 * with {@code false}.
 */
public static boolean isIgnoredSyntaxErrorNode(final INode leaf, final String... ignoredSyntaxErrorIssues) {
	if (leaf instanceof LeafNodeWithSyntaxError) {
		final SyntaxErrorMessage errorMessage = leaf.getSyntaxErrorMessage();
		if (null != errorMessage) {
			return contains(errorMessage.getIssueCode(), ignoredSyntaxErrorIssues);
		}
	}
	return false;
}
 
Example 4
Source File: FormatterTester.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
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());
	}
}
 
Example 5
Source File: FormatterTester.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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());
	}
}
 
Example 6
Source File: InvariantChecker.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected int doCheckChildNodeAndReturnTotalLength(INode child, ICompositeNode parent, int startsAt) {
	exceptionSeen |= child.getSyntaxErrorMessage() != null;
	if (((AbstractNode) child).basicGetNextSibling().basicGetPreviousSibling() != child)
		throw new InconsistentNodeModelException("child.next.previous != child");
	if (((AbstractNode) child).basicGetPreviousSibling().basicGetNextSibling() != child)
		throw new InconsistentNodeModelException("child.previous.next != child");
	if (((AbstractNode) child).basicGetPreviousSibling().basicGetParent() != ((AbstractNode) child).basicGetParent())
		throw new InconsistentNodeModelException("child.previous.parent != child.parent");
	if (((AbstractNode) child).basicGetNextSibling().basicGetParent() != ((AbstractNode) child).basicGetParent())
		throw new InconsistentNodeModelException("child.next.parent != child.parent");
	if (((AbstractNode) child).basicGetParent() != parent) {
		throw new InconsistentNodeModelException("node does not point to its parent");
	}
	if (child instanceof ILeafNode) {
		if (child.getGrammarElement() == null) {
			if (!exceptionSeen) {
				throw new InconsistentNodeModelException("leaf node without grammar element");
			}
		}
		return doCheckLeafNodeAndReturnLength((ILeafNode) child, startsAt);
	} else {
		if (child.getGrammarElement() == null) {
			throw new InconsistentNodeModelException("node without grammar element");
		}
		return doCheckCompositeNodeAndReturnTotalLength((ICompositeNode) child, startsAt);
	}
}
 
Example 7
Source File: GrammarResource.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.9
 */
@Override
protected void addSyntaxDiagnostic(List<Diagnostic> diagnostics, INode node) {
	SyntaxErrorMessage syntaxErrorMessage = node.getSyntaxErrorMessage();
	if (CardinalityAwareSyntaxErrorMessageProvider.CARDINALITY_ISSUE.equals(syntaxErrorMessage.getIssueCode())) {
		super.getWarnings().add(new XtextSyntaxDiagnostic(node));
	} else {
		super.addSyntaxDiagnostic(diagnostics, node);
	}
}
 
Example 8
Source File: XtextResource.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.7
 */
protected void addSyntaxDiagnostic(List<Diagnostic> diagnostics, INode error) {
	SyntaxErrorMessage syntaxErrorMessage = error.getSyntaxErrorMessage();
	if (org.eclipse.xtext.diagnostics.Diagnostic.SYNTAX_DIAGNOSTIC_WITH_RANGE.equals(syntaxErrorMessage.getIssueCode())) {
		String[] issueData = syntaxErrorMessage.getIssueData();
		if (issueData.length == 1) {
			String data = issueData[0];
			int colon = data.indexOf(':');
			diagnostics.add(new XtextSyntaxDiagnosticWithRange(error, Integer.valueOf(data.substring(0, colon)), Integer.valueOf(data.substring(colon + 1)), null));
			return;
		}
	}
	diagnostics.add(new XtextSyntaxDiagnostic(error));
}
 
Example 9
Source File: FormatterTestHelper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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());
	}
}
 
Example 10
Source File: DotSubgrammarValidationMessageAcceptor.java    From gef with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Helper Method to allow this message acceptor to handle syntax errors
 * issued while parsing the sub grammar as validation issues of the main
 * grammar.
 *
 * @param error
 *            Error node from parsing.
 */
public void acceptSyntaxError(INode error) {
	SyntaxErrorMessage errorMessage = error.getSyntaxErrorMessage();
	hostMessageAcceptor.acceptError(
			buildSyntaxErrorMessage(errorMessage.getMessage()), attribute,
			calculateOffset(error.getOffset()), error.getLength(),
			errorMessage.getIssueCode(), errorMessage.getIssueData());
}