本文整理汇总了Java中org.eclipse.xtext.nodemodel.ILeafNode.getText方法的典型用法代码示例。如果您正苦于以下问题:Java ILeafNode.getText方法的具体用法?Java ILeafNode.getText怎么用?Java ILeafNode.getText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.xtext.nodemodel.ILeafNode
的用法示例。
在下文中一共展示了ILeafNode.getText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getErrorName
import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
private QualifiedName getErrorName(INode errorNode) {
List<String> segments = Lists.newArrayListWithCapacity(4);
for(ILeafNode leaf: errorNode.getLeafNodes()) {
if (!leaf.isHidden()) {
String text = leaf.getText();
// XParenthesizedExpression
if (text.equals("(") || text.equals(")")) {
continue;
}
if (!text.equals(".") && !text.equals("::")) {
if (text.charAt(0) == '^')
segments.add(text.substring(1));
else
segments.add(text);
}
}
}
return QualifiedName.create(segments);
}
示例2: 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;
}
示例3: 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;
}
示例4: 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);
}
示例5: nextToken
import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
/**
* Implementation of the {@link TokenSource} interface. Return new tokens as long as there are some, afterwards
* return {@link Token#EOF_TOKEN}.
*/
@Override
public Token nextToken() {
if (next != null) {
Token result = next;
next = null;
return result;
}
if (!leafNodes.hasNext()) {
return Token.EOF_TOKEN;
}
ILeafNode leaf = leafNodes.next();
if (leaf.getTotalOffset() >= endOffset) {
leafNodes = Iterators.emptyIterator();
return Token.EOF_TOKEN;
}
if (leaf.getTotalEndOffset() <= startOffset) {
return nextToken();
}
if (leaf.getTotalEndOffset() > endOffset) {
return toPrefixToken(leaf);
}
SyntaxErrorMessage syntaxErrorMessage = leaf.getSyntaxErrorMessage();
if (syntaxErrorMessage != null && SEMICOLON_INSERTED.equals(syntaxErrorMessage.getIssueCode())) {
return toASIToken(leaf);
}
if (leaf.isHidden()) {
return processHiddenToken(leaf);
}
int tokenType = tokenTypeMapper.getInternalTokenType(leaf);
return new CommonToken(tokenType, leaf.getText());
}
示例6: processHiddenToken
import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
/**
* Skips the given leaf as it's hidden. If it was the last token to be returned, a hidden token may be syntesized if
* would affect the semicolon insertion.
*/
private Token processHiddenToken(ILeafNode leaf) {
Token result = nextToken();
if (result == Token.EOF_TOKEN && Strings.countLineBreaks(leaf.getText()) > 0) {
next = result;
CommonToken hidden = new CommonToken(tokenTypeMapper.getInternalTokenType(leaf), leaf.getText());
hidden.setChannel(Token.HIDDEN_CHANNEL);
return hidden;
}
return result;
}
示例7: toPrefixToken
import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
/**
* Produce an Antlr token for the prefix of the given leaf that overlaps the requested region
*
* @see #endOffset
*/
private Token toPrefixToken(ILeafNode leaf) {
Lexer lexer = new InternalN4JSLexer();
String text = leaf.getText();
String prefix = text.substring(0, endOffset - leaf.getTotalOffset());
ANTLRStringStream stream = new ANTLRStringStream(prefix);
lexer.setCharStream(stream);
Token nextToken = lexer.nextToken();
// copy to get rid of the reference to the stream again
return new CommonToken(nextToken.getType(), nextToken.getText());
}
示例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;
}
示例9: getTypeNameSegmentsFromConcreteSyntax
import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
protected List<String> getTypeNameSegmentsFromConcreteSyntax(List<INode> nodes, boolean staticNotation) {
List<String> result = null;
for(INode node: nodes) {
for(ILeafNode leaf: node.getLeafNodes()) {
if (!leaf.isHidden()) {
String text = leaf.getText();
// XParenthesizedExpression
if (text.equals("(") || text.equals(")")) {
return null;
}
if (text.equals(".")) {
if (staticNotation) {
return null;
}
}
if (text.equals("::")) {
if (!staticNotation) {
return null;
}
}
if (!text.equals(".") && !text.equals("::")) {
if (result == null) {
result = Lists.newArrayListWithCapacity(4);
}
if (text.charAt(0) == '^') {
result.add(text.substring(1));
} else {
result.add(text);
}
}
}
}
}
return result;
}
示例10: toString
import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
@Override
public String toString() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("WS: \"");
ILeafNode _node = this.getNode();
String _text = null;
if (_node!=null) {
_text=_node.getText();
}
_builder.append(_text);
_builder.append("\"");
_builder.newLineIfNotEmpty();
return _builder.toString();
}
示例11: 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);
}
}
}
}
示例12: isComment
import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
protected boolean isComment(ILeafNode leaf) {
String text = leaf.getText();
for (int i = 0; i < text.length(); i++)
if (!Character.isWhitespace(text.charAt(i)))
return true;
return false;
}
示例13: newSemicolonToken
import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
/**
* Creates a new semicolon token with the text of the given leaf. It is put on the default channel.
*/
private Token newSemicolonToken(ILeafNode leaf) {
int tokenType = tokenTypeMapper.getInternalTokenType(semicolon);
return new CommonToken(tokenType, leaf.getText());
}
示例14: computeRegions
import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
/**
* Computes regions between a given string to search and different ends searched by their precedence
*
* @param regions - List to put new regions in
* @param leafNodes - nodes to search in
* @param toSearch - String to search
* @param ends - ends in decreasing precedence
* @since 2.6
*/
protected void computeRegions(List<ReplaceRegion> regions, Iterable<ILeafNode> leafNodes, String toSearch, String... ends) {
for (ILeafNode leafNode : leafNodes) {
String text = leafNode.getText();
int offset = leafNode.getOffset();
int position = text.indexOf(toSearch);
int textLength = text.length();
while (position != -1) {
int beginIndex = position + toSearch.length();
// Skip leading whitespaces
if(Character.isWhitespace(text.charAt(beginIndex))){
while(beginIndex < textLength && Character.isWhitespace(text.charAt(beginIndex))){
beginIndex ++;
}
}
int endIndex = -1;
for (int i = ends.length -1; i >= 0; i--) {
String end = ends[i];
int endCandidate = text.indexOf(end, beginIndex);
if (endCandidate != -1) {
if (endIndex == -1) {
endIndex = endCandidate;
} else {
if (endIndex > endCandidate) {
endIndex = endCandidate;
}
}
}
}
if (endIndex == -1) {
break;
} else {
String simpleName = text.substring(beginIndex, endIndex).replaceAll(" ", "");
if(simpleName.length() > 0 && simpleName.matches("[0-9a-zA-Z\\.\\$_]*")){
ReplaceRegion region = new ReplaceRegion(offset + beginIndex, simpleName.length(), simpleName);
regions.add(region);
}
}
position = text.indexOf(toSearch, endIndex);
}
}
}
示例15: addComment
import org.eclipse.xtext.nodemodel.ILeafNode; //导入方法依赖的package包/类
/**
* Add a comment for a given node (if applicable).
*
* @param builder
* add comments to this
* @param node
* the node read comments from
* @param contextEndLine
* the end line (number) of the root object, used for line number comparison
*/
private void addComment(final StringBuilder builder, final ILeafNode node, final int contextEndLine) {
if (node.getGrammarElement() instanceof TerminalRule && ruleName.equals(((TerminalRule) node.getGrammarElement()).getName())
&& node.getStartLine() == contextEndLine) {
final String comment = node.getText();
if (getCommentPattern().matcher(comment).matches()) {
builder.append(comment);
}
}
}