org.eclipse.xtext.nodemodel.impl.HiddenLeafNode Java Examples

The following examples show how to use org.eclipse.xtext.nodemodel.impl.HiddenLeafNode. 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: HiddenAndTokenNodeIteratorTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
	nodes = new INode[NUM_NODES];
	NodeModelBuilder builder = new NodeModelBuilder();
	nodes[0] = new CompositeNode();
	nodes[1] = new CompositeNode();
	nodes[2] = new HiddenLeafNode();
	nodes[3] = new LeafNode();
	nodes[4] = new HiddenLeafNode();
	nodes[5] = new CompositeNode();
	nodes[6] = new LeafNode();
	nodes[7] = new CompositeNode();
	nodes[8] = new HiddenLeafNode();
	nodes[9] = new LeafNode();
	
	builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[1]);
	builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[5]);
	builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[7]);
	builder.addChild((ICompositeNode)nodes[0], (AbstractNode)nodes[9]);
	builder.addChild((ICompositeNode)nodes[1], (AbstractNode)nodes[2]);
	builder.addChild((ICompositeNode)nodes[1], (AbstractNode)nodes[3]);
	builder.addChild((ICompositeNode)nodes[1], (AbstractNode)nodes[4]);
	builder.addChild((ICompositeNode)nodes[5], (AbstractNode)nodes[6]);
	builder.addChild((ICompositeNode)nodes[7], (AbstractNode)nodes[8]);
}
 
Example #2
Source File: AbstractLabelProvider.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a default styled string for the given {@link EObject} model element.
 *
 * @param eObject
 *          the {@link EObject} model element
 * @return the styled string for the given {@link EObject} model element
 */
public Object getStyledLabel(final EObject eObject) {
  // first check if object is foreign to this grammar
  if (isForeignXtextObject(eObject)) {
    return getForeignObjectLabel(eObject);
  }
  // first check if object has a name
  String name = getNameOfObject(eObject);
  if (name != null) {
    return qualifiedStyledString(name, getTypeOfObject(eObject));
  }
  // secondly check first parsed element (keyword / feature)
  ICompositeNode node = NodeModelUtils.getNode(eObject);
  if (node != null) {
    Iterator<ILeafNode> leafNodesIterator = node.getLeafNodes().iterator();
    while (leafNodesIterator.hasNext()) {
      ILeafNode genericLeafNode = leafNodesIterator.next();
      if (!(genericLeafNode instanceof HiddenLeafNode)) {
        LeafNode leafNode = (LeafNode) genericLeafNode;
        return getLabelName(leafNode.getText(), eObject.eClass().getName(), true);
      }
    }
  }
  // fallback
  return super.doGetText(eObject);
}
 
Example #3
Source File: SleighHighlightingCalculator.java    From ghidra with Apache License 2.0 5 votes vote down vote up
INode skipWhiteSpace(IHighlightedPositionAcceptor acceptor,
		BidiIterator<INode> it) {
	INode n = null;
	while (it.hasNext()
			&& (n = it.next()).getClass() == HiddenLeafNode.class)
		processHiddenNode(acceptor, (HiddenLeafNode) n);
	return n;
}
 
Example #4
Source File: SleighHighlightingCalculator.java    From ghidra with Apache License 2.0 5 votes vote down vote up
INode skipWhiteSpaceBackwards(IHighlightedPositionAcceptor acceptor,
		BidiIterator<INode> it) {
	INode n = null;
	while (it.hasPrevious()
			&& (n = it.previous()).getClass() == HiddenLeafNode.class)
		processHiddenNode(acceptor, (HiddenLeafNode) n);
	return n;
}
 
Example #5
Source File: SleighHighlightingCalculator.java    From ghidra with Apache License 2.0 5 votes vote down vote up
void processHiddenNode(IHighlightedPositionAcceptor acceptor,
		HiddenLeafNode node) {
	if (node.getGrammarElement() instanceof TerminalRuleImpl) {
		TerminalRuleImpl ge = (TerminalRuleImpl) node.getGrammarElement();
		String name = ge.getName();
		if (name.equalsIgnoreCase("PDL_COMMENT") || name.equalsIgnoreCase("ML_COMMENT") || name.equalsIgnoreCase("SL_COMMENT")) {
			acceptor.addPosition(node.getOffset(), node.getLength(), COMMENT_ID);
		}
	}

}
 
Example #6
Source File: SiblingIterable.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Iterator<INode> iterator() {
	return new Iterator<>() {
		private INode currNode = skipHidden(firstSibling);

		@Override
		public boolean hasNext() {
			return currNode != null;
		}

		@Override
		public INode next() {
			if (!hasNext()) {
				throw new NoSuchElementException();
			}
			final INode result = currNode;
			currNode = skipHidden(currNode.getNextSibling());
			return result;
		}

		private INode skipHidden(INode node) {
			if (skipHidden) {
				while (node instanceof HiddenLeafNode) {
					node = node.getNextSibling();
				}
			}
			return node;
		}
	};
}
 
Example #7
Source File: JSONValidator.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks the document for comments (single or multi-line) which are not valid JSON constructs but accepted by our
 * parser.
 */
@Check
public void checkDocumentForComments(JSONDocument document) {
	ICompositeNode documentNode = NodeModelUtils.findActualNodeFor(document);
	ICompositeNode rootNode = documentNode.getRootNode();

	// find hidden leaf nodes that fulfill #isCommentNode criteria and add an issue
	StreamSupport.stream(rootNode.getAsTreeIterable().spliterator(), false)
			.filter(n -> n instanceof HiddenLeafNode)
			.filter(n -> isCommentNode(n))
			.forEach(n -> {
				addIssue(JSONIssueCodes.getMessageForJSON_COMMENT_UNSUPPORTED(), document, n.getOffset(),
						n.getLength(), JSONIssueCodes.JSON_COMMENT_UNSUPPORTED);
			});
}