not a statement -> declaration not allowed here (IDEA-152090)

This commit is contained in:
Anna Kozlova
2016-02-24 13:12:24 +01:00
parent 439cac6bcb
commit f8e59f5965
3 changed files with 10 additions and 3 deletions
@@ -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;
@@ -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
@@ -16,9 +16,9 @@ public class a12 {
<error descr="Not a statement">new int[]{1};</error>
<error descr="Not a statement">new String[]{new String()};</error>
if (i==1)
<error descr="Not a statement">String s00 = "";</error>
<error descr="Declaration not allowed here">String s00 = "";</error>
for (;;)
<error descr="Not a statement">String s01 = "";</error>
<error descr="Declaration not allowed here">String s01 = "";</error>
for (<error descr="Not a statement">1==2,i=3;</error> i<3; <error descr="Not a statement">!(1==2)</error>);