TextRange (boolean shouldWarn, PsiStatement statement, boolean isOnTheFly) { boolean wholeStatement = isOnTheFly && (!shouldWarn || InspectionProjectProfileManager.isInformationLevel(SHORT_NAME, statement)); if (statement instanceof PsiForeachStatement) { PsiJavaToken rParenth = ((PsiForeachStatement)statement).getRParenth(); if (wholeStatement && rParenth != null) { return new TextRange(statement.getTextOffset(), rParenth.getTextOffset() + 1); } PsiExpression iteratedValue = ((PsiForeachStatement)statement).getIteratedValue(); LOG.assertTrue(iteratedValue != null); return iteratedValue.getTextRange(); } else if (statement instanceof PsiForStatement) { PsiJavaToken rParenth = ((PsiForStatement)statement).getRParenth(); if (wholeStatement && rParenth != null) { return new TextRange(statement.getTextOffset(), rParenth.getTextOffset() + 1); } PsiStatement initialization = ((PsiForStatement)statement).getInitialization(); LOG.assertTrue(initialization != null); return initialization.getTextRange(); } else if (statement instanceof PsiWhileStatement) { PsiJavaToken rParenth = ((PsiWhileStatement)statement).getRParenth(); if (wholeStatement && rParenth != null) { return new TextRange(statement.getTextOffset(), rParenth.getTextOffset() + 1); } return statement.getFirstChild().getTextRange(); } else { throw new IllegalStateException("Unexpected statement type: " + statement); } }