mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IG: ignore blocks containing error elements (IDEA-177570)
This commit is contained in:
+6
-1
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.FileTypeUtils;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
@@ -97,7 +98,11 @@ public class SingleStatementInBlockInspection extends BaseInspection {
|
||||
@Override
|
||||
protected boolean isApplicable(PsiStatement body) {
|
||||
if (body instanceof PsiBlockStatement) {
|
||||
final PsiStatement[] statements = ((PsiBlockStatement)body).getCodeBlock().getStatements();
|
||||
final PsiCodeBlock codeBlock = ((PsiBlockStatement)body).getCodeBlock();
|
||||
if (PsiUtilCore.hasErrorElementChild(codeBlock)) {
|
||||
return false;
|
||||
}
|
||||
final PsiStatement[] statements = codeBlock.getStatements();
|
||||
if (statements.length == 1 && !(statements[0] instanceof PsiDeclarationStatement) && !isDanglingElseProblem(statements[0], body)) {
|
||||
final PsiFile file = body.getContainingFile();
|
||||
//this inspection doesn't work in JSP files, as it can't tell about tags
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
class X {
|
||||
public int toIntegerValue() {
|
||||
int result = 0;
|
||||
fo<caret>r (CssPrefix prefix : myEnabledPrefixes) {
|
||||
float (getValue) {
|
||||
result |= prefix.myIntMask;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void anotherMethod() {}
|
||||
}
|
||||
+1
@@ -33,6 +33,7 @@ public class SingleStatementInBlockFixTest extends IGQuickFixesTestCase {
|
||||
public void testWhile() { doTest("while"); }
|
||||
public void testForEach() { doTest("for"); }
|
||||
public void testForIndex() { doTest("for"); }
|
||||
public void testForMalformed() { assertQuickfixNotAvailable(getMessage("for"));}
|
||||
public void testDoWhile() { doTest("do"); }
|
||||
public void testIfWithLoop() { doTest("if"); }
|
||||
public void testElseWithLoop() { doTest("else"); }
|
||||
|
||||
Reference in New Issue
Block a user