Extract PropertyDescriptor interface
This commit is contained in:
@@ -24,7 +24,7 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public class AccessorForPropertyDescriptor extends PropertyDescriptor {
|
||||
public class AccessorForPropertyDescriptor extends PropertyDescriptorImpl {
|
||||
public AccessorForPropertyDescriptor(PropertyDescriptor pd, DeclarationDescriptor containingDeclaration, int index) {
|
||||
super(containingDeclaration, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibilities.PUBLIC,
|
||||
pd.isVar(), Name.identifier(pd.getName() + "$b$" + index),
|
||||
|
||||
+1
-1
@@ -181,7 +181,7 @@ public final class JavaPropertyResolver {
|
||||
}
|
||||
|
||||
boolean isEnumEntry = DescriptorUtils.isEnumClassObject(owner);
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
|
||||
PropertyDescriptorImpl propertyDescriptor = new PropertyDescriptorImpl(
|
||||
owner,
|
||||
annotationResolver.resolveAnnotations(psiData.getCharacteristicPsi()),
|
||||
DescriptorResolverUtils.resolveModality(characteristicMember.getMember(),
|
||||
|
||||
@@ -16,298 +16,33 @@
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
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.DescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.OverridingUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.DescriptorSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class PropertyDescriptor extends VariableDescriptorImpl implements CallableMemberDescriptor {
|
||||
|
||||
private final Modality modality;
|
||||
private Visibility visibility;
|
||||
private final boolean isVar;
|
||||
private final Set<PropertyDescriptor> overriddenProperties = Sets.newLinkedHashSet(); // LinkedHashSet is essential here
|
||||
private final PropertyDescriptor original;
|
||||
private final Kind kind;
|
||||
|
||||
private ReceiverParameterDescriptor expectedThisObject;
|
||||
private ReceiverParameterDescriptor receiverParameter;
|
||||
private List<TypeParameterDescriptor> typeParameters;
|
||||
private PropertyGetterDescriptor getter;
|
||||
private PropertySetterDescriptor setter;
|
||||
|
||||
private PropertyDescriptor(
|
||||
@Nullable PropertyDescriptor original,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean isVar,
|
||||
@NotNull Name name,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
super(containingDeclaration, annotations, name);
|
||||
this.isVar = isVar;
|
||||
this.modality = modality;
|
||||
this.visibility = visibility;
|
||||
this.original = original == null ? this : original.getOriginal();
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
public PropertyDescriptor(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean isVar,
|
||||
@NotNull Name name,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
this(null, containingDeclaration, annotations, modality, visibility, isVar, name, kind);
|
||||
}
|
||||
|
||||
public PropertyDescriptor(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean isVar,
|
||||
@Nullable JetType receiverType,
|
||||
@Nullable ReceiverParameterDescriptor expectedThisObject,
|
||||
@NotNull Name name,
|
||||
@NotNull JetType outType,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
this(containingDeclaration, annotations, modality, visibility, isVar, name, kind);
|
||||
setType(outType, Collections.<TypeParameterDescriptor>emptyList(), expectedThisObject, receiverType);
|
||||
}
|
||||
|
||||
public void setType(
|
||||
@NotNull JetType outType,
|
||||
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@Nullable ReceiverParameterDescriptor expectedThisObject,
|
||||
@Nullable JetType receiverType
|
||||
) {
|
||||
ReceiverParameterDescriptor receiverParameter = DescriptorResolver.resolveReceiverParameterFor(this, receiverType);
|
||||
setType(outType, typeParameters, expectedThisObject, receiverParameter);
|
||||
}
|
||||
|
||||
public void setType(
|
||||
@NotNull JetType outType,
|
||||
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@Nullable ReceiverParameterDescriptor expectedThisObject,
|
||||
@Nullable ReceiverParameterDescriptor receiverParameter
|
||||
) {
|
||||
setOutType(outType);
|
||||
|
||||
this.typeParameters = Lists.newArrayList(typeParameters);
|
||||
|
||||
this.receiverParameter = receiverParameter;
|
||||
this.expectedThisObject = expectedThisObject;
|
||||
}
|
||||
|
||||
public void initialize(@Nullable PropertyGetterDescriptor getter, @Nullable PropertySetterDescriptor setter) {
|
||||
this.getter = getter;
|
||||
this.setter = setter;
|
||||
}
|
||||
|
||||
public void setVisibility(@NotNull Visibility visibility) {
|
||||
this.visibility = visibility;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> getTypeParameters() {
|
||||
return typeParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public interface PropertyDescriptor
|
||||
extends Annotated, Named, DeclarationDescriptor, DeclarationDescriptorNonRoot, VariableDescriptor, CallableMemberDescriptor {
|
||||
@Nullable
|
||||
public ReceiverParameterDescriptor getReceiverParameter() {
|
||||
return receiverParameter;
|
||||
}
|
||||
PropertyGetterDescriptor getGetter();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getExpectedThisObject() {
|
||||
return expectedThisObject;
|
||||
}
|
||||
PropertySetterDescriptor getSetter();
|
||||
|
||||
@NotNull
|
||||
List<PropertyAccessorDescriptor> getAccessors();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getReturnType() {
|
||||
return getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVar() {
|
||||
return isVar;
|
||||
}
|
||||
PropertyDescriptor getOriginal();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Modality getModality() {
|
||||
return modality;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Visibility getVisibility() {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PropertyGetterDescriptor getGetter() {
|
||||
return getter;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PropertySetterDescriptor getSetter() {
|
||||
return setter;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<PropertyAccessorDescriptor> getAccessors() {
|
||||
List<PropertyAccessorDescriptor> r = Lists.newArrayListWithCapacity(2);
|
||||
if (getter != null) {
|
||||
r.add(getter);
|
||||
}
|
||||
if (setter != null) {
|
||||
r.add(setter);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
Set<? extends PropertyDescriptor> getOverriddenDescriptors();
|
||||
|
||||
@Override
|
||||
public PropertyDescriptor substitute(TypeSubstitutor originalSubstitutor) {
|
||||
if (originalSubstitutor.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
return doSubstitute(originalSubstitutor, getContainingDeclaration(), modality, visibility, true, true, getKind());
|
||||
}
|
||||
|
||||
private PropertyDescriptor doSubstitute(TypeSubstitutor originalSubstitutor,
|
||||
DeclarationDescriptor newOwner, Modality newModality, Visibility newVisibility, boolean preserveOriginal, boolean copyOverrides, Kind kind) {
|
||||
PropertyDescriptor substitutedDescriptor = new PropertyDescriptor(preserveOriginal ? getOriginal() : this, newOwner,
|
||||
getAnnotations(), newModality, newVisibility, isVar(), getName(), kind);
|
||||
|
||||
List<TypeParameterDescriptor> substitutedTypeParameters = Lists.newArrayList();
|
||||
TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(getTypeParameters(), originalSubstitutor, substitutedDescriptor, substitutedTypeParameters);
|
||||
|
||||
JetType originalOutType = getType();
|
||||
JetType outType = substitutor.substitute(originalOutType, Variance.OUT_VARIANCE);
|
||||
if (outType == null) {
|
||||
return null; // TODO : tell the user that the property was projected out
|
||||
}
|
||||
|
||||
|
||||
ReceiverParameterDescriptor substitutedExpectedThisObject;
|
||||
ReceiverParameterDescriptor expectedThisObject = getExpectedThisObject();
|
||||
if (expectedThisObject != null) {
|
||||
substitutedExpectedThisObject = expectedThisObject.substitute(substitutor);
|
||||
if (substitutedExpectedThisObject == null) return null;
|
||||
}
|
||||
else {
|
||||
substitutedExpectedThisObject = null;
|
||||
}
|
||||
|
||||
JetType substitutedReceiverType;
|
||||
if (receiverParameter != null) {
|
||||
substitutedReceiverType = substitutor.substitute(receiverParameter.getType(), Variance.IN_VARIANCE);
|
||||
if (substitutedReceiverType == null) return null;
|
||||
}
|
||||
else {
|
||||
substitutedReceiverType = null;
|
||||
}
|
||||
|
||||
substitutedDescriptor.setType(outType, substitutedTypeParameters, substitutedExpectedThisObject, substitutedReceiverType);
|
||||
|
||||
PropertyGetterDescriptor newGetter = getter == null ? null : new PropertyGetterDescriptor(
|
||||
substitutedDescriptor, Lists.newArrayList(getter.getAnnotations()),
|
||||
DescriptorUtils.convertModality(getter.getModality(), false), convertVisibility(getter.getVisibility(), newVisibility),
|
||||
getter.hasBody(), getter.isDefault(), kind, getter.getOriginal());
|
||||
if (newGetter != null) {
|
||||
JetType returnType = getter.getReturnType();
|
||||
newGetter.initialize(returnType != null ? substitutor.substitute(returnType, Variance.OUT_VARIANCE) : null);
|
||||
}
|
||||
PropertySetterDescriptor newSetter = setter == null ? null : new PropertySetterDescriptor(
|
||||
substitutedDescriptor, Lists.newArrayList(setter.getAnnotations()), DescriptorUtils.convertModality(setter.getModality(), false),
|
||||
convertVisibility(setter.getVisibility(), newVisibility), setter.hasBody(), setter.isDefault(), kind, setter.getOriginal());
|
||||
if (newSetter != null) {
|
||||
List<ValueParameterDescriptor> substitutedValueParameters = FunctionDescriptorUtil.getSubstitutedValueParameters(newSetter, setter, substitutor);
|
||||
if (substitutedValueParameters == null) {
|
||||
return null;
|
||||
}
|
||||
if (substitutedValueParameters.size() != 1) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
newSetter.initialize(substitutedValueParameters.get(0));
|
||||
}
|
||||
|
||||
substitutedDescriptor.initialize(newGetter, newSetter);
|
||||
|
||||
if (copyOverrides) {
|
||||
for (PropertyDescriptor propertyDescriptor : overriddenProperties) {
|
||||
OverridingUtil.bindOverride(substitutedDescriptor, propertyDescriptor.substitute(substitutor));
|
||||
}
|
||||
}
|
||||
|
||||
return substitutedDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Visibility convertVisibility(Visibility orig, Visibility candidate) {
|
||||
if (candidate == Visibilities.INHERITED) {
|
||||
return candidate;
|
||||
}
|
||||
|
||||
Integer result = Visibilities.compare(orig, candidate);
|
||||
return result != null && result < 0 ? candidate : orig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitPropertyDescriptor(this, data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PropertyDescriptor getOriginal() {
|
||||
return original;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOverriddenDescriptor(@NotNull CallableMemberDescriptor overridden) {
|
||||
overriddenProperties.add((PropertyDescriptor) overridden);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<? extends PropertyDescriptor> getOverriddenDescriptors() {
|
||||
return overriddenProperties;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PropertyDescriptor copy(DeclarationDescriptor newOwner, Modality modality, Visibility visibility, Kind kind, boolean copyOverrides) {
|
||||
return doSubstitute(TypeSubstitutor.EMPTY, newOwner, modality, visibility, false, copyOverrides, kind);
|
||||
}
|
||||
PropertyDescriptor substitute(TypeSubstitutor substitutor);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,316 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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 com.google.common.collect.Lists;
|
||||
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.DescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.OverridingUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.DescriptorSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class PropertyDescriptorImpl extends VariableDescriptorImpl implements PropertyDescriptor {
|
||||
|
||||
private final Modality modality;
|
||||
private Visibility visibility;
|
||||
private final boolean isVar;
|
||||
private final Set<PropertyDescriptor> overriddenProperties = Sets.newLinkedHashSet(); // LinkedHashSet is essential here
|
||||
private final PropertyDescriptor original;
|
||||
private final Kind kind;
|
||||
|
||||
private ReceiverParameterDescriptor expectedThisObject;
|
||||
private ReceiverParameterDescriptor receiverParameter;
|
||||
private List<TypeParameterDescriptor> typeParameters;
|
||||
private PropertyGetterDescriptor getter;
|
||||
private PropertySetterDescriptor setter;
|
||||
|
||||
private PropertyDescriptorImpl(
|
||||
@Nullable PropertyDescriptor original,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean isVar,
|
||||
@NotNull Name name,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
super(containingDeclaration, annotations, name);
|
||||
this.isVar = isVar;
|
||||
this.modality = modality;
|
||||
this.visibility = visibility;
|
||||
this.original = original == null ? this : original.getOriginal();
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
public PropertyDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean isVar,
|
||||
@NotNull Name name,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
this(null, containingDeclaration, annotations, modality, visibility, isVar, name, kind);
|
||||
}
|
||||
|
||||
public PropertyDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean isVar,
|
||||
@Nullable JetType receiverType,
|
||||
@Nullable ReceiverParameterDescriptor expectedThisObject,
|
||||
@NotNull Name name,
|
||||
@NotNull JetType outType,
|
||||
@NotNull Kind kind
|
||||
) {
|
||||
this(containingDeclaration, annotations, modality, visibility, isVar, name, kind);
|
||||
setType(outType, Collections.<TypeParameterDescriptor>emptyList(), expectedThisObject, receiverType);
|
||||
}
|
||||
|
||||
public void setType(
|
||||
@NotNull JetType outType,
|
||||
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@Nullable ReceiverParameterDescriptor expectedThisObject,
|
||||
@Nullable JetType receiverType
|
||||
) {
|
||||
ReceiverParameterDescriptor receiverParameter = DescriptorResolver.resolveReceiverParameterFor(this, receiverType);
|
||||
setType(outType, typeParameters, expectedThisObject, receiverParameter);
|
||||
}
|
||||
|
||||
public void setType(
|
||||
@NotNull JetType outType,
|
||||
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
|
||||
@Nullable ReceiverParameterDescriptor expectedThisObject,
|
||||
@Nullable ReceiverParameterDescriptor receiverParameter
|
||||
) {
|
||||
setOutType(outType);
|
||||
|
||||
this.typeParameters = Lists.newArrayList(typeParameters);
|
||||
|
||||
this.receiverParameter = receiverParameter;
|
||||
this.expectedThisObject = expectedThisObject;
|
||||
}
|
||||
|
||||
public void initialize(@Nullable PropertyGetterDescriptor getter, @Nullable PropertySetterDescriptor setter) {
|
||||
this.getter = getter;
|
||||
this.setter = setter;
|
||||
}
|
||||
|
||||
public void setVisibility(@NotNull Visibility visibility) {
|
||||
this.visibility = visibility;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> getTypeParameters() {
|
||||
return typeParameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ReceiverParameterDescriptor getReceiverParameter() {
|
||||
return receiverParameter;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ReceiverParameterDescriptor getExpectedThisObject() {
|
||||
return expectedThisObject;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetType getReturnType() {
|
||||
return getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVar() {
|
||||
return isVar;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Modality getModality() {
|
||||
return modality;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Visibility getVisibility() {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public PropertyGetterDescriptor getGetter() {
|
||||
return getter;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public PropertySetterDescriptor getSetter() {
|
||||
return setter;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<PropertyAccessorDescriptor> getAccessors() {
|
||||
List<PropertyAccessorDescriptor> r = Lists.newArrayListWithCapacity(2);
|
||||
if (getter != null) {
|
||||
r.add(getter);
|
||||
}
|
||||
if (setter != null) {
|
||||
r.add(setter);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyDescriptor substitute(TypeSubstitutor originalSubstitutor) {
|
||||
if (originalSubstitutor.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
return doSubstitute(originalSubstitutor, getContainingDeclaration(), modality, visibility, true, true, getKind());
|
||||
}
|
||||
|
||||
private PropertyDescriptor doSubstitute(TypeSubstitutor originalSubstitutor,
|
||||
DeclarationDescriptor newOwner, Modality newModality, Visibility newVisibility, boolean preserveOriginal, boolean copyOverrides, Kind kind) {
|
||||
PropertyDescriptorImpl substitutedDescriptor = new PropertyDescriptorImpl(preserveOriginal ? getOriginal() : this, newOwner,
|
||||
getAnnotations(), newModality, newVisibility, isVar(), getName(), kind);
|
||||
|
||||
List<TypeParameterDescriptor> substitutedTypeParameters = Lists.newArrayList();
|
||||
TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(getTypeParameters(), originalSubstitutor, substitutedDescriptor, substitutedTypeParameters);
|
||||
|
||||
JetType originalOutType = getType();
|
||||
JetType outType = substitutor.substitute(originalOutType, Variance.OUT_VARIANCE);
|
||||
if (outType == null) {
|
||||
return null; // TODO : tell the user that the property was projected out
|
||||
}
|
||||
|
||||
|
||||
ReceiverParameterDescriptor substitutedExpectedThisObject;
|
||||
ReceiverParameterDescriptor expectedThisObject = getExpectedThisObject();
|
||||
if (expectedThisObject != null) {
|
||||
substitutedExpectedThisObject = expectedThisObject.substitute(substitutor);
|
||||
if (substitutedExpectedThisObject == null) return null;
|
||||
}
|
||||
else {
|
||||
substitutedExpectedThisObject = null;
|
||||
}
|
||||
|
||||
JetType substitutedReceiverType;
|
||||
if (receiverParameter != null) {
|
||||
substitutedReceiverType = substitutor.substitute(receiverParameter.getType(), Variance.IN_VARIANCE);
|
||||
if (substitutedReceiverType == null) return null;
|
||||
}
|
||||
else {
|
||||
substitutedReceiverType = null;
|
||||
}
|
||||
|
||||
substitutedDescriptor.setType(outType, substitutedTypeParameters, substitutedExpectedThisObject, substitutedReceiverType);
|
||||
|
||||
PropertyGetterDescriptor newGetter = getter == null ? null : new PropertyGetterDescriptor(
|
||||
substitutedDescriptor, Lists.newArrayList(getter.getAnnotations()),
|
||||
DescriptorUtils.convertModality(getter.getModality(), false), convertVisibility(getter.getVisibility(), newVisibility),
|
||||
getter.hasBody(), getter.isDefault(), kind, getter.getOriginal());
|
||||
if (newGetter != null) {
|
||||
JetType returnType = getter.getReturnType();
|
||||
newGetter.initialize(returnType != null ? substitutor.substitute(returnType, Variance.OUT_VARIANCE) : null);
|
||||
}
|
||||
PropertySetterDescriptor newSetter = setter == null ? null : new PropertySetterDescriptor(
|
||||
substitutedDescriptor, Lists.newArrayList(setter.getAnnotations()), DescriptorUtils.convertModality(setter.getModality(), false),
|
||||
convertVisibility(setter.getVisibility(), newVisibility), setter.hasBody(), setter.isDefault(), kind, setter.getOriginal());
|
||||
if (newSetter != null) {
|
||||
List<ValueParameterDescriptor> substitutedValueParameters = FunctionDescriptorUtil.getSubstitutedValueParameters(newSetter, setter, substitutor);
|
||||
if (substitutedValueParameters == null) {
|
||||
return null;
|
||||
}
|
||||
if (substitutedValueParameters.size() != 1) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
newSetter.initialize(substitutedValueParameters.get(0));
|
||||
}
|
||||
|
||||
substitutedDescriptor.initialize(newGetter, newSetter);
|
||||
|
||||
if (copyOverrides) {
|
||||
for (PropertyDescriptor propertyDescriptor : overriddenProperties) {
|
||||
OverridingUtil.bindOverride(substitutedDescriptor, propertyDescriptor.substitute(substitutor));
|
||||
}
|
||||
}
|
||||
|
||||
return substitutedDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Visibility convertVisibility(Visibility orig, Visibility candidate) {
|
||||
if (candidate == Visibilities.INHERITED) {
|
||||
return candidate;
|
||||
}
|
||||
|
||||
Integer result = Visibilities.compare(orig, candidate);
|
||||
return result != null && result < 0 ? candidate : orig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
return visitor.visitPropertyDescriptor(this, data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PropertyDescriptor getOriginal() {
|
||||
return original;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOverriddenDescriptor(@NotNull CallableMemberDescriptor overridden) {
|
||||
overriddenProperties.add((PropertyDescriptorImpl) overridden);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<? extends PropertyDescriptor> getOverriddenDescriptors() {
|
||||
return overriddenProperties;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PropertyDescriptor copy(DeclarationDescriptor newOwner, Modality modality, Visibility visibility, Kind kind, boolean copyOverrides) {
|
||||
return doSubstitute(TypeSubstitutor.EMPTY, newOwner, modality, visibility, false, copyOverrides, kind);
|
||||
}
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl {
|
||||
this.returnType = returnType;
|
||||
scriptCodeDescriptor.initialize(implicitReceiver, valueParameters, returnType);
|
||||
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(classDescriptor,
|
||||
PropertyDescriptorImpl propertyDescriptor = new PropertyDescriptorImpl(classDescriptor,
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
Modality.FINAL,
|
||||
Visibilities.PUBLIC,
|
||||
@@ -104,7 +104,7 @@ public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl {
|
||||
if(jetDeclaration instanceof JetProperty) {
|
||||
VariableDescriptor descriptor = bindingContext.get(BindingContext.VARIABLE, jetDeclaration);
|
||||
assert descriptor != null;
|
||||
initializeWithDefaultGetterSetter((PropertyDescriptor) descriptor);
|
||||
initializeWithDefaultGetterSetter((PropertyDescriptorImpl) descriptor);
|
||||
classScope.addPropertyDescriptor(descriptor);
|
||||
}
|
||||
else if(jetDeclaration instanceof JetNamedFunction) {
|
||||
@@ -117,7 +117,7 @@ public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl {
|
||||
}
|
||||
}
|
||||
|
||||
public static void initializeWithDefaultGetterSetter(PropertyDescriptor propertyDescriptor) {
|
||||
public static void initializeWithDefaultGetterSetter(PropertyDescriptorImpl propertyDescriptor) {
|
||||
PropertyGetterDescriptor getter = propertyDescriptor.getGetter();
|
||||
if(getter == null) {
|
||||
getter = propertyDescriptor.getVisibility() != Visibilities.PRIVATE ? DescriptorResolver.createDefaultGetter(propertyDescriptor) : null;
|
||||
@@ -177,7 +177,7 @@ public class ScriptDescriptor extends DeclarationDescriptorNonRootImpl {
|
||||
classDescriptor.setPrimaryConstructor(constructorDescriptor);
|
||||
|
||||
for (ValueParameterDescriptor parameter : valueParameters) {
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(classDescriptor,
|
||||
PropertyDescriptorImpl propertyDescriptor = new PropertyDescriptorImpl(classDescriptor,
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
Modality.FINAL,
|
||||
Visibilities.PUBLIC,
|
||||
|
||||
@@ -718,7 +718,7 @@ public class DescriptorResolver {
|
||||
BindingTrace trace
|
||||
) {
|
||||
if (JetPsiUtil.isScriptDeclaration(variable)) {
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
|
||||
PropertyDescriptorImpl propertyDescriptor = new PropertyDescriptorImpl(
|
||||
containingDeclaration,
|
||||
annotationResolver.getResolvedAnnotations(variable.getModifierList(), trace),
|
||||
Modality.FINAL,
|
||||
@@ -787,7 +787,7 @@ public class DescriptorResolver {
|
||||
@NotNull ClassDescriptor classDescriptor, BindingTrace trace
|
||||
) {
|
||||
JetModifierList modifierList = objectDeclaration.getModifierList();
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
|
||||
PropertyDescriptorImpl propertyDescriptor = new PropertyDescriptorImpl(
|
||||
containingDeclaration,
|
||||
annotationResolver.getResolvedAnnotations(modifierList, trace),
|
||||
Modality.FINAL,
|
||||
@@ -899,7 +899,7 @@ public class DescriptorResolver {
|
||||
? resolveModalityFromModifiers(property, getDefaultModality(containingDeclaration, hasBody))
|
||||
: Modality.FINAL;
|
||||
Visibility visibility = resolveVisibilityFromModifiers(property, getDefaultVisibility(property, containingDeclaration));
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
|
||||
PropertyDescriptorImpl propertyDescriptor = new PropertyDescriptorImpl(
|
||||
containingDeclaration,
|
||||
annotationResolver.resolveAnnotations(scope, modifierList, trace),
|
||||
modality,
|
||||
@@ -1196,7 +1196,7 @@ public class DescriptorResolver {
|
||||
}
|
||||
}
|
||||
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
|
||||
PropertyDescriptorImpl propertyDescriptor = new PropertyDescriptorImpl(
|
||||
classDescriptor,
|
||||
valueParameter.getAnnotations(),
|
||||
resolveModalityFromModifiers(parameter, Modality.FINAL),
|
||||
|
||||
@@ -880,8 +880,8 @@ public class OverrideResolver {
|
||||
visibility = Visibilities.PUBLIC;
|
||||
}
|
||||
|
||||
if (memberDescriptor instanceof PropertyDescriptor) {
|
||||
((PropertyDescriptor)memberDescriptor).setVisibility(visibility);
|
||||
if (memberDescriptor instanceof PropertyDescriptorImpl) {
|
||||
((PropertyDescriptorImpl)memberDescriptor).setVisibility(visibility);
|
||||
for (PropertyAccessorDescriptor accessor : ((PropertyDescriptor) memberDescriptor).getAccessors()) {
|
||||
resolveUnknownVisibilityForMember(null, accessor, trace);
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ public class ErrorUtils {
|
||||
}
|
||||
|
||||
private static final JetType ERROR_PROPERTY_TYPE = createErrorType("<ERROR PROPERTY TYPE>");
|
||||
private static final VariableDescriptor ERROR_PROPERTY = new PropertyDescriptor(
|
||||
private static final VariableDescriptor ERROR_PROPERTY = new PropertyDescriptorImpl(
|
||||
ERROR_CLASS,
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
Modality.OPEN,
|
||||
|
||||
Reference in New Issue
Block a user