Java Code Examples for org.eclipse.xtext.parsetree.reconstr.ITokenStream#writeHidden()

The following examples show how to use org.eclipse.xtext.parsetree.reconstr.ITokenStream#writeHidden() . 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: FormattingConfigBasedStream.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @param endIndex
 *            the index of the last entry to flush, exclusive.
 */
protected void flush(ITokenStream intoStream, int endIndex) throws IOException {
	for (int i = 0; i < endIndex; i++) {
		LineEntry e = this.entries.get(i);
		Pair<AbstractRule, String> spaces = getSpaces(e, i == 0);
		//				if (i == 0 && startWithNL && !e.isBreakable())
		//					throw new IllegalStateException("break for non-breakable item");
		//				else if (i != 0 && e.isBreak())
		//					throw new IllegalStateException("break within line");
		//				if (i == 0 && startWithNL && spaces.getSecond().indexOf('\n') < 0)
		//					throw new IllegalStateException("missing newline before " + e.value);
		// System.out.println("Spaces: '" + sp + "' before '" + e.val
		// + "'");
		if (spaces != null)
			intoStream.writeHidden(spaces.getFirst(), spaces.getSecond());
		if (e.isHidden)
			intoStream.writeHidden(e.grammarElement, e.value);
		else
			intoStream.writeSemantic(e.grammarElement, e.value);
	}
}
 
Example 2
Source File: ExtendedLine.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Write part of this line to a token stream. The part to be written are
 * all line entries from 0 .. endIndex.
 *
 * @param intoStream
 *          - the token stream into which to write this line.
 * @param endIndex
 *          the index of the last entry to flush, exclusive.
 * @throws IOException
 *           - propagated exception from underlying token stream
 */
@Override
protected void flush(final ITokenStream intoStream, final int endIndex) throws IOException {
  if (firstNotIgnored == 0 && getLinewrapEntry() != null) {
    intoStream.writeHidden(getLinewrapEntry().getGrammarElement(), getLinewrapEntry().getValue());
  }
  for (int i = firstNotIgnored; i < endIndex; i++) {
    final ExtendedLineEntry entry = getEntries().get(i);
    int previousEntryIndex = findPredecessorOrLastEntryIndex(entry);
    final ExtendedLineEntry previousEntry = lineEntries.get(previousEntryIndex);
    final boolean shouldBreakTheLine = entry.isFixedLocatorOpening() && entry.isFixed() && (getAbsoluteLineLength(entry) >= entry.getColumnIndent());
    final boolean isPreviousDifferentThanCurrent = (previousEntryIndex == 0 && !previousEntry.equals(entry));
    final boolean isPreviousColumnAlignedAndNotUtmost = (previousEntry.getColumnIndent() > 0 && !previousEntry.isFixedLocatorClosing()
        && !previousEntry.isFixedLocatorOpening());
    final boolean isCurrentBreakableAndColumnAligned = !entry.isNoBreak() && entry.isFixedLocatorOpening() && entry.isFixedLocatorClosing();

    if (shouldBreakTheLine || (isCurrentBreakableAndColumnAligned && isPreviousDifferentThanCurrent && isPreviousColumnAlignedAndNotUtmost)) { // nobreak
      intoStream.writeHidden(entry.getGrammarElement(), "\n" + SpaceEntry.createPadding(entry.getColumnIndent())); //$NON-NLS-1$
    } else {
      intoStream.writeHidden(entry.getGrammarElement(), entry.getLeadingWS());
    }
    if (entry.isHidden()) {
      intoStream.writeHidden(entry.getGrammarElement(), entry.getValue());
    } else {
      intoStream.writeSemantic(entry.getGrammarElement(), entry.getValue());
    }
  }
  firstNotIgnored = 0; // Reset
}
 
Example 3
Source File: DirectNodeModelStreamer.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void writeHidden(final ITokenStream out, final ILeafNode node) throws IOException {
  if (out instanceof ExtendedFormattingConfigBasedStream) {
    ((ExtendedFormattingConfigBasedStream) out).setNode(node);
  }
  out.writeHidden(node.getGrammarElement(), node.getText());
}
 
Example 4
Source File: NodeModelStreamer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void writeHidden(ITokenStream out, ILeafNode node) throws IOException {
	out.writeHidden(node.getGrammarElement(), node.getText());
}
 
Example 5
Source File: NodeModelStreamer.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void writeHiddenEmpty(ITokenStream out) throws IOException {
	out.writeHidden(hiddenTokenHelper.getWhitespaceRuleFor(null, ""), "");
}