IG: don't on the order of results of ReferencesSearch.search()

in "Type may be weakened" inspection

GitOrigin-RevId: ef0776fdba0befd950342a8b63816a5537af8966
This commit is contained in:
Bas Leijdekkers
2019-10-15 11:04:20 +00:00
committed by intellij-monorepo-bot
parent 48f29241ad
commit 8a7e155191
@@ -1,18 +1,4 @@
/*
* Copyright 2008-2017 Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.siyeh.ig.psiutils;
import com.intellij.openapi.progress.ProgressManager;
@@ -67,7 +53,7 @@ public class WeakestTypeFinder {
if (variableOrMethodClass == null || variableOrMethodClass instanceof PsiTypeParameter) {
return Collections.emptyList();
}
Set<PsiClass> weakestTypeClasses = new HashSet<>();
final Set<PsiClass> weakestTypeClasses = new HashSet<>();
final GlobalSearchScope scope = variableOrMethod.getResolveScope();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(variableOrMethod.getProject());
final PsiClass lowerBoundClass;
@@ -108,8 +94,8 @@ public class WeakestTypeFinder {
referenceParent = PsiUtil.skipParenthesizedExprUp(referenceElement.getParent());
}
final PsiElement referenceGrandParent = referenceParent.getParent();
if (reference instanceof PsiMethodReferenceExpression) {
final PsiMethodReferenceExpression methodReferenceExpression = (PsiMethodReferenceExpression)reference;
if (referenceElement instanceof PsiMethodReferenceExpression) {
final PsiMethodReferenceExpression methodReferenceExpression = (PsiMethodReferenceExpression)referenceElement;
final PsiType type = methodReferenceExpression.getFunctionalInterfaceType();
final PsiType returnType = LambdaUtil.getFunctionalInterfaceReturnType(type);
if (!PsiType.VOID.equals(returnType) && !checkType(returnType, weakestTypeClasses)) {
@@ -125,12 +111,9 @@ public class WeakestTypeFinder {
}
}
else if (referenceParent instanceof PsiLambdaExpression) {
PsiLambdaExpression lambda = (PsiLambdaExpression)referenceParent;
PsiClassType returnType = ObjectUtils.tryCast(LambdaUtil.getFunctionalInterfaceReturnType(lambda), PsiClassType.class);
if (returnType == null) return Collections.emptyList();
PsiClass resolvedClass = returnType.resolve();
if (resolvedClass == null) return Collections.emptyList();
weakestTypeClasses.add(resolvedClass);
final PsiLambdaExpression lambda = (PsiLambdaExpression)referenceParent;
final PsiClassType returnType = ObjectUtils.tryCast(LambdaUtil.getFunctionalInterfaceReturnType(lambda), PsiClassType.class);
checkType(returnType, weakestTypeClasses);
}
else if (referenceGrandParent instanceof PsiMethodCallExpression) {
final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)referenceGrandParent;
@@ -140,11 +123,8 @@ public class WeakestTypeFinder {
}
}
else if (referenceParent instanceof PsiResourceExpression) {
PsiClass closeable = facade.findClass(CommonClassNames.JAVA_LANG_AUTO_CLOSEABLE, scope);
if (closeable == null || variableOrMethodClass.equals(closeable)) {
return Collections.emptyList();
}
weakestTypeClasses.add(closeable);
final PsiClass closeable = facade.findClass(CommonClassNames.JAVA_LANG_AUTO_CLOSEABLE, scope);
checkClass(closeable, weakestTypeClasses);
}
else if (referenceParent instanceof PsiAssignmentExpression) {
final PsiAssignmentExpression assignmentExpression = (PsiAssignmentExpression)referenceParent;