mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Report 191889
This commit is contained in:
+5
-4
@@ -35,14 +35,15 @@ public class RemoveRedundantElseAction extends PsiElementBaseIntentionAction {
|
||||
PsiKeyword.ELSE.equals(element.getText())) {
|
||||
PsiIfStatement ifStatement = (PsiIfStatement)element.getParent();
|
||||
if (ifStatement.getElseBranch() == null) return false;
|
||||
if (ifStatement.getThenBranch() == null) return false;
|
||||
PsiStatement thenBranch = ifStatement.getThenBranch();
|
||||
if (thenBranch == null) return false;
|
||||
PsiElement block = PsiTreeUtil.getParentOfType(ifStatement, PsiCodeBlock.class);
|
||||
if (block != null) {
|
||||
try {
|
||||
ControlFlow controlFlow = ControlFlowFactory.getInstance(project).getControlFlow(block, LocalsOrMyInstanceFieldsControlFlowPolicy.getInstance());
|
||||
int startOffset = controlFlow.getStartOffset(ifStatement.getThenBranch());
|
||||
int endOffset = controlFlow.getEndOffset(ifStatement.getThenBranch());
|
||||
return !ControlFlowUtil.canCompleteNormally(controlFlow, startOffset,endOffset);
|
||||
int startOffset = controlFlow.getStartOffset(thenBranch);
|
||||
int endOffset = controlFlow.getEndOffset(thenBranch);
|
||||
return startOffset != -1 && endOffset != -1 && !ControlFlowUtil.canCompleteNormally(controlFlow, startOffset,endOffset);
|
||||
}
|
||||
catch (AnalysisCanceledException e) {
|
||||
return false;
|
||||
|
||||
@@ -4,19 +4,21 @@
|
||||
package com.intellij.psi.controlFlow;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ControlFlow {
|
||||
ControlFlow EMPTY = new ControlFlowImpl();
|
||||
|
||||
@NotNull
|
||||
List<Instruction> getInstructions();
|
||||
|
||||
int getSize();
|
||||
|
||||
int getStartOffset(PsiElement element);
|
||||
int getStartOffset(@NotNull PsiElement element);
|
||||
|
||||
int getEndOffset(PsiElement element);
|
||||
int getEndOffset(@NotNull PsiElement element);
|
||||
|
||||
PsiElement getElement(int offset);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiStatement;
|
||||
import gnu.trove.TObjectIntHashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -47,6 +48,7 @@ class ControlFlowImpl implements ControlFlow {
|
||||
myElementToEndOffsetMap.put(element, myInstructions.size());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<Instruction> getInstructions() {
|
||||
return myInstructions;
|
||||
}
|
||||
@@ -54,7 +56,7 @@ class ControlFlowImpl implements ControlFlow {
|
||||
return myInstructions.size();
|
||||
}
|
||||
|
||||
public int getStartOffset(PsiElement element) {
|
||||
public int getStartOffset(@NotNull PsiElement element) {
|
||||
int value = myElementToStartOffsetMap.get(element);
|
||||
if (value == 0){
|
||||
if (!myElementToStartOffsetMap.containsKey(element)) return -1;
|
||||
@@ -62,7 +64,7 @@ class ControlFlowImpl implements ControlFlow {
|
||||
return value;
|
||||
}
|
||||
|
||||
public int getEndOffset(PsiElement element) {
|
||||
public int getEndOffset(@NotNull PsiElement element) {
|
||||
int value = myElementToEndOffsetMap.get(element);
|
||||
if (value == 0){
|
||||
if (!myElementToEndOffsetMap.containsKey(element)) return -1;
|
||||
|
||||
@@ -5,6 +5,7 @@ package com.intellij.psi.controlFlow;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -21,6 +22,7 @@ public class ControlFlowSubRange implements ControlFlow {
|
||||
myEnd = end;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<Instruction> getInstructions() {
|
||||
if (myInstructions == null) {
|
||||
final List<Instruction> list = new ArrayList<Instruction>(myEnd - myStart);
|
||||
@@ -59,12 +61,12 @@ public class ControlFlowSubRange implements ControlFlow {
|
||||
return myEnd - myStart;
|
||||
}
|
||||
|
||||
public int getStartOffset(PsiElement element) {
|
||||
public int getStartOffset(@NotNull PsiElement element) {
|
||||
return patchOffset(myControlFlow.getStartOffset(element));
|
||||
//return (myControlFlow.getStartOffset(element));
|
||||
}
|
||||
|
||||
public int getEndOffset(PsiElement element) {
|
||||
public int getEndOffset(@NotNull PsiElement element) {
|
||||
return patchOffset(myControlFlow.getEndOffset(element));
|
||||
//return myControlFlow.getEndOffset(element);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user