mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
show static import suggestion: ensure normal inference process for method candidate (IDEA-152985)
This commit is contained in:
+4
-5
@@ -21,6 +21,7 @@ import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.DefaultParameterTypeInferencePolicy;
|
||||
import com.intellij.psi.infos.MethodCandidateInfo;
|
||||
import com.intellij.psi.search.PsiShortNamesCache;
|
||||
import com.intellij.psi.util.PsiFormatUtil;
|
||||
import com.intellij.psi.util.PsiFormatUtilBase;
|
||||
@@ -105,12 +106,10 @@ public class StaticImportMethodFix extends StaticImportMemberFix<PsiMethod> {
|
||||
|
||||
@Override
|
||||
protected boolean isApplicable(PsiMethod method, PsiElement place) {
|
||||
final PsiResolveHelper resolveHelper = JavaPsiFacade.getInstance(place.getProject()).getResolveHelper();
|
||||
final PsiExpressionList argumentList = ((PsiMethodCallExpression)place).getArgumentList();
|
||||
PsiSubstitutor substitutorForMethod = resolveHelper
|
||||
.inferTypeArguments(method.getTypeParameters(), method.getParameterList().getParameters(),
|
||||
argumentList.getExpressions(),
|
||||
PsiSubstitutor.EMPTY, place.getParent(), DefaultParameterTypeInferencePolicy.INSTANCE);
|
||||
final MethodCandidateInfo candidateInfo =
|
||||
new MethodCandidateInfo(method, PsiSubstitutor.EMPTY, false, false, argumentList, null, argumentList.getExpressionTypes(), null);
|
||||
PsiSubstitutor substitutorForMethod = candidateInfo.getSubstitutor();
|
||||
if (PsiUtil.isApplicable(method, substitutorForMethod, argumentList)) {
|
||||
final PsiType returnType = substitutorForMethod.substitute(method.getReturnType());
|
||||
final PsiType expectedType = getExpectedType();
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Static import method 'java.util.Collections.emptyList'" "true"
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
public class X {
|
||||
List<String> get() {
|
||||
return emptyList();
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Static import method 'java.util.Collections.emptyList'" "true"
|
||||
import java.util.List;
|
||||
public class X {
|
||||
List<String> get() {
|
||||
return <caret>emptyList();
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
public class StaticImportMethod8Test extends LightQuickFixParameterizedTestCase {
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/staticImportMethod8";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user