IDEA-92545 (Type maybe weakened does not always work)

This commit is contained in:
Bas Leijdekkers
2013-11-27 20:51:49 +01:00
parent 5558fef7f7
commit 4d5bfb7bdd
3 changed files with 43 additions and 13 deletions
@@ -557,7 +557,7 @@ public class WeakestTypeFinder {
@Nullable
private static PsiClass getVisibleInheritor(@NotNull PsiClass superClass, PsiElement context) {
final Query<PsiClass> search = DirectClassInheritorsSearch.search(superClass, context.getResolveScope());
Project project = superClass.getProject();
final Project project = superClass.getProject();
for (PsiClass aClass : search) {
if (superClass.isInheritor(aClass, true)) {
if (PsiUtil.isAccessible(project, aClass, context, null)) {
@@ -576,21 +576,19 @@ public class WeakestTypeFinder {
return false;
}
boolean shouldAdd = true;
for (Iterator<PsiClass> iterator = weakestTypeClasses.iterator(); iterator.hasNext(); ) {
for (final Iterator<PsiClass> iterator = weakestTypeClasses.iterator(); iterator.hasNext(); ) {
final PsiClass weakestTypeClass = iterator.next();
if (!weakestTypeClass.equals(aClass)) {
if (aClass.isInheritor(weakestTypeClass, true)) {
iterator.remove();
}
else if (weakestTypeClass.isInheritor(aClass, true)) {
shouldAdd = false;
}
else {
iterator.remove();
shouldAdd = false;
}
if (weakestTypeClass.equals(aClass)) {
return true;
}
if (aClass.isInheritor(weakestTypeClass, true)) {
iterator.remove();
}
else if (weakestTypeClass.isInheritor(aClass, true)) {
shouldAdd = false;
}
else {
iterator.remove();
shouldAdd = false;
}
}
@@ -125,4 +125,29 @@ public class TypeMayBeWeakened {
if (ref != null) ref.set(value);
return ref;
}
}
class MyClass {
public MyClass(java.util.Date date, String[] classNames) {}
static MyClass readMyClass(final ObjectInputStream objectInput) {
final long time = objectInput.readLong();
final int size = objectInput.readInt();
final String[] classNames = new String[size];
for (int i = 0; i < size; i++) {
classNames[i] = objectInput.readUTF();
}
return new MyClass(new java.util.Date(time), classNames);
}
}
interface DataInput {
long readLong();
int readInt();
String readUTF();
}
abstract class ObjectInputStream implements DataInput {
public String readUTF() {
return null;
}
}
@@ -22,6 +22,13 @@
<description>Type of variable &lt;code&gt;iaex&lt;/code&gt; may be weakened to 'java.lang.RuntimeException'</description>
</problem>
<problem>
<file>TypeMayBeWeakened.java</file>
<line>133</line>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Type may be weakened</problem_class>
<description>Type of parameter &lt;code&gt;objectInput&lt;/code&gt; may be weakened to 'com.siyeh.igtest.abstraction.weaken_type.DataInput' #loc</description>
</problem>
<problem>
<file>AutoClosableTest.java</file>
<line>34</line>