From f8e59f5965fac730889b284db2e9a4fdb03fed68 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Wed, 24 Feb 2016 12:28:47 +0100 Subject: [PATCH] not a statement -> declaration not allowed here (IDEA-152090) --- .../codeInsight/daemon/impl/analysis/HighlightUtil.java | 8 +++++++- .../src/messages/JavaErrorMessages.properties | 1 + .../advHighlighting/InvalidExpressions.java | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index 80ce625903ce..f2c5b5139498 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -1391,7 +1391,13 @@ public class HighlightUtil extends HighlightUtilBase { @Nullable static HighlightInfo checkNotAStatement(@NotNull PsiStatement statement) { if (!PsiUtil.isStatement(statement) && !PsiUtilCore.hasErrorElementChild(statement)) { - String description = JavaErrorMessages.message("not.a.statement"); + boolean isDeclarationNotAllowed = false; + if (statement instanceof PsiDeclarationStatement) { + final PsiElement parent = statement.getParent(); + isDeclarationNotAllowed = parent instanceof PsiIfStatement || parent instanceof PsiLoopStatement; + } + + String description = JavaErrorMessages.message(isDeclarationNotAllowed ? "declaration.not.allowed" : "not.a.statement"); return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(statement).descriptionAndTooltip(description).create(); } return null; diff --git a/java/java-psi-impl/src/messages/JavaErrorMessages.properties b/java/java-psi-impl/src/messages/JavaErrorMessages.properties index d03c02b68c72..4befd0929037 100644 --- a/java/java-psi-impl/src/messages/JavaErrorMessages.properties +++ b/java/java-psi-impl/src/messages/JavaErrorMessages.properties @@ -401,3 +401,4 @@ feature.type.annotations=Type annotations feature.type.receivers=Receiver parameters feature.try.with.resources.refs=Resource references insufficient.language.level={0} are not supported at this language level +declaration.not.allowed=Declaration not allowed here diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InvalidExpressions.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InvalidExpressions.java index 79ab2bdd2748..abff05e7ed60 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InvalidExpressions.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InvalidExpressions.java @@ -16,9 +16,9 @@ public class a12 { new int[]{1}; new String[]{new String()}; if (i==1) - String s00 = ""; + String s00 = ""; for (;;) - String s01 = ""; + String s01 = ""; for (1==2,i=3; i<3; !(1==2));