本文整理匯總了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);
}
示例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);
}
示例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;
}