incorporating Sveta's patch on VariableAsFunctionResolvedCall
This commit is contained in:
-58
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class VariableAsFunctionDescriptor extends FunctionDescriptorImpl {
|
||||
public static VariableAsFunctionDescriptor create(@NotNull VariableDescriptor variableDescriptor) {
|
||||
JetType outType = variableDescriptor.getType();
|
||||
assert outType != null;
|
||||
VariableAsFunctionDescriptor result = new VariableAsFunctionDescriptor(variableDescriptor);
|
||||
FunctionDescriptorUtil.initializeFromFunctionType(result, outType, variableDescriptor.getExpectedThisObject());
|
||||
return result;
|
||||
}
|
||||
|
||||
private final VariableDescriptor variableDescriptor;
|
||||
|
||||
private VariableAsFunctionDescriptor(VariableDescriptor variableDescriptor) {
|
||||
super(variableDescriptor.getContainingDeclaration(), Collections.<AnnotationDescriptor>emptyList(), variableDescriptor.getName(), Kind.DECLARATION);
|
||||
this.variableDescriptor = variableDescriptor;
|
||||
}
|
||||
|
||||
public VariableDescriptor getVariableDescriptor() {
|
||||
return variableDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public VariableAsFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract, Kind kind, boolean copyOverrides) {
|
||||
throw new UnsupportedOperationException("Should not be copied for overriding");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
@@ -49,12 +49,12 @@ public class BindingContextUtils {
|
||||
throw new IllegalStateException("non-declaration descriptors should be filtered out earler: " + callable);
|
||||
}
|
||||
}
|
||||
if (declarationDescriptor instanceof VariableAsFunctionDescriptor) {
|
||||
VariableAsFunctionDescriptor descriptor = (VariableAsFunctionDescriptor) declarationDescriptor;
|
||||
if (descriptor.getOriginal() != descriptor) {
|
||||
throw new IllegalStateException("original should be resolved earlier: " + descriptor);
|
||||
}
|
||||
}
|
||||
//if (declarationDescriptor instanceof VariableAsFunctionDescriptor) {
|
||||
// VariableAsFunctionDescriptor descriptor = (VariableAsFunctionDescriptor) declarationDescriptor;
|
||||
// if (descriptor.getOriginal() != descriptor) {
|
||||
// throw new IllegalStateException("original should be resolved earlier: " + descriptor);
|
||||
// }
|
||||
//}
|
||||
return declarationDescriptor.getOriginal();
|
||||
}
|
||||
};
|
||||
@@ -118,9 +118,6 @@ public class BindingContextUtils {
|
||||
if (descriptor instanceof VariableDescriptor) {
|
||||
return (VariableDescriptor) descriptor;
|
||||
}
|
||||
if (descriptor instanceof VariableAsFunctionDescriptor) {
|
||||
return ((VariableAsFunctionDescriptor) descriptor).getVariableDescriptor();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -99,7 +99,11 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends R
|
||||
public final TracingStrategy tracing = new TracingStrategy() {
|
||||
@Override
|
||||
public <D extends CallableDescriptor> void bindResolvedCall(@NotNull BindingTrace trace, @NotNull ResolvedCallWithTrace<D> resolvedCall) {
|
||||
trace.record(REFERENCE_TARGET, reference, resolvedCall.getResultingDescriptor());
|
||||
CallableDescriptor descriptor = resolvedCall.getResultingDescriptor();
|
||||
if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
|
||||
descriptor = ((VariableAsFunctionResolvedCall) resolvedCall).getVariableCall().getResultingDescriptor();
|
||||
}
|
||||
trace.record(REFERENCE_TARGET, reference, descriptor);
|
||||
trace.record(RESOLVED_CALL, call.getCalleeExpression(), resolvedCall);
|
||||
}
|
||||
|
||||
|
||||
+7
-13
@@ -17,11 +17,13 @@
|
||||
package org.jetbrains.jet.lang.resolve.calls;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -32,18 +34,11 @@ import java.util.Map;
|
||||
public class VariableAsFunctionResolvedCall implements ResolvedCallWithTrace<FunctionDescriptor> {
|
||||
private final ResolvedCallWithTrace<FunctionDescriptor> functionCall;
|
||||
private final ResolvedCallWithTrace<VariableDescriptor> variableCall;
|
||||
private final VariableAsFunctionDescriptor variableAsFunctionDescriptor;
|
||||
|
||||
public VariableAsFunctionResolvedCall(@NotNull ResolvedCallWithTrace<FunctionDescriptor> functionCall,
|
||||
@NotNull ResolvedCallWithTrace<VariableDescriptor> variableCall) {
|
||||
this.functionCall = functionCall;
|
||||
this.variableCall = variableCall;
|
||||
if (JetStandardClasses.isFunctionType(variableCall.getResultingDescriptor().getType())) {
|
||||
variableAsFunctionDescriptor = VariableAsFunctionDescriptor.create(variableCall.getResultingDescriptor());
|
||||
}
|
||||
else {
|
||||
variableAsFunctionDescriptor = null;
|
||||
}
|
||||
}
|
||||
|
||||
public ResolvedCallWithTrace<FunctionDescriptor> getFunctionCall() {
|
||||
@@ -57,20 +52,19 @@ public class VariableAsFunctionResolvedCall implements ResolvedCallWithTrace<Fun
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionDescriptor getCandidateDescriptor() {
|
||||
return variableAsFunctionDescriptor != null ? variableAsFunctionDescriptor : functionCall.getResultingDescriptor();
|
||||
return functionCall.getResultingDescriptor();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionDescriptor getResultingDescriptor() {
|
||||
return variableAsFunctionDescriptor != null ? variableAsFunctionDescriptor : functionCall.getResultingDescriptor();
|
||||
return functionCall.getResultingDescriptor();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ReceiverDescriptor getReceiverArgument() {
|
||||
ReceiverDescriptor receiverArgument = variableCall.getReceiverArgument();
|
||||
return receiverArgument.exists() ? receiverArgument : functionCall.getReceiverArgument();
|
||||
return variableCall.getReceiverArgument();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user