本文整理匯總了Java中com.intellij.lang.ParserDefinition.getWhitespaceTokens方法的典型用法代碼示例。如果您正苦於以下問題:Java ParserDefinition.getWhitespaceTokens方法的具體用法?Java ParserDefinition.getWhitespaceTokens怎麽用?Java ParserDefinition.getWhitespaceTokens使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.lang.ParserDefinition
的用法示例。
在下文中一共展示了ParserDefinition.getWhitespaceTokens方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: insertWhitespaceIfNeeded
import com.intellij.lang.ParserDefinition; //導入方法依賴的package包/類
private static ASTNode insertWhitespaceIfNeeded(ASTNode anchorNode, final ASTNode elementNode, final ASTNode parentNode,
final ASTNode insertionPlaceNode) throws IncorrectOperationException
{
ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(parentNode.getPsi().getLanguage());
final TokenSet comments = parserDef.getCommentTokens(parentNode.getPsi().getLanguage().getVersions()[0]);
final TokenSet whitespaces = parserDef.getWhitespaceTokens(parentNode.getPsi().getLanguage().getVersions()[0]);
if(anchorNode != null && ((!whitespaces.contains(anchorNode.getElementType()) && !whitespaces.contains(elementNode.getElementType())) ||
comments.contains(anchorNode.getElementType()) ||
comments.contains(elementNode.getElementType()) ||
elementNode.getPsi() instanceof PsiComment))
{
String commentString = " ";
if(comments.contains(anchorNode.getElementType()) ||
comments.contains(elementNode.getElementType()) ||
elementNode.getPsi() instanceof PsiComment)
{
commentString = "\n";
}
final ASTNode wsNode = PsiParserFacade.SERVICE.getInstance(parentNode.getPsi().getProject()).createWhiteSpaceFromText(commentString).getNode();
parentNode.addChild(wsNode, insertionPlaceNode);
anchorNode = wsNode;
}
return anchorNode;
}
示例2: isMinified
import com.intellij.lang.ParserDefinition; //導入方法依賴的package包/類
protected static boolean isMinified(Lexer lexer, ParserDefinition parserDefinition, TokenSet noWSRequireAfterTokenSet) {
int offsetIgnoringComments = 0;
int offsetIgnoringCommentsAndStrings = 0;
int lineLength = 0;
int unneededWhitespaceCount = 0;
IElementType lastTokenType = null;
TokenSet whitespaceTokens = parserDefinition.getWhitespaceTokens();
TokenSet stringLiteralElements = parserDefinition.getStringLiteralElements();
TokenSet commentTokens = parserDefinition.getCommentTokens();
for (IElementType tokenType = lexer.getTokenType(); tokenType != null; lexer.advance(), tokenType = lexer.getTokenType()) {
if (commentTokens.contains(tokenType)) {
lastTokenType = tokenType;
continue;
}
int tokenLength = lexer.getTokenEnd() - lexer.getTokenStart();
offsetIgnoringComments += tokenLength;
if (stringLiteralElements.contains(tokenType)) {
lineLength += tokenLength;
lastTokenType = tokenType;
continue;
}
offsetIgnoringCommentsAndStrings += tokenLength;
if (whitespaceTokens.contains(tokenType)) {
if (!commentTokens.contains(lastTokenType) && tokenLength > 1) {
lexer.advance();
if (lexer.getTokenType() == null) {
// it was last token
break;
} else {
return false;
}
}
if (lexer.getTokenText().contains("\n")) {
if (lineLength > MIN_LINE_LENGTH) {
break;
}
lineLength = 0;
}
if (" ".equals(lexer.getTokenText()) && noWSRequireAfterTokenSet.contains(lastTokenType)) {
unneededWhitespaceCount++;
}
}
else {
lineLength += tokenLength;
}
if (offsetIgnoringComments >= MAX_OFFSET) {
break;
}
lastTokenType = tokenType;
}
return offsetIgnoringComments >= MIN_SIZE &&
(unneededWhitespaceCount + 0.0d) / offsetIgnoringCommentsAndStrings < MAX_UNNEEDED_OFFSET_PERCENTAGE;
}
示例3: 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 lexer Lexer started on content of target file
* @param parserDefinition Parser definition of target language
* @param noWSRequireAfterTokenSet TokenSet of types that doesn't require whitespaces after them.
*/
public static boolean isMinified(Lexer lexer,
ParserDefinition parserDefinition,
TokenSet noWSRequireAfterTokenSet) {
int offsetIgnoringComments = 0;
int offsetIgnoringCommentsAndStrings = 0;
int lineLength = 0;
int unneededWhitespaceCount = 0;
IElementType lastTokenType = null;
TokenSet whitespaceTokens = parserDefinition.getWhitespaceTokens();
TokenSet stringLiteralElements = parserDefinition.getStringLiteralElements();
TokenSet commentTokens = parserDefinition.getCommentTokens();
for (IElementType tokenType = lexer.getTokenType(); tokenType != null; lexer.advance(), tokenType = lexer.getTokenType()) {
if (commentTokens.contains(tokenType)) {
lastTokenType = tokenType;
continue;
}
int tokenLength = lexer.getTokenEnd() - lexer.getTokenStart();
offsetIgnoringComments += tokenLength;
if (stringLiteralElements.contains(tokenType)) {
lineLength += tokenLength;
lastTokenType = tokenType;
continue;
}
offsetIgnoringCommentsAndStrings += tokenLength;
if (whitespaceTokens.contains(tokenType)) {
if (!commentTokens.contains(lastTokenType) && tokenLength > 1) {
return false;
}
if (lexer.getTokenText().contains("\n")) {
if (lineLength > MIN_LINE_LENGTH) {
break;
}
lineLength = 0;
}
if (" ".equals(lexer.getTokenText()) && noWSRequireAfterTokenSet.contains(lastTokenType)) {
unneededWhitespaceCount++;
}
}
else {
lineLength += tokenLength;
}
if (offsetIgnoringComments >= MAX_OFFSET) {
break;
}
lastTokenType = tokenType;
}
return offsetIgnoringComments >= MIN_SIZE && (unneededWhitespaceCount + 0.0d) / offsetIgnoringCommentsAndStrings < MAX_UNNEEDED_OFFSET_PERCENTAGE;
}