Resolution problem avoided for member properties

This commit is contained in:
Andrey Breslav
2011-09-05 18:11:13 +04:00
parent 324922506c
commit 8c35668bfa
2 changed files with 20 additions and 24 deletions
@@ -194,8 +194,6 @@ public class WritableScopeImpl extends WritableScopeWithImports {
@Override @Override
@NotNull @NotNull
public FunctionGroup getFunctionGroup(@NotNull String name) { public FunctionGroup getFunctionGroup(@NotNull String name) {
addVariablesAsFunctions();
WritableFunctionGroup result = new WritableFunctionGroup(name); WritableFunctionGroup result = new WritableFunctionGroup(name);
FunctionGroup functionGroup = getFunctionGroups().get(name); FunctionGroup functionGroup = getFunctionGroups().get(name);
@@ -203,12 +201,6 @@ public class WritableScopeImpl extends WritableScopeWithImports {
result.addAllFunctions(functionGroup); result.addAllFunctions(functionGroup);
} }
// ClassifierDescriptor classifier = getClassifier(name);
// if (classifier instanceof ClassDescriptor) {
// ClassDescriptor classDescriptor = (ClassDescriptor) classifier;
// result.addAllFunctions(classDescriptor.getConstructors());
// }
if (thisType != null) { if (thisType != null) {
result.addAllFunctions(getThisType().getMemberScope().getFunctionGroup(name)); result.addAllFunctions(getThisType().getMemberScope().getFunctionGroup(name));
} }
@@ -220,17 +212,6 @@ public class WritableScopeImpl extends WritableScopeWithImports {
return result; return result;
} }
private void addVariablesAsFunctions() {
List<VariableDescriptor> variableDescriptors = getVariableDescriptors();
this.variableDescriptors = null;
for (VariableDescriptor variableDescriptor : variableDescriptors) {
JetType outType = variableDescriptor.getOutType();
if (outType != null && JetStandardClasses.isFunctionType(outType)) {
addFunctionDescriptor(VariableAsFunctionDescriptor.create(variableDescriptor));
}
}
}
@Override @Override
public void addTypeParameterDescriptor(@NotNull TypeParameterDescriptor typeParameterDescriptor) { public void addTypeParameterDescriptor(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
String name = typeParameterDescriptor.getName(); String name = typeParameterDescriptor.getName();
@@ -27,7 +27,6 @@ import static org.jetbrains.jet.lang.types.JetTypeInferrer.NO_EXPECTED_TYPE;
*/ */
public class CallResolver { public class CallResolver {
// private final BindingTrace trace;
private final TypeResolver typeResolver; private final TypeResolver typeResolver;
private final JetTypeInferrer typeInferrer; private final JetTypeInferrer typeInferrer;
private final JetSemanticServices semanticServices; private final JetSemanticServices semanticServices;
@@ -35,7 +34,6 @@ public class CallResolver {
private final OverloadingConflictResolver overloadingConflictResolver; private final OverloadingConflictResolver overloadingConflictResolver;
public CallResolver(JetSemanticServices semanticServices, BindingTrace trace, JetTypeInferrer typeInferrer) { public CallResolver(JetSemanticServices semanticServices, BindingTrace trace, JetTypeInferrer typeInferrer) {
// this.trace = trace;
this.typeInferrer = typeInferrer; this.typeInferrer = typeInferrer;
this.typeResolver = new TypeResolver(semanticServices, trace, true); this.typeResolver = new TypeResolver(semanticServices, trace, true);
this.classDescriptorResolver = semanticServices.getClassDescriptorResolver(trace); this.classDescriptorResolver = semanticServices.getClassDescriptorResolver(trace);
@@ -659,7 +657,9 @@ public class CallResolver {
iterator.remove(); iterator.remove();
} }
} }
addConstrtuctors(scope, name, functions); addConstructors(scope, name, functions);
addVariableAsFunction(scope, name, functions, false);
return functions; return functions;
} }
@@ -667,7 +667,8 @@ public class CallResolver {
@Override @Override
protected Collection<FunctionDescriptor> getMembersByName(@NotNull JetType receiverType, String name) { protected Collection<FunctionDescriptor> getMembersByName(@NotNull JetType receiverType, String name) {
Set<FunctionDescriptor> members = Sets.newHashSet(receiverType.getMemberScope().getFunctionGroup(name).getFunctionDescriptors()); Set<FunctionDescriptor> members = Sets.newHashSet(receiverType.getMemberScope().getFunctionGroup(name).getFunctionDescriptors());
addConstrtuctors(receiverType.getMemberScope(), name, members); addConstructors(receiverType.getMemberScope(), name, members);
addVariableAsFunction(receiverType.getMemberScope(), name, members, false);
return members; return members;
} }
@@ -681,6 +682,7 @@ public class CallResolver {
iterator.remove(); iterator.remove();
} }
} }
addVariableAsFunction(scope, name, extensionFunctions, true);
return extensionFunctions; return extensionFunctions;
} }
@@ -690,7 +692,7 @@ public class CallResolver {
return new ResolutionTask<FunctionDescriptor>(candidates, receiverType, call); return new ResolutionTask<FunctionDescriptor>(candidates, receiverType, call);
} }
private void addConstrtuctors(JetScope scope, String name, Collection<FunctionDescriptor> functions) { private void addConstructors(JetScope scope, String name, Collection<FunctionDescriptor> functions) {
ClassifierDescriptor classifier = scope.getClassifier(name); ClassifierDescriptor classifier = scope.getClassifier(name);
if (classifier instanceof ClassDescriptor && !ErrorUtils.isError(classifier.getTypeConstructor())) { if (classifier instanceof ClassDescriptor && !ErrorUtils.isError(classifier.getTypeConstructor())) {
ClassDescriptor classDescriptor = (ClassDescriptor) classifier; ClassDescriptor classDescriptor = (ClassDescriptor) classifier;
@@ -698,8 +700,21 @@ public class CallResolver {
} }
} }
private void addVariableAsFunction(JetScope scope, String name, Set<FunctionDescriptor> functions, boolean receiverNeeded) {
VariableDescriptor variable = scope.getVariable(name);
if (variable != null && variable.getReceiverType() == null) {
JetType outType = variable.getOutType();
if (outType != null && JetStandardClasses.isFunctionType(outType)) {
VariableAsFunctionDescriptor functionDescriptor = VariableAsFunctionDescriptor.create(variable);
if ((functionDescriptor.getReceiverType() != null) == receiverNeeded) {
functions.add(functionDescriptor);
}
}
}
}
}; };
private static TaskPrioritizer<VariableDescriptor> PROPERTY_TASK_PRIORITIZER = new TaskPrioritizer<VariableDescriptor>() { private static TaskPrioritizer<VariableDescriptor> PROPERTY_TASK_PRIORITIZER = new TaskPrioritizer<VariableDescriptor>() {
@NotNull @NotNull