use of com.intellij.psi.tree.TokenSet in project intellij-community by JetBrains.
the class ShiftIndentInsideHelper method isComment.
private static boolean isComment(final ASTNode node) {
final PsiElement psiElement = SourceTreeToPsiMap.treeElementToPsi(node);
if (psiElement instanceof PsiComment)
return true;
final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(psiElement.getLanguage());
if (parserDefinition == null)
return false;
final TokenSet commentTokens = parserDefinition.getCommentTokens();
return commentTokens.contains(node.getElementType());
}
use of com.intellij.psi.tree.TokenSet in project intellij-community by JetBrains.
the class PlatformIdTableBuilding method getTodoIndexer.
@Nullable
public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, final VirtualFile virtualFile) {
final DataIndexer<TodoIndexEntry, Integer, FileContent> extIndexer;
if (fileType instanceof SubstitutedFileType && !((SubstitutedFileType) fileType).isSameFileType()) {
SubstitutedFileType sft = (SubstitutedFileType) fileType;
extIndexer = new CompositeTodoIndexer(getTodoIndexer(sft.getOriginalFileType(), virtualFile), getTodoIndexer(sft.getFileType(), virtualFile));
} else {
extIndexer = TodoIndexers.INSTANCE.forFileType(fileType);
}
if (extIndexer != null) {
return extIndexer;
}
if (fileType instanceof LanguageFileType) {
final Language lang = ((LanguageFileType) fileType).getLanguage();
final ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens() : null;
if (commentTokens != null) {
return new TokenSetTodoIndexer(commentTokens, virtualFile);
}
}
if (fileType instanceof CustomSyntaxTableFileType) {
return new TokenSetTodoIndexer(ABSTRACT_FILE_COMMENT_TOKENS, virtualFile);
}
return null;
}
use of com.intellij.psi.tree.TokenSet in project intellij-plugins by JetBrains.
the class OgnlKeywordCompletionContributor method installBooleanNull.
private void installBooleanNull() {
final TokenSet precedingOperators = TokenSet.create(OgnlTypes.EQUAL, OgnlTypes.EQ_KEYWORD, OgnlTypes.NOT_EQUAL, OgnlTypes.NEQ_KEYWORD, OgnlTypes.QUESTION, OgnlTypes.COLON, OgnlTypes.AND_KEYWORD, OgnlTypes.AND_AND, OgnlTypes.OR_KEYWORD, OgnlTypes.OR_OR, OgnlTypes.NEGATE, OgnlTypes.NOT_KEYWORD, OgnlTypes.EQ);
extendKeywordCompletion(psiElement().afterLeaf(psiElement().inside(OgnlExpression.class).withElementType(precedingOperators)), FALSE, TRUE, NULL);
}
use of com.intellij.psi.tree.TokenSet in project intellij-plugins by JetBrains.
the class CucumberStepRenameProcessor method prepareRegexAndGetStaticTexts.
/**
* Wraps all special symbols of regexp with group and cut static text.
* @param source regex to work with
* @return List of strings. The first one is prepared regex, then static elements of the regex
*/
@NotNull
public static List<String> prepareRegexAndGetStaticTexts(@NotNull final String source) {
final ArrayList<String> result = new ArrayList<>();
final StringBuilder preparedRegexp = new StringBuilder();
final RegExpLexer lexer = new RegExpLexer(EnumSet.noneOf(RegExpCapability.class));
lexer.start(source);
IElementType previous = null;
final TokenSet toSkip = TokenSet.create(RegExpTT.CHARACTER, RegExpTT.CARET, RegExpTT.DOLLAR);
StringBuilder currentStaticText = new StringBuilder();
boolean insideAddedGroup = false;
final Stack<IElementType> elementsWaitingToClose = new Stack<>();
while (lexer.getTokenType() != null) {
if (!toSkip.contains(lexer.getTokenType())) {
if (!insideAddedGroup) {
insideAddedGroup = true;
preparedRegexp.append('(');
result.add(currentStaticText.toString());
currentStaticText = new StringBuilder();
}
if (lexer.getTokenType() == RegExpTT.GROUP_BEGIN || lexer.getTokenType() == RegExpTT.NON_CAPT_GROUP) {
elementsWaitingToClose.push(RegExpTT.GROUP_END);
} else if (lexer.getTokenType() == RegExpTT.CLASS_BEGIN) {
elementsWaitingToClose.push(RegExpTT.CLASS_END);
} else if (elementsWaitingToClose.size() > 0 && lexer.getTokenType() == elementsWaitingToClose.peek()) {
elementsWaitingToClose.pop();
}
} else {
if (elementsWaitingToClose.size() == 0) {
if (previous != null && previous != RegExpTT.CHARACTER && insideAddedGroup) {
insideAddedGroup = false;
preparedRegexp.append(')');
}
if (lexer.getTokenType() == RegExpTT.CHARACTER) {
currentStaticText.append(lexer.getTokenText());
}
}
}
preparedRegexp.append(lexer.getTokenText());
if (lexer.getTokenType() == RegExpTT.GROUP_BEGIN) {
//Making all group in the regex non capturing
preparedRegexp.append("?:");
}
previous = lexer.getTokenType();
lexer.advance();
}
if (insideAddedGroup) {
preparedRegexp.append(')');
}
result.add(currentStaticText.toString());
result.add(0, preparedRegexp.toString());
return result;
}
use of com.intellij.psi.tree.TokenSet in project WebStormRequireJsPlugin by Fedott.
the class RequirejsProjectComponent method parsePackages.
private void parsePackages(TreeElement node) {
TokenSet tokenSet = TokenSet.create(JSElementTypes.OBJECT_LITERAL_EXPRESSION, JSElementTypes.LITERAL_EXPRESSION);
TreeElement packageNode = (TreeElement) node.findChildByType(tokenSet);
parsePackage(packageNode);
}
Aggregations