Resolution in generic classes fixed
This commit is contained in:
@@ -9,6 +9,7 @@ import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
|
||||
@@ -28,6 +29,11 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
||||
JetStandardLibrary lib = JetStandardLibrary.getJetStandardLibrary(project);
|
||||
Map<String, DeclarationDescriptor> nameToDescriptor = new HashMap<String, DeclarationDescriptor>();
|
||||
nameToDescriptor.put("std::Int.plus(Int)", standardFunction(lib.getInt(), "plus", lib.getIntType()));
|
||||
FunctionDescriptor descriptorForGet = standardFunction(lib.getArray(), Collections.singletonList(new TypeProjection(lib.getIntType())), "get", lib.getIntType());
|
||||
nameToDescriptor.put("std::Array.get(Int)", descriptorForGet.getOriginal());
|
||||
@NotNull
|
||||
FunctionDescriptor descriptorForSet = standardFunction(lib.getArray(), Collections.singletonList(new TypeProjection(lib.getIntType())), "set", lib.getIntType(), lib.getIntType());
|
||||
nameToDescriptor.put("std::Array.set(Int, Int)", descriptorForSet.getOriginal());
|
||||
|
||||
Map<String,PsiElement> nameToDeclaration = new HashMap<String, PsiElement>();
|
||||
nameToDeclaration.put("java::java.util.Collections.emptyList()", findMethod(findClass("java.util.Collections"), "emptyList"));
|
||||
@@ -43,20 +49,22 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
||||
nameToDeclaration.put("java::java.io.PrintStream.print(Int)", methods[2]);
|
||||
nameToDeclaration.put("java::java.lang.System.out", findClass("java.lang.System").findFieldByName("out", true));
|
||||
|
||||
|
||||
return new ExpectedResolveData(nameToDescriptor, nameToDeclaration);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private PsiElement findPackage(String qualifiedName) {
|
||||
JavaPsiFacade javaFacade = JavaPsiFacade.getInstance(getProject());
|
||||
return javaFacade.findPackage(qualifiedName);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private PsiMethod findMethod(PsiClass psiClass, String name) {
|
||||
PsiMethod[] emptyLists = psiClass.findMethodsByName(name, true);
|
||||
return emptyLists[0];
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private PsiClass findClass(String qualifiedName) {
|
||||
Project project = getProject();
|
||||
JavaPsiFacade javaFacade = JavaPsiFacade.getInstance(project);
|
||||
@@ -64,15 +72,27 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
||||
return javaFacade.findClass(qualifiedName, javaSearchScope);
|
||||
}
|
||||
|
||||
private DeclarationDescriptor standardFunction(ClassDescriptor classDescriptor, String name, Type parameterType) {
|
||||
FunctionGroup functionGroup = classDescriptor.getMemberScope(Collections.<TypeProjection>emptyList()).getFunctionGroup(name);
|
||||
Collection<FunctionDescriptor> functions = functionGroup.getPossiblyApplicableFunctions(Collections.<Type>emptyList(), Collections.singletonList(parameterType));
|
||||
@NotNull
|
||||
private FunctionDescriptor standardFunction(ClassDescriptor classDescriptor, String name, Type parameterType) {
|
||||
List<TypeProjection> typeArguments = Collections.emptyList();
|
||||
return standardFunction(classDescriptor, typeArguments, name, parameterType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private FunctionDescriptor standardFunction(ClassDescriptor classDescriptor, List<TypeProjection> typeArguments, String name, Type... parameterType) {
|
||||
FunctionGroup functionGroup = classDescriptor.getMemberScope(typeArguments).getFunctionGroup(name);
|
||||
List<Type> parameterTypeList = Arrays.asList(parameterType);
|
||||
Collection<FunctionDescriptor> functions = functionGroup.getPossiblyApplicableFunctions(Collections.<Type>emptyList(), parameterTypeList);
|
||||
for (FunctionDescriptor function : functions) {
|
||||
if (function.getUnsubstitutedValueParameters().get(0).getType().equals(parameterType)) {
|
||||
return function;
|
||||
List<ValueParameterDescriptor> unsubstitutedValueParameters = function.getUnsubstitutedValueParameters();
|
||||
for (int i = 0, unsubstitutedValueParametersSize = unsubstitutedValueParameters.size(); i < unsubstitutedValueParametersSize; i++) {
|
||||
ValueParameterDescriptor unsubstitutedValueParameter = unsubstitutedValueParameters.get(i);
|
||||
if (unsubstitutedValueParameter.getType().equals(parameterType[i])) {
|
||||
return function;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Not found: std::" + classDescriptor.getName() + "." + name + "(" + parameterType + ")");
|
||||
throw new IllegalArgumentException("Not found: std::" + classDescriptor.getName() + "." + name + "(" + parameterTypeList + ")");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,7 +104,9 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
||||
protected Sdk getProjectJDK() {
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
properties.load(new FileReader(getHomeDirectory() + "/idea/idea.properties"));
|
||||
FileReader reader = new FileReader(getHomeDirectory() + "/idea/idea.properties");
|
||||
properties.load(reader);
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user