added default property accessor descriptors
This commit is contained in:
@@ -784,8 +784,10 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
setter = null;
|
||||
}
|
||||
else {
|
||||
getter = isInsideClass && propertyDescriptor.getGetter() == null ? null : typeMapper.mapGetterSignature(propertyDescriptor);
|
||||
setter = isInsideClass && propertyDescriptor.getSetter() == null ? null : typeMapper.mapSetterSignature(propertyDescriptor);
|
||||
getter = isInsideClass && (propertyDescriptor.getGetter() == null || propertyDescriptor.getGetter().isDefault())
|
||||
? null : typeMapper.mapGetterSignature(propertyDescriptor);
|
||||
setter = isInsideClass && (propertyDescriptor.getSetter() == null || propertyDescriptor.getSetter().isDefault())
|
||||
? null : typeMapper.mapSetterSignature(propertyDescriptor);
|
||||
}
|
||||
|
||||
String owner;
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.util.List;
|
||||
public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorImpl implements FunctionDescriptor, MemberDescriptor {
|
||||
|
||||
private final boolean hasBody;
|
||||
private final boolean isDefault;
|
||||
private final MemberModifiers modifiers;
|
||||
|
||||
protected PropertyAccessorDescriptor(
|
||||
@@ -20,16 +21,22 @@ public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorIm
|
||||
@NotNull PropertyDescriptor correspondingProperty,
|
||||
@NotNull List<AnnotationDescriptor> annotations,
|
||||
@NotNull String name,
|
||||
boolean hasBody) {
|
||||
boolean hasBody,
|
||||
boolean isDefault) {
|
||||
super(correspondingProperty.getContainingDeclaration(), annotations, name);
|
||||
this.modifiers = modifiers;
|
||||
this.hasBody = hasBody;
|
||||
this.isDefault = isDefault;
|
||||
}
|
||||
|
||||
public boolean hasBody() {
|
||||
return hasBody;
|
||||
}
|
||||
|
||||
public boolean isDefault() {
|
||||
return isDefault;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PropertyAccessorDescriptor getOriginal() {
|
||||
|
||||
@@ -17,8 +17,8 @@ public class PropertyGetterDescriptor extends PropertyAccessorDescriptor {
|
||||
private final Set<PropertyGetterDescriptor> overriddenGetters = Sets.newHashSet();
|
||||
private JetType returnType;
|
||||
|
||||
public PropertyGetterDescriptor(@NotNull MemberModifiers modifiers, @NotNull PropertyDescriptor correspondingProperty, @NotNull List<AnnotationDescriptor> annotations, @Nullable JetType returnType, boolean hasBody) {
|
||||
super(modifiers, correspondingProperty, annotations, "get-" + correspondingProperty.getName(), 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, isDefault);
|
||||
this.returnType = returnType == null ? correspondingProperty.getOutType() : returnType;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ public class PropertySetterDescriptor extends PropertyAccessorDescriptor {
|
||||
private MutableValueParameterDescriptor parameter;
|
||||
private final Set<PropertySetterDescriptor> overriddenSetters = Sets.newHashSet();
|
||||
|
||||
public PropertySetterDescriptor(@NotNull MemberModifiers modifiers, @NotNull PropertyDescriptor correspondingProperty, @NotNull List<AnnotationDescriptor> annotations, boolean hasBody) {
|
||||
super(modifiers, correspondingProperty, annotations, "set-" + correspondingProperty.getName(), 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, isDefault);
|
||||
}
|
||||
|
||||
public void initialize(@NotNull MutableValueParameterDescriptor parameter) {
|
||||
|
||||
@@ -568,18 +568,20 @@ public class ClassDescriptorResolver {
|
||||
@Nullable
|
||||
private PropertySetterDescriptor resolvePropertySetterDescriptor(@NotNull JetScope scope, @NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
|
||||
JetPropertyAccessor setter = property.getSetter();
|
||||
if (setter != null && !property.isVar()) {
|
||||
trace.getErrorHandler().genericError(setter.asElement().getNode(), "A 'val'-property cannot have a setter");
|
||||
if (! property.isVar()) {
|
||||
if (setter != null) {
|
||||
trace.getErrorHandler().genericError(setter.asElement().getNode(), "A 'val'-property cannot have a setter");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
PropertySetterDescriptor setterDescriptor = null;
|
||||
PropertySetterDescriptor setterDescriptor;
|
||||
if (setter != null) {
|
||||
List<AnnotationDescriptor> annotations = annotationResolver.resolveAnnotations(scope, setter.getModifierList());
|
||||
JetParameter parameter = setter.getParameter();
|
||||
|
||||
setterDescriptor = new PropertySetterDescriptor(
|
||||
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.isRef()) {
|
||||
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);
|
||||
}
|
||||
else {
|
||||
setterDescriptor = new PropertySetterDescriptor(
|
||||
propertyDescriptor.getModifiers(),
|
||||
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), false, true);
|
||||
}
|
||||
return setterDescriptor;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PropertyGetterDescriptor resolvePropertyGetterDescriptor(@NotNull JetScope scope, @NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
|
||||
PropertyGetterDescriptor getterDescriptor = null;
|
||||
PropertyGetterDescriptor getterDescriptor;
|
||||
JetPropertyAccessor getter = property.getGetter();
|
||||
if (getter != null) {
|
||||
List<AnnotationDescriptor> annotations = annotationResolver.resolveAnnotations(scope, getter.getModifierList());
|
||||
@@ -632,9 +639,14 @@ public class ClassDescriptorResolver {
|
||||
|
||||
getterDescriptor = new PropertyGetterDescriptor(
|
||||
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);
|
||||
}
|
||||
else {
|
||||
getterDescriptor = new PropertyGetterDescriptor(
|
||||
propertyDescriptor.getModifiers(),
|
||||
propertyDescriptor, Collections.<AnnotationDescriptor>emptyList(), propertyDescriptor.getOutType(), false, true);
|
||||
}
|
||||
return getterDescriptor;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user