NO_RECEIVER_PARAMETER is now simply null
This commit is contained in:
@@ -28,10 +28,10 @@ import java.util.Set;
|
||||
* @author abreslav
|
||||
*/
|
||||
public interface CallableDescriptor extends DeclarationDescriptorWithVisibility, DeclarationDescriptorNonRoot {
|
||||
@NotNull
|
||||
@Nullable
|
||||
ReceiverParameterDescriptor getReceiverParameter();
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
ReceiverParameterDescriptor getExpectedThisObject();
|
||||
|
||||
@NotNull
|
||||
|
||||
+2
-1
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
@@ -56,7 +57,7 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
private static ReceiverParameterDescriptor getExpectedThisObject(@NotNull ClassDescriptor descriptor) {
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
return DescriptorUtils.getExpectedThisObjectIfNeeded(containingDeclaration);
|
||||
|
||||
+10
-7
@@ -72,7 +72,7 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
|
||||
protected FunctionDescriptorImpl initialize(
|
||||
@Nullable JetType receiverParameterType,
|
||||
@NotNull ReceiverParameterDescriptor expectedThisObject,
|
||||
@Nullable ReceiverParameterDescriptor expectedThisObject,
|
||||
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
|
||||
@Nullable JetType unsubstitutedReturnType,
|
||||
@@ -117,13 +117,13 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
this.unsubstitutedReturnType = unsubstitutedReturnType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getReceiverParameter() {
|
||||
return receiverParameter;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getExpectedThisObject() {
|
||||
return expectedThisObject;
|
||||
@@ -196,16 +196,19 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(getTypeParameters(), originalSubstitutor, substitutedDescriptor, substitutedTypeParameters);
|
||||
|
||||
JetType substitutedReceiverParameterType = null;
|
||||
if (receiverParameter.exists()) {
|
||||
if (receiverParameter != null) {
|
||||
substitutedReceiverParameterType = substitutor.substitute(getReceiverParameter().getType(), Variance.IN_VARIANCE);
|
||||
if (substitutedReceiverParameterType == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
ReceiverParameterDescriptor substitutedExpectedThis = expectedThisObject.substitute(substitutor);
|
||||
if (substitutedExpectedThis == null) {
|
||||
return null;
|
||||
ReceiverParameterDescriptor substitutedExpectedThis = null;
|
||||
if (expectedThisObject != null) {
|
||||
substitutedExpectedThis = expectedThisObject.substitute(substitutor);
|
||||
if (substitutedExpectedThis == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
List<ValueParameterDescriptor> substitutedValueParameters = FunctionDescriptorUtil.getSubstitutedValueParameters(substitutedDescriptor, this, substitutor);
|
||||
|
||||
+8
-3
@@ -105,7 +105,7 @@ public class FunctionDescriptorUtil {
|
||||
public static JetScope getFunctionInnerScope(@NotNull JetScope outerScope, @NotNull FunctionDescriptor descriptor, @NotNull BindingTrace trace) {
|
||||
WritableScope parameterScope = new WritableScopeImpl(outerScope, descriptor, new TraceBasedRedeclarationHandler(trace), "Function inner scope");
|
||||
ReceiverParameterDescriptor receiver = descriptor.getReceiverParameter();
|
||||
if (receiver.exists()) {
|
||||
if (receiver != null) {
|
||||
parameterScope.setImplicitReceiver(receiver);
|
||||
}
|
||||
for (TypeParameterDescriptor typeParameter : descriptor.getTypeParameters()) {
|
||||
@@ -119,8 +119,13 @@ public class FunctionDescriptorUtil {
|
||||
return parameterScope;
|
||||
}
|
||||
|
||||
public static void initializeFromFunctionType(@NotNull FunctionDescriptorImpl functionDescriptor, @NotNull JetType functionType, @NotNull ReceiverParameterDescriptor expectedThisObject,
|
||||
@NotNull Modality modality, @NotNull Visibility visibility) {
|
||||
public static void initializeFromFunctionType(
|
||||
@NotNull FunctionDescriptorImpl functionDescriptor,
|
||||
@NotNull JetType functionType,
|
||||
@Nullable ReceiverParameterDescriptor expectedThisObject,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility
|
||||
) {
|
||||
|
||||
assert KotlinBuiltIns.getInstance().isFunctionType(functionType);
|
||||
functionDescriptor.initialize(KotlinBuiltIns.getInstance().getReceiverType(functionType),
|
||||
|
||||
@@ -1,95 +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.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/*package*/ class NoReceiverParameter implements ReceiverParameterDescriptor {
|
||||
/*package*/ static final ReceiverParameterDescriptor INSTANCE = new NoReceiverParameter();
|
||||
|
||||
private NoReceiverParameter() {}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getType() {
|
||||
throw new UnsupportedOperationException("NO_RECEIVER_PARAMETER.getType()");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ReceiverValue getValue() {
|
||||
return ReceiverValue.NO_RECEIVER;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getOriginal() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
throw new UnsupportedOperationException("NO_RECEIVER_PARAMETER.getContainingDeclaration()");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverParameterDescriptor substitute(TypeSubstitutor substitutor) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitReceiverParameterDescriptor(this, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptVoid(DeclarationDescriptorVisitor<Void, Void> visitor) {
|
||||
visitor.visitReceiverParameterDescriptor(this, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NO_RECEIVER_PARAMETER";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AnnotationDescriptor> getAnnotations() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Name getName() {
|
||||
throw new UnsupportedOperationException("NO_RECEIVER_PARAMETER.getName()");
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
@@ -106,13 +107,13 @@ public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorNo
|
||||
return correspondingProperty;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getReceiverParameter() {
|
||||
return getCorrespondingProperty().getReceiverParameter();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getExpectedThisObject() {
|
||||
return getCorrespondingProperty().getExpectedThisObject();
|
||||
|
||||
@@ -89,7 +89,7 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
@NotNull Visibility visibility,
|
||||
boolean isVar,
|
||||
@Nullable JetType receiverType,
|
||||
@NotNull ReceiverParameterDescriptor expectedThisObject,
|
||||
@Nullable ReceiverParameterDescriptor expectedThisObject,
|
||||
@NotNull Name name,
|
||||
@NotNull JetType outType,
|
||||
@NotNull Kind kind
|
||||
@@ -101,7 +101,7 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
public void setType(
|
||||
@NotNull JetType outType,
|
||||
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@NotNull ReceiverParameterDescriptor expectedThisObject,
|
||||
@Nullable ReceiverParameterDescriptor expectedThisObject,
|
||||
@Nullable JetType receiverType
|
||||
) {
|
||||
ReceiverParameterDescriptor receiverParameter = DescriptorResolver.resolveReceiverParameterFor(this, receiverType);
|
||||
@@ -111,8 +111,8 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
public void setType(
|
||||
@NotNull JetType outType,
|
||||
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@NotNull ReceiverParameterDescriptor expectedThisObject,
|
||||
@NotNull ReceiverParameterDescriptor receiverParameter
|
||||
@Nullable ReceiverParameterDescriptor expectedThisObject,
|
||||
@Nullable ReceiverParameterDescriptor receiverParameter
|
||||
) {
|
||||
setOutType(outType);
|
||||
|
||||
@@ -138,12 +138,12 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
@Nullable
|
||||
public ReceiverParameterDescriptor getReceiverParameter() {
|
||||
return receiverParameter;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getExpectedThisObject() {
|
||||
return expectedThisObject;
|
||||
@@ -216,10 +216,19 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
return null; // TODO : tell the user that the property was projected out
|
||||
}
|
||||
|
||||
ReceiverParameterDescriptor substitutedExpectedThisObject = getExpectedThisObject().substitute(substitutor);
|
||||
|
||||
ReceiverParameterDescriptor substitutedExpectedThisObject;
|
||||
ReceiverParameterDescriptor expectedThisObject = getExpectedThisObject();
|
||||
if (expectedThisObject != null) {
|
||||
substitutedExpectedThisObject = expectedThisObject.substitute(substitutor);
|
||||
if (substitutedExpectedThisObject == null) return null;
|
||||
}
|
||||
else {
|
||||
substitutedExpectedThisObject = null;
|
||||
}
|
||||
|
||||
JetType substitutedReceiverType;
|
||||
if (receiverParameter.exists()) {
|
||||
if (receiverParameter != null) {
|
||||
substitutedReceiverType = substitutor.substitute(receiverParameter.getType(), Variance.IN_VARIANCE);
|
||||
if (substitutedReceiverType == null) return null;
|
||||
}
|
||||
|
||||
+3
-4
@@ -27,8 +27,9 @@ import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
*/
|
||||
public interface ReceiverParameterDescriptor extends DeclarationDescriptor {
|
||||
|
||||
// NOTE: Instead of comparing to NO_RECEIVER_PARAMETER, call exists()
|
||||
ReceiverParameterDescriptor NO_RECEIVER_PARAMETER = NoReceiverParameter.INSTANCE;
|
||||
// This field exists for better readability of the client code
|
||||
@Nullable
|
||||
ReceiverParameterDescriptor NO_RECEIVER_PARAMETER = null;
|
||||
|
||||
@NotNull
|
||||
JetType getType();
|
||||
@@ -40,8 +41,6 @@ public interface ReceiverParameterDescriptor extends DeclarationDescriptor {
|
||||
@NotNull
|
||||
DeclarationDescriptor getContainingDeclaration();
|
||||
|
||||
boolean exists();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
ReceiverParameterDescriptor substitute(TypeSubstitutor substitutor);
|
||||
|
||||
-5
@@ -52,9 +52,4 @@ public class ReceiverParameterDescriptorImpl extends AbstractReceiverParameterDe
|
||||
public DeclarationDescriptor getContainingDeclaration() {
|
||||
return containingDeclaration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ public class SimpleFunctionDescriptorImpl extends FunctionDescriptorImpl impleme
|
||||
|
||||
public SimpleFunctionDescriptorImpl initialize(
|
||||
@Nullable JetType receiverParameterType,
|
||||
@NotNull ReceiverParameterDescriptor expectedThisObject,
|
||||
@Nullable ReceiverParameterDescriptor expectedThisObject,
|
||||
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
|
||||
@Nullable JetType unsubstitutedReturnType,
|
||||
|
||||
@@ -86,13 +86,11 @@ public abstract class VariableDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getReceiverParameter() {
|
||||
return ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getExpectedThisObject() {
|
||||
return ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
|
||||
|
||||
@@ -26,23 +26,23 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintsUtil;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.InferenceErrorData;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.rendering.TabledDescriptorRenderer.*;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.inference.InferenceErrorData.ExtendedInferenceErrorData;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.diagnostics.rendering.TabledDescriptorRenderer.*;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.inference.InferenceErrorData.ExtendedInferenceErrorData;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
@@ -193,7 +193,7 @@ public class Renderers {
|
||||
.text("None of the following substitutions");
|
||||
|
||||
for (CallableDescriptor substitutedDescriptor : substitutedDescriptors) {
|
||||
JetType receiverType = substitutedDescriptor.getReceiverParameter().exists() ? substitutedDescriptor.getReceiverParameter().getType() : null;
|
||||
JetType receiverType = DescriptorUtils.getReceiverParameterType(substitutedDescriptor.getReceiverParameter());
|
||||
|
||||
final Collection<ConstraintPosition> errorPositions = Sets.newHashSet();
|
||||
List<JetType> parameterTypes = Lists.newArrayList();
|
||||
|
||||
@@ -300,7 +300,7 @@ public class DeclarationResolver {
|
||||
public boolean apply(@Nullable DeclarationDescriptor descriptor) {
|
||||
if (descriptor instanceof PropertyDescriptor) {
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor)descriptor;
|
||||
return !propertyDescriptor.getReceiverParameter().exists();
|
||||
return propertyDescriptor.getReceiverParameter() == null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -840,7 +840,7 @@ public class DescriptorResolver {
|
||||
|
||||
public JetScope getPropertyDeclarationInnerScope(
|
||||
@NotNull JetScope outerScope, @NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@NotNull ReceiverParameterDescriptor receiver, BindingTrace trace
|
||||
@Nullable ReceiverParameterDescriptor receiver, BindingTrace trace
|
||||
) {
|
||||
WritableScopeImpl result = new WritableScopeImpl(
|
||||
outerScope, outerScope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(trace),
|
||||
@@ -848,7 +848,7 @@ public class DescriptorResolver {
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
|
||||
result.addTypeParameterDescriptor(typeParameterDescriptor);
|
||||
}
|
||||
if (receiver.exists()) {
|
||||
if (receiver != null) {
|
||||
result.setImplicitReceiver(receiver);
|
||||
}
|
||||
result.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
@@ -1314,11 +1314,6 @@ public class DescriptorResolver {
|
||||
return classDescriptor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "class " + classDescriptor.getName() + "::this";
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.jet.lang.types.DescriptorSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
@@ -54,13 +55,13 @@ public class DescriptorUtils {
|
||||
|
||||
return substitutedFunction;
|
||||
}
|
||||
|
||||
|
||||
public static Modality convertModality(Modality modality, boolean makeNonAbstract) {
|
||||
if (makeNonAbstract && modality == Modality.ABSTRACT) return Modality.OPEN;
|
||||
return modality;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
public static ReceiverParameterDescriptor getExpectedThisObjectIfNeeded(@NotNull DeclarationDescriptor containingDeclaration) {
|
||||
if (containingDeclaration instanceof ClassDescriptor) {
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) containingDeclaration;
|
||||
@@ -144,8 +145,8 @@ public class DescriptorUtils {
|
||||
@Nullable
|
||||
public static <D extends DeclarationDescriptor> D getParentOfType(@Nullable DeclarationDescriptor descriptor, @NotNull Class<D> aClass) {
|
||||
return getParentOfType(descriptor, aClass, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <D extends DeclarationDescriptor> D getParentOfType(@Nullable DeclarationDescriptor descriptor, @NotNull Class<D> aClass, boolean strict) {
|
||||
if (descriptor == null) return null;
|
||||
@@ -161,7 +162,7 @@ public class DescriptorUtils {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isAncestor(@Nullable DeclarationDescriptor ancestor, @NotNull DeclarationDescriptor declarationDescriptor, boolean strict) {
|
||||
if (ancestor == null) return false;
|
||||
DeclarationDescriptor descriptor = strict ? declarationDescriptor.getContainingDeclaration() : declarationDescriptor;
|
||||
@@ -175,7 +176,7 @@ public class DescriptorUtils {
|
||||
@Nullable
|
||||
public static VariableDescriptor filterNonExtensionProperty(Collection<VariableDescriptor> variables) {
|
||||
for (VariableDescriptor variable : variables) {
|
||||
if (!variable.getReceiverParameter().exists()) {
|
||||
if (variable.getReceiverParameter() == null) {
|
||||
return variable;
|
||||
}
|
||||
}
|
||||
@@ -344,7 +345,7 @@ public class DescriptorUtils {
|
||||
assert classKind == ClassKind.CLASS || classKind == ClassKind.TRAIT || classKind == ClassKind.ANNOTATION_CLASS;
|
||||
return Visibilities.PUBLIC;
|
||||
}
|
||||
|
||||
|
||||
public static List<String> getSortedValueArguments(AnnotationDescriptor descriptor) {
|
||||
List<String> resultList = Lists.newArrayList();
|
||||
for (Map.Entry<ValueParameterDescriptor, CompileTimeConstant<?>> entry : descriptor.getAllValueArguments().entrySet()) {
|
||||
@@ -368,4 +369,21 @@ public class DescriptorUtils {
|
||||
assert constructors.size() == 1 : "Data class must have only one constructor: " + constructors;
|
||||
return constructors.iterator().next();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetType getReceiverParameterType(@Nullable ReceiverParameterDescriptor receiverParameterDescriptor) {
|
||||
if (receiverParameterDescriptor == null) {
|
||||
return null;
|
||||
}
|
||||
return receiverParameterDescriptor.getType();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ReceiverValue safeGetValue(@Nullable ReceiverParameterDescriptor receiverParameterDescriptor) {
|
||||
if (receiverParameterDescriptor == null) {
|
||||
return ReceiverValue.NO_RECEIVER;
|
||||
}
|
||||
return receiverParameterDescriptor.getValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ public class OverridingUtil {
|
||||
private static List<JetType> compiledValueParameters(CallableDescriptor callableDescriptor) {
|
||||
ReceiverParameterDescriptor receiverParameter = callableDescriptor.getReceiverParameter();
|
||||
ArrayList<JetType> parameters = new ArrayList<JetType>();
|
||||
if (receiverParameter.exists()) {
|
||||
if (receiverParameter != null) {
|
||||
parameters.add(receiverParameter.getType());
|
||||
}
|
||||
for (ValueParameterDescriptor valueParameterDescriptor : callableDescriptor.getValueParameters()) {
|
||||
@@ -123,7 +123,7 @@ public class OverridingUtil {
|
||||
}
|
||||
|
||||
private static int compiledValueParameterCount(CallableDescriptor callableDescriptor) {
|
||||
if (callableDescriptor.getReceiverParameter().exists()) {
|
||||
if (callableDescriptor.getReceiverParameter() != null) {
|
||||
return 1 + callableDescriptor.getValueParameters().size();
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -578,7 +578,7 @@ public class CallResolver {
|
||||
boolean found = false;
|
||||
for (ResolutionCandidate<FunctionDescriptor> resolvedCall : candidates) {
|
||||
FunctionDescriptor functionDescriptor = resolvedCall.getDescriptor();
|
||||
if (functionDescriptor.getReceiverParameter().exists()) continue;
|
||||
if (functionDescriptor.getReceiverParameter() != null) continue;
|
||||
if (!functionDescriptor.getTypeParameters().isEmpty()) continue;
|
||||
if (!checkValueParameters(functionDescriptor, parameterTypes)) continue;
|
||||
result.add(resolvedCall);
|
||||
@@ -593,7 +593,7 @@ public class CallResolver {
|
||||
for (ResolutionCandidate<FunctionDescriptor> candidate : candidates) {
|
||||
FunctionDescriptor functionDescriptor = candidate.getDescriptor();
|
||||
ReceiverParameterDescriptor functionReceiver = functionDescriptor.getReceiverParameter();
|
||||
if (!functionReceiver.exists()) continue;
|
||||
if (functionReceiver == null) continue;
|
||||
if (!functionDescriptor.getTypeParameters().isEmpty()) continue;
|
||||
if (!typeChecker.isSubtypeOf(receiver.getType(), functionReceiver.getType())) continue;
|
||||
if (!checkValueParameters(functionDescriptor, parameterTypes))continue;
|
||||
|
||||
@@ -316,7 +316,7 @@ public class CandidateResolver {
|
||||
// Error is already reported if something is missing
|
||||
ReceiverValue receiverArgument = candidateCall.getReceiverArgument();
|
||||
ReceiverParameterDescriptor receiverParameter = candidateWithFreshVariables.getReceiverParameter();
|
||||
if (receiverArgument.exists() && receiverParameter.exists()) {
|
||||
if (receiverArgument.exists() && receiverParameter != null) {
|
||||
constraintsSystem.addSubtypeConstraint(receiverParameter.getType(), receiverArgument.getType(),
|
||||
ConstraintPosition.RECEIVER_POSITION);
|
||||
}
|
||||
@@ -473,7 +473,7 @@ public class CandidateResolver {
|
||||
BindingContext bindingContext = context.candidateCall.getTrace().getBindingContext();
|
||||
|
||||
ResolutionStatus result = SUCCESS;
|
||||
if (receiverParameter.exists() && receiverArgument.exists()) {
|
||||
if (receiverParameter != null && receiverArgument.exists()) {
|
||||
boolean safeAccess = isExplicitReceiver && !implicitInvokeCheck && candidateCall.isSafeCall();
|
||||
JetType receiverArgumentType = receiverArgument.getType();
|
||||
AutoCastServiceImpl autoCastService = new AutoCastServiceImpl(context.dataFlowInfo, bindingContext);
|
||||
|
||||
+3
-3
@@ -214,11 +214,11 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
|
||||
|
||||
ReceiverParameterDescriptor receiverParameter = candidate.getReceiverParameter();
|
||||
ReceiverValue receiverArgument = candidateCall.getReceiverArgument();
|
||||
if (receiverParameter.exists() &&!receiverArgument.exists()) {
|
||||
if (receiverParameter != null &&!receiverArgument.exists()) {
|
||||
tracing.missingReceiver(traceForCall, receiverParameter);
|
||||
status = ERROR;
|
||||
}
|
||||
if (!receiverParameter.exists() && receiverArgument.exists()) {
|
||||
if (receiverParameter == null && receiverArgument.exists()) {
|
||||
tracing.noReceiverAllowed(traceForCall);
|
||||
if (call.getCalleeExpression() instanceof JetSimpleNameExpression) {
|
||||
status = STRONG_ERROR;
|
||||
@@ -228,7 +228,7 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
|
||||
}
|
||||
}
|
||||
|
||||
assert (candidateCall.getThisObject().exists() == candidateCall.getResultingDescriptor().getExpectedThisObject().exists()) : "Shouldn't happen because of TaskPrioritizer: " + candidateCall.getCandidateDescriptor();
|
||||
assert (candidateCall.getThisObject().exists() == (candidateCall.getResultingDescriptor().getExpectedThisObject() != null)) : "Shouldn't happen because of TaskPrioritizer: " + candidateCall.getCandidateDescriptor();
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ public class OverloadingConflictResolver {
|
||||
|
||||
ReceiverParameterDescriptor receiverOfF = f.getReceiverParameter();
|
||||
ReceiverParameterDescriptor receiverOfG = g.getReceiverParameter();
|
||||
if (f.getReceiverParameter().exists() && g.getReceiverParameter().exists()) {
|
||||
if (receiverOfF != null && receiverOfG != null) {
|
||||
if (!typeMoreSpecific(receiverOfF.getType(), receiverOfG.getType())) return false;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ public class CallableDescriptorCollectors {
|
||||
Set<FunctionDescriptor> functions = Sets.newLinkedHashSet(scope.getFunctions(name));
|
||||
for (Iterator<FunctionDescriptor> iterator = functions.iterator(); iterator.hasNext(); ) {
|
||||
FunctionDescriptor functionDescriptor = iterator.next();
|
||||
if (functionDescriptor.getReceiverParameter().exists()) {
|
||||
if (functionDescriptor.getReceiverParameter() != null) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -204,7 +204,7 @@ public abstract class TaskPrioritizer {
|
||||
}
|
||||
if (receiverParameters.size() == 1 && !receiverParameters.iterator().next().exists()) {
|
||||
for (D descriptor : descriptors) {
|
||||
if (descriptor.getExpectedThisObject().exists() && !descriptor.getReceiverParameter().exists()) {
|
||||
if (descriptor.getExpectedThisObject() != null && descriptor.getReceiverParameter() == null) {
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
if (descriptor instanceof ConstructorDescriptor) {
|
||||
assert containingDeclaration != null;
|
||||
@@ -224,7 +224,7 @@ public abstract class TaskPrioritizer {
|
||||
|
||||
private static <D extends CallableDescriptor> boolean setImpliedThis(@NotNull JetScope scope, ResolutionCandidate<D> candidate) {
|
||||
ReceiverParameterDescriptor expectedThisObject = candidate.getDescriptor().getExpectedThisObject();
|
||||
if (!expectedThisObject.exists()) return true;
|
||||
if (expectedThisObject == null) return true;
|
||||
List<ReceiverParameterDescriptor> receivers = scope.getImplicitReceiversHierarchy();
|
||||
for (ReceiverParameterDescriptor receiver : receivers) {
|
||||
if (JetTypeChecker.INSTANCE.isSubtypeOf(receiver.getType(), expectedThisObject.getType())) {
|
||||
|
||||
+2
-2
@@ -264,13 +264,13 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
||||
@Override
|
||||
public List<ReceiverParameterDescriptor> getImplicitReceiversHierarchy() {
|
||||
ReceiverParameterDescriptor receiver = getImplicitReceiver();
|
||||
if (receiver.exists()) {
|
||||
if (receiver != null) {
|
||||
return Collections.singletonList(receiver);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Nullable
|
||||
protected abstract ReceiverParameterDescriptor getImplicitReceiver();
|
||||
|
||||
// Do not change this, override in concrete subclasses:
|
||||
|
||||
@@ -75,7 +75,6 @@ public class LazyPackageMemberScope extends AbstractLazyMemberScope<NamespaceDes
|
||||
.getFileScopeForDeclarationResolution((JetFile) declaration.getContainingFile());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected ReceiverParameterDescriptor getImplicitReceiver() {
|
||||
return ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
|
||||
|
||||
@@ -62,7 +62,7 @@ public final class JetScopeUtils {
|
||||
for (DeclarationDescriptor descriptor : scope.getAllDescriptors()) {
|
||||
if (descriptor instanceof CallableDescriptor) {
|
||||
CallableDescriptor callDescriptor = (CallableDescriptor) descriptor;
|
||||
if (callDescriptor.getReceiverParameter().exists()) {
|
||||
if (callDescriptor.getReceiverParameter() != null) {
|
||||
result.add(callDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
checkForPropertyRedeclaration(name, variableDescriptor);
|
||||
getPropertyGroups().put(name, variableDescriptor);
|
||||
}
|
||||
if (!variableDescriptor.getReceiverParameter().exists()) {
|
||||
if (variableDescriptor.getReceiverParameter() == null) {
|
||||
checkForRedeclaration(name, variableDescriptor);
|
||||
// TODO : Should this always happen?
|
||||
getVariableClassOrNamespaceDescriptors().put(name, variableDescriptor);
|
||||
@@ -374,7 +374,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
ReceiverParameterDescriptor receiverParameter = variableDescriptor.getReceiverParameter();
|
||||
for (VariableDescriptor oldProperty : properties) {
|
||||
ReceiverParameterDescriptor receiverParameterForOldVariable = oldProperty.getReceiverParameter();
|
||||
if (((receiverParameter.exists() && receiverParameterForOldVariable.exists()) &&
|
||||
if (((receiverParameter != null && receiverParameterForOldVariable != null) &&
|
||||
(JetTypeChecker.INSTANCE.equalTypes(receiverParameter.getType(), receiverParameterForOldVariable.getType())))) {
|
||||
redeclarationHandler.handleRedeclaration(oldProperty, variableDescriptor);
|
||||
}
|
||||
@@ -464,7 +464,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
@Override
|
||||
protected List<ReceiverParameterDescriptor> computeImplicitReceiversHierarchy() {
|
||||
List<ReceiverParameterDescriptor> implicitReceiverHierarchy = Lists.newArrayList();
|
||||
if (implicitReceiver != null && implicitReceiver.exists()) {
|
||||
if (implicitReceiver != null) {
|
||||
implicitReceiverHierarchy.add(implicitReceiver);
|
||||
}
|
||||
implicitReceiverHierarchy.addAll(super.computeImplicitReceiversHierarchy());
|
||||
|
||||
+1
-1
@@ -548,7 +548,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
else if (!receivers.isEmpty()) {
|
||||
result = receivers.get(0);
|
||||
}
|
||||
if (result.exists()) {
|
||||
if (result != NO_RECEIVER_PARAMETER) {
|
||||
context.trace.record(REFERENCE_TARGET, expression.getInstanceReference(), result.getContainingDeclaration());
|
||||
}
|
||||
return LabelResolver.LabeledReceiverResolutionResult.labelResolutionSuccess(result);
|
||||
|
||||
+1
-1
@@ -104,7 +104,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
|
||||
parameterTypes.add(valueParameter.getType());
|
||||
}
|
||||
ReceiverParameterDescriptor receiverParameter = functionDescriptor.getReceiverParameter();
|
||||
JetType receiver = receiverParameter.exists() ? receiverParameter.getType() : null;
|
||||
JetType receiver = DescriptorUtils.getReceiverParameterType(receiverParameter);
|
||||
|
||||
JetType returnType = TypeUtils.NO_EXPECTED_TYPE;
|
||||
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace);
|
||||
|
||||
+2
-2
@@ -234,12 +234,12 @@ public class ExpressionTypingUtils {
|
||||
) {
|
||||
ReceiverParameterDescriptor receiverParameter = callableDescriptor.getReceiverParameter();
|
||||
|
||||
if (!receiverArgument.exists() && !receiverParameter.exists()) {
|
||||
if (!receiverArgument.exists() && receiverParameter == null) {
|
||||
// Both receivers do not exist
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(receiverArgument.exists() && receiverParameter.exists())) {
|
||||
if (!(receiverArgument.exists() && receiverParameter != null)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ public class LabelResolver {
|
||||
DeclarationDescriptor declarationDescriptor = context.trace.getBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, element);
|
||||
if (declarationDescriptor instanceof FunctionDescriptor) {
|
||||
ReceiverParameterDescriptor thisReceiver = ((FunctionDescriptor) declarationDescriptor).getReceiverParameter();
|
||||
if (thisReceiver.exists()) {
|
||||
if (thisReceiver != null) {
|
||||
context.trace.record(LABEL_TARGET, targetLabel, element);
|
||||
context.trace.record(REFERENCE_TARGET, thisReference, declarationDescriptor);
|
||||
}
|
||||
@@ -177,8 +177,8 @@ public class LabelResolver {
|
||||
}
|
||||
|
||||
public static final class LabeledReceiverResolutionResult {
|
||||
public static LabeledReceiverResolutionResult labelResolutionSuccess(@NotNull ReceiverParameterDescriptor receiverParameterDescriptor) {
|
||||
if (!receiverParameterDescriptor.exists()) {
|
||||
public static LabeledReceiverResolutionResult labelResolutionSuccess(@Nullable ReceiverParameterDescriptor receiverParameterDescriptor) {
|
||||
if (receiverParameterDescriptor == null) {
|
||||
return new LabeledReceiverResolutionResult(Code.NO_THIS, null);
|
||||
}
|
||||
return new LabeledReceiverResolutionResult(Code.SUCCESS, receiverParameterDescriptor);
|
||||
|
||||
@@ -354,7 +354,7 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
|
||||
@NotNull StringBuilder builder,
|
||||
@Nullable Boolean isVar,
|
||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||
@NotNull ReceiverParameterDescriptor receiver,
|
||||
@Nullable ReceiverParameterDescriptor receiver,
|
||||
@Nullable JetType outType) {
|
||||
String typeString = lt() + "no type>";
|
||||
if (outType != null) {
|
||||
@@ -366,7 +366,7 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
|
||||
|
||||
renderTypeParameters(typeParameters, builder);
|
||||
|
||||
if (receiver.exists()) {
|
||||
if (receiver != null) {
|
||||
builder.append(escape(renderType(receiver.getType()))).append(".");
|
||||
}
|
||||
|
||||
@@ -424,7 +424,7 @@ public class DescriptorRenderer implements Renderer<DeclarationDescriptor> {
|
||||
}
|
||||
|
||||
ReceiverParameterDescriptor receiver = descriptor.getReceiverParameter();
|
||||
if (receiver.exists()) {
|
||||
if (receiver != null) {
|
||||
builder.append(escape(renderType(receiver.getType()))).append(".");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user