當前位置: 首頁>>代碼示例>>Java>>正文


Java ParserDefinition.createLexer方法代碼示例

本文整理匯總了Java中com.intellij.lang.ParserDefinition.createLexer方法的典型用法代碼示例。如果您正苦於以下問題:Java ParserDefinition.createLexer方法的具體用法?Java ParserDefinition.createLexer怎麽用?Java ParserDefinition.createLexer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.lang.ParserDefinition的用法示例。


在下文中一共展示了ParserDefinition.createLexer方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isMinified

import com.intellij.lang.ParserDefinition; //導入方法依賴的package包/類
/**
 * Finds out whether the file minified by using common (not language-specific) heuristics.
 * Can be used for checking of css/less/scss/sass and js files.
 *
 * @param fileContent              target file content
 * @param parserDefinition         Parser definition of target language
 * @param noWSRequireAfterTokenSet TokenSet of types that doesn't require whitespaces after them.
 */
public static boolean isMinified(@NotNull CharSequence fileContent,
                                 @NotNull ParserDefinition parserDefinition,
                                 @NotNull TokenSet noWSRequireAfterTokenSet) {
  Lexer lexer = parserDefinition.createLexer(null);
  lexer.start(fileContent);
  if (!isMinified(lexer, parserDefinition, noWSRequireAfterTokenSet)) {
    return false;
  }
  else if (lexer.getTokenType() == null) {
    // whole file had been considered
    return true;
  }

  int startOffset = fileContent.length() - COUNT_OF_CONSIDERING_CHARACTERS_FROM_END_OF_FILE;
  if (startOffset <= 0) {
    return true;
  }
  lexer.start(fileContent, startOffset, fileContent.length());
  return isMinified(lexer, parserDefinition, noWSRequireAfterTokenSet);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:29,代碼來源:MinifiedFilesUtil.java

示例2: createAST

import com.intellij.lang.ParserDefinition; //導入方法依賴的package包/類
private ASTNode createAST(String text) {
  ParserDefinition definition = new BuildParserDefinition();
  PsiParser parser = definition.createParser(getProject());
  Lexer lexer = definition.createLexer(getProject());
  PsiBuilderImpl psiBuilder =
      new PsiBuilderImpl(
          getProject(), null, definition, lexer, new CharTableImpl(), text, null, null);
  PsiBuilderAdapter adapter =
      new PsiBuilderAdapter(psiBuilder) {
        @Override
        public void error(String messageText) {
          super.error(messageText);
          errors.add(messageText);
        }
      };
  return parser.parse(definition.getFileNodeType(), adapter);
}
 
開發者ID:bazelbuild,項目名稱:intellij,代碼行數:18,代碼來源:BuildParserTest.java

示例3: parseText

import com.intellij.lang.ParserDefinition; //導入方法依賴的package包/類
public static @NotNull <T extends PsiElement> T parseText(
    @NotNull String text,
    @NotNull IElementType rootElementType,
    @NotNull Class<T> rootElementClass,
    @NotNull ParserDefinition parserDefinition,
    @Nullable ErrorProcessor errorProcessor) {

  LanguageParserDefinitions.INSTANCE.addExplicitExtension(
      parserDefinition.getFileNodeType().getLanguage(),
      parserDefinition
  );

  PsiParser parser = parserDefinition.createParser(model.first);
  Lexer lexer = parserDefinition.createLexer(model.first);
  PsiBuilderImpl psiBuilder = new PsiBuilderImpl(
      model.first,
      null,
      parserDefinition,
      lexer,
      new CharTableImpl(),
      text,
      null,
      null
  );

  ASTNode astNode = parser.parse(rootElementType, psiBuilder);
  T res = astNode.getPsi(rootElementClass);
  collectErrors(res, errorProcessor);

  return res;
}
 
開發者ID:SumoLogic,項目名稱:epigraph,代碼行數:32,代碼來源:EpigraphPsiUtil.java


注:本文中的com.intellij.lang.ParserDefinition.createLexer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。