Search in sources :

Example 11 with PsiStatement

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

the class SplitElseIfIntention method processIntention.

public void processIntention(PsiElement element) throws IncorrectOperationException {
    final PsiJavaToken token = (PsiJavaToken) element;
    final PsiIfStatement parentStatement = (PsiIfStatement) token.getParent();
    if (parentStatement == null) {
        return;
    }
    final PsiStatement elseBranch = parentStatement.getElseBranch();
    if (elseBranch == null) {
        return;
    }
    final String newStatement = '{' + elseBranch.getText() + '}';
    PsiReplacementUtil.replaceStatement(elseBranch, newStatement);
}
Also used : PsiStatement(com.intellij.psi.PsiStatement) PsiJavaToken(com.intellij.psi.PsiJavaToken) PsiIfStatement(com.intellij.psi.PsiIfStatement)

Example 12 with PsiStatement

use of com.intellij.psi.PsiStatement in project PermissionsDispatcher by hotchemi.

the class CallOnRequestPermissionsResultDetector method checkMethodCall.

private static boolean checkMethodCall(PsiMethod method, PsiClass psiClass) {
    PsiCodeBlock codeBlock = method.getBody();
    if (codeBlock == null) {
        return false;
    }
    PsiStatement[] statements = codeBlock.getStatements();
    for (PsiStatement statement : statements) {
        if (!(statement instanceof PsiExpressionStatement)) {
            continue;
        }
        PsiExpression expression = ((PsiExpressionStatement) statement).getExpression();
        if (!(expression instanceof PsiCallExpression)) {
            continue;
        }
        PsiCallExpression callExpression = (PsiCallExpression) expression;
        String targetClassName = psiClass.getName() + "PermissionsDispatcher";
        PsiMethod resolveMethod = callExpression.resolveMethod();
        if (resolveMethod == null) {
            continue;
        }
        PsiClass containingClass = resolveMethod.getContainingClass();
        if (containingClass == null) {
            continue;
        }
        if (targetClassName.equals(containingClass.getName()) && "onRequestPermissionsResult".equals(resolveMethod.getName())) {
            return true;
        }
    }
    return false;
}
Also used : PsiStatement(com.intellij.psi.PsiStatement) PsiCodeBlock(com.intellij.psi.PsiCodeBlock) PsiExpressionStatement(com.intellij.psi.PsiExpressionStatement) PsiExpression(com.intellij.psi.PsiExpression) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) PsiCallExpression(com.intellij.psi.PsiCallExpression)

Example 13 with PsiStatement

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

the class JavaSurroundWithStatementRangeAdjuster method adjustSurroundWithRange.

@Nullable
@Override
public TextRange adjustSurroundWithRange(PsiFile file, TextRange selectedRange, boolean hasSelection) {
    if (!hasSelection) {
        int startOffset = selectedRange.getStartOffset();
        int endOffset = selectedRange.getEndOffset();
        if (CodeInsightUtil.findStatementsInRange(file, startOffset, endOffset).length == 0) {
            PsiElement elementAtLineStart = PsiTreeUtil.skipSiblingsForward(file.findElementAt(startOffset), PsiWhiteSpace.class);
            if (elementAtLineStart instanceof PsiStatement) {
                return elementAtLineStart.getTextRange();
            }
        }
    }
    return selectedRange;
}
Also used : PsiStatement(com.intellij.psi.PsiStatement) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with PsiStatement

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

the class MigrateToStreamFix method applyFix.

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    PsiElement element = descriptor.getPsiElement();
    if (element instanceof PsiLoopStatement) {
        PsiLoopStatement loopStatement = (PsiLoopStatement) element;
        StreamSource source = StreamSource.tryCreate(loopStatement);
        PsiStatement body = loopStatement.getBody();
        if (body == null || source == null)
            return;
        TerminalBlock tb = TerminalBlock.from(source, body);
        PsiElement result = myMigration.migrate(project, body, tb);
        if (result != null) {
            tb.operations().forEach(StreamApiMigrationInspection.Operation::cleanUp);
            simplifyAndFormat(project, result);
        }
    }
}
Also used : PsiStatement(com.intellij.psi.PsiStatement) StreamSource(com.intellij.codeInspection.streamMigration.StreamApiMigrationInspection.StreamSource) PsiLoopStatement(com.intellij.psi.PsiLoopStatement) PsiElement(com.intellij.psi.PsiElement)

Example 15 with PsiStatement

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

the class ExtractIncrementPredicate method satisfiedBy.

public boolean satisfiedBy(PsiElement element) {
    if (IncrementUtil.getIncrementOrDecrementOperand(element) == null) {
        return false;
    }
    final PsiElement parent = element.getParent();
    if (parent instanceof PsiExpressionStatement) {
        return false;
    }
    final PsiStatement containingStatement = PsiTreeUtil.getParentOfType(element, PsiStatement.class);
    return containingStatement != null;
}
Also used : PsiStatement(com.intellij.psi.PsiStatement) PsiExpressionStatement(com.intellij.psi.PsiExpressionStatement) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiStatement (com.intellij.psi.PsiStatement)16 PsiElement (com.intellij.psi.PsiElement)9 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)7 PsiExpression (com.intellij.psi.PsiExpression)6 PsiAssignmentExpression (com.intellij.psi.PsiAssignmentExpression)5 PsiDeclarationStatement (com.intellij.psi.PsiDeclarationStatement)5 PsiField (com.intellij.psi.PsiField)5 PsiLocalVariable (com.intellij.psi.PsiLocalVariable)5 PsiReference (com.intellij.psi.PsiReference)5 PsiReferenceExpression (com.intellij.psi.PsiReferenceExpression)5 Nullable (com.android.annotations.Nullable)4 PsiIfStatement (com.intellij.psi.PsiIfStatement)4 PsiMethod (com.intellij.psi.PsiMethod)4 PsiParenthesizedExpression (com.intellij.psi.PsiParenthesizedExpression)4 PsiClass (com.intellij.psi.PsiClass)3 PsiConditionalExpression (com.intellij.psi.PsiConditionalExpression)3 PsiType (com.intellij.psi.PsiType)3 ResourceUrl (com.android.ide.common.resources.ResourceUrl)2 PsiArrayType (com.intellij.psi.PsiArrayType)2 PsiCodeBlock (com.intellij.psi.PsiCodeBlock)2