summaryrefslogtreecommitdiff
path: root/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2014-08-19 22:27:03 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-08-19 21:25:05 +0000
commit4ca751c002784c4bfd349cc5240b045b62277c80 (patch)
treedfc17b31990e2429535609b85f6d080c4fa0d9fe /plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java
parent890d9a2952301682ffecaed4495f5f65c84c3642 (diff)
parent060e58b3afea3ea39f5ba1cb5a443ca3ebda28c8 (diff)
downloadidea-4ca751c002784c4bfd349cc5240b045b62277c80.tar.gz
Merge "Merge remote-tracking branch 'aosp/upstream-master' into merge"
Diffstat (limited to 'plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java')
-rw-r--r--plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java37
1 files changed, 19 insertions, 18 deletions
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java
index 1440c58e5113..aade5a56361f 100644
--- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/WeakestTypeFinder.java
@@ -132,7 +132,7 @@ public class WeakestTypeFinder {
else if (referenceParent instanceof PsiVariable) {
final PsiVariable variable = (PsiVariable)referenceParent;
final PsiType type = variable.getType();
- if (!checkType(type, weakestTypeClasses)) {
+ if (!type.isAssignableFrom(variableOrMethodType) || !checkType(type, weakestTypeClasses)) {
return Collections.emptyList();
}
}
@@ -251,7 +251,7 @@ public class WeakestTypeFinder {
if (!hasUsages) {
return Collections.emptyList();
}
- weakestTypeClasses = filterAccessibleClasses(weakestTypeClasses, variableOrMethod);
+ weakestTypeClasses = filterAccessibleClasses(weakestTypeClasses, variableOrMethodClass, variableOrMethod);
return weakestTypeClasses;
}
@@ -442,22 +442,23 @@ public class WeakestTypeFinder {
}
final PsiExpression lhs = assignmentExpression.getLExpression();
final PsiExpression rhs = assignmentExpression.getRExpression();
+ if (rhs == null) {
+ return false;
+ }
final PsiType lhsType = lhs.getType();
+ final PsiType rhsType = rhs.getType();
+ if (lhsType == null || rhsType == null || !lhsType.isAssignableFrom(rhsType)) {
+ return false;
+ }
if (referenceElement.equals(rhs)) {
if (!checkType(lhsType, weakestTypeClasses)) {
return false;
}
}
- else if (useRighthandTypeAsWeakestTypeInAssignments) {
- if (rhs == null) {
- return false;
- }
- if (!(rhs instanceof PsiNewExpression) || !(rhs instanceof PsiTypeCastExpression)) {
- final PsiType rhsType = rhs.getType();
- if (lhsType == null || lhsType.equals(rhsType)) {
- return false;
- }
- }
+ else if (useRighthandTypeAsWeakestTypeInAssignments &&
+ (!(rhs instanceof PsiNewExpression) || !(rhs instanceof PsiTypeCastExpression)) &&
+ lhsType.equals(rhsType)) {
+ return false;
}
return true;
}
@@ -546,14 +547,14 @@ public class WeakestTypeFinder {
return true;
}
- public static Set<PsiClass> filterAccessibleClasses(Set<PsiClass> weakestTypeClasses, PsiElement context) {
+ public static Set<PsiClass> filterAccessibleClasses(Set<PsiClass> weakestTypeClasses, PsiClass upperBound, PsiElement context) {
final Set<PsiClass> result = new HashSet<PsiClass>();
for (PsiClass weakestTypeClass : weakestTypeClasses) {
- if (PsiUtil.isAccessible(weakestTypeClass, context, null)) {
+ if (PsiUtil.isAccessible(weakestTypeClass, context, null) && !weakestTypeClass.isDeprecated()) {
result.add(weakestTypeClass);
continue;
}
- final PsiClass visibleInheritor = getVisibleInheritor(weakestTypeClass, context);
+ final PsiClass visibleInheritor = getVisibleInheritor(weakestTypeClass, upperBound, context);
if (visibleInheritor != null) {
result.add(visibleInheritor);
}
@@ -562,16 +563,16 @@ public class WeakestTypeFinder {
}
@Nullable
- private static PsiClass getVisibleInheritor(@NotNull PsiClass superClass, PsiElement context) {
+ private static PsiClass getVisibleInheritor(@NotNull PsiClass superClass, PsiClass upperBound, PsiElement context) {
final Query<PsiClass> search = DirectClassInheritorsSearch.search(superClass, context.getResolveScope());
final Project project = superClass.getProject();
for (PsiClass aClass : search) {
- if (superClass.isInheritor(aClass, true)) {
+ if (aClass.isInheritor(superClass, true) && upperBound.isInheritor(aClass, true)) {
if (PsiUtil.isAccessible(project, aClass, context, null)) {
return aClass;
}
else {
- return getVisibleInheritor(aClass, context);
+ return getVisibleInheritor(aClass, upperBound, context);
}
}
}