EA-47838 (CCE: ForCanBeForeachInspection$ForCanBeForeachFix.createArrayIterationText)

This commit is contained in:
Bas Leijdekkers
2013-07-17 22:50:06 +02:00
parent 20a31e3918
commit 8088237a11
2 changed files with 16 additions and 5 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -522,10 +522,11 @@ public class ForCanBeForeachInspection extends BaseInspection {
return null;
}
}
final PsiArrayType arrayType = (PsiArrayType)arrayReference.getType();
if (arrayType == null) {
final PsiType type = arrayReference.getType();
if (!(type instanceof PsiArrayType)) {
return null;
}
final PsiArrayType arrayType = (PsiArrayType)type;
final PsiType componentType = arrayType.getComponentType();
final String typeText = componentType.getCanonicalText();
final PsiElement target = arrayReference.resolve();
@@ -1067,8 +1068,7 @@ public class ForCanBeForeachInspection extends BaseInspection {
if (initialValue == null) {
return false;
}
final Object constant =
ExpressionUtils.computeConstantExpression(initialValue);
final Object constant = ExpressionUtils.computeConstantExpression(initialValue);
if (!(constant instanceof Integer)) {
return false;
}
@@ -1085,6 +1085,9 @@ public class ForCanBeForeachInspection extends BaseInspection {
if (arrayReference == null) {
return false;
}
if (!(arrayReference.getType() instanceof PsiArrayType)) {
return false;
}
final PsiElement element = arrayReference.resolve();
if (!(element instanceof PsiVariable)) {
return false;
@@ -267,4 +267,12 @@ public class ForCanBeForEach {
System.out.println(j);
}
}
class X<T> {
void m(T ts) {
for (int i = 0; i < ts.length; i++) {
System.out.println();
}
}
}
}