org.eclipse.xtext.nodemodel.ILeafNode Java Examples

The following examples show how to use org.eclipse.xtext.nodemodel.ILeafNode. 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: HiddenTokenSequencer.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected void emitHiddenTokens(List<INode> hiddens /* Set<INode> comments, */) {
	if (hiddens == null)
		return;
	boolean lastNonWhitespace = true;
	for (INode node : hiddens) {
		if (tokenUtil.isCommentNode(node)) {
			if (lastNonWhitespace)
				delegate.acceptWhitespace(hiddenTokenHelper.getWhitespaceRuleFor(null, ""), "", null);
			lastNonWhitespace = true;
			//				comments.remove(node);
			delegate.acceptComment((AbstractRule) node.getGrammarElement(), node.getText(), (ILeafNode) node);
		} else {
			delegate.acceptWhitespace((AbstractRule) node.getGrammarElement(), node.getText(), (ILeafNode) node);
			lastNonWhitespace = false;
		}
		lastEmittedNode = node;
	}
	if (lastNonWhitespace)// FIXME: determine the whitespace rule correctly 
		delegate.acceptWhitespace(hiddenTokenHelper.getWhitespaceRuleFor(null, ""), "", null);
}
 
Example #2
Source File: N4JSSyntaxValidator.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Check that not more than one access modifier is given. Access modifiers are those for which
 * {@link ModifierUtils#isAccessModifier(N4Modifier)} returns <code>true</code>.
 */
private boolean holdsNotMoreThanOneAccessModifier(ModifiableElement elem) {
	boolean hasIssue = false;
	boolean hasAccessModifier = false;
	for (int idx = 0; idx < elem.getDeclaredModifiers().size(); idx++) {
		final N4Modifier mod = elem.getDeclaredModifiers().get(idx);
		final boolean isAccessModifier = ModifierUtils.isAccessModifier(mod);
		if (hasAccessModifier && isAccessModifier) {
			final ILeafNode node = ModifierUtils.getNodeForModifier(elem, idx);
			addIssue(IssueCodes.getMessageForSYN_MODIFIER_ACCESS_SEVERAL(),
					elem, node.getOffset(), node.getLength(),
					IssueCodes.SYN_MODIFIER_ACCESS_SEVERAL);
			hasIssue = true;
		}
		hasAccessModifier |= isAccessModifier;
	}
	return !hasIssue;
}
 
Example #3
Source File: XtextLinkingService.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private List<EObject> getPackage(ReferencedMetamodel context, ILeafNode text) {
	String nsUri = getMetamodelNsURI(text);
	if (nsUri == null)
		return Collections.emptyList();
	Grammar grammar = GrammarUtil.getGrammar(context);
	Set<Grammar> visitedGrammars = new HashSet<Grammar>();
	for (Grammar usedGrammar: grammar.getUsedGrammars()) {
		List<EObject> result = getPackage(nsUri, usedGrammar, visitedGrammars);
		if (result != null)
			return result;
	}
	QualifiedName packageNsURI = QualifiedName.create(nsUri);
	EPackage pack = findPackageInScope(context, packageNsURI);
	if (pack == null) {
		pack = findPackageInAllDescriptions(context, packageNsURI);
		if (pack == null) {
			pack = loadEPackage(nsUri, context.eResource().getResourceSet());
		}
	}
	if (pack != null)
		return Collections.<EObject>singletonList(pack);
	return Collections.emptyList();
}
 
Example #4
Source File: IndentationAwareCompletionPrefixProvider.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private PeekingIterator<ILeafNode> createReversedLeafIterator(INode root, INode candidate, LinkedList<ILeafNode> sameGrammarElement) {
	EObject grammarElement = null;
	PeekingIterator<ILeafNode> iterator = Iterators.peekingIterator(Iterators.filter(root.getAsTreeIterable().reverse().iterator(), ILeafNode.class));
	// traverse until we find the current candidate
	while(iterator.hasNext()) {
		ILeafNode next = iterator.next();
		if (candidate.equals(next)) {
			break;
		} else if (next.getTotalLength() == 0) {
			EObject otherGrammarElement = tryGetGrammarElementAsRule(next);
			if (grammarElement == null) {
				grammarElement = otherGrammarElement;
			}
			if (otherGrammarElement.equals(grammarElement)) {
				sameGrammarElement.add(next);
			} else {
				sameGrammarElement.removeLast();
			}
		}
	}
	return iterator;
}
 
Example #5
Source File: ParserBasedContentAssistContextFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public String getNodeTextUpToCompletionOffset(INode currentNode) {
	int startOffset = currentNode.getOffset();
	int length = completionOffset - startOffset;
	String nodeText = ((ILeafNode) currentNode).getText();
	String trimmedNodeText = length > nodeText.length() ? nodeText : nodeText.substring(0, length);
	if (viewer.getDocument() != null /* testing */ && length >= 0) {
		try {
			String text = viewer.getDocument().get(startOffset, trimmedNodeText.length());
			if (trimmedNodeText.equals(text))
				return text;
			return viewer.getDocument().get(startOffset, length);
		} catch (BadLocationException e) {
			log.error(e.getMessage(), e);
		}
	}
	return trimmedNodeText;
}
 
Example #6
Source File: TokenUtil.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public String serializeNode(INode node) {
	if (node instanceof ILeafNode)
		return ((ILeafNode) node).getText();
	List<ILeafNode> leafNodes = Lists.newArrayList(node.getLeafNodes());
	int begin = 0, end = leafNodes.size() - 1;
	while (begin <= end && isWhitespaceOrCommentNode(leafNodes.get(begin)))
		begin++;
	while (begin <= end && isWhitespaceOrCommentNode(leafNodes.get(end)))
		end--;
	if (begin == end)
		return isWhitespaceOrCommentNode(leafNodes.get(begin)) ? "" : leafNodes.get(begin).getText();
	StringBuilder b = new StringBuilder();
	for (int i = begin; i <= end; i++)
		b.append(leafNodes.get(i).getText());
	return b.toString();
}
 
Example #7
Source File: SemanticChangeProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the offset to place the @Internal annotation in the same line
 */
private int internalAnnotationOffset(ModifiableElement element) {
	if (!(element instanceof AnnotableElement)) {
		throw new IllegalArgumentException("Can't compute @Internal offset for non-annotable element");
	}

	// If element is exported put the @Internal annotation in front of the export keyword
	// Otherwise place it in front of the modifiers

	EObject containerExportDeclaration = element.eContainer();
	if (containerExportDeclaration instanceof ExportDeclaration) {
		ILeafNode node = nodeModelAccess.nodeForKeyword(containerExportDeclaration,
				N4JSLanguageConstants.EXPORT_KEYWORD);
		if (node != null) {
			return node.getOffset();
		} else {
			throw new NullPointerException("Failed to retrieve node for export keyword");
		}
	} else {
		return modifierOffset(element);
	}
}
 
Example #8
Source File: ValueSerializer.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected String serialize(INode node) {
	if (node instanceof ILeafNode)
		return ((ILeafNode) node).getText();
	else {
		StringBuilder builder = new StringBuilder(node.getLength());
		boolean hiddenSeen = false;
		for(ILeafNode leaf: node.getLeafNodes()) {
			if (!leaf.isHidden()) {
				if (hiddenSeen && builder.length() > 0)
					builder.append(' ');
				builder.append(leaf.getText());
				hiddenSeen = false;
			} else {
				hiddenSeen = true;
			}
		}
		return builder.toString();
	}
}
 
Example #9
Source File: ParserBasedContentAssistContextFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void handleLastCompleteNodeIsAtEndOfDatatypeNode() throws BadLocationException {
	String prefix = getPrefix(lastCompleteNode);
	INode previousNode = getLastCompleteNodeByOffset(rootNode, lastCompleteNode.getOffset());
	EObject previousModel = previousNode.getSemanticElement();
	INode currentDatatypeNode = getContainingDatatypeRuleNode(currentNode);
	Collection<FollowElement> followElements = parseFollowElements(lastCompleteNode.getOffset(), false);
	int prevSize = contextBuilders.size();
	doCreateContexts(previousNode, currentDatatypeNode, prefix, previousModel, followElements);

	if (lastCompleteNode instanceof ILeafNode && lastCompleteNode.getGrammarElement() == null
			&& contextBuilders.size() != prevSize) {
		handleLastCompleteNodeHasNoGrammarElement(contextBuilders.subList(prevSize, contextBuilders.size()),
				previousModel);
	}
}
 
Example #10
Source File: DefaultImportsConfiguration.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public String getLegacyImportSyntax(XImportDeclaration importDeclaration) {
	List<INode> list = NodeModelUtils.findNodesForFeature(importDeclaration, XtypePackage.Literals.XIMPORT_DECLARATION__IMPORTED_TYPE);
	if (list.isEmpty()) {
		return null;
	}
	INode singleNode = list.get(0);
	if (singleNode.getText().indexOf('$') < 0) {
		return null;
	}
	StringBuilder sb = new StringBuilder();
	for(ILeafNode node: singleNode.getLeafNodes()) {
		if (!node.isHidden()) {
			sb.append(node.getText().replace("^", ""));
		}
	}
	return sb.toString();
}
 
Example #11
Source File: PartialParsingHelper.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private boolean isRangePartOfExceedingLookAhead(CompositeNode node, ReplaceRegion replaceRegion) {
	TreeIterator<AbstractNode> iterator = node.basicIterator();
	int lookAhead = node.getLookAhead();
	if (lookAhead == 0) {
		return false;
	}
	while(iterator.hasNext()) {
		AbstractNode child = iterator.next();
		if (child instanceof CompositeNode) {
			if (child.getTotalOffset() < replaceRegion.getEndOffset())
				lookAhead = Math.max(((CompositeNode) child).getLookAhead(), lookAhead);
		} else if (!((ILeafNode) child).isHidden()) {
			lookAhead--;
			if (lookAhead == 0) {
				if (child.getTotalOffset() >= replaceRegion.getEndOffset())
					return false;
			}
		}
	}
	return lookAhead > 0;
}
 
Example #12
Source File: SyntacticSequencerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private List<String> getNodeSequence(EObject model) {
	List<String> result = Lists.newArrayList();
	GrammarElementTitleSwitch titleSwitch = new GrammarElementTitleSwitch().showAssignments();
	org.eclipse.xtext.serializer.sequencer.EmitterNodeIterator ni = 
			new org.eclipse.xtext.serializer.sequencer.EmitterNodeIterator(NodeModelUtils.findActualNodeFor(model));
	while (ni.hasNext()) {
		INode next = ni.next();
		EObject ele = next.getGrammarElement() instanceof CrossReference ? ((CrossReference) next
				.getGrammarElement()).getTerminal() : next.getGrammarElement();
		if (next instanceof ILeafNode || GrammarUtil.isDatatypeRuleCall(ele))
			result.add(titleSwitch.doSwitch(ele) + " -> " + next.getText().trim());
		else if (next instanceof ICompositeNode)
			result.add(titleSwitch.doSwitch(ele));
	}
	return result;
}
 
Example #13
Source File: LazyURIEncoderTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testNodePath() throws Exception {
	NodeModelBuilder builder = new NodeModelBuilder();
	ICompositeNode n = new CompositeNode();
	ICompositeNode n1 = new CompositeNode();
	builder.addChild(n, (AbstractNode) n1);
	ICompositeNode n2 = new CompositeNode();
	builder.addChild(n, (AbstractNode) n2);
	ILeafNode l1 = new LeafNode();
	builder.addChild(n2, (AbstractNode) l1);
	ILeafNode l2 = new LeafNode();
	builder.addChild(n2, (AbstractNode) l2);
	
	assertEquals(n, find(n,n));
	assertEquals(n1, find(n,n1));
	assertEquals(n2, find(n,n2));
	assertEquals(l1, find(n,l1));
	assertEquals(l2, find(n,l2));
}
 
Example #14
Source File: PartialParserTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testPartialParseConcreteRuleInnermostToken_02() throws Exception {
	with(PartialParserTestLanguageStandaloneSetup.class);
	String model = 
			"container c1 {\n" +
			"  children {\n" +
			"    -> C ( ch1 )\n" +
			"  }" +
			"}";
	XtextResource resource = getResourceFromString(model);
	assertTrue(resource.getErrors().isEmpty());
	ICompositeNode root = resource.getParseResult().getRootNode();
	ILeafNode childrenLeaf = findLeafNodeByText(root, model, "children");
	ILeafNode ch1Leaf = findLeafNodeByText(root, model, "ch1");
	// change the model and undo the change
	resource.update(model.indexOf("ch1") + 1, 1, "x");
	resource.update(model.indexOf("ch1") + 1, 1, "h");
	assertSame(root, resource.getParseResult().getRootNode());
	assertSame(childrenLeaf, findLeafNodeByText(root, model, "children"));
	assertNotSame(ch1Leaf, findLeafNodeByText(root, model, "ch1"));
}
 
Example #15
Source File: SequenceFeeder.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public void accept(Keyword keyword, Object value, String token, ILeafNode node) {
	Assignment ass = getAssignment(keyword);
	EStructuralFeature feature = getFeature(ass.getFeature());
	assertIndex(feature);
	assertValue(feature, value);
	acceptKeyword(ass, keyword, value, token, ISemanticSequenceAcceptor.NO_INDEX, node);
}
 
Example #16
Source File: XtextProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void completeTypeRef_Classifier(EObject model, Assignment assignment, ContentAssistContext context,
		ICompletionProposalAcceptor acceptor) {
	Grammar grammar = GrammarUtil.getGrammar(model);
	ContentAssistContext.Builder myContextBuilder = context.copy();
	myContextBuilder.setMatcher(new ClassifierPrefixMatcher(context.getMatcher(), classifierQualifiedNameConverter));
	if (model instanceof TypeRef) {
		ICompositeNode node = NodeModelUtils.getNode(model);
		if (node != null) {
			int offset = node.getOffset();
			Region replaceRegion = new Region(offset, context.getReplaceRegion().getLength()
					+ context.getReplaceRegion().getOffset() - offset);
			myContextBuilder.setReplaceRegion(replaceRegion);
			myContextBuilder.setLastCompleteNode(node);
			StringBuilder availablePrefix = new StringBuilder(4);
			for (ILeafNode leaf : node.getLeafNodes()) {
				if (leaf.getGrammarElement() != null && !leaf.isHidden()) {
					if ((leaf.getTotalLength() + leaf.getTotalOffset()) < context.getOffset())
						availablePrefix.append(leaf.getText());
					else
						availablePrefix.append(leaf.getText().substring(0,
								context.getOffset() - leaf.getTotalOffset()));
				}
				if (leaf.getTotalOffset() >= context.getOffset())
					break;
			}
			myContextBuilder.setPrefix(availablePrefix.toString());
		}
	}
	ContentAssistContext myContext = myContextBuilder.toContext();
	for (AbstractMetamodelDeclaration declaration : grammar.getMetamodelDeclarations()) {
		if (declaration.getEPackage() != null) {
			createClassifierProposals(declaration, model, myContext, acceptor);
		}
	}
}
 
Example #17
Source File: CreateMemberQuickfixes.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.3
 */
protected int getFirstOffsetOfKeyword(EObject object, String keyword) {
	int offset = -1;
	ICompositeNode node = NodeModelUtils.getNode(object);
	if (node != null) {
		for (ILeafNode leafNode : node.getLeafNodes()) {
			if (leafNode.getGrammarElement() instanceof Keyword
					&& equal(keyword, ((Keyword) leafNode.getGrammarElement()).getValue())) {
				return leafNode.getOffset() + 1;
			}
		}
	}
	return offset;
}
 
Example #18
Source File: Bug250313Test.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testIDConversion_03() throws Exception {
	Model model = (Model) getModel("str");
	assertEquals("str", model.getValue());
	assertEquals("org.eclipse.xtext.common.Terminals.ID", lexerRule);
	assertTrue(node instanceof ILeafNode);
	assertEquals("str", string);
	assertEquals(1, convertCallCount);
}
 
Example #19
Source File: PartialParsingHelper.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private INode getLastLeaf(ICompositeNode parent) {
	BidiTreeIterator<? extends INode> iterator = parent.getAsTreeIterable().iterator();
	while(iterator.hasPrevious()) {
		INode previous = iterator.previous();
		if (previous instanceof ILeafNode) {
			return previous;
		} 
	}
	return null;
}
 
Example #20
Source File: DefaultEcoreElementFactoryTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testValueConverterException() throws Exception {
	EClass eClass = EcoreFactory.eINSTANCE.createEClass();
	final ILeafNode node = new LeafNode();
	final ValueConverterException expected = new ValueConverterException("Foo", node, null);
	
	Function2<String, INode, Object> toValueImpl = new Function2<String, INode, Object>() {

		@Override
		public Object apply(String lexerRule, INode nodeParam) {
			if ("foo".equals(lexerRule) && node.equals(nodeParam)) {
				throw expected;
			}
			fail();
			return null;
		}
	};

	DefaultEcoreElementFactory factory = new DefaultEcoreElementFactory();
	factory.setConverterService(new MockedConverterService(toValueImpl));
	try {
		factory.set(eClass, "abstract", null, "foo", node);
		fail("Expected ValueConverterException");
	} catch (ValueConverterException ex) {
		assertSame(expected, ex);
	}
}
 
Example #21
Source File: HiddenLeafAccess.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected List<ILeafNode> findPreviousHiddenLeafs(final INode node) {
  List<ILeafNode> _xblockexpression = null;
  {
    INode current = node;
    while ((current instanceof ICompositeNode)) {
      current = ((ICompositeNode)current).getLastChild();
    }
    final ArrayList<ILeafNode> result = CollectionLiterals.<ILeafNode>newArrayList();
    if ((current != null)) {
      final NodeIterator ni = new NodeIterator(current);
      while (ni.hasPrevious()) {
        {
          final INode previous = ni.previous();
          if (((!Objects.equal(previous, current)) && (previous instanceof ILeafNode))) {
            boolean _isHidden = ((ILeafNode) previous).isHidden();
            if (_isHidden) {
              result.add(((ILeafNode) previous));
            } else {
              return ListExtensions.<ILeafNode>reverse(result);
            }
          }
        }
      }
    }
    _xblockexpression = ListExtensions.<ILeafNode>reverse(result);
  }
  return _xblockexpression;
}
 
Example #22
Source File: ContentAssistContextFactory.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public String getPrefix(INode prefixNode) {
	if (prefixNode instanceof ILeafNode) {
		if (((ILeafNode) prefixNode).isHidden() && prefixNode.getGrammarElement() != null)
			return "";
		return getNodeTextUpToCompletionOffset(prefixNode);
	}
	StringBuilder result = new StringBuilder(prefixNode.getTotalLength());
	doComputePrefix((ICompositeNode) prefixNode, result);
	return result.toString();
}
 
Example #23
Source File: DebugSequenceAcceptor.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String node2text(INode node) {
	if (node == null)
		return "(node is null)";
	if (node instanceof ILeafNode)
		return titles.doSwitch(node.getGrammarElement()) + " -> " + node.getText();
	if (node instanceof ICompositeNode)
		return titles.doSwitch(node.getGrammarElement());
	return "(unknown node)";
}
 
Example #24
Source File: ContentAssistContextFactory.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected void handleLastCompleteNodeHasNoGrammarElement(List<Builder> contextBuilderToCheck, EObject previousModel) {
	List<ContentAssistContext> newContexts = Lists.transform(contextBuilderToCheck, this);
	boolean wasValid = isLikelyToBeValidProposal(lastCompleteNode, newContexts);
	if (wasValid && !(lastCompleteNode instanceof ILeafNode && ((ILeafNode) lastCompleteNode).isHidden())) {
		createContextsForLastCompleteNode(previousModel, false);
	}
}
 
Example #25
Source File: XbaseQualifiedNameValueConverter.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String toValue(String string, INode node) throws ValueConverterException {
	StringBuilder buffer = new StringBuilder();
	boolean isFirst = true;
	if (node != null) {
		for(INode child: node.getAsTreeIterable()) {
			EObject grammarElement = child.getGrammarElement();
			if (isDelegateRuleCall(grammarElement) || isWildcardLiteral(grammarElement)) {
				if (!isFirst)
					buffer.append(getValueNamespaceDelimiter());
				isFirst = false;
				if (isDelegateRuleCall(grammarElement))
					for(ILeafNode leafNode :child.getLeafNodes()){
						if(!leafNode.isHidden())
							buffer.append(delegateToValue(leafNode));
					}
				else 
					buffer.append(getWildcardLiteral());
			}
		}
	} else {
		for (String segment : Strings.split(string, getStringNamespaceDelimiter())) {
			if (!isFirst)
				buffer.append(getValueNamespaceDelimiter());
			isFirst = false;
			if(getWildcardLiteral().equals(segment)) {
				buffer.append(getWildcardLiteral());
			} else {
				buffer.append((String) valueConverterService.toValue(segment, getDelegateRuleName(), null));
			}
		}
	}
	return buffer.toString();
}
 
Example #26
Source File: AbstractNode.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<ILeafNode> getLeafNodes() {
	return new Iterable<ILeafNode>() {
		@Override
		public Iterator<ILeafNode> iterator() {
			return Iterators.filter(basicIterator(), ILeafNode.class);
		}
	};
}
 
Example #27
Source File: DiagnosticOnFirstKeyword.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected INode getNode() {
	INode result = super.getNode();
	for(ILeafNode leaf: result.getLeafNodes()) {
		if (!leaf.isHidden()) {
			return leaf;
		}
	}
	return result;
}
 
Example #28
Source File: ReorderingHiddenTokenSequencer.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void acceptAssignedCrossRefKeyword(final Keyword keyword, final String token, final EObject value, final int index, final ILeafNode node) {
  emitHiddenTokens(getHiddenNodesBetween(lastNode, node));
  lastNode = node;
  delegate.acceptAssignedCrossRefKeyword(keyword, token, value, index, node);
  emitTrailingTokens(node);
}
 
Example #29
Source File: NodeModelAccess.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public ILeafNode findNextLeaf(INode node, Function1<? super ILeafNode, ? extends Boolean> matches) {
	if (node != null) {
		if (node instanceof ILeafNode && matches.apply((ILeafNode) node)) {
			return (ILeafNode) node;
		}
		NodeIterator ni = new NodeIterator(node);
		while (ni.hasNext()) {
			INode next = ni.next();
			if (next instanceof ILeafNode && matches.apply((ILeafNode) next)) {
				return (ILeafNode) next;
			}
		}
	}
	return null;
}
 
Example #30
Source File: XbaseValidator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected ILeafNode getFirstLeafNode(BidiTreeIterator<INode> iterator) {
	while(iterator.hasNext()) {
		INode child = iterator.next();
		if (isHidden(child)) {
			continue;
		}
		if (child instanceof ILeafNode) {
			return (ILeafNode) child;
		}
	}
	return null;
}