java: redundant type arguments: check that parent call substitutor remains the same (IDEA-241259)

GitOrigin-RevId: 8e0e8d23e2868a47a857fb84bfb3a43fc34263f6
This commit is contained in:
Anna Kozlova
2020-06-05 10:12:42 +03:00
committed by intellij-monorepo-bot
parent e35fd2396a
commit dadcc9adde
2 changed files with 36 additions and 4 deletions
@@ -216,18 +216,18 @@ public class PsiDiamondTypeUtil {
}
}
}
final PsiCallExpression exprCopy = PsiTreeUtil.getParentOfType(copy, PsiCallExpression.class, false);
if (context instanceof PsiMethodReferenceExpression) {
PsiMethodReferenceExpression methodRefCopy = PsiTreeUtil.getParentOfType(copy, PsiMethodReferenceExpression.class, false);
if (methodRefCopy != null && !isInferenceEquivalent(typeArguments, typeParameters, method, methodRefCopy)) {
return false;
}
return true;
}
final PsiCallExpression exprCopy = PsiTreeUtil.getParentOfType(copy, PsiCallExpression.class, false);
if (exprCopy != null) {
else if (exprCopy != null) {
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(exprCopy.getProject());
if (constructorRef) {
if (!(exprCopy instanceof PsiNewExpression) || !isInferenceEquivalent(typeArguments, elementFactory, (PsiNewExpression)exprCopy)) {
if (!(exprCopy instanceof PsiNewExpression) ||
!isInferenceEquivalent(typeArguments, elementFactory, (PsiNewExpression)exprCopy)) {
return false;
}
}
@@ -238,6 +238,13 @@ public class PsiDiamondTypeUtil {
}
}
}
PsiCallExpression newParentCall = exprCopy != null ? PsiTreeUtil.getParentOfType(exprCopy, PsiCallExpression.class) : null;
PsiCallExpression oldParentCall = PsiTreeUtil.getParentOfType(context, PsiCallExpression.class);
if (newParentCall != null && oldParentCall != null &&
!newParentCall.resolveMethodGenerics().equals(oldParentCall.resolveMethodGenerics())) {
return false;
}
}
catch (IncorrectOperationException e) {
LOG.info(e);
@@ -0,0 +1,25 @@
// "Remove type arguments" "false"
import java.util.function.Function;
class MyTest {
public JBIterable<String> getChildren(JBIterable<? extends Integer> children) {
return children
.map(this.<St<caret>ring>wrapper())
.filter();
}
protected <De extends String> Function<Integer, De> wrapper() {
return null;
}
abstract class JBIterable<E>{
public final <T> JBIterable<T> map(Function<? super E, ? extends T> function) {
return null;
}
public final JBIterable<E> filter() {
return null;
}
}
}