JET-67 Property with abstract getter forces class to have primary constructor
This commit is contained in:
@@ -9,12 +9,19 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorImpl implements FunctionDescriptor {
|
public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorImpl implements FunctionDescriptor, MemberDescriptor {
|
||||||
|
|
||||||
private final boolean hasBody;
|
private final boolean hasBody;
|
||||||
|
private final MemberModifiers modifiers;
|
||||||
|
|
||||||
protected PropertyAccessorDescriptor(@NotNull PropertyDescriptor correspondingProperty, @NotNull List<Annotation> annotations, @NotNull String name, boolean hasBody) {
|
protected PropertyAccessorDescriptor(
|
||||||
|
@NotNull MemberModifiers modifiers,
|
||||||
|
@NotNull PropertyDescriptor correspondingProperty,
|
||||||
|
@NotNull List<Annotation> annotations,
|
||||||
|
@NotNull String name,
|
||||||
|
boolean hasBody) {
|
||||||
super(correspondingProperty.getContainingDeclaration(), annotations, name);
|
super(correspondingProperty.getContainingDeclaration(), annotations, name);
|
||||||
|
this.modifiers = modifiers;
|
||||||
this.hasBody = hasBody;
|
this.hasBody = hasBody;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,4 +46,10 @@ public abstract class PropertyAccessorDescriptor extends DeclarationDescriptorIm
|
|||||||
public List<TypeParameterDescriptor> getTypeParameters() {
|
public List<TypeParameterDescriptor> getTypeParameters() {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public MemberModifiers getModifiers() {
|
||||||
|
return modifiers;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,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 PropertyDescriptor correspondingProperty, @NotNull List<Annotation> annotations, @Nullable JetType returnType, boolean hasBody) {
|
public PropertyGetterDescriptor(@NotNull MemberModifiers modifiers, @NotNull PropertyDescriptor correspondingProperty, @NotNull List<Annotation> annotations, @Nullable JetType returnType, boolean hasBody) {
|
||||||
super(correspondingProperty, annotations, "get-" + correspondingProperty.getName(), hasBody);
|
super(modifiers, correspondingProperty, annotations, "get-" + correspondingProperty.getName(), hasBody);
|
||||||
this.returnType = returnType == null ? correspondingProperty.getOutType() : returnType;
|
this.returnType = returnType == null ? correspondingProperty.getOutType() : returnType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,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 PropertyDescriptor correspondingProperty, @NotNull List<Annotation> annotations, boolean hasBody) {
|
public PropertySetterDescriptor(@NotNull MemberModifiers modifiers, @NotNull PropertyDescriptor correspondingProperty, @NotNull List<Annotation> annotations, boolean hasBody) {
|
||||||
super(correspondingProperty, annotations, "set-" + correspondingProperty.getName(), hasBody);
|
super(modifiers, correspondingProperty, annotations, "set-" + correspondingProperty.getName(), hasBody);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initialize(@NotNull MutableValueParameterDescriptor parameter) {
|
public void initialize(@NotNull MutableValueParameterDescriptor parameter) {
|
||||||
|
|||||||
@@ -256,10 +256,10 @@ public class BindingTraceContext implements BindingContext, BindingTrace {
|
|||||||
else if (propertyDescriptor.isVar() && setter == null) {
|
else if (propertyDescriptor.isVar() && setter == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (setter != null && !setter.hasBody()) {
|
else if (setter != null && !setter.hasBody() && !setter.getModifiers().isAbstract()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if (!getter.hasBody()) {
|
else if (!getter.hasBody() && !getter.getModifiers().isAbstract()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return backingFieldRequired.contains(propertyDescriptor);
|
return backingFieldRequired.contains(propertyDescriptor);
|
||||||
|
|||||||
@@ -453,7 +453,9 @@ public class ClassDescriptorResolver {
|
|||||||
List<Annotation> annotations = AnnotationResolver.INSTANCE.resolveAnnotations(setter.getModifierList());
|
List<Annotation> annotations = AnnotationResolver.INSTANCE.resolveAnnotations(setter.getModifierList());
|
||||||
JetParameter parameter = setter.getParameter();
|
JetParameter parameter = setter.getParameter();
|
||||||
|
|
||||||
setterDescriptor = new PropertySetterDescriptor(propertyDescriptor, annotations, setter.getBodyExpression() != null);
|
setterDescriptor = new PropertySetterDescriptor(
|
||||||
|
resolveModifiers(setter.getModifierList(), DEFAULT_MODIFIERS), // TODO : default modifiers differ in different contexts
|
||||||
|
propertyDescriptor, annotations, setter.getBodyExpression() != null);
|
||||||
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'");
|
||||||
@@ -504,7 +506,9 @@ public class ClassDescriptorResolver {
|
|||||||
returnType = typeResolver.resolveType(scope, returnTypeReference);
|
returnType = typeResolver.resolveType(scope, returnTypeReference);
|
||||||
}
|
}
|
||||||
|
|
||||||
getterDescriptor = new PropertyGetterDescriptor(propertyDescriptor, annotations, returnType, getter.getBodyExpression() != null);
|
getterDescriptor = new PropertyGetterDescriptor(
|
||||||
|
resolveModifiers(getter.getModifierList(), DEFAULT_MODIFIERS), // TODO : default modifiers differ in different contexts
|
||||||
|
propertyDescriptor, annotations, returnType, getter.getBodyExpression() != null);
|
||||||
trace.recordDeclarationResolution(getter, getterDescriptor);
|
trace.recordDeclarationResolution(getter, getterDescriptor);
|
||||||
}
|
}
|
||||||
return getterDescriptor;
|
return getterDescriptor;
|
||||||
|
|||||||
@@ -33,6 +33,12 @@ class Test() {
|
|||||||
|
|
||||||
var <info>v5</info> : Int <info>get</info>() = 1; <info>set</info>(x){$v5 = x}
|
var <info>v5</info> : Int <info>get</info>() = 1; <info>set</info>(x){$v5 = x}
|
||||||
var <info>v6</info> : Int <info>get</info>() = $v6 + 1; <info>set</info>(x){}
|
var <info>v6</info> : Int <info>get</info>() = $v6 + 1; <info>set</info>(x){}
|
||||||
|
|
||||||
|
val v7 : Int <info>abstract</info> <info>get</info>
|
||||||
|
var v8 : Int <info>abstract</info> <info>get</info> <info>abstract</info> <info>set</info>
|
||||||
|
var <info>v9</info> : Int <info>abstract</info> <info>set</info>
|
||||||
|
var <info>v10</info> : Int <info>abstract</info> <info>get</info>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<info>open</info> class Super(i : Int)
|
<info>open</info> class Super(i : Int)
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
class XXX {
|
||||||
|
val a : Int abstract get
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user