• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ILeafNode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.eclipse.xtext.nodemodel.ILeafNode的典型用法代码示例。如果您正苦于以下问题:Java ILeafNode类的具体用法?Java ILeafNode怎么用?Java ILeafNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ILeafNode类属于org.eclipse.xtext.nodemodel包,在下文中一共展示了ILeafNode类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getTokens

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
/**
 * Parses the input and returns a list of lexer tokens. Asserts that the produced tokens are equal to the tokens
 * that the production parser produced.
 *
 * @return the tokens for the highlighting.
 */
public List<Token> getTokens(CharSequence input) {
	List<Token> result;
	IParseResult parseResult = parser.parse(new StringReader(input.toString()));
	if (!parseResult.hasSyntaxErrors()) {
		result = throwingHighlightingParser.getTokens(input);
	} else {
		result = highlightingParser.getTokens(input);
	}
	// assert equal tokens
	Iterator<Token> iter = result.iterator();
	for (ILeafNode leaf : parseResult.getRootNode().getLeafNodes()) {
		Assert.assertTrue("hasNext at index " + leaf.getTotalOffset() + " for leaf '" + leaf.getText() + "'",
				iter.hasNext());
		Token token = iter.next();
		// TODO: assert token type
		Assert.assertEquals(leaf.getText(), token.getText());
	}
	return result;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:26,代码来源:HighlightingParserTester.java


示例2: collectAllResolutions

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
/**
 * CollectAll resolutions under the cursor at offset.
 *
 */
List<IssueResolution> collectAllResolutions(XtextResource resource, RegionWithCursor offset,
		Multimap<Integer, Issue> offset2issue) {

	EObject script = resource.getContents().get(0);
	ICompositeNode scriptNode = NodeModelUtils.getNode(script);
	ILeafNode offsetNode = NodeModelUtils.findLeafNodeAtOffset(scriptNode, offset.getGlobalCursorOffset());
	int offStartLine = offsetNode.getTotalStartLine();
	List<Issue> allIssues = QuickFixTestHelper.extractAllIssuesInLine(offStartLine, offset2issue);

	List<IssueResolution> resolutions = Lists.newArrayList();

	for (Issue issue : allIssues) {
		if (issue.getLineNumber() == offsetNode.getStartLine()
				&& issue.getLineNumber() <= offsetNode.getEndLine()) {
			Display.getDefault().syncExec(() -> resolutions.addAll(quickfixProvider.getResolutions(issue)));
		}
	}
	return resolutions;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:24,代码来源:QuickFixXpectMethod.java


示例3: handleLastCompleteNodeIsAtEndOfDatatypeNode

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
@Override
protected void handleLastCompleteNodeIsAtEndOfDatatypeNode() {
	String prefix = getPrefix(lastCompleteNode);
	INode previousNode = getLastCompleteNodeByOffset(rootNode, lastCompleteNode.getOffset());
	EObject previousModel = previousNode.getSemanticElement();
	INode currentDatatypeNode = getContainingDatatypeRuleNode(currentNode);
	Collection<FollowElement> followElements = getParser().getFollowElements(rootNode, 0,
			lastCompleteNode.getOffset(), true);
	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);
	}
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:18,代码来源:ContentAssistContextFactory.java


示例4: holdsNotMoreThanOneAccessModifier

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:22,代码来源:N4JSSyntaxValidator.java


示例5: holdsCorrectOrder

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
/**
 * Check for correct ordering of access modifiers.
 */
private boolean holdsCorrectOrder(ModifiableElement elem) {
	boolean isOrderMessedUp = false;
	int lastValue = -1;
	for (N4Modifier mod : elem.getDeclaredModifiers()) {
		final int currValue = mod.getValue();
		if (currValue < lastValue) {
			isOrderMessedUp = true;
			break;
		}
		lastValue = currValue;
	}
	if (isOrderMessedUp) {
		final List<N4Modifier> modifiers = ModifierUtils.getSortedModifiers(elem.getDeclaredModifiers());
		final String modifiersStr = Joiner.on(' ').join(modifiers.iterator());
		final ILeafNode nodeFirst = ModifierUtils.getNodeForModifier(elem, 0);
		final ILeafNode nodeLast = ModifierUtils.getNodeForModifier(elem,
				elem.getDeclaredModifiers().size() - 1);
		addIssue(IssueCodes.getMessageForSYN_MODIFIER_BAD_ORDER(modifiersStr),
				elem, nodeFirst.getOffset(),
				nodeLast.getOffset() - nodeFirst.getOffset() + nodeLast.getLength(),
				IssueCodes.SYN_MODIFIER_BAD_ORDER);
		return false;
	}
	return true;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:29,代码来源:N4JSSyntaxValidator.java


示例6: FQN

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
@ValueConverter(rule = "FQN")
// CHECKSTYLE:OFF
public IValueConverter<String> FQN() { // NOPMD
  // CHECKSTYLE:ON
  return new AbstractNullSafeConverter<String>() {
    @Override
    protected String internalToValue(final String string, final INode node) {
      if (!string.equals(string.trim())) {
        throw new RuntimeException(); // NOPMD
      }
      StringBuffer b = new StringBuffer();
      for (ILeafNode l : node.getLeafNodes()) {
        if (!l.isHidden()) {
          b.append(l.getText());
        }
      }
      return b.toString();
    }

    @Override
    protected String internalToString(final String value) {
      return value;
    }
  };
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:26,代码来源:FormatterTestValueConverters.java


示例7: getDocumentationNodes

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public List<INode> getDocumentationNodes(final EObject object) {
  ICompositeNode node = NodeModelUtils.getNode(object);
  if (node == null) {
    return ImmutableList.of();
  }

  // get all single line comments before a non hidden leaf node
  List<INode> result = Lists.newArrayList();
  for (ILeafNode leaf : node.getLeafNodes()) {
    if (!leaf.isHidden()) {
      break;
    }
    EObject grammarElement = leaf.getGrammarElement();
    if (grammarElement instanceof AbstractRule && ruleName.equals(((AbstractRule) grammarElement).getName())) {
      String comment = leaf.getText();
      if (getCommentPattern().matcher(comment).matches() && !comment.matches(ignore)) {
        result.add(leaf);
      }
    }
  }

  return result;
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:26,代码来源:SingleLineCommentDocumentationProvider.java


示例8: highlightNode

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
/**
 * Highlights the non-hidden parts of {@code node} with the styles given by the {@code styleIds}
 */
protected void highlightNode(IHighlightedPositionAcceptor acceptor, INode node, String... styleIds) {
	if (node == null)
		return;
	if (node instanceof ILeafNode) {
		ITextRegion textRegion = node.getTextRegion();
		acceptor.addPosition(textRegion.getOffset(), textRegion.getLength(), styleIds);
	} else {
		for (ILeafNode leaf : node.getLeafNodes()) {
			if (!leaf.isHidden()) {
				ITextRegion leafRegion = leaf.getTextRegion();
				acceptor.addPosition(leafRegion.getOffset(), leafRegion.getLength(), styleIds);
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:19,代码来源:DefaultSemanticHighlightingCalculator.java


示例9: getNodeSequence

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
@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;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:18,代码来源:SyntacticSequencerTest.java


示例10: getLegacyImportSyntax

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
@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();
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:19,代码来源:DefaultImportsConfiguration.java


示例11: getHiddenLeafsAfter

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
public HiddenLeafs getHiddenLeafsAfter(final INode node) {
  HiddenLeafs _xblockexpression = null;
  {
    final Function1<ILeafNode, Boolean> _function = (ILeafNode it) -> {
      boolean _isHidden = it.isHidden();
      return Boolean.valueOf((!_isHidden));
    };
    final ILeafNode start = this.findPreviousLeaf(node, _function);
    HiddenLeafs _xifexpression = null;
    if ((start != null)) {
      _xifexpression = this.newHiddenLeafs(start.getEndOffset(), this.findNextHiddenLeafs(start));
    } else {
      int _offset = 0;
      if (node!=null) {
        _offset=node.getOffset();
      }
      _xifexpression = new HiddenLeafs(_offset);
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:23,代码来源:HiddenLeafAccess.java


示例12: getTypeRefName

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
public static String getTypeRefName(TypeRef typeRef) {
	if (typeRef.getClassifier() != null)
		return typeRef.getClassifier().getName();
	final ICompositeNode node = NodeModelUtils.getNode(typeRef);
	if (node != null) {
		final BidiIterator<INode> leafNodes = node.getAsTreeIterable().iterator();
		while (leafNodes.hasPrevious()) {
			INode previous = leafNodes.previous();
			if (previous instanceof ILeafNode && !((ILeafNode) previous).isHidden()) {
				String result = previous.getText();
				if (result != null && result.startsWith("^")) {
					result = result.substring(1);
				}
				return result;
			}
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:20,代码来源:GrammarUtil.java


示例13: findTrailingComment

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
/**
 * Finds trailing comment for a given context object. I.e. the comment after / on the same line as the context object.
 *
 * @param context
 *          the object
 * @return the documentation string
 */
protected String findTrailingComment(final EObject context) {
  StringBuilder returnValue = new StringBuilder();
  ICompositeNode node = NodeModelUtils.getNode(context);
  final int contextEndLine = node.getEndLine();
  if (node != null) {
    // process all leaf nodes first
    for (ILeafNode leave : node.getLeafNodes()) {
      addComment(returnValue, leave, contextEndLine);
    }
    // we also need to process siblings (leave nodes only) due to the fact that the last comment after
    // a given element is not a leaf node of that element anymore.
    INode sibling = node.getNextSibling();
    while (sibling instanceof ILeafNode) {
      addComment(returnValue, (ILeafNode) sibling, contextEndLine);
      sibling = sibling.getNextSibling();
    }
  }
  return returnValue.toString();
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:27,代码来源:SingleLineCommentDocumentationProvider.java


示例14: findNextLeaf

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
public ILeafNode findNextLeaf(final INode node, final Function1<? super ILeafNode, ? extends Boolean> matches) {
  Object _xifexpression = null;
  if ((node != null)) {
    if (((node instanceof ILeafNode) && (matches.apply(((ILeafNode) node))).booleanValue())) {
      return ((ILeafNode) node);
    }
    final NodeIterator ni = new NodeIterator(node);
    while (ni.hasNext()) {
      {
        final INode next = ni.next();
        if (((next instanceof ILeafNode) && (matches.apply(((ILeafNode) next))).booleanValue())) {
          return ((ILeafNode) next);
        }
      }
    }
  }
  return ((ILeafNode)_xifexpression);
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:19,代码来源:NodeModelAccess.java


示例15: add

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
protected void add(NodeModelBasedRegionAccess access, INode node) {
	if (node instanceof ILeafNode && ((ILeafNode) node).isHidden()) {
		ILeafNode leafNode = (ILeafNode) node;
		lastHidden.addPart(createHidden(lastHidden, leafNode));
	} else if (node instanceof ICompositeNode || node.getLength() > 0) {
		NodeEObjectRegion eObjectTokens = stack.peek();
		NodeSemanticRegion newSemantic = createSemanticRegion(access, node);
		NodeHiddenRegion newHidden = createHiddenRegion(access);
		newSemantic.setTrailingHiddenRegion(newHidden);
		newHidden.setPrevious(newSemantic);
		newSemantic.setLeadingHiddenRegion(lastHidden);
		lastHidden.setNext(newSemantic);
		eObjectTokens.addChild(newSemantic);
		newSemantic.setEObjectTokens(eObjectTokens);
		lastHidden = newHidden;
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:18,代码来源:NodeModelBasedRegionAccessBuilder.java


示例16: findNext

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
protected Triple<INode, AbstractElement, EObject> findNext(INode node, boolean prune) {
	INode current = next(node, prune);
	while (current != null) {
		if (current instanceof ILeafNode && ((ILeafNode) current).isHidden()) {
			current = next(current, true);
			continue;
		}
		EObject ge = current.getGrammarElement();
		if (ge instanceof AbstractElement && isEObjectNode(current))
			return Tuples.create(current, (AbstractElement) ge, getEObjectNodeEObject(current));
		else if (GrammarUtil.isAssigned(ge) && !GrammarUtil.isEObjectRuleCall(ge)) {
			if (ge instanceof CrossReference)
				return Tuples.create(current, ((CrossReference) ge).getTerminal(), null);
			else
				return Tuples.create(current, (AbstractElement) ge, null);
		} else
			current = next(current, false);
	}
	return null;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:21,代码来源:SemanticNodeIterator.java


示例17: collectImports

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
/**
 * Collects import declarations in XtextResource for the given range (selectedRegion)
 */
public void collectImports(final XtextResource state, final ITextRegion selectedRegion, final ImportsAcceptor acceptor) {
  ICompositeNode rootNode = state.getParseResult().getRootNode();
  final EObject selectedSemanticObj = this.findActualSemanticObjectFor(rootNode, selectedRegion);
  final Iterable<ILeafNode> contentsIterator = NodeModelUtils.findActualNodeFor(selectedSemanticObj).getLeafNodes();
  for (final ILeafNode node : contentsIterator) {
    {
      final ITextRegion nodeRegion = node.getTotalTextRegion();
      boolean _contains = selectedRegion.contains(nodeRegion);
      if (_contains) {
        final EObject semanticElement = node.getSemanticElement();
        if ((semanticElement != null)) {
          this.visit(semanticElement, NodeModelUtils.findActualNodeFor(semanticElement), acceptor);
        }
      }
      if ((node.isHidden() && this.grammarAccess.getML_COMMENTRule().equals(node.getGrammarElement()))) {
        this.addJavaDocReferences(node, selectedRegion, acceptor);
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:24,代码来源:ImportsCollector.java


示例18: getTokenText

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
/**
 * This method converts a node to text.
 * 
 * Leading and trailing text from hidden tokens (whitespace/comments) is removed. Text from hidden tokens that is
 * surrounded by text from non-hidden tokens is summarized to a single whitespace.
 * 
 * The preferred use case of this method is to convert the {@link ICompositeNode} that has been created for a data
 * type rule to text.
 * 
 * This is also the recommended way to convert a node to text if you want to invoke
 * {@link org.eclipse.xtext.conversion.IValueConverterService#toValue(String, String, INode)}
 * 
 */
public static String getTokenText(INode node) {
	if (node instanceof ILeafNode)
		return ((ILeafNode) node).getText();
	else {
		StringBuilder builder = new StringBuilder(Math.max(node.getTotalLength(), 1));
		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();
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:33,代码来源:NodeModelUtils.java


示例19: newLeafNode

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
public ILeafNode newLeafNode(int offset, int length, EObject grammarElement, boolean isHidden, /* @Nullable */ SyntaxErrorMessage errorMessage,
		ICompositeNode parent) {
	LeafNode result = null;
	if (errorMessage != null) {
		if (isHidden) {
			result = new HiddenLeafNodeWithSyntaxError();
			((HiddenLeafNodeWithSyntaxError)result).basicSetSyntaxErrorMessage(errorMessage);
		} else {
			result = new LeafNodeWithSyntaxError();
			((LeafNodeWithSyntaxError)result).basicSetSyntaxErrorMessage(errorMessage);
		}
	} else {
		if (isHidden) {
			result = new HiddenLeafNode();
		} else {
			result = new LeafNode();
		}
	}
	result.basicSetGrammarElement(grammarElement);
	result.basicSetTotalOffset(offset);
	result.basicSetTotalLength(length);
	addChild(parent, result);
	return result;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:25,代码来源:NodeModelBuilder.java


示例20: testPartialParseConcreteRuleFirstToken_01

import org.eclipse.xtext.nodemodel.ILeafNode; //导入依赖的package包/类
@Test public void testPartialParseConcreteRuleFirstToken_01() 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 children = findLeafNodeByText(root, model, "children");
	resource.update(model.indexOf("n {") + 2, 1, "{");
	resource.update(model.indexOf("n {") + 2, 1, "{");
	assertSame(root, resource.getParseResult().getRootNode());
	assertSame(children, findLeafNodeByText(root, model, "children"));
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:17,代码来源:PartialParserTest.java



注:本文中的org.eclipse.xtext.nodemodel.ILeafNode类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java OutputSettings类代码示例发布时间:2022-05-21
下一篇:
Java Jukebox类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap