当前位置: 首页>>代码示例>>Java>>正文


Java ILeafNode.getGrammarElement方法代码示例

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


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

示例1: checkNoJavaStyleTypeCasting

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
protected void checkNoJavaStyleTypeCasting(INode node) {
	BidiTreeIterator<INode> iterator = node.getAsTreeIterable().reverse().iterator();
	ILeafNode child = getFirstLeafNode(iterator);
	if (child != null && child.getGrammarElement() == grammarAccess.getXParenthesizedExpressionAccess().getRightParenthesisKeyword_2()) {
		INode expressionNode = getNode(iterator, grammarAccess.getXParenthesizedExpressionAccess().getXExpressionParserRuleCall_1());
		EObject semanticObject = NodeModelUtils.findActualSemanticObjectFor(expressionNode);
		if (semanticObject instanceof XFeatureCall || semanticObject instanceof XMemberFeatureCall) {
			XAbstractFeatureCall featureCall = (XAbstractFeatureCall) semanticObject;
			if (featureCall.isTypeLiteral()) {
				ICompositeNode parenthesizedNode = child.getParent();
				ITextRegion parenthesizedRegion = parenthesizedNode.getTextRegion();
				addIssue("Use 'as' keyword for type casting.", featureCall, parenthesizedRegion.getOffset(), parenthesizedRegion.getLength(), JAVA_STYLE_TYPE_CAST);
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:17,代码来源:XbaseValidator.java

示例2: getLinkedMetaModel

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
private List<EObject> getLinkedMetaModel(TypeRef context, EReference ref, ILeafNode text) throws IllegalNodeException {
	final ICompositeNode parentNode = text.getParent();
	BidiIterator<INode> iterator = parentNode.getChildren().iterator();
	while(iterator.hasPrevious()) {
		INode child = iterator.previous();
		if (child instanceof ILeafNode) {
			ILeafNode leaf = (ILeafNode) child;
			if (text == leaf)
				return super.getLinkedObjects(context, ref, text);
			if (!(leaf.getGrammarElement() instanceof Keyword) && !leaf.isHidden()) {
				IScope scope = getScope(context, ref);
				return XtextMetamodelReferenceHelper.findBestMetamodelForType(
						context, text.getText(), leaf.getText(), scope);
			}
		}
	}
	return Collections.emptyList();
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:19,代码来源:XtextLinkingService.java

示例3: getFileHeaderNodes

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
/**
 * Returns the first non-whitespace leaf node in the file if it is a multi-line comment node.
 * 
 * @since 2.3
 * @return a list with exactly one node or an empty list if there is no header is undocumented.
 */
/* @NonNull */
@Override
public List<INode> getFileHeaderNodes(Resource resource) {
	if (resource instanceof XtextResource) {
		IParseResult parseResult = ((XtextResource) resource).getParseResult();
		if(parseResult != null) {
			for(ILeafNode leafNode: parseResult.getRootNode().getLeafNodes()) {
				EObject grammarElement = leafNode.getGrammarElement();
				if(grammarElement instanceof TerminalRule) {
					String terminalRuleName = ((TerminalRule) grammarElement).getName();
					if (ruleName.equalsIgnoreCase(terminalRuleName)) {
						return singletonList((INode) leafNode);
					} else if(wsRuleName.equals(terminalRuleName)) {
						continue;
					}
				}
				break;
			}
		}
	}
	return Collections.emptyList();
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:29,代码来源:MultiLineFileHeaderProvider.java

示例4: getDocumentationNodes

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
/**
 * Returns the nearest multi line comment node that precedes the given object. 
 * @since 2.3
 * @return a list with exactly one node or an empty list if the object is undocumented.
 */
/* @NonNull */
@Override
public List<INode> getDocumentationNodes(/* @NonNull */ EObject object) {
	ICompositeNode node = NodeModelUtils.getNode(object);
	List<INode> result = Collections.emptyList();
	if (node != null) {
		// get the last multi line comment before a non hidden leaf node
		for (ILeafNode leafNode : node.getLeafNodes()) {
			if (!leafNode.isHidden())
				break;
			if (leafNode.getGrammarElement() instanceof TerminalRule
					&& ruleName.equalsIgnoreCase(((TerminalRule) leafNode.getGrammarElement()).getName())) {
				String comment = leafNode.getText();
				if (commentStartTagRegex.matcher(comment).matches()) {
					result = Collections.<INode>singletonList(leafNode);
				}
			}
		}
	}
	return result;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:27,代码来源:MultiLineCommentDocumentationProvider.java

示例5: 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

示例6: highlightSpecialIdentifiers

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
@Override
protected void highlightSpecialIdentifiers(final IHighlightedPositionAcceptor acceptor, final ICompositeNode root) {
  TerminalRule idRule = grammarAccess.getIDRule();

  for (ILeafNode leaf : root.getLeafNodes()) {
    if (commentProvider.isJavaDocComment(leaf)) {
      // not really a special identifier, but we don't want to iterate over the leaf nodes twice, do we?
      acceptor.addPosition(leaf.getOffset(), leaf.getLength(), CheckHighlightingConfiguration.JAVADOC_ID);
    } else if (!leaf.isHidden()) {
      if (leaf.getGrammarElement() instanceof Keyword) {
        // Check if it is a keyword used as an identifier.
        ParserRule rule = GrammarUtil.containingParserRule(leaf.getGrammarElement());
        if (FEATURE_CALL_ID_RULE_NAME.equals(rule.getName())) {
          acceptor.addPosition(leaf.getOffset(), leaf.getLength(), DefaultHighlightingConfiguration.DEFAULT_ID);
        }
      } else {
        highlightSpecialIdentifiers(leaf, acceptor, idRule);
      }
    }
  }
}
 
开发者ID:dsldevkit,项目名称:dsl-devkit,代码行数:22,代码来源:CheckHighlightingCalculator.java

示例7: getInternalTokenType

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
/**
 * Converts a leaf node an Antlr token type (int).
 */
public int getInternalTokenType(ILeafNode leafNode) {
	EObject grammarElement = leafNode.getGrammarElement();
	if (grammarElement != null) {
		return getInternalTokenType(grammarElement);
	}
	String text = leafNode.getText();
	Integer type = tokenTypes.get("'" + text + "'");
	if (type != null) {
		return type;
	}
	throw new IllegalArgumentException(text);
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:16,代码来源:ContentAssistTokenTypeMapper.java

示例8: getDocumentation

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
private String getDocumentation(/* @NonNull */EObject object) {
	if (object.eContainer() == null) {
		// if a comment is at the beginning of the file it will be returned for
		// the root element (e.g. Script in N4JS) as well -> avoid this!
		return null;
	}

	ICompositeNode node = NodeModelUtils.getNode(object);
	if (node != null) {
		// get the last multi line comment before a non hidden leaf node
		for (ILeafNode leafNode : node.getLeafNodes()) {
			if (!leafNode.isHidden())
				break;

			EObject grammarElem = leafNode.getGrammarElement();
			if (grammarElem instanceof TerminalRule
					&& "ML_COMMENT".equalsIgnoreCase(((TerminalRule) grammarElem).getName())) {

				String comment = leafNode.getText();
				if (commentStartTagRegex.matcher(comment).matches()) {
					return leafNode.getText();
				}
			}
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:28,代码来源:ASTGraphProvider.java

示例9: filterLeafsWithKeywordInsteadOfComma

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
/**
 * Returns nodes which represent keywords and specified in keywords.
 *
 * @param keywords
 *            keywords in natural order used in Arrays#s
 */
protected List<ILeafNode> filterLeafsWithKeywordInsteadOfComma(EObject semanticElement, String stopAtKeyword,
		ICompositeNode node,
		final String... keywords) {
	List<ILeafNode> filteredLeaves = null;
	for (BidiTreeIterator<INode> iter = node.getAsTreeIterable().iterator(); iter.hasNext();) {
		INode child = iter.next();
		EObject childSemElement = child.getSemanticElement();
		if (child != node && childSemElement != null && childSemElement != semanticElement) {
			iter.prune();
		} else if (child instanceof ILeafNode) {
			ILeafNode leaf = (ILeafNode) child;
			EObject grammarElement = leaf.getGrammarElement();
			if (grammarElement instanceof Keyword) {
				String value = ((Keyword) grammarElement).getValue();
				if (stopAtKeyword.equals(value)) {
					break;
				}
				if (Arrays.binarySearch(keywords, value) >= 0) {
					if (grammarElement.eContainer() instanceof Alternatives) {
						AbstractElement first = ((Alternatives) (grammarElement.eContainer())).getElements().get(0);
						boolean inCommaAlternative = (first instanceof Keyword && ",".equals(((Keyword) first)
								.getValue()));
						if (inCommaAlternative) {
							if (filteredLeaves == null) {
								filteredLeaves = new ArrayList<>(5);
							}
							filteredLeaves.add(leaf);
						}
					}
				}
			}
		}
	}
	return filteredLeaves == null ? Collections.emptyList() : filteredLeaves;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:42,代码来源:N4JSSyntaxValidator.java

示例10: highlightSpecialIdentifiers

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
protected void highlightSpecialIdentifiers(ILeafNode leafNode, IHighlightedPositionAcceptor acceptor,
		TerminalRule idRule) {
	ITextRegion leafRegion = leafNode.getTextRegion();
	if (idLengthsToHighlight.get(leafRegion.getLength())) {
		EObject element = leafNode.getGrammarElement();
		if (element == idRule || (element instanceof RuleCall && ((RuleCall) element).getRule() == idRule)) {
			String text = leafNode.getText();
			String highlightingID = highlightedIdentifiers.get(text);
			if (highlightingID != null) {
				acceptor.addPosition(leafRegion.getOffset(), leafRegion.getLength(), highlightingID);
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:15,代码来源:XbaseHighlightingCalculator.java

示例11: getLiteral

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
protected Keyword getLiteral(INode node) {
	if (node != null) {
		for(ILeafNode leaf: node.getLeafNodes()) {
			if (leaf.getGrammarElement() instanceof EnumLiteralDeclaration)
				return ((EnumLiteralDeclaration) leaf.getGrammarElement()).getLiteral();
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:10,代码来源:EnumLiteralSerializer.java

示例12: toValue

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
@Override
public String toValue(String string, INode node) throws ValueConverterException {
	StringBuilder buffer = new StringBuilder();
	boolean isFirst = true;
	if (node != null) {
		for(ILeafNode leafNode: node.getLeafNodes()) {
			EObject grammarElement = leafNode.getGrammarElement();
			if (isDelegateRuleCall(grammarElement) || isWildcardLiteral(grammarElement)) {
				if (!isFirst)
					buffer.append(getValueNamespaceDelimiter());
				isFirst = false;
				if (isDelegateRuleCall(grammarElement))
					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();
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:32,代码来源:QualifiedNameValueConverter.java

示例13: getLiteral

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
protected Keyword getLiteral(INode node) {
	if (node != null) {
		for (ILeafNode leaf : node.getLeafNodes()) {
			if (leaf.getGrammarElement() instanceof EnumLiteralDeclaration)
				return ((EnumLiteralDeclaration) leaf.getGrammarElement()).getLiteral();
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:10,代码来源:EnumLiteralSerializer.java

示例14: canContainTaskTags

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
protected boolean canContainTaskTags(final ILeafNode node) {
  final EObject rule = node.getGrammarElement();
  if ((rule instanceof AbstractRule)) {
    return this.hiddenTokenHelper.isComment(((AbstractRule)rule));
  }
  return false;
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:8,代码来源:DefaultTaskFinder.java

示例15: doFindLeafWithKeyword

import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
/**
 * Returns the first keyword with the given value, or null if no such keyword is found.
 */
private ILeafNode doFindLeafWithKeyword(EObject semanticElement, String stopAtKeyword, ICompositeNode node,
		String keyWord,
		boolean commaAlternative, int hitNumber) {
	EObject grammarElement;
	int foundHits = 0;

	for (BidiTreeIterator<INode> iter = node.getAsTreeIterable().iterator(); iter.hasNext();) {
		INode child = iter.next();
		EObject childSemElement = child.getSemanticElement();
		if (child != node && childSemElement != null && childSemElement != semanticElement) {
			iter.prune();
		} else if (child instanceof ILeafNode) {
			ILeafNode leaf = (ILeafNode) child;
			grammarElement = leaf.getGrammarElement();
			if (grammarElement instanceof Keyword) {
				String value = ((Keyword) grammarElement).getValue();
				if (stopAtKeyword.equals(value)) {
					return null;
				}
				if (keyWord.equals(value)) {
					if (grammarElement.eContainer() instanceof Alternatives) {
						AbstractElement first = ((Alternatives) (grammarElement.eContainer())).getElements().get(0);
						boolean inCommaAlternative = (first instanceof Keyword && ",".equals(((Keyword) first)
								.getValue()));
						if (inCommaAlternative == commaAlternative) {
							foundHits++;
							if (foundHits >= hitNumber) {
								return leaf;
							}
						}
					} else {
						if (!commaAlternative) {
							foundHits++;
							if (foundHits >= hitNumber) {
								return leaf;
							}
						}
					}
				}
			}
		}
	}
	return null;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:48,代码来源:N4JSSyntaxValidator.java


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