本文整理汇总了Java中org.eclipse.xtext.nodemodel.ILeafNode类的典型用法代码示例。如果您正苦于以下问题:Java ILeafNode类的具体用法?Java ILeafNode怎么用?Java ILeafNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ILeafNode类属于org.eclipse.xtext.nodemodel包,在下文中一共展示了ILeafNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
};
}
示例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;
}
示例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);
}
}
}
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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;
}
}