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;
}
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(), "{}");
}
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);
}
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();
}
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());
}
Aggregations