Search in sources :

Example 6 with PsiCodeBlock

use of com.intellij.psi.PsiCodeBlock 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 7 with PsiCodeBlock

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

the class MissingSwitchBodyFixer method apply.

@Override
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException {
    if (!(psiElement instanceof PsiSwitchStatement))
        return;
    PsiSwitchStatement switchStatement = (PsiSwitchStatement) psiElement;
    final Document doc = editor.getDocument();
    final PsiCodeBlock body = switchStatement.getBody();
    if (body != null)
        return;
    final PsiJavaToken rParenth = switchStatement.getRParenth();
    assert rParenth != null;
    doc.insertString(rParenth.getTextRange().getEndOffset(), "{}");
}
Also used : PsiCodeBlock(com.intellij.psi.PsiCodeBlock) PsiJavaToken(com.intellij.psi.PsiJavaToken) PsiSwitchStatement(com.intellij.psi.PsiSwitchStatement) Document(com.intellij.openapi.editor.Document)

Example 8 with PsiCodeBlock

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

the class JavaSynchronizedUnwrapper method doUnwrap.

@Override
protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException {
    PsiCodeBlock body = ((PsiSynchronizedStatement) element).getBody();
    context.extractFromCodeBlock(body, element);
    context.delete(element);
}
Also used : PsiSynchronizedStatement(com.intellij.psi.PsiSynchronizedStatement) PsiCodeBlock(com.intellij.psi.PsiCodeBlock)

Example 9 with PsiCodeBlock

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

the class DeleteMethodBodyFix method invoke.

@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    final PsiCodeBlock body = myMethod.getBody();
    assert body != null;
    body.delete();
}
Also used : PsiCodeBlock(com.intellij.psi.PsiCodeBlock)

Example 10 with PsiCodeBlock

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

the class ControlFlowTest method testMethodWithOnlyDoWhileStatementHasExitPoints.

public void testMethodWithOnlyDoWhileStatementHasExitPoints() throws Exception {
    configureFromFileText("a.java", "public class Foo {\n" + "  public void foo() {\n" + "    boolean f;\n" + "    do {\n" + "      f = something();\n" + "    } while (f);\n" + "  }\n" + "}");
    final PsiCodeBlock body = ((PsiJavaFile) getFile()).getClasses()[0].getMethods()[0].getBody();
    ControlFlow flow = ControlFlowFactory.getInstance(getProject()).getControlFlow(body, new LocalsControlFlowPolicy(body), false);
    IntArrayList exitPoints = new IntArrayList();
    ControlFlowUtil.findExitPointsAndStatements(flow, 0, flow.getSize() - 1, exitPoints, ControlFlowUtil.DEFAULT_EXIT_STATEMENTS_CLASSES);
    assertEquals(1, exitPoints.size());
}
Also used : PsiCodeBlock(com.intellij.psi.PsiCodeBlock) PsiJavaFile(com.intellij.psi.PsiJavaFile) IntArrayList(com.intellij.util.containers.IntArrayList)

Aggregations

PsiCodeBlock (com.intellij.psi.PsiCodeBlock)10 PsiElement (com.intellij.psi.PsiElement)3 PsiStatement (com.intellij.psi.PsiStatement)2 ASTNode (com.intellij.lang.ASTNode)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 Document (com.intellij.openapi.editor.Document)1 EditorActionHandler (com.intellij.openapi.editor.actionSystem.EditorActionHandler)1 EditorActionManager (com.intellij.openapi.editor.actionSystem.EditorActionManager)1 TextRange (com.intellij.openapi.util.TextRange)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiCallExpression (com.intellij.psi.PsiCallExpression)1 PsiClass (com.intellij.psi.PsiClass)1 PsiExpression (com.intellij.psi.PsiExpression)1 PsiExpressionStatement (com.intellij.psi.PsiExpressionStatement)1 PsiJavaFile (com.intellij.psi.PsiJavaFile)1 PsiJavaToken (com.intellij.psi.PsiJavaToken)1 PsiMethod (com.intellij.psi.PsiMethod)1 PsiSwitchStatement (com.intellij.psi.PsiSwitchStatement)1 PsiSynchronizedStatement (com.intellij.psi.PsiSynchronizedStatement)1 PsiTryStatement (com.intellij.psi.PsiTryStatement)1