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


Java Lexer.getTokenText方法代码示例

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


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

示例1: doLexerTest

import com.intellij.lexer.Lexer; //导入方法依赖的package包/类
public static void doLexerTest(String text,
                               Lexer lexer,
                               boolean checkTokenText,
                               String... expectedTokens) {
  lexer.start(text);
  int idx = 0;
  int tokenPos = 0;
  while (lexer.getTokenType() != null) {
    if (idx >= expectedTokens.length) {
      StringBuilder remainingTokens = new StringBuilder("\"" + lexer.getTokenType().toString() + "\"");
      lexer.advance();
      while (lexer.getTokenType() != null) {
        remainingTokens.append(",");
        remainingTokens.append(" \"").append(checkTokenText ? lexer.getTokenText() : lexer.getTokenType().toString()).append("\"");
        lexer.advance();
      }
      fail("Too many tokens. Following tokens: " + remainingTokens.toString());
    }
    assertEquals("Token offset mismatch at position " + idx, tokenPos, lexer.getTokenStart());
    String tokenName = checkTokenText ? lexer.getTokenText() : lexer.getTokenType().toString();
    assertEquals("Token mismatch at position " + idx, expectedTokens[idx], tokenName);
    idx++;
    tokenPos = lexer.getTokenEnd();
    lexer.advance();
  }

  if (idx < expectedTokens.length) fail("Not enough tokens");
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:PyLexerTestCase.java

示例2: replaceImportAliases

import com.intellij.lexer.Lexer; //导入方法依赖的package包/类
private String replaceImportAliases(String type) {
  Map<String, String> lookup = myAliasCache.getValue();
  if (lookup == null || lookup.isEmpty()) {
    return type;
  }
  Lexer lexer = getJavaLexer();
  lexer.start(type);
  boolean checkNext = true;
  StringBuilder out = new StringBuilder();
  IElementType tokenType = lexer.getTokenType();
  while (tokenType != null) {
    if (checkNext && tokenType == JavaTokenType.IDENTIFIER) {
      // this might be something we want to replace
      String tokenText = lexer.getTokenText();
      String replacement = lookup.get(tokenText);
      if (replacement != null) {
        out.append(replacement);
      } else {
        out.append(tokenText);
      }
    } else {
      out.append(lexer.getTokenText());
    }
    if (tokenType != TokenType.WHITE_SPACE) { // ignore spaces
      if (tokenType == JavaTokenType.LT || tokenType == JavaTokenType.COMMA) {
        checkNext = true;
      } else {
        checkNext = false;
      }
    }
    lexer.advance();
    tokenType = lexer.getTokenType();
  }
  return out.toString();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:DataBindingUtil.java

示例3: lookAhead

import com.intellij.lexer.Lexer; //导入方法依赖的package包/类
@Override
protected void lookAhead(Lexer baseLexer) {
  final IElementType type = baseLexer.getTokenType();

  if (type == XPath2TokenTypes.IF) { // "if" / "(" EXPRESSION
    if (replaceTokenNotFollowedBy(baseLexer, XPathTokenTypes.NCNAME, XPathTokenTypes.LPAREN)) {
      return;
    }
  } else if (type == XPathTokenTypes.NCNAME) {
    if (handleNCName(baseLexer, type)) return;
  } else if (type == XPathTokenTypes.RPAREN) {
    if (getState() == _XPathLexer.TYPE) {
      if (!lookingAt(baseLexer, XPath2TokenTypes.OCCURRENCE_OPS)) {
        setState(baseLexer, _XPathLexer.YYINITIAL);
      }
    }
  } else if (type == XPathTokenTypes.AXIS_NAME) {
    if (replaceTokenNotFollowedBy(baseLexer, XPathTokenTypes.NCNAME, XPathTokenTypes.COLCOL)) { // AXIS_NAME / "::"
      setState(baseLexer, _XPathLexer.YYINITIAL);
      return;
    }
  } else if (type == XPathTokenTypes.NODE_TYPE) {
    final String text = baseLexer.getTokenText();
    // NODE_TYPE2
    if ("attribute".equals(text) || "element".equals(text) || "schema-element".equals(text) || "schema-attribute".equals(text) || "document-node".equals(text)) {
      // "attribute::" vs. "attribute("
      if ("attribute".equals(text)) {
        if (replaceTokenFollowedBy(baseLexer, XPathTokenTypes.AXIS_NAME, XPathTokenTypes.COLCOL)) {
          setState(baseLexer, _XPathLexer.S1);
          return;
        }
      }

      if (myXPath2Syntax) {
        if (!replaceTokenNotFollowedBy(baseLexer, XPathTokenTypes.NCNAME, XPathTokenTypes.LPAREN)) {
          advanceAs(baseLexer, type);
        }
      } else {
        handleNCName(baseLexer, XPathTokenTypes.NCNAME);
      }
      return;
    } else if (replaceTokenNotFollowedBy(baseLexer, XPathTokenTypes.NCNAME, XPathTokenTypes.LPAREN)) {
      // other NODE_TYPEs
      setState(baseLexer, _XPathLexer.YYINITIAL);
      return;
    }
  } else if (XPath2TokenTypes.QUANTIFIERS.contains(type) || type == XPath2TokenTypes.FOR) { // ("some" | "every" | "for") / "$" VARNAME
    if (replaceTokenNotFollowedBy(baseLexer, XPathTokenTypes.NCNAME, XPathTokenTypes.DOLLAR)) {
      return;
    }
  }

  advanceAs(baseLexer, type);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:55,代码来源:XPathLexer.java


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