mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-71638 Type inferrence loses methods of <? extends T> generic parameter
This commit is contained in:
+6
-1
@@ -23,7 +23,9 @@ import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.groovy.lang.completion.closureParameters.ClosureParameterInfo;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGdkMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -61,7 +63,10 @@ public class EachWithIndexClosureCompleter extends ClosureCompleter {
|
||||
|
||||
final PsiType iterable = PsiUtil.extractIterableTypeParameter(collection, true);
|
||||
if (iterable != null) {
|
||||
return Arrays.asList(new ClosureParameterInfo(iterable.getCanonicalText(), "entry"), new ClosureParameterInfo("int", "i"));
|
||||
return Arrays.asList(
|
||||
new ClosureParameterInfo(PsiImplUtil.normalizeWildcardTypeByPosition(iterable, (GrExpression)parent).getCanonicalText(), "entry"),
|
||||
new ClosureParameterInfo("int", "i")
|
||||
);
|
||||
}
|
||||
|
||||
if (InheritanceUtil.isInheritor(collection, CommonClassNames.JAVA_UTIL_MAP)) {
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.arithmet
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrStringInjection;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrRangeType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleType;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GdkMethodUtil;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames;
|
||||
@@ -257,7 +258,7 @@ public class ClosureParameterEnhancer extends AbstractClosureParameterEnhancer {
|
||||
|
||||
PsiType res = PsiUtil.extractIterableTypeParameter(iterType, true);
|
||||
if (res != null) {
|
||||
return res;
|
||||
return PsiImplUtil.normalizeWildcardTypeByPosition(res, qualifier);
|
||||
}
|
||||
|
||||
if (TypesUtil.isClassType(iterType, CommonClassNames.JAVA_LANG_STRING) || TypesUtil.isClassType(iterType, JAVA_IO_FILE)) {
|
||||
|
||||
+12
@@ -556,6 +556,18 @@ private void getCommonAncestor() {
|
||||
|
||||
}
|
||||
|
||||
void testWildcardClosureParam() {
|
||||
doTest('''\
|
||||
class Tx {
|
||||
def methodOfT() {}
|
||||
}
|
||||
|
||||
def method(List<? extends Tx> t) {
|
||||
t.collect { print i<caret>t }
|
||||
}
|
||||
''', 'Tx')
|
||||
}
|
||||
|
||||
private void doTest(String text, String type) {
|
||||
def file = myFixture.configureByText('_.groovy', text)
|
||||
def ref = file.findReferenceAt(myFixture.editor.caretModel.offset) as GrReferenceExpression
|
||||
|
||||
Reference in New Issue
Block a user