summaryrefslogtreecommitdiff
path: root/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/ConstantIfStatementInspection.java
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/ConstantIfStatementInspection.java')
-rw-r--r--plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/ConstantIfStatementInspection.java17
1 files changed, 14 insertions, 3 deletions
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/ConstantIfStatementInspection.java b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/ConstantIfStatementInspection.java
index 4e06728a7a75..088dbf977482 100644
--- a/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/ConstantIfStatementInspection.java
+++ b/plugins/InspectionGadgets/src/com/siyeh/ig/controlflow/ConstantIfStatementInspection.java
@@ -119,9 +119,20 @@ public class ConstantIfStatementInspection extends BaseInspection {
final PsiStatement[] statements = block.getStatements();
if (statements.length > 0) {
assert containingElement != null;
- final PsiElement added =
- containingElement.addRangeBefore(statements[0],
- statements[statements.length - 1], statement);
+ final PsiJavaToken lBrace = block.getLBrace();
+ final PsiJavaToken rBrace = block.getRBrace();
+ PsiElement added = null;
+ if (lBrace != null && rBrace != null) {
+ final PsiElement firstNonBrace = lBrace.getNextSibling();
+ final PsiElement lastNonBrace = rBrace.getPrevSibling();
+ if (firstNonBrace != null && lastNonBrace != null) {
+ added = containingElement.addRangeBefore(firstNonBrace, lastNonBrace, statement);
+ }
+ }
+ if (added == null) {
+ added = containingElement.addRangeBefore(statements[0],
+ statements[statements.length - 1], statement);
+ }
final Project project = statement.getProject();
final CodeStyleManager codeStyleManager =
CodeStyleManager.getInstance(project);