Search in sources :

Example 1 with PsiKeyword

use of com.intellij.psi.PsiKeyword in project intellij-community by JetBrains.

the class IfStatementSelectioner method select.

@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
    List<TextRange> result = new ArrayList<>();
    result.addAll(expandToWholeLine(editorText, e.getTextRange(), false));
    PsiIfStatement statement = (PsiIfStatement) e;
    final PsiKeyword elseKeyword = statement.getElseElement();
    if (elseKeyword != null) {
        final PsiStatement then = statement.getThenBranch();
        if (then != null) {
            final TextRange thenRange = new TextRange(statement.getTextRange().getStartOffset(), then.getTextRange().getEndOffset());
            if (thenRange.contains(cursorOffset)) {
                result.addAll(expandToWholeLine(editorText, thenRange, false));
            }
        }
        result.addAll(expandToWholeLine(editorText, new TextRange(elseKeyword.getTextRange().getStartOffset(), statement.getTextRange().getEndOffset()), false));
        final PsiStatement branch = statement.getElseBranch();
        if (branch instanceof PsiIfStatement) {
            PsiIfStatement elseIf = (PsiIfStatement) branch;
            final PsiKeyword element = elseIf.getElseElement();
            if (element != null) {
                final PsiStatement elseThen = elseIf.getThenBranch();
                if (elseThen != null) {
                    result.addAll(expandToWholeLine(editorText, new TextRange(elseKeyword.getTextRange().getStartOffset(), elseThen.getTextRange().getEndOffset()), false));
                }
            }
        }
    }
    return result;
}
Also used : PsiStatement(com.intellij.psi.PsiStatement) PsiIfStatement(com.intellij.psi.PsiIfStatement) ArrayList(java.util.ArrayList) PsiKeyword(com.intellij.psi.PsiKeyword) TextRange(com.intellij.openapi.util.TextRange)

Example 2 with PsiKeyword

use of com.intellij.psi.PsiKeyword in project intellij-community by JetBrains.

the class ThrowsUsageTargetProvider method getTargets.

@Override
@Nullable
public UsageTarget[] getTargets(Editor editor, final PsiFile file) {
    if (editor == null || file == null)
        return null;
    PsiElement element = file.findElementAt(TargetElementUtil.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset()));
    if (element == null)
        return null;
    if (element instanceof PsiKeyword && PsiKeyword.THROWS.equals(element.getText())) {
        return new UsageTarget[] { new PsiElement2UsageTargetAdapter(element) };
    }
    final PsiElement parent = element.getParent();
    if (parent instanceof PsiThrowStatement) {
        return new UsageTarget[] { new PsiElement2UsageTargetAdapter(parent) };
    }
    return null;
}
Also used : PsiThrowStatement(com.intellij.psi.PsiThrowStatement) PsiKeyword(com.intellij.psi.PsiKeyword) PsiElement(com.intellij.psi.PsiElement) UsageTarget(com.intellij.usages.UsageTarget) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with PsiKeyword

use of com.intellij.psi.PsiKeyword in project android by JetBrains.

the class Modifier method ParseModifierList.

public static int ParseModifierList(@NotNull PsiModifierList modList) {
    int modifierBits = Modifier.PRIVATE;
    if (modList != null) {
        for (PsiElement pe : modList.getChildren()) {
            if (pe instanceof PsiKeyword) {
                PsiKeyword curWord = (PsiKeyword) pe;
                if (curWord.textMatches("public")) {
                    modifierBits &= ~0x3;
                    modifierBits |= Modifier.PUBLIC;
                } else if (curWord.textMatches("private")) {
                    modifierBits &= ~0x3;
                    modifierBits |= Modifier.PRIVATE;
                } else if (curWord.textMatches("final")) {
                    modifierBits |= Modifier.FINAL;
                } else if (curWord.textMatches("abstract")) {
                    modifierBits |= Modifier.ABSTRACT;
                } else if (curWord.textMatches("interface")) {
                    modifierBits |= Modifier.INTERFACE;
                } else if (curWord.textMatches("native")) {
                    modifierBits |= Modifier.NATIVE;
                } else if (curWord.textMatches("protected")) {
                    modifierBits &= ~0x3;
                    modifierBits |= Modifier.PROTECTED;
                } else if (curWord.textMatches("static")) {
                    modifierBits |= Modifier.STATIC;
                } else if (curWord.textMatches("synchronized")) {
                    modifierBits |= Modifier.SYNCHRONIZED;
                } else if (curWord.textMatches("transient")) {
                    modifierBits |= Modifier.TRANSIENT;
                } else if (curWord.textMatches("volatile")) {
                    modifierBits |= Modifier.VOLATILE;
                } else if (curWord.textMatches("strictfp")) {
                    modifierBits |= Modifier.STRICTFP;
                } else if (curWord.textMatches("annotation")) {
                    modifierBits |= Modifier.ANNOTATION;
                } else if (curWord.textMatches("enum")) {
                    modifierBits |= Modifier.ENUM;
                }
            }
        }
    }
    return modifierBits;
}
Also used : PsiKeyword(com.intellij.psi.PsiKeyword) PsiElement(com.intellij.psi.PsiElement)

Example 4 with PsiKeyword

use of com.intellij.psi.PsiKeyword in project oxy-template-support-plugin by mutant-industries.

the class GlobalVariableTypeProvider method getTypeFromProvider.

@Nullable
private JSType getTypeFromProvider(@NotNull PsiClass provider) {
    PsiMethod[] provideMethods = provider.findMethodsByName(PROVIDE_METHOD_NAME, true);
    PsiElement elementAt;
    PsiReturnStatement returnStatement;
    if (provideMethods.length < 1 || (returnStatement = PsiTreeUtil.findChildOfType(provideMethods[0], PsiReturnStatement.class)) == null || !((elementAt = returnStatement.getFirstChild()) instanceof PsiKeyword) || !((elementAt = elementAt.getNextSibling()) instanceof PsiWhiteSpace)) {
        return null;
    }
    elementAt = elementAt.getNextSibling();
    if (elementAt instanceof PsiExpression) {
        return InnerJsJavaTypeConverter.getPsiElementJsType(elementAt);
    }
    return null;
}
Also used : PsiExpression(com.intellij.psi.PsiExpression) PsiMethod(com.intellij.psi.PsiMethod) PsiReturnStatement(com.intellij.psi.PsiReturnStatement) PsiKeyword(com.intellij.psi.PsiKeyword) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PsiKeyword (com.intellij.psi.PsiKeyword)4 PsiElement (com.intellij.psi.PsiElement)3 Nullable (org.jetbrains.annotations.Nullable)2 TextRange (com.intellij.openapi.util.TextRange)1 PsiExpression (com.intellij.psi.PsiExpression)1 PsiIfStatement (com.intellij.psi.PsiIfStatement)1 PsiMethod (com.intellij.psi.PsiMethod)1 PsiReturnStatement (com.intellij.psi.PsiReturnStatement)1 PsiStatement (com.intellij.psi.PsiStatement)1 PsiThrowStatement (com.intellij.psi.PsiThrowStatement)1 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)1 UsageTarget (com.intellij.usages.UsageTarget)1 ArrayList (java.util.ArrayList)1