use of com.intellij.psi.tree.TokenSet in project intellij-community by JetBrains.
the class SpacingBuilder method aroundInside.
public RuleBuilder aroundInside(IElementType token, IElementType parent) {
final TokenSet tokenSet = TokenSet.create(token);
RuleCondition before = new RuleCondition(TokenSet.create(parent), null, tokenSet);
RuleCondition after = new RuleCondition(TokenSet.create(parent), tokenSet, null);
return new RuleBuilder(before, after);
}
use of com.intellij.psi.tree.TokenSet in project intellij-community by JetBrains.
the class AbstractXmlBlock 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 PyUnconditionalStatementPartFixer method doApply.
@Override
public void doApply(@NotNull Editor editor, @NotNull PySmartEnterProcessor processor, @NotNull PyElement psiElement) throws IncorrectOperationException {
if (PyUtil.instanceOf(psiElement, PyElsePart.class, PyTryPart.class, PyFinallyPart.class)) {
final PsiElement colon = PyPsiUtils.getFirstChildOfType(psiElement, PyTokenTypes.COLON);
if (colon == null) {
final TokenSet keywords = TokenSet.create(PyTokenTypes.ELSE_KEYWORD, PyTokenTypes.TRY_KEYWORD, PyTokenTypes.FINALLY_KEYWORD);
final PsiElement keywordToken = PyPsiUtils.getChildByFilter(psiElement, keywords, 0);
editor.getDocument().insertString(sure(keywordToken).getTextRange().getEndOffset(), ":");
}
}
}
use of com.intellij.psi.tree.TokenSet in project kotlin by JetBrains.
the class KotlinParsing method parsePropertyGetterOrSetter.
/*
* getterOrSetter
* : modifiers ("get" | "set")
* :
* ( "get" "(" ")"
* |
* "set" "(" modifiers parameter ")"
* ) functionBody
* ;
*/
@Nullable
private AccessorKind parsePropertyGetterOrSetter(@Nullable AccessorKind notAllowedKind) {
PsiBuilder.Marker getterOrSetter = mark();
parseModifierList(DEFAULT, TokenSet.EMPTY);
AccessorKind accessorKind;
if (at(GET_KEYWORD)) {
accessorKind = AccessorKind.GET;
} else if (at(SET_KEYWORD)) {
accessorKind = AccessorKind.SET;
} else {
getterOrSetter.rollbackTo();
return null;
}
if (accessorKind == notAllowedKind) {
getterOrSetter.rollbackTo();
return null;
}
// GET_KEYWORD or SET_KEYWORD
advance();
if (!at(LPAR)) {
// Account for Jet-114 (val a : int get {...})
TokenSet ACCESSOR_FIRST_OR_PROPERTY_END = TokenSet.orSet(MODIFIER_KEYWORDS, TokenSet.create(AT, GET_KEYWORD, SET_KEYWORD, EOL_OR_SEMICOLON, RBRACE));
if (!atSet(ACCESSOR_FIRST_OR_PROPERTY_END)) {
errorUntil("Accessor body expected", TokenSet.orSet(ACCESSOR_FIRST_OR_PROPERTY_END, TokenSet.create(LBRACE, LPAR, EQ)));
} else {
closeDeclarationWithCommentBinders(getterOrSetter, PROPERTY_ACCESSOR, false);
return accessorKind;
}
}
myBuilder.disableNewlines();
expect(LPAR, "Expecting '('", TokenSet.create(RPAR, IDENTIFIER, COLON, LBRACE, EQ));
if (accessorKind == AccessorKind.SET) {
PsiBuilder.Marker parameterList = mark();
PsiBuilder.Marker setterParameter = mark();
parseModifierList(DEFAULT, TokenSet.create(COMMA, COLON, RPAR));
expect(IDENTIFIER, "Expecting parameter name", TokenSet.create(RPAR, COLON, LBRACE, EQ));
if (at(COLON)) {
// COLON
advance();
parseTypeRef();
}
setterParameter.done(VALUE_PARAMETER);
parameterList.done(VALUE_PARAMETER_LIST);
}
if (!at(RPAR)) {
errorUntil("Expecting ')'", TokenSet.create(RPAR, COLON, LBRACE, RBRACE, EQ, EOL_OR_SEMICOLON));
}
if (at(RPAR)) {
advance();
}
myBuilder.restoreNewlinesState();
if (at(COLON)) {
advance();
parseTypeRef();
}
parseFunctionBody();
closeDeclarationWithCommentBinders(getterOrSetter, PROPERTY_ACCESSOR, false);
return accessorKind;
}
use of com.intellij.psi.tree.TokenSet in project kotlin by JetBrains.
the class KotlinExpressionParsing method parseTry.
/*
* try
* : "try" block catchBlock* finallyBlock?
* ;
* catchBlock
* : "catch" "(" annotations SimpleName ":" userType ")" block
* ;
*
* finallyBlock
* : "finally" block
* ;
*/
private void parseTry() {
assert _at(TRY_KEYWORD);
PsiBuilder.Marker tryExpression = mark();
// TRY_KEYWORD
advance();
myKotlinParsing.parseBlock();
boolean catchOrFinally = false;
while (at(CATCH_KEYWORD)) {
catchOrFinally = true;
PsiBuilder.Marker catchBlock = mark();
// CATCH_KEYWORD
advance();
TokenSet recoverySet = TokenSet.create(LBRACE, RBRACE, FINALLY_KEYWORD, CATCH_KEYWORD);
if (atSet(recoverySet)) {
error("Expecting exception variable declaration");
} else {
PsiBuilder.Marker parameters = mark();
expect(LPAR, "Expecting '('", recoverySet);
if (!atSet(recoverySet)) {
myKotlinParsing.parseValueParameter(/*typeRequired = */
true);
expect(RPAR, "Expecting ')'", recoverySet);
} else {
error("Expecting exception variable declaration");
}
parameters.done(VALUE_PARAMETER_LIST);
}
if (at(LBRACE)) {
myKotlinParsing.parseBlock();
} else {
error("Expecting a block: { ... }");
}
catchBlock.done(CATCH);
}
if (at(FINALLY_KEYWORD)) {
catchOrFinally = true;
PsiBuilder.Marker finallyBlock = mark();
// FINALLY_KEYWORD
advance();
myKotlinParsing.parseBlock();
finallyBlock.done(FINALLY);
}
if (!catchOrFinally) {
error("Expecting 'catch' or 'finally'");
}
tryExpression.done(TRY);
}
Aggregations