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);
}
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;
}
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;
}
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);
}
}
}
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;
}
Aggregations