mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
static method import: collect all overloaded methods to filter them after finish of stub processing (IDEA-147745)
This commit is contained in:
@@ -44,6 +44,8 @@ import com.intellij.util.ArrayUtilRt;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.LinkedMultiMap;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -164,25 +166,28 @@ public class StaticImportMethodFix implements IntentionAction {
|
||||
final List<PsiMethod> applicableList = new ArrayList<PsiMethod>();
|
||||
final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(element.getProject()).getResolveHelper();
|
||||
|
||||
final Map<PsiClass, PsiMethod> deprecated = new LinkedHashMap<PsiClass, PsiMethod>();
|
||||
final Map<PsiClass, PsiMethod> suggestions = new LinkedHashMap<PsiClass, PsiMethod>();
|
||||
final MultiMap<PsiClass, PsiMethod> deprecated = new LinkedMultiMap<PsiClass, PsiMethod>();
|
||||
final MultiMap<PsiClass, PsiMethod> suggestions = new LinkedMultiMap<PsiClass, PsiMethod>();
|
||||
class RegisterMethodsProcessor {
|
||||
private void registerMethod(PsiClass containingClass, PsiMethod method) {
|
||||
private void registerMethod(PsiClass containingClass, Collection<PsiMethod> methods) {
|
||||
final Boolean alreadyMentioned = possibleClasses.get(containingClass);
|
||||
if (alreadyMentioned == Boolean.TRUE) return;
|
||||
if (alreadyMentioned == null) {
|
||||
list.add(method);
|
||||
list.addAll(methods);
|
||||
possibleClasses.put(containingClass, false);
|
||||
}
|
||||
PsiSubstitutor substitutorForMethod = resolveHelper
|
||||
.inferTypeArguments(method.getTypeParameters(), method.getParameterList().getParameters(),
|
||||
argumentList.getExpressions(),
|
||||
PsiSubstitutor.EMPTY, element.getParent(), DefaultParameterTypeInferencePolicy.INSTANCE);
|
||||
if (PsiUtil.isApplicable(method, substitutorForMethod, argumentList)) {
|
||||
final PsiType returnType = substitutorForMethod.substitute(method.getReturnType());
|
||||
if (expectedType == null || returnType == null || TypeConversionUtil.isAssignable(expectedType, returnType)) {
|
||||
applicableList.add(method);
|
||||
possibleClasses.put(containingClass, true);
|
||||
for (PsiMethod method : methods) {
|
||||
PsiSubstitutor substitutorForMethod = resolveHelper
|
||||
.inferTypeArguments(method.getTypeParameters(), method.getParameterList().getParameters(),
|
||||
argumentList.getExpressions(),
|
||||
PsiSubstitutor.EMPTY, element.getParent(), DefaultParameterTypeInferencePolicy.INSTANCE);
|
||||
if (PsiUtil.isApplicable(method, substitutorForMethod, argumentList)) {
|
||||
final PsiType returnType = substitutorForMethod.substitute(method.getReturnType());
|
||||
if (expectedType == null || returnType == null || TypeConversionUtil.isAssignable(expectedType, returnType)) {
|
||||
applicableList.add(method);
|
||||
possibleClasses.put(containingClass, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,10 +207,10 @@ public class StaticImportMethodFix implements IntentionAction {
|
||||
&& !((PsiJavaFile)file).getPackageName().isEmpty()
|
||||
&& PsiUtil.isAccessible(file.getProject(), method, element, containingClass)) {
|
||||
if (isEffectivelyDeprecated(method)) {
|
||||
deprecated.put(containingClass, method);
|
||||
deprecated.putValue(containingClass, method);
|
||||
return processCondition();
|
||||
}
|
||||
suggestions.put(containingClass, method);
|
||||
suggestions.putValue(containingClass, method);
|
||||
}
|
||||
return processCondition();
|
||||
}
|
||||
@@ -229,11 +234,11 @@ public class StaticImportMethodFix implements IntentionAction {
|
||||
}
|
||||
});
|
||||
|
||||
for (Map.Entry<PsiClass, PsiMethod> methodEntry : suggestions.entrySet()) {
|
||||
for (Map.Entry<PsiClass, Collection<PsiMethod>> methodEntry : suggestions.entrySet()) {
|
||||
registrar.registerMethod(methodEntry.getKey(), methodEntry.getValue());
|
||||
}
|
||||
|
||||
for (Map.Entry<PsiClass, PsiMethod> deprecatedMethod : deprecated.entrySet()) {
|
||||
for (Map.Entry<PsiClass, Collection<PsiMethod>> deprecatedMethod : deprecated.entrySet()) {
|
||||
registrar.registerMethod(deprecatedMethod.getKey(), deprecatedMethod.getValue());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// "Static import method..." "true"
|
||||
package foo;
|
||||
|
||||
import static foo.B.a;
|
||||
|
||||
public class X {
|
||||
{
|
||||
a("");
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
|
||||
public static Integer a(Integer i) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static Integer a() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static Integer a(String s) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static Integer a(String s, String s) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
class A {
|
||||
public static Integer a(String s) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// "Static import method..." "true"
|
||||
package foo;
|
||||
|
||||
public class X {
|
||||
{
|
||||
<caret>a("");
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
|
||||
public static Integer a(Integer i) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static Integer a() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static Integer a(String s) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static Integer a(String s, String s) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
class A {
|
||||
public static Integer a(String s) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user