當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。