rewrite owner when copying FunctionDescriptor from supertype scope
that fixes invocation: >>> StringBuilder.length() that was compiled to >>> invokevirtual CharSequence.length() and now compiles to >>> invokevirtual StringBuilder.length() Essentially patch rewrites FunctionDescriptor.containingDeclaration when FunctionDescriptor is copied to subclass scope. FunctionDescriptor now has kind field that can be * DECLARATION (for "real" function, maybe abstract) * DELEGATION * FAKE_OVERRIDE (created for functions from supertypes) All tests pass although some parts of code are buggy and ugly. Random comments about this patch: * FunctionDescriptor.overrides point to function descriptors of supertype scopes * Filling of memberScope with supertypes is moved to OverrideResolver * ExpressionCodegen.intermediateValueForProperty must be rewritten * Patch adds not nice REDECLARATION reports (see compiler/testData/diagnostics/tests/*). Will be fixed later.
This commit is contained in:
+17
-1
@@ -12,6 +12,22 @@ public interface CallableMemberDescriptor extends CallableDescriptor, MemberDesc
|
||||
@Override
|
||||
Set<? extends CallableMemberDescriptor> getOverriddenDescriptors();
|
||||
|
||||
public enum Kind {
|
||||
DECLARATION,
|
||||
FAKE_OVERRIDE,
|
||||
DELEGATION,
|
||||
;
|
||||
|
||||
public boolean isReal() {
|
||||
return this == DECLARATION || this == DELEGATION;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this a real function or function projection.
|
||||
*/
|
||||
Kind getKind();
|
||||
|
||||
@NotNull
|
||||
CallableMemberDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract);
|
||||
CallableMemberDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract, Kind kind, boolean copyOverrides);
|
||||
}
|
||||
|
||||
+7
-4
@@ -19,12 +19,12 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
private final boolean isPrimary;
|
||||
|
||||
public ConstructorDescriptorImpl(@NotNull ClassDescriptor containingDeclaration, @NotNull List<AnnotationDescriptor> annotations, boolean isPrimary) {
|
||||
super(containingDeclaration, annotations, "<init>");
|
||||
super(containingDeclaration, annotations, "<init>", Kind.DECLARATION);
|
||||
this.isPrimary = isPrimary;
|
||||
}
|
||||
|
||||
public ConstructorDescriptorImpl(@NotNull ClassDescriptor containingDeclaration, @NotNull ConstructorDescriptor original, @NotNull List<AnnotationDescriptor> annotations, boolean isPrimary) {
|
||||
super(containingDeclaration, original, annotations, "<init>");
|
||||
super(containingDeclaration, original, annotations, "<init>", Kind.DECLARATION);
|
||||
this.isPrimary = isPrimary;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,10 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal) {
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||
if (kind != Kind.DECLARATION) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return new ConstructorDescriptorImpl(
|
||||
(ClassDescriptor) newOwner,
|
||||
this,
|
||||
@@ -95,7 +98,7 @@ public class ConstructorDescriptorImpl extends FunctionDescriptorImpl implements
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ConstructorDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) {
|
||||
public ConstructorDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract, Kind kind, boolean copyOverrides) {
|
||||
throw new UnsupportedOperationException("Constructors should not be copied for overriding");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,5 +26,5 @@ public interface FunctionDescriptor extends CallableMemberDescriptor {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
FunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract);
|
||||
FunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract, Kind kind, boolean copyOverrides);
|
||||
}
|
||||
|
||||
+23
-11
@@ -31,24 +31,29 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorImpl i
|
||||
|
||||
protected Modality modality;
|
||||
protected Visibility visibility;
|
||||
private final Set<FunctionDescriptor> overriddenFunctions = Sets.newLinkedHashSet();
|
||||
protected final Set<FunctionDescriptor> overriddenFunctions = Sets.newLinkedHashSet();
|
||||
private final FunctionDescriptor original;
|
||||
private final Kind kind;
|
||||
|
||||
protected FunctionDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull String name) {
|
||||
@NotNull String name,
|
||||
Kind kind) {
|
||||
super(containingDeclaration, annotations, name);
|
||||
this.original = this;
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
protected FunctionDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containigDeclaration,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull FunctionDescriptor original,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull String name) {
|
||||
super(containigDeclaration, annotations, name);
|
||||
@NotNull String name,
|
||||
Kind kind) {
|
||||
super(containingDeclaration, annotations, name);
|
||||
this.original = original;
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
public FunctionDescriptorImpl initialize(
|
||||
@@ -146,17 +151,22 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorImpl i
|
||||
return original == this ? this : original.getOriginal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final FunctionDescriptor substitute(TypeSubstitutor originalSubstitutor) {
|
||||
if (originalSubstitutor.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
return doSubstitute(originalSubstitutor, getContainingDeclaration(), modality, true);
|
||||
return doSubstitute(originalSubstitutor, getContainingDeclaration(), modality, true, true, getKind());
|
||||
}
|
||||
|
||||
protected FunctionDescriptor doSubstitute(TypeSubstitutor originalSubstitutor,
|
||||
DeclarationDescriptor newOwner, Modality newModality, boolean preserveOriginal) {
|
||||
FunctionDescriptorImpl substitutedDescriptor = createSubstitutedCopy(newOwner, preserveOriginal);
|
||||
DeclarationDescriptor newOwner, Modality newModality, boolean preserveOriginal, boolean copyOverrides, Kind kind) {
|
||||
FunctionDescriptorImpl substitutedDescriptor = createSubstitutedCopy(newOwner, preserveOriginal, kind);
|
||||
|
||||
List<TypeParameterDescriptor> substitutedTypeParameters = Lists.newArrayList();
|
||||
TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(getTypeParameters(), originalSubstitutor, substitutedDescriptor, substitutedTypeParameters);
|
||||
@@ -197,13 +207,15 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorImpl i
|
||||
newModality,
|
||||
visibility
|
||||
);
|
||||
for (FunctionDescriptor overriddenFunction : overriddenFunctions) {
|
||||
substitutedDescriptor.addOverriddenFunction(overriddenFunction);
|
||||
if (copyOverrides) {
|
||||
for (FunctionDescriptor overriddenFunction : overriddenFunctions) {
|
||||
substitutedDescriptor.addOverriddenFunction(overriddenFunction.substitute(substitutor));
|
||||
}
|
||||
}
|
||||
return substitutedDescriptor;
|
||||
}
|
||||
|
||||
protected abstract FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal);
|
||||
protected abstract FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind);
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ public class FunctionDescriptorUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static List<ValueParameterDescriptor> getSubstitutedValueParameters(FunctionDescriptor substitutedDescriptor, @NotNull FunctionDescriptor functionDescriptor, TypeSubstitutor substitutor) {
|
||||
public static List<ValueParameterDescriptor> getSubstitutedValueParameters(FunctionDescriptor substitutedDescriptor, @NotNull FunctionDescriptor functionDescriptor, @NotNull TypeSubstitutor substitutor) {
|
||||
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>();
|
||||
List<ValueParameterDescriptor> unsubstitutedValueParameters = functionDescriptor.getValueParameters();
|
||||
for (int i = 0, unsubstitutedValueParametersSize = unsubstitutedValueParameters.size(); i < unsubstitutedValueParametersSize; i++) {
|
||||
|
||||
+1
-7
@@ -104,17 +104,11 @@ public class MutableClassDescriptorLite extends MutableDeclarationDescriptor imp
|
||||
}
|
||||
}
|
||||
|
||||
private WritableScope getScopeForMemberLookupAsWritableScope() {
|
||||
public WritableScope getScopeForMemberLookupAsWritableScope() {
|
||||
// hack
|
||||
return (WritableScope) scopeForMemberLookup;
|
||||
}
|
||||
|
||||
public void addSupertypesToScopeForMemberLookup() {
|
||||
for (JetType supertype : supertypes) {
|
||||
getScopeForMemberLookupAsWritableScope().importScope(supertype.getMemberScope());
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetScope getMemberScope(List<TypeProjection> typeArguments) {
|
||||
|
||||
+5
-1
@@ -11,5 +11,9 @@ public interface NamedFunctionDescriptor extends FunctionDescriptor {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
NamedFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract);
|
||||
NamedFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract, Kind kind, boolean copyOverrides);
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
NamedFunctionDescriptor getOriginal();
|
||||
}
|
||||
|
||||
+20
-10
@@ -1,6 +1,5 @@
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
@@ -13,12 +12,21 @@ import java.util.List;
|
||||
*/
|
||||
public class NamedFunctionDescriptorImpl extends FunctionDescriptorImpl implements NamedFunctionDescriptor {
|
||||
|
||||
public NamedFunctionDescriptorImpl(@NotNull DeclarationDescriptor containingDeclaration, @NotNull List<AnnotationDescriptor> annotations, @NotNull String name) {
|
||||
super(containingDeclaration, annotations, name);
|
||||
public NamedFunctionDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull String name,
|
||||
Kind kind) {
|
||||
super(containingDeclaration, annotations, name, kind);
|
||||
}
|
||||
|
||||
private NamedFunctionDescriptorImpl(@NotNull DeclarationDescriptor containingDeclaration, @NotNull NamedFunctionDescriptor original, @NotNull List<AnnotationDescriptor> annotations, @NotNull String name) {
|
||||
super(containingDeclaration, original, annotations, name);
|
||||
private NamedFunctionDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull NamedFunctionDescriptor original,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull String name,
|
||||
Kind kind) {
|
||||
super(containingDeclaration, original, annotations, name, kind);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -28,26 +36,28 @@ public class NamedFunctionDescriptorImpl extends FunctionDescriptorImpl implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal) {
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||
if (preserveOriginal) {
|
||||
return new NamedFunctionDescriptorImpl(
|
||||
newOwner,
|
||||
getOriginal(),
|
||||
// TODO : safeSubstitute
|
||||
getAnnotations(),
|
||||
getName());
|
||||
getName(),
|
||||
kind);
|
||||
} else {
|
||||
return new NamedFunctionDescriptorImpl(
|
||||
newOwner,
|
||||
// TODO : safeSubstitute
|
||||
getAnnotations(),
|
||||
getName());
|
||||
getName(),
|
||||
kind);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NamedFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) {
|
||||
return (NamedFunctionDescriptor) doSubstitute(TypeSubstitutor.EMPTY, newOwner, DescriptorUtils.convertModality(modality, makeNonAbstract), false);
|
||||
public NamedFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract, Kind kind, boolean copyOverrides) {
|
||||
return (NamedFunctionDescriptor) doSubstitute(TypeSubstitutor.EMPTY, newOwner, DescriptorUtils.convertModality(modality, makeNonAbstract), false, copyOverrides, kind);
|
||||
}
|
||||
}
|
||||
|
||||
+10
-2
@@ -20,6 +20,7 @@ public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorIm
|
||||
private final Modality modality;
|
||||
private final Visibility visibility;
|
||||
private final PropertyDescriptor correspondingProperty;
|
||||
private final Kind kind;
|
||||
|
||||
public PropertyAccessorDescriptor(
|
||||
@NotNull Modality modality,
|
||||
@@ -28,13 +29,15 @@ public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorIm
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull String name,
|
||||
boolean hasBody,
|
||||
boolean isDefault) {
|
||||
boolean isDefault,
|
||||
Kind kind) {
|
||||
super(correspondingProperty.getContainingDeclaration(), annotations, name);
|
||||
this.modality = modality;
|
||||
this.visibility = visibility;
|
||||
this.correspondingProperty = correspondingProperty;
|
||||
this.hasBody = hasBody;
|
||||
this.isDefault = isDefault;
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
public boolean hasBody() {
|
||||
@@ -45,6 +48,11 @@ public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorIm
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PropertyAccessorDescriptor getOriginal() {
|
||||
@@ -94,7 +102,7 @@ public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorIm
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PropertyAccessorDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) {
|
||||
public PropertyAccessorDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract, Kind kind, boolean copyOverrides) {
|
||||
throw new UnsupportedOperationException("Accessors must be copied by the corresponding property");
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
private final boolean isObject;
|
||||
private final Set<PropertyDescriptor> overriddenProperties = Sets.newLinkedHashSet();
|
||||
private final PropertyDescriptor original;
|
||||
private final Kind kind;
|
||||
|
||||
private ReceiverDescriptor expectedThisObject;
|
||||
private ReceiverDescriptor receiver;
|
||||
@@ -46,6 +47,7 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
this.isVar = false;
|
||||
this.isObject = false;
|
||||
this.original = null;
|
||||
this.kind = Kind.DECLARATION;
|
||||
}
|
||||
|
||||
private PropertyDescriptor(
|
||||
@@ -56,13 +58,15 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
@NotNull Visibility visibility,
|
||||
boolean isVar,
|
||||
boolean isObject,
|
||||
@NotNull String name) {
|
||||
@NotNull String name,
|
||||
Kind kind) {
|
||||
super(containingDeclaration, annotations, name);
|
||||
this.isVar = isVar;
|
||||
this.isObject = isObject;
|
||||
this.modality = modality;
|
||||
this.visibility = visibility;
|
||||
this.original = original == null ? this : original.getOriginal();
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
public PropertyDescriptor(
|
||||
@@ -72,8 +76,9 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
@NotNull Visibility visibility,
|
||||
boolean isVar,
|
||||
boolean isObject,
|
||||
@NotNull String name) {
|
||||
this(null, containingDeclaration, annotations, modality, visibility, isVar, isObject, name);
|
||||
@NotNull String name,
|
||||
Kind kind) {
|
||||
this(null, containingDeclaration, annotations, modality, visibility, isVar, isObject, name, kind);
|
||||
}
|
||||
|
||||
public PropertyDescriptor(
|
||||
@@ -86,9 +91,10 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
@Nullable JetType receiverType,
|
||||
@NotNull ReceiverDescriptor expectedThisObject,
|
||||
@NotNull String name,
|
||||
@NotNull JetType outType
|
||||
@NotNull JetType outType,
|
||||
Kind kind
|
||||
) {
|
||||
this(containingDeclaration, annotations, modality, visibility, isVar, isObject, name);
|
||||
this(containingDeclaration, annotations, modality, visibility, isVar, isObject, name, kind);
|
||||
setType(outType, Collections.<TypeParameterDescriptor>emptyList(), expectedThisObject, receiverType);
|
||||
}
|
||||
|
||||
@@ -171,7 +177,13 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
if (originalSubstitutor.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
PropertyDescriptor substitutedDescriptor = new PropertyDescriptor(this, getContainingDeclaration(), getAnnotations(), getModality(), getVisibility(), isVar(), isObjectDeclaration(), getName());
|
||||
return doSubstitute(originalSubstitutor, getContainingDeclaration(), modality, true, true, getKind());
|
||||
}
|
||||
|
||||
private PropertyDescriptor doSubstitute(TypeSubstitutor originalSubstitutor,
|
||||
DeclarationDescriptor newOwner, Modality newModality, boolean preserveOriginal, boolean copyOverrides, Kind kind) {
|
||||
PropertyDescriptor substitutedDescriptor = new PropertyDescriptor(preserveOriginal ? getOriginal() : this, newOwner,
|
||||
getAnnotations(), newModality, getVisibility(), isVar(), isObjectDeclaration(), getName(), kind);
|
||||
|
||||
List<TypeParameterDescriptor> substitutedTypeParameters = Lists.newArrayList();
|
||||
TypeSubstitutor substitutor = DescriptorSubstitutor.substituteTypeParameters(getTypeParameters(), originalSubstitutor, substitutedDescriptor, substitutedTypeParameters);
|
||||
@@ -202,6 +214,36 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
|
||||
substitutedDescriptor.setType(outType, substitutedTypeParameters, substitutedExpectedThisObject, substitutedReceiverType);
|
||||
|
||||
PropertyGetterDescriptor newGetter = getter == null ? null : new PropertyGetterDescriptor(
|
||||
substitutedDescriptor, Lists.newArrayList(getter.getAnnotations()),
|
||||
DescriptorUtils.convertModality(getter.getModality(), false), getter.getVisibility(),
|
||||
getter.hasBody(), getter.isDefault(), kind);
|
||||
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), setter.getVisibility(),
|
||||
setter.hasBody(), setter.isDefault(), kind);
|
||||
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) {
|
||||
substitutedDescriptor.addOverriddenDescriptor(propertyDescriptor.substitute(substitutor));
|
||||
}
|
||||
}
|
||||
|
||||
return substitutedDescriptor;
|
||||
}
|
||||
|
||||
@@ -216,6 +258,11 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
return original;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
public void addOverriddenDescriptor(PropertyDescriptor overridden) {
|
||||
overriddenProperties.add(overridden);
|
||||
}
|
||||
@@ -228,30 +275,8 @@ public class PropertyDescriptor extends VariableDescriptorImpl implements Callab
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PropertyDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) {
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(
|
||||
newOwner,
|
||||
Lists.newArrayList(getAnnotations()),
|
||||
DescriptorUtils.convertModality(modality, makeNonAbstract), visibility, isVar, isObject,
|
||||
getName());
|
||||
|
||||
propertyDescriptor.setType(getOutType(), DescriptorUtils.copyTypeParameters(propertyDescriptor, getTypeParameters()), expectedThisObject, receiver.exists() ? receiver.getType() : null);
|
||||
|
||||
PropertyGetterDescriptor newGetter = getter == null ? null : new PropertyGetterDescriptor(
|
||||
propertyDescriptor, Lists.newArrayList(getter.getAnnotations()),
|
||||
DescriptorUtils.convertModality(getter.getModality(), makeNonAbstract), getter.getVisibility(),
|
||||
getter.hasBody(), getter.isDefault());
|
||||
if (newGetter != null) {
|
||||
newGetter.initialize(getter.getReturnType());
|
||||
}
|
||||
PropertySetterDescriptor newSetter = setter == null ? null : new PropertySetterDescriptor(
|
||||
propertyDescriptor, Lists.newArrayList(setter.getAnnotations()), DescriptorUtils.convertModality(setter.getModality(), makeNonAbstract), setter.getVisibility(),
|
||||
setter.hasBody(), setter.isDefault());
|
||||
if (newSetter != null) {
|
||||
newSetter.initialize(setter.getValueParameters().get(0).copy(newSetter));
|
||||
}
|
||||
propertyDescriptor.initialize(newGetter, newSetter);
|
||||
return propertyDescriptor;
|
||||
public PropertyDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract, Kind kind, boolean copyOverrides) {
|
||||
return doSubstitute(TypeSubstitutor.EMPTY, newOwner, DescriptorUtils.convertModality(modality, makeNonAbstract), false, copyOverrides, kind);
|
||||
}
|
||||
|
||||
public static PropertyDescriptor createDummy() {
|
||||
|
||||
+2
-2
@@ -18,9 +18,9 @@ public class PropertyGetterDescriptor extends PropertyAccessorDescriptor {
|
||||
private JetType returnType;
|
||||
|
||||
public PropertyGetterDescriptor(@NotNull PropertyDescriptor correspondingProperty, @NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull Modality modality, @NotNull Visibility visibility, boolean hasBody, boolean isDefault)
|
||||
@NotNull Modality modality, @NotNull Visibility visibility, boolean hasBody, boolean isDefault, Kind kind)
|
||||
{
|
||||
super(modality, visibility, correspondingProperty, annotations, "get-" + correspondingProperty.getName(), hasBody, isDefault);
|
||||
super(modality, visibility, correspondingProperty, annotations, "get-" + correspondingProperty.getName(), hasBody, isDefault, kind);
|
||||
}
|
||||
|
||||
public void initialize(JetType returnType) {
|
||||
|
||||
+6
-2
@@ -22,8 +22,9 @@ public class PropertySetterDescriptor extends PropertyAccessorDescriptor {
|
||||
@NotNull Modality modality,
|
||||
@NotNull Visibility visibility,
|
||||
boolean hasBody,
|
||||
boolean isDefault) {
|
||||
super(modality, visibility, correspondingProperty, annotations, "set-" + correspondingProperty.getName(), hasBody, isDefault);
|
||||
boolean isDefault,
|
||||
Kind kind) {
|
||||
super(modality, visibility, correspondingProperty, annotations, "set-" + correspondingProperty.getName(), hasBody, isDefault, kind);
|
||||
}
|
||||
|
||||
public void initialize(@NotNull ValueParameterDescriptor parameter) {
|
||||
@@ -45,6 +46,9 @@ public class PropertySetterDescriptor extends PropertyAccessorDescriptor {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<ValueParameterDescriptor> getValueParameters() {
|
||||
if (parameter == null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
return Collections.singletonList(parameter);
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -238,7 +238,8 @@ public class TypeParameterDescriptor extends DeclarationDescriptorImpl implement
|
||||
@NotNull
|
||||
public TypeParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner) {
|
||||
TypeParameterDescriptor copy = new TypeParameterDescriptor(newOwner, Lists.newArrayList(getAnnotations()), reified, variance, getName(), index);
|
||||
copy.upperBounds.addAll(this.upperBounds);
|
||||
copy.initialized = this.initialized;
|
||||
return copy;
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -21,7 +21,7 @@ public class VariableAsFunctionDescriptor extends FunctionDescriptorImpl {
|
||||
private final VariableDescriptor variableDescriptor;
|
||||
|
||||
private VariableAsFunctionDescriptor(VariableDescriptor variableDescriptor) {
|
||||
super(variableDescriptor.getContainingDeclaration(), Collections.<AnnotationDescriptor>emptyList(), variableDescriptor.getName());
|
||||
super(variableDescriptor.getContainingDeclaration(), Collections.<AnnotationDescriptor>emptyList(), variableDescriptor.getName(), Kind.DECLARATION);
|
||||
this.variableDescriptor = variableDescriptor;
|
||||
}
|
||||
|
||||
@@ -31,12 +31,12 @@ public class VariableAsFunctionDescriptor extends FunctionDescriptorImpl {
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public VariableAsFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) {
|
||||
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) {
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.jetbrains.jet.util.Box;
|
||||
import org.jetbrains.jet.util.slicedmap.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.jet.util.slicedmap.RewritePolicy.DO_NOTHING;
|
||||
|
||||
@@ -65,6 +66,9 @@ public interface BindingContext {
|
||||
WritableSlice<PropertyDescriptor, Boolean> BACKING_FIELD_REQUIRED = new Slices.SetSlice<PropertyDescriptor>(DO_NOTHING) {
|
||||
@Override
|
||||
public Boolean computeValue(SlicedMap map, PropertyDescriptor propertyDescriptor, Boolean backingFieldRequired, boolean valueNotFound) {
|
||||
if (propertyDescriptor.getKind() != CallableMemberDescriptor.Kind.DECLARATION) {
|
||||
return false;
|
||||
}
|
||||
backingFieldRequired = valueNotFound ? false : backingFieldRequired;
|
||||
assert backingFieldRequired != null;
|
||||
PsiElement declarationPsiElement = map.get(DESCRIPTOR_TO_DECLARATION, propertyDescriptor);
|
||||
@@ -105,6 +109,18 @@ public interface BindingContext {
|
||||
Slices.KeyNormalizer<DeclarationDescriptor> DECLARATION_DESCRIPTOR_NORMALIZER = new Slices.KeyNormalizer<DeclarationDescriptor>() {
|
||||
@Override
|
||||
public DeclarationDescriptor normalize(DeclarationDescriptor declarationDescriptor) {
|
||||
if (declarationDescriptor instanceof CallableMemberDescriptor) {
|
||||
CallableMemberDescriptor callable = (CallableMemberDescriptor) declarationDescriptor;
|
||||
if (callable.getKind() != CallableMemberDescriptor.Kind.DECLARATION) {
|
||||
Set<? extends CallableMemberDescriptor> overriddenDescriptors = callable.getOverriddenDescriptors();
|
||||
if (overriddenDescriptors.size() != 1) {
|
||||
throw new IllegalStateException(
|
||||
"cannot find declaration: fake descriptor" +
|
||||
" has more then one overriden descriptor: " + declarationDescriptor);
|
||||
}
|
||||
return normalize(overriddenDescriptors.iterator().next());
|
||||
}
|
||||
}
|
||||
if (declarationDescriptor instanceof VariableAsFunctionDescriptor) {
|
||||
VariableAsFunctionDescriptor descriptor = (VariableAsFunctionDescriptor) declarationDescriptor;
|
||||
return descriptor.getVariableDescriptor().getOriginal();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamedFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
@@ -45,7 +45,7 @@ public class DelegationResolver {
|
||||
if (declarationDescriptor instanceof PropertyDescriptor) {
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) declarationDescriptor;
|
||||
if (propertyDescriptor.getModality().isOverridable()) {
|
||||
PropertyDescriptor copy = propertyDescriptor.copy(classDescriptor, true);
|
||||
PropertyDescriptor copy = propertyDescriptor.copy(classDescriptor, true, CallableMemberDescriptor.Kind.DELEGATION, true);
|
||||
classDescriptor.addPropertyDescriptor(copy);
|
||||
context.getTrace().record(DELEGATED, copy);
|
||||
}
|
||||
@@ -53,7 +53,7 @@ public class DelegationResolver {
|
||||
else if (declarationDescriptor instanceof NamedFunctionDescriptor) {
|
||||
NamedFunctionDescriptor functionDescriptor = (NamedFunctionDescriptor) declarationDescriptor;
|
||||
if (functionDescriptor.getModality().isOverridable()) {
|
||||
NamedFunctionDescriptor copy = functionDescriptor.copy(classDescriptor, true);
|
||||
NamedFunctionDescriptor copy = functionDescriptor.copy(classDescriptor, true, CallableMemberDescriptor.Kind.DELEGATION, true);
|
||||
classDescriptor.addFunctionDescriptor(copy);
|
||||
context.getTrace().record(DELEGATED, copy);
|
||||
}
|
||||
|
||||
@@ -142,7 +142,8 @@ public class DescriptorResolver {
|
||||
final NamedFunctionDescriptorImpl functionDescriptor = new NamedFunctionDescriptorImpl(
|
||||
containingDescriptor,
|
||||
annotationResolver.resolveAnnotations(scope, function.getModifierList()),
|
||||
JetPsiUtil.safeName(function.getName())
|
||||
JetPsiUtil.safeName(function.getName()),
|
||||
CallableMemberDescriptor.Kind.DECLARATION
|
||||
);
|
||||
WritableScope innerScope = new WritableScopeImpl(scope, functionDescriptor, new TraceBasedRedeclarationHandler(trace)).setDebugName("Function descriptor header scope");
|
||||
innerScope.addLabeledDeclaration(functionDescriptor);
|
||||
@@ -470,7 +471,8 @@ public class DescriptorResolver {
|
||||
visibility,
|
||||
false,
|
||||
true,
|
||||
JetPsiUtil.safeName(objectDeclaration.getName())
|
||||
JetPsiUtil.safeName(objectDeclaration.getName()),
|
||||
CallableMemberDescriptor.Kind.DECLARATION
|
||||
);
|
||||
propertyDescriptor.setType(classDescriptor.getDefaultType(), Collections.<TypeParameterDescriptor>emptyList(), DescriptorUtils.getExpectedThisObjectIfNeeded(containingDeclaration), ReceiverDescriptor.NO_RECEIVER);
|
||||
propertyDescriptor.initialize(createDefaultGetter(propertyDescriptor), null);
|
||||
@@ -527,7 +529,8 @@ public class DescriptorResolver {
|
||||
resolveVisibilityFromModifiers(property.getModifierList()),
|
||||
isVar,
|
||||
false,
|
||||
JetPsiUtil.safeName(property.getName())
|
||||
JetPsiUtil.safeName(property.getName()),
|
||||
CallableMemberDescriptor.Kind.DECLARATION
|
||||
);
|
||||
|
||||
List<TypeParameterDescriptor> typeParameterDescriptors;
|
||||
@@ -677,7 +680,7 @@ public class DescriptorResolver {
|
||||
setterDescriptor = new PropertySetterDescriptor(
|
||||
propertyDescriptor, annotations, resolveModalityFromModifiers(setter.getModifierList(), propertyDescriptor.getModality()),
|
||||
resolveVisibilityFromModifiers(setter.getModifierList(), propertyDescriptor.getVisibility()),
|
||||
setter.getBodyExpression() != null, false);
|
||||
setter.getBodyExpression() != null, false, CallableMemberDescriptor.Kind.DECLARATION);
|
||||
if (parameter != null) {
|
||||
|
||||
// This check is redundant: the parser does not allow a default value, but we'll keep it just in case
|
||||
@@ -731,7 +734,7 @@ public class DescriptorResolver {
|
||||
setterDescriptor = new PropertySetterDescriptor(
|
||||
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
|
||||
propertyDescriptor.getVisibility(),
|
||||
false, true);
|
||||
false, true, CallableMemberDescriptor.Kind.DECLARATION);
|
||||
setterDescriptor.initializeDefault();
|
||||
return setterDescriptor;
|
||||
}
|
||||
@@ -757,7 +760,7 @@ public class DescriptorResolver {
|
||||
getterDescriptor = new PropertyGetterDescriptor(
|
||||
propertyDescriptor, annotations, resolveModalityFromModifiers(getter.getModifierList(), propertyDescriptor.getModality()),
|
||||
resolveVisibilityFromModifiers(getter.getModifierList(), propertyDescriptor.getVisibility()),
|
||||
getter.getBodyExpression() != null, false);
|
||||
getter.getBodyExpression() != null, false, CallableMemberDescriptor.Kind.DECLARATION);
|
||||
getterDescriptor.initialize(returnType);
|
||||
trace.record(BindingContext.PROPERTY_ACCESSOR, getter, getterDescriptor);
|
||||
}
|
||||
@@ -773,7 +776,7 @@ public class DescriptorResolver {
|
||||
getterDescriptor = new PropertyGetterDescriptor(
|
||||
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getModality(),
|
||||
propertyDescriptor.getVisibility(),
|
||||
false, true);
|
||||
false, true, CallableMemberDescriptor.Kind.DECLARATION);
|
||||
return getterDescriptor;
|
||||
}
|
||||
|
||||
@@ -845,7 +848,8 @@ public class DescriptorResolver {
|
||||
resolveVisibilityFromModifiers(parameter.getModifierList()),
|
||||
isMutable,
|
||||
false,
|
||||
name == null ? "<no name>" : name
|
||||
name == null ? "<no name>" : name,
|
||||
CallableMemberDescriptor.Kind.DECLARATION
|
||||
);
|
||||
propertyDescriptor.setType(type, Collections.<TypeParameterDescriptor>emptyList(), DescriptorUtils.getExpectedThisObjectIfNeeded(classDescriptor), ReceiverDescriptor.NO_RECEIVER);
|
||||
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.util.CommonSuppliers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -34,46 +37,205 @@ public class OverrideResolver {
|
||||
}
|
||||
|
||||
public void process() {
|
||||
bindOverrides();
|
||||
generateOverrides();
|
||||
checkOverrides();
|
||||
}
|
||||
|
||||
private void bindOverrides() {
|
||||
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
|
||||
bindOverridesInAClass(entry.getValue());
|
||||
}
|
||||
for (Map.Entry<JetObjectDeclaration, MutableClassDescriptor> entry : context.getObjects().entrySet()) {
|
||||
bindOverridesInAClass(entry.getValue());
|
||||
/**
|
||||
* Generate fake overrides and add overriden descriptors to existing descriptors.
|
||||
*/
|
||||
private void generateOverrides() {
|
||||
Set<MutableClassDescriptor> ourClasses = new HashSet<MutableClassDescriptor>();
|
||||
ourClasses.addAll(context.getClasses().values());
|
||||
ourClasses.addAll(context.getObjects().values());
|
||||
|
||||
Set<ClassifierDescriptor> processed = new HashSet<ClassifierDescriptor>();
|
||||
|
||||
for (MutableClassDescriptor clazz : ourClasses) {
|
||||
generateOverridesInAClass(clazz, processed, ourClasses);
|
||||
}
|
||||
}
|
||||
|
||||
private void bindOverridesInAClass(MutableClassDescriptor classDescriptor) {
|
||||
for (FunctionDescriptor declaredFunction : classDescriptor.getFunctions()) {
|
||||
for (JetType supertype : classDescriptor.getTypeConstructor().getSupertypes()) {
|
||||
Collection<FunctionDescriptor> overridden = findFunctionsOverridableBy(declaredFunction, supertype);
|
||||
for (FunctionDescriptor functionDescriptor : overridden) {
|
||||
((FunctionDescriptorImpl) declaredFunction).addOverriddenFunction(functionDescriptor);
|
||||
}
|
||||
private void generateOverridesInAClass(final MutableClassDescriptor classDescriptor, Set<ClassifierDescriptor> processed, Set<MutableClassDescriptor> ourClasses) {
|
||||
if (!processed.add(classDescriptor)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// avoid processing stdlib classes twice
|
||||
if (!ourClasses.contains(classDescriptor)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (JetType supertype : classDescriptor.getTypeConstructor().getSupertypes()) {
|
||||
ClassDescriptor superclass = (ClassDescriptor) supertype.getConstructor().getDeclarationDescriptor();
|
||||
if (superclass instanceof MutableClassDescriptor) {
|
||||
generateOverridesInAClass((MutableClassDescriptor) superclass, processed, ourClasses);
|
||||
}
|
||||
}
|
||||
|
||||
for (PropertyDescriptor propertyDescriptor : classDescriptor.getProperties()) {
|
||||
for (JetType supertype : classDescriptor.getTypeConstructor().getSupertypes()) {
|
||||
Collection<PropertyDescriptor> overridden = findPropertiesOverridableBy(propertyDescriptor, supertype);
|
||||
for (PropertyDescriptor descriptor : overridden) {
|
||||
propertyDescriptor.addOverriddenDescriptor(descriptor);
|
||||
List<NamedFunctionDescriptor> functionsFromSupertypes = getDescriptorsFromSupertypes(classDescriptor, NamedFunctionDescriptor.class);
|
||||
List<PropertyDescriptor> propertiesFromSupertypes = getDescriptorsFromSupertypes(classDescriptor, PropertyDescriptor.class);
|
||||
|
||||
MultiMap<String, NamedFunctionDescriptor> functionsFromSupertypesByName = groupDescriptorsByName(functionsFromSupertypes);
|
||||
MultiMap<String, PropertyDescriptor> propertiesFromSupertypesByName = groupDescriptorsByName(propertiesFromSupertypes);
|
||||
|
||||
MultiMap<String, NamedFunctionDescriptor> functionsFromCurrentByName = groupDescriptorsByName(classDescriptor.getFunctions());
|
||||
MultiMap<String, PropertyDescriptor> propertiesFromCurrentByName = groupDescriptorsByName(classDescriptor.getProperties());
|
||||
|
||||
Set<String> functionNames = new HashSet<String>();
|
||||
functionNames.addAll(functionsFromSupertypesByName.keySet());
|
||||
functionNames.addAll(functionsFromCurrentByName.keySet());
|
||||
|
||||
Set<String> propertyNames = new HashSet<String>();
|
||||
propertyNames.addAll(propertiesFromSupertypesByName.keySet());
|
||||
propertyNames.addAll(propertiesFromCurrentByName.keySet());
|
||||
|
||||
|
||||
for (String functionName : functionNames) {
|
||||
generateOverridesInFunctionGroup(functionName,
|
||||
functionsFromSupertypesByName.get(functionName),
|
||||
functionsFromCurrentByName.get(functionName),
|
||||
classDescriptor,
|
||||
new DescriptorSink<NamedFunctionDescriptor>() {
|
||||
@Override
|
||||
public void addToScope(NamedFunctionDescriptor fakeOverride) {
|
||||
classDescriptor.getScopeForMemberLookupAsWritableScope().addFunctionDescriptor(fakeOverride);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
for (String propertyName : propertyNames) {
|
||||
generateOverridesInPropertyGroup(propertyName,
|
||||
propertiesFromSupertypesByName.get(propertyName),
|
||||
propertiesFromCurrentByName.get(propertyName),
|
||||
classDescriptor,
|
||||
new DescriptorSink<PropertyDescriptor>() {
|
||||
@Override
|
||||
public void addToScope(PropertyDescriptor fakeOverride) {
|
||||
classDescriptor.getScopeForMemberLookupAsWritableScope().addPropertyDescriptor(fakeOverride);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public interface DescriptorSink<D extends CallableMemberDescriptor> {
|
||||
void addToScope(D fakeOverride);
|
||||
}
|
||||
|
||||
public static void generateOverridesInFunctionGroup(
|
||||
@NotNull String name,
|
||||
@NotNull Collection<NamedFunctionDescriptor> functionsFromSupertypes,
|
||||
@NotNull Collection<NamedFunctionDescriptor> functionsFromCurrent,
|
||||
@NotNull ClassDescriptor current,
|
||||
@NotNull DescriptorSink<NamedFunctionDescriptor> sink) {
|
||||
|
||||
List<NamedFunctionDescriptor> fakeOverrides = Lists.newArrayList();
|
||||
|
||||
for (NamedFunctionDescriptor functionFromSupertype : functionsFromSupertypes) {
|
||||
|
||||
boolean overrides = false;
|
||||
|
||||
for (NamedFunctionDescriptor functionFromCurrent : functionsFromCurrent) {
|
||||
if (OverridingUtil.isOverridableBy(functionFromSupertype, functionFromCurrent).isSuccess()) {
|
||||
((FunctionDescriptorImpl) functionFromCurrent).addOverriddenFunction(functionFromSupertype);
|
||||
overrides = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (NamedFunctionDescriptor fakeOverride : fakeOverrides) {
|
||||
if (OverridingUtil.isOverridableBy(functionFromSupertype, fakeOverride).isSuccess()) {
|
||||
((FunctionDescriptorImpl) fakeOverride).addOverriddenFunction(functionFromSupertype);
|
||||
overrides = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!overrides) {
|
||||
NamedFunctionDescriptor fakeOverride = functionFromSupertype.copy(current, false, CallableMemberDescriptor.Kind.FAKE_OVERRIDE, false);
|
||||
((FunctionDescriptorImpl) fakeOverride).addOverriddenFunction(functionFromSupertype);
|
||||
|
||||
fakeOverrides.add(fakeOverride);
|
||||
|
||||
sink.addToScope(fakeOverride);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateOverridesInPropertyGroup(
|
||||
@NotNull String name,
|
||||
@NotNull Collection<PropertyDescriptor> propertiesFromSupertypes,
|
||||
@NotNull Collection<PropertyDescriptor> propertiesFromCurrent,
|
||||
@NotNull ClassDescriptor current,
|
||||
@NotNull DescriptorSink<PropertyDescriptor> sink) {
|
||||
|
||||
List<PropertyDescriptor> fakeOverrides = Lists.newArrayList();
|
||||
|
||||
for (PropertyDescriptor propertyFromSupertype : propertiesFromSupertypes) {
|
||||
boolean overrides = false;
|
||||
for (PropertyDescriptor propertyFromCurrent : propertiesFromCurrent) {
|
||||
if (OverridingUtil.isOverridableBy(propertyFromSupertype, propertyFromCurrent).isSuccess()) {
|
||||
propertyFromCurrent.addOverriddenDescriptor(propertyFromSupertype);
|
||||
overrides = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (PropertyDescriptor fakeOverride : fakeOverrides) {
|
||||
if (OverridingUtil.isOverridableBy(propertyFromSupertype, fakeOverride).isSuccess()) {
|
||||
((PropertyDescriptor) fakeOverride).addOverriddenDescriptor(propertyFromSupertype);
|
||||
overrides = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!overrides) {
|
||||
PropertyDescriptor fakeOverride = propertyFromSupertype.copy(current, false, CallableMemberDescriptor.Kind.FAKE_OVERRIDE, false);
|
||||
fakeOverride.addOverriddenDescriptor(propertyFromSupertype);
|
||||
|
||||
fakeOverrides.add(fakeOverride);
|
||||
|
||||
sink.addToScope(fakeOverride);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static <T extends DeclarationDescriptor> MultiMap<String, T> groupDescriptorsByName(Collection<T> properties) {
|
||||
MultiMap<String, T> r = new MultiMap<String, T>();
|
||||
for (T property : properties) {
|
||||
r.putValue(property.getName(), property);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
private static <T extends DeclarationDescriptor> List<T> getDescriptorsFromSupertypes(
|
||||
ClassDescriptor classDescriptor, Class<T> descriptorClass) {
|
||||
Set<T> r = Sets.newHashSet();
|
||||
for (JetType supertype : classDescriptor.getTypeConstructor().getSupertypes()) {
|
||||
r.addAll(getDescriptorsOfType(supertype.getMemberScope(), descriptorClass));
|
||||
}
|
||||
return new ArrayList<T>(r);
|
||||
}
|
||||
|
||||
private static <T extends DeclarationDescriptor> List<T> getDescriptorsOfType(
|
||||
JetScope scope, Class<T> descriptorClass) {
|
||||
List<T> r = Lists.newArrayList();
|
||||
for (DeclarationDescriptor decl : scope.getAllDescriptors()) {
|
||||
if (descriptorClass.isInstance(decl)) {
|
||||
r.add((T) decl);
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Collection<FunctionDescriptor> findFunctionsOverridableBy(@NotNull FunctionDescriptor declaredFunction, @NotNull JetType supertype) {
|
||||
List<FunctionDescriptor> result = Lists.newArrayList();
|
||||
List<FunctionDescriptor> result2 = Lists.newArrayList();
|
||||
Set<FunctionDescriptor> functionGroup = supertype.getMemberScope().getFunctions(declaredFunction.getName());
|
||||
for (FunctionDescriptor functionDescriptor : functionGroup) {
|
||||
if (OverridingUtil.isOverridableBy(functionDescriptor, declaredFunction).isSuccess()) {
|
||||
result.add(functionDescriptor);
|
||||
} else {
|
||||
result2.add(functionDescriptor);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -172,37 +334,32 @@ public class OverrideResolver {
|
||||
}
|
||||
|
||||
public static void collectMissingImplementations(MutableClassDescriptor classDescriptor, Set<CallableMemberDescriptor> abstractNoImpl, Set<CallableMemberDescriptor> manyImpl) {
|
||||
// Everything from supertypes
|
||||
Map<CallableMemberDescriptor, CallableMemberDescriptor> implementedWithDelegationBy = Maps.newHashMap();
|
||||
Multimap<CallableMemberDescriptor, CallableMemberDescriptor> factoredMembers = collectSuperMethods(classDescriptor);
|
||||
|
||||
for (DeclarationDescriptor descriptor : classDescriptor.getScopeForMemberLookup().getAllDescriptors()) {
|
||||
if (descriptor instanceof CallableMemberDescriptor) {
|
||||
collectMissingImplementations((CallableMemberDescriptor) descriptor, abstractNoImpl, manyImpl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (CallableMemberDescriptor key : factoredMembers.keySet()) {
|
||||
Collection<CallableMemberDescriptor> mutuallyOverridable = factoredMembers.get(key);
|
||||
|
||||
int implementationCount = 0;
|
||||
for (CallableMemberDescriptor member : mutuallyOverridable) {
|
||||
if (member.getModality() != Modality.ABSTRACT) {
|
||||
implementationCount++;
|
||||
private static void collectMissingImplementations(CallableMemberDescriptor descriptor, Set<CallableMemberDescriptor> abstractNoImpl, Set<CallableMemberDescriptor> manyImpl) {
|
||||
if (descriptor.getKind().isReal()) {
|
||||
if (descriptor.getModality() == Modality.ABSTRACT) {
|
||||
//abstractNoImpl.add(descriptor);
|
||||
}
|
||||
} else {
|
||||
Collection<CallableMemberDescriptor> overridenDeclarations = OverridingUtil.getOverridenDeclarations(descriptor);
|
||||
if (overridenDeclarations.size() == 0) {
|
||||
throw new IllegalStateException();
|
||||
} else if (overridenDeclarations.size() == 1) {
|
||||
CallableMemberDescriptor single = overridenDeclarations.iterator().next();
|
||||
if (single.getModality() == Modality.ABSTRACT) {
|
||||
abstractNoImpl.add(single);
|
||||
}
|
||||
}
|
||||
|
||||
if (implementationCount == 0) {
|
||||
abstractNoImpl.addAll(mutuallyOverridable);
|
||||
}
|
||||
else if (implementationCount > 1) {
|
||||
manyImpl.addAll(mutuallyOverridable);
|
||||
} else {
|
||||
manyImpl.addAll(overridenDeclarations);
|
||||
}
|
||||
}
|
||||
|
||||
// Members actually present (declared) in the class
|
||||
Set<CallableMemberDescriptor> actuallyOverridden = Sets.newHashSet(implementedWithDelegationBy.keySet());
|
||||
for (CallableMemberDescriptor member : classDescriptor.getCallableMembers()) {
|
||||
actuallyOverridden.addAll(member.getOverriddenDescriptors());
|
||||
}
|
||||
|
||||
// Those to be overridden that are actually not
|
||||
abstractNoImpl.removeAll(actuallyOverridden);
|
||||
manyImpl.removeAll(actuallyOverridden);
|
||||
}
|
||||
|
||||
public static Multimap<CallableMemberDescriptor, CallableMemberDescriptor> collectSuperMethods(MutableClassDescriptor classDescriptor) {
|
||||
@@ -242,6 +399,10 @@ public class OverrideResolver {
|
||||
return;
|
||||
}
|
||||
|
||||
if (declared.getKind() != CallableMemberDescriptor.Kind.DECLARATION) {
|
||||
return;
|
||||
}
|
||||
|
||||
JetModifierList modifierList = member.getModifierList();
|
||||
ASTNode overrideNode = modifierList != null ? modifierList.getModifierNode(JetTokens.OVERRIDE_KEYWORD) : null;
|
||||
boolean hasOverrideModifier = overrideNode != null;
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
@@ -21,21 +22,6 @@ public class OverridingUtil {
|
||||
private OverridingUtil() {
|
||||
}
|
||||
|
||||
public static Set<CallableDescriptor> getEffectiveMembers(@NotNull ClassDescriptor classDescriptor) {
|
||||
Collection<DeclarationDescriptor> allDescriptors = classDescriptor.getDefaultType().getMemberScope().getAllDescriptors();
|
||||
Set<CallableDescriptor> allMembers = Sets.newLinkedHashSet();
|
||||
for (DeclarationDescriptor descriptor : allDescriptors) {
|
||||
assert !(descriptor instanceof ConstructorDescriptor);
|
||||
if (descriptor instanceof CallableDescriptor && descriptor instanceof MemberDescriptor) {
|
||||
CallableDescriptor callableDescriptor = (CallableDescriptor) descriptor;
|
||||
if (((MemberDescriptor) descriptor).getModality() != Modality.ABSTRACT) {
|
||||
allMembers.add(callableDescriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
return filterOverrides(allMembers);
|
||||
}
|
||||
|
||||
public static <D extends CallableDescriptor> Set<D> filterOverrides(Set<D> candidateSet) {
|
||||
return filterOverrides(candidateSet, Function.ID);
|
||||
}
|
||||
@@ -198,6 +184,30 @@ public class OverridingUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get overriden descriptors that are declarations or delegations.
|
||||
*
|
||||
* @see CallableMemberDescriptor.Kind#isReal()
|
||||
*/
|
||||
public static Collection<CallableMemberDescriptor> getOverridenDeclarations(CallableMemberDescriptor descriptor) {
|
||||
Map<ClassDescriptor, CallableMemberDescriptor> result = Maps.newHashMap();
|
||||
getOverridenDeclarations(descriptor, result);
|
||||
return result.values();
|
||||
}
|
||||
|
||||
private static void getOverridenDeclarations(CallableMemberDescriptor descriptor, Map<ClassDescriptor, CallableMemberDescriptor> r) {
|
||||
if (descriptor.getKind().isReal()) {
|
||||
r.put((ClassDescriptor) descriptor.getContainingDeclaration(), descriptor);
|
||||
} else {
|
||||
if (descriptor.getOverriddenDescriptors().isEmpty()) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
for (CallableMemberDescriptor overriden : descriptor.getOverriddenDescriptors()) {
|
||||
getOverridenDeclarations(overriden, r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class OverrideCompatibilityInfo {
|
||||
|
||||
private static final OverrideCompatibilityInfo SUCCESS = new OverrideCompatibilityInfo(true, "SUCCESS");
|
||||
|
||||
@@ -8,7 +8,13 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.Configuration;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamedFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceLike;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclaration;
|
||||
@@ -66,8 +72,8 @@ public class TopDownAnalyzer {
|
||||
new TypeHierarchyResolver(context).process(outerScope, owner, declarations);
|
||||
new DeclarationResolver(context).process();
|
||||
new DelegationResolver(context).process();
|
||||
lockScopes(context);
|
||||
new OverrideResolver(context).process();
|
||||
lockScopes(context);
|
||||
new OverloadResolver(context).process();
|
||||
if (!context.analyzingBootstrapLibrary()) {
|
||||
new BodyResolver(context).resolveBehaviorDeclarationBodies();
|
||||
@@ -79,6 +85,7 @@ public class TopDownAnalyzer {
|
||||
context.printDebugOutput(System.out);
|
||||
}
|
||||
|
||||
|
||||
private static void lockScopes(TopDownAnalysisContext context) {
|
||||
for (MutableClassDescriptor mutableClassDescriptor : context.getClasses().values()) {
|
||||
mutableClassDescriptor.lockScopes();
|
||||
|
||||
@@ -57,9 +57,6 @@ public class TypeHierarchyResolver {
|
||||
checkSupertypesForConsistency();
|
||||
// computeSuperclasses();
|
||||
|
||||
// Add supertypes to resolution scopes of classes
|
||||
addSupertypesToScopes();
|
||||
|
||||
checkTypesInClassHeaders(); // Check bounds in the types used in generic bounds and supertype lists
|
||||
}
|
||||
|
||||
@@ -440,15 +437,6 @@ public class TypeHierarchyResolver {
|
||||
public abstract boolean removeNeeded(JetType subject, JetType other);
|
||||
}
|
||||
|
||||
private void addSupertypesToScopes() {
|
||||
for (MutableClassDescriptor mutableClassDescriptor : context.getClasses().values()) {
|
||||
mutableClassDescriptor.addSupertypesToScopeForMemberLookup();
|
||||
}
|
||||
for (MutableClassDescriptor mutableClassDescriptor : context.getObjects().values()) {
|
||||
mutableClassDescriptor.addSupertypesToScopeForMemberLookup();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkTypesInClassHeaders() {
|
||||
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
|
||||
JetClass jetClass = entry.getKey();
|
||||
|
||||
+3
-8
@@ -1,32 +1,27 @@
|
||||
package org.jetbrains.jet.lang.resolve.calls;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
*/
|
||||
public class ExpressionAsFunctionDescriptor extends FunctionDescriptorImpl {
|
||||
public ExpressionAsFunctionDescriptor(DeclarationDescriptor containingDeclaration, String name) {
|
||||
super(containingDeclaration, Collections.<AnnotationDescriptor>emptyList(), name);
|
||||
super(containingDeclaration, Collections.<AnnotationDescriptor>emptyList(), name, Kind.DECLARATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal) {
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) {
|
||||
public FunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract, Kind kind, boolean copyOverrides) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -33,6 +34,10 @@ public interface ResolvedCall<D extends CallableDescriptor> {
|
||||
@NotNull
|
||||
Map<ValueParameterDescriptor, ResolvedValueArgument> getValueArguments();
|
||||
|
||||
/** Values (arguments) for value parameters indexed by parameter index */
|
||||
@NotNull
|
||||
List<ResolvedValueArgument> getValueArgumentsByIndex();
|
||||
|
||||
/** What's substituted for type parameters */
|
||||
@NotNull
|
||||
Map<TypeParameterDescriptor, JetType> getTypeArguments();
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -143,6 +144,29 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements ResolvedC
|
||||
return valueArguments;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<ResolvedValueArgument> getValueArgumentsByIndex() {
|
||||
List<ResolvedValueArgument> arguments = new ArrayList<ResolvedValueArgument>(candidateDescriptor.getValueParameters().size());
|
||||
for (int i = 0; i < candidateDescriptor.getValueParameters().size(); ++i) {
|
||||
arguments.add(null);
|
||||
}
|
||||
|
||||
for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> entry : valueArguments.entrySet()) {
|
||||
if (arguments.set(entry.getKey().getIndex(), entry.getValue()) != null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
for (Object o : arguments) {
|
||||
if (o == null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
return arguments;
|
||||
}
|
||||
|
||||
public void argumentHasNoType() {
|
||||
this.someArgumentHasNoType = true;
|
||||
}
|
||||
|
||||
+31
-1
@@ -9,6 +9,7 @@ import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.TemporaryBindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -31,7 +32,10 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
|
||||
Set<ValueParameterDescriptor> usedParameters = Sets.newHashSet();
|
||||
|
||||
D candidate = candidateCall.getCandidateDescriptor();
|
||||
List<ValueParameterDescriptor> valueParameters = candidate.getValueParameters();
|
||||
|
||||
D base = getDescriptorForValueArgumentsResolving(candidate);
|
||||
|
||||
List<ValueParameterDescriptor> valueParameters = base.getValueParameters();
|
||||
|
||||
Map<String, ValueParameterDescriptor> parameterByName = Maps.newHashMap();
|
||||
for (ValueParameterDescriptor valueParameter : valueParameters) {
|
||||
@@ -187,4 +191,30 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
|
||||
candidateCall.recordValueArgument(valueParameterDescriptor, argument);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Descriptor used to resolve parameter names and default parameter values.
|
||||
*/
|
||||
@NotNull
|
||||
private static <D extends CallableDescriptor> D getDescriptorForValueArgumentsResolving(D descriptor) {
|
||||
Set<D> allBases = new HashSet<D>();
|
||||
getAllDescriptorsForValueArgumentsResolving(descriptor, allBases);
|
||||
|
||||
if (allBases.size() == 1) {
|
||||
return allBases.iterator().next();
|
||||
} else {
|
||||
// TODO remove parameter names and parameter default values
|
||||
return descriptor;
|
||||
}
|
||||
}
|
||||
|
||||
private static <D extends CallableDescriptor> void getAllDescriptorsForValueArgumentsResolving(D descriptor, Set<D> dest) {
|
||||
if (descriptor.getOverriddenDescriptors().isEmpty()) {
|
||||
dest.add(descriptor);
|
||||
} else {
|
||||
for (CallableDescriptor overriden : descriptor.getOverriddenDescriptors()) {
|
||||
getAllDescriptorsForValueArgumentsResolving((D) overriden, dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,4 +79,4 @@ public interface JetScope {
|
||||
* @param result
|
||||
*/
|
||||
void getImplicitReceiversHierarchy(@NotNull List<ReceiverDescriptor> result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,7 +142,8 @@ public class ErrorUtils {
|
||||
null,
|
||||
ReceiverDescriptor.NO_RECEIVER,
|
||||
"<ERROR PROPERTY>",
|
||||
ERROR_PROPERTY_TYPE);
|
||||
ERROR_PROPERTY_TYPE,
|
||||
CallableMemberDescriptor.Kind.DECLARATION);
|
||||
private static final Set<VariableDescriptor> ERROR_PROPERTY_GROUP = Collections.singleton(ERROR_PROPERTY);
|
||||
|
||||
private static NamedFunctionDescriptor createErrorFunction(ErrorScope ownerScope) {
|
||||
|
||||
@@ -120,9 +120,9 @@ public class JetStandardClasses {
|
||||
Collections.<AnnotationDescriptor>emptyList(),
|
||||
true, Variance.OUT_VARIANCE, "T" + (j + 1), j);
|
||||
parameters.add(typeParameterDescriptor);
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(classDescriptor, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibility.PUBLIC, false, false, "_" + (j + 1));
|
||||
PropertyDescriptor propertyDescriptor = new PropertyDescriptor(classDescriptor, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibility.PUBLIC, false, false, "_" + (j + 1), CallableMemberDescriptor.Kind.DECLARATION);
|
||||
propertyDescriptor.setType(typeParameterDescriptor.getDefaultType(), Collections.<TypeParameterDescriptor>emptyList(), classDescriptor.getImplicitReceiver(), ReceiverDescriptor.NO_RECEIVER);
|
||||
PropertyGetterDescriptor getterDescriptor = new PropertyGetterDescriptor(propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibility.PUBLIC, false, true);
|
||||
PropertyGetterDescriptor getterDescriptor = new PropertyGetterDescriptor(propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), Modality.FINAL, Visibility.PUBLIC, false, true, CallableMemberDescriptor.Kind.DECLARATION);
|
||||
getterDescriptor.initialize(typeParameterDescriptor.getDefaultType());
|
||||
propertyDescriptor.initialize(getterDescriptor, null);
|
||||
writableScope.addPropertyDescriptor(propertyDescriptor);
|
||||
|
||||
+3
-4
@@ -9,7 +9,6 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Stepan Koltsov
|
||||
@@ -20,18 +19,18 @@ public class NamedFunctionDescriptorErrorImpl extends NamedFunctionDescriptorImp
|
||||
private final ErrorUtils.ErrorScope ownerScope;
|
||||
|
||||
public NamedFunctionDescriptorErrorImpl(ErrorUtils.ErrorScope ownerScope) {
|
||||
super(ErrorUtils.getErrorClass(), Collections.<AnnotationDescriptor>emptyList(), "<ERROR FUNCTION>");
|
||||
super(ErrorUtils.getErrorClass(), Collections.<AnnotationDescriptor>emptyList(), "<ERROR FUNCTION>", Kind.DECLARATION);
|
||||
this.ownerScope = ownerScope;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal) {
|
||||
protected FunctionDescriptorImpl createSubstitutedCopy(DeclarationDescriptor newOwner, boolean preserveOriginal, Kind kind) {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public NamedFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract) {
|
||||
public NamedFunctionDescriptor copy(DeclarationDescriptor newOwner, boolean makeNonAbstract, Kind kind, boolean copyOverrides) {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
|
||||
JetFunctionLiteral functionLiteral = expression.getFunctionLiteral();
|
||||
JetTypeReference receiverTypeRef = functionLiteral.getReceiverTypeRef();
|
||||
NamedFunctionDescriptorImpl functionDescriptor = new NamedFunctionDescriptorImpl(
|
||||
context.scope.getContainingDeclaration(), Collections.<AnnotationDescriptor>emptyList(), "<anonymous>");
|
||||
context.scope.getContainingDeclaration(), Collections.<AnnotationDescriptor>emptyList(), "<anonymous>", CallableMemberDescriptor.Kind.DECLARATION);
|
||||
|
||||
List<ValueParameterDescriptor> valueParameterDescriptors = createValueParameterDescriptors(context, functionLiteral, functionDescriptor, functionTypeExpected);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user