added default property accessor descriptors

This commit is contained in:
svtk
2011-09-02 18:18:16 +04:00
parent 705f4796d5
commit 555ebebe1b
5 changed files with 34 additions and 13 deletions
@@ -784,8 +784,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
setter = null; setter = null;
} }
else { else {
getter = isInsideClass && propertyDescriptor.getGetter() == null ? null : typeMapper.mapGetterSignature(propertyDescriptor); getter = isInsideClass && (propertyDescriptor.getGetter() == null || propertyDescriptor.getGetter().isDefault())
setter = isInsideClass && propertyDescriptor.getSetter() == null ? null : typeMapper.mapSetterSignature(propertyDescriptor); ? null : typeMapper.mapGetterSignature(propertyDescriptor);
setter = isInsideClass && (propertyDescriptor.getSetter() == null || propertyDescriptor.getSetter().isDefault())
? null : typeMapper.mapSetterSignature(propertyDescriptor);
} }
String owner; String owner;
@@ -13,6 +13,7 @@ import java.util.List;
public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorImpl implements FunctionDescriptor, MemberDescriptor { public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorImpl implements FunctionDescriptor, MemberDescriptor {
private final boolean hasBody; private final boolean hasBody;
private final boolean isDefault;
private final MemberModifiers modifiers; private final MemberModifiers modifiers;
protected PropertyAccessorDescriptor( protected PropertyAccessorDescriptor(
@@ -20,16 +21,22 @@ public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorIm
@NotNull PropertyDescriptor correspondingProperty, @NotNull PropertyDescriptor correspondingProperty,
@NotNull List<AnnotationDescriptor> annotations, @NotNull List<AnnotationDescriptor> annotations,
@NotNull String name, @NotNull String name,
boolean hasBody) { boolean hasBody,
boolean isDefault) {
super(correspondingProperty.getContainingDeclaration(), annotations, name); super(correspondingProperty.getContainingDeclaration(), annotations, name);
this.modifiers = modifiers; this.modifiers = modifiers;
this.hasBody = hasBody; this.hasBody = hasBody;
this.isDefault = isDefault;
} }
public boolean hasBody() { public boolean hasBody() {
return hasBody; return hasBody;
} }
public boolean isDefault() {
return isDefault;
}
@NotNull @NotNull
@Override @Override
public PropertyAccessorDescriptor getOriginal() { public PropertyAccessorDescriptor getOriginal() {
@@ -17,8 +17,8 @@ public class PropertyGetterDescriptor extends PropertyAccessorDescriptor {
private final Set<PropertyGetterDescriptor> overriddenGetters = Sets.newHashSet(); private final Set<PropertyGetterDescriptor> overriddenGetters = Sets.newHashSet();
private JetType returnType; private JetType returnType;
public PropertyGetterDescriptor(@NotNull MemberModifiers modifiers, @NotNull PropertyDescriptor correspondingProperty, @NotNull List<AnnotationDescriptor> annotations, @Nullable JetType returnType, boolean hasBody) { public PropertyGetterDescriptor(@NotNull MemberModifiers modifiers, @NotNull PropertyDescriptor correspondingProperty, @NotNull List<AnnotationDescriptor> annotations, @Nullable JetType returnType, boolean hasBody, boolean isDefault) {
super(modifiers, correspondingProperty, annotations, "get-" + correspondingProperty.getName(), hasBody); super(modifiers, correspondingProperty, annotations, "get-" + correspondingProperty.getName(), hasBody, isDefault);
this.returnType = returnType == null ? correspondingProperty.getOutType() : returnType; this.returnType = returnType == null ? correspondingProperty.getOutType() : returnType;
} }
@@ -18,8 +18,8 @@ public class PropertySetterDescriptor extends PropertyAccessorDescriptor {
private MutableValueParameterDescriptor parameter; private MutableValueParameterDescriptor parameter;
private final Set<PropertySetterDescriptor> overriddenSetters = Sets.newHashSet(); private final Set<PropertySetterDescriptor> overriddenSetters = Sets.newHashSet();
public PropertySetterDescriptor(@NotNull MemberModifiers modifiers, @NotNull PropertyDescriptor correspondingProperty, @NotNull List<AnnotationDescriptor> annotations, boolean hasBody) { public PropertySetterDescriptor(@NotNull MemberModifiers modifiers, @NotNull PropertyDescriptor correspondingProperty, @NotNull List<AnnotationDescriptor> annotations, boolean hasBody, boolean isDefault) {
super(modifiers, correspondingProperty, annotations, "set-" + correspondingProperty.getName(), hasBody); super(modifiers, correspondingProperty, annotations, "set-" + correspondingProperty.getName(), hasBody, isDefault);
} }
public void initialize(@NotNull MutableValueParameterDescriptor parameter) { public void initialize(@NotNull MutableValueParameterDescriptor parameter) {
@@ -568,18 +568,20 @@ public class ClassDescriptorResolver {
@Nullable @Nullable
private PropertySetterDescriptor resolvePropertySetterDescriptor(@NotNull JetScope scope, @NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) { private PropertySetterDescriptor resolvePropertySetterDescriptor(@NotNull JetScope scope, @NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
JetPropertyAccessor setter = property.getSetter(); JetPropertyAccessor setter = property.getSetter();
if (setter != null && !property.isVar()) { if (! property.isVar()) {
trace.getErrorHandler().genericError(setter.asElement().getNode(), "A 'val'-property cannot have a setter"); if (setter != null) {
trace.getErrorHandler().genericError(setter.asElement().getNode(), "A 'val'-property cannot have a setter");
}
return null; return null;
} }
PropertySetterDescriptor setterDescriptor = null; PropertySetterDescriptor setterDescriptor;
if (setter != null) { if (setter != null) {
List<AnnotationDescriptor> annotations = annotationResolver.resolveAnnotations(scope, setter.getModifierList()); List<AnnotationDescriptor> annotations = annotationResolver.resolveAnnotations(scope, setter.getModifierList());
JetParameter parameter = setter.getParameter(); JetParameter parameter = setter.getParameter();
setterDescriptor = new PropertySetterDescriptor( setterDescriptor = new PropertySetterDescriptor(
resolveModifiers(setter.getModifierList(), DEFAULT_MODIFIERS), // TODO : default modifiers differ in different contexts resolveModifiers(setter.getModifierList(), DEFAULT_MODIFIERS), // TODO : default modifiers differ in different contexts
propertyDescriptor, annotations, setter.getBodyExpression() != null); propertyDescriptor, annotations, setter.getBodyExpression() != null, false);
if (parameter != null) { if (parameter != null) {
if (parameter.isRef()) { if (parameter.isRef()) {
trace.getErrorHandler().genericError(parameter.getRefNode(), "Setter parameters can not be 'ref'"); trace.getErrorHandler().genericError(parameter.getRefNode(), "Setter parameters can not be 'ref'");
@@ -614,12 +616,17 @@ public class ClassDescriptorResolver {
} }
trace.record(BindingContext.PROPERTY_ACCESSOR, setter, setterDescriptor); trace.record(BindingContext.PROPERTY_ACCESSOR, setter, setterDescriptor);
} }
else {
setterDescriptor = new PropertySetterDescriptor(
propertyDescriptor.getModifiers(),
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), false, true);
}
return setterDescriptor; return setterDescriptor;
} }
@Nullable @Nullable
private PropertyGetterDescriptor resolvePropertyGetterDescriptor(@NotNull JetScope scope, @NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) { private PropertyGetterDescriptor resolvePropertyGetterDescriptor(@NotNull JetScope scope, @NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
PropertyGetterDescriptor getterDescriptor = null; PropertyGetterDescriptor getterDescriptor;
JetPropertyAccessor getter = property.getGetter(); JetPropertyAccessor getter = property.getGetter();
if (getter != null) { if (getter != null) {
List<AnnotationDescriptor> annotations = annotationResolver.resolveAnnotations(scope, getter.getModifierList()); List<AnnotationDescriptor> annotations = annotationResolver.resolveAnnotations(scope, getter.getModifierList());
@@ -632,9 +639,14 @@ public class ClassDescriptorResolver {
getterDescriptor = new PropertyGetterDescriptor( getterDescriptor = new PropertyGetterDescriptor(
resolveModifiers(getter.getModifierList(), DEFAULT_MODIFIERS), // TODO : default modifiers differ in different contexts resolveModifiers(getter.getModifierList(), DEFAULT_MODIFIERS), // TODO : default modifiers differ in different contexts
propertyDescriptor, annotations, returnType, getter.getBodyExpression() != null); propertyDescriptor, annotations, returnType, getter.getBodyExpression() != null, false);
trace.record(BindingContext.PROPERTY_ACCESSOR, getter, getterDescriptor); trace.record(BindingContext.PROPERTY_ACCESSOR, getter, getterDescriptor);
} }
else {
getterDescriptor = new PropertyGetterDescriptor(
propertyDescriptor.getModifiers(),
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getOutType(), false, true);
}
return getterDescriptor; return getterDescriptor;
} }