IDEA-19619 (highlight invalid for init statements)

This commit is contained in:
Roman Shevchenko
2013-05-03 18:04:42 +02:00
parent f1f7357ee0
commit b0711041bb
4 changed files with 38 additions and 21 deletions
@@ -2644,6 +2644,19 @@ public class HighlightUtil extends HighlightUtilBase {
return null;
}
@Nullable
static HighlightInfo checkForStatement(@NotNull PsiForStatement statement) {
PsiStatement init = statement.getInitialization();
if (!(init == null || init instanceof PsiEmptyStatement ||
init instanceof PsiDeclarationStatement ||
init instanceof PsiExpressionStatement || init instanceof PsiExpressionListStatement)) {
String message = JavaErrorMessages.message("invalid.statement");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(init).descriptionAndTooltip(message).create();
}
return null;
}
private enum Feature {
GENERICS(LanguageLevel.JDK_1_5, "feature.generics"),
ANNOTATIONS(LanguageLevel.JDK_1_5, "feature.annotations"),
@@ -468,6 +468,11 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
if (!myHolder.hasErrorResults()) myHolder.add(HighlightControlFlowUtil.checkFinalFieldInitialized(field));
}
@Override
public void visitForStatement(PsiForStatement statement) {
myHolder.add(HighlightUtil.checkForStatement(statement));
}
@Override
public void visitForeachStatement(final PsiForeachStatement statement) {
myHolder.add(HighlightUtil.checkForEachFeature(statement));
@@ -217,6 +217,7 @@ modifier.not.allowed=Modifier ''{0}'' not allowed here
exception.never.thrown.try=Exception ''{0}'' is never thrown in the corresponding try block
exception.already.caught.warn=Unreachable section: {1, choice, 0#exception|2#exceptions} ''{0}'' {1, choice, 0#has|2#have} already been caught
not.a.statement=Not a statement
invalid.statement=Invalid statement
incompatible.types=Incompatible types. Found: ''{1}'', required: ''{0}''
valid.switch.selector.types=byte, char, short or int
dot.expected.after.super.or.this='.' expected
@@ -1,54 +1,54 @@
// continue outside of.../loop label
public class a {
class a {
class ff { }
void f() {
<error descr="Continue outside of loop">continue;</error>
while (true) {
continue;
}
do { continue; } while (true);
switch (1) {
case 1: <error descr="Continue outside of loop">continue;</error>
}
for (;;) {
continue;
}
for (;;) {
new ff() {
void f() {
void f() {
<error descr="Continue outside of loop">continue;</error>
}
};
continue;
}
while (true) {
class s {
{
<error descr="Continue outside of loop">continue;</error>
}
{
<error descr="Continue outside of loop">continue;</error>
}
}
continue;
}
do {
class s {
{
<error descr="Continue outside of loop">continue;</error>
}
{
<error descr="Continue outside of loop">continue;</error>
}
}
continue;
} while (true);
a:
if (2==4) {
for (;;) {
<error descr="Not a loop label: 'a'">continue a;</error>
}
for (;;) {
<error descr="Not a loop label: 'a'">continue a;</error>
}
}
a:
@@ -56,12 +56,10 @@ public class a {
for (;;) {
<error descr="Not a loop label: 'a'">continue a;</error>
}
int i = 0;
for (<error descr="Not a statement">i==0?7:8;</error> ; ) ;
for (<error descr="Invalid statement">if (i<0) i++;</error> ; ) ;
for (new ff(), new ff(); ; ) ;
}
}
class ff {
}