mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
redundant lambda param types: take site subst into account
This commit is contained in:
+4
-2
@@ -22,6 +22,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.resolve.DefaultParameterTypeInferencePolicy;
|
||||
import com.intellij.psi.infos.MethodCandidateInfo;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.Function;
|
||||
@@ -64,7 +65,8 @@ public class RedundantLambdaParameterTypeIntention extends PsiElementBaseIntenti
|
||||
if (lambdaParent instanceof PsiExpressionList) {
|
||||
final PsiElement gParent = lambdaParent.getParent();
|
||||
if (gParent instanceof PsiCallExpression && ((PsiCallExpression)gParent).getTypeArguments().length == 0) {
|
||||
final PsiMethod method = ((PsiCallExpression)gParent).resolveMethod();
|
||||
final JavaResolveResult resolveResult = ((PsiCallExpression)gParent).resolveMethodGenerics();
|
||||
final PsiMethod method = (PsiMethod)resolveResult.getElement();
|
||||
if (method == null) return false;
|
||||
final int idx = LambdaUtil.getLambdaIdx((PsiExpressionList)lambdaParent, expression);
|
||||
if (idx < 0) return false;
|
||||
@@ -80,7 +82,7 @@ public class RedundantLambdaParameterTypeIntention extends PsiElementBaseIntenti
|
||||
}
|
||||
}, ", ") + ") -> {}", expression);
|
||||
final PsiSubstitutor substitutor = javaPsiFacade.getResolveHelper()
|
||||
.inferTypeArguments(typeParameters, method.getParameterList().getParameters(), arguments, PsiSubstitutor.EMPTY,
|
||||
.inferTypeArguments(typeParameters, method.getParameterList().getParameters(), arguments, ((MethodCandidateInfo)resolveResult).getSiteSubstitutor(),
|
||||
gParent, DefaultParameterTypeInferencePolicy.INSTANCE);
|
||||
|
||||
for (PsiTypeParameter parameter : typeParameters) {
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Remove redundant types" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Sample {
|
||||
List<String> foo = new ArrayList<>();
|
||||
{
|
||||
foo.forEach(s -> {});
|
||||
}
|
||||
}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Remove redundant types" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Sample {
|
||||
List<String> foo = new ArrayList<>();
|
||||
{
|
||||
foo.forEach((Str<caret>ing s) -> {});
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
|
||||
public class RedundantLambdaParameterTypeIntentionTest extends LightQuickFixParameterizedTestCase {
|
||||
public void test() throws Exception { doAllTests(); }
|
||||
|
||||
@@ -23,4 +26,8 @@ public class RedundantLambdaParameterTypeIntentionTest extends LightQuickFixPara
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/redundantLambdaParameterType";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return IdeaTestUtil.getMockJdk18();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user