Extract JetProperty#hasDelegate() and hasDelegateExpression() and use it where appropriate
This commit is contained in:
@@ -317,7 +317,7 @@ public abstract class MemberCodegen<T extends JetElement/* TODO: & JetDeclaratio
|
|||||||
for (JetDeclaration declaration : ((JetDeclarationContainer) element).getDeclarations()) {
|
for (JetDeclaration declaration : ((JetDeclarationContainer) element).getDeclarations()) {
|
||||||
if (declaration instanceof JetProperty) {
|
if (declaration instanceof JetProperty) {
|
||||||
JetProperty property = (JetProperty) declaration;
|
JetProperty property = (JetProperty) declaration;
|
||||||
if (property.getDelegate() != null) {
|
if (property.hasDelegate()) {
|
||||||
delegatedProperties.add(property);
|
delegatedProperties.add(property);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ public class PropertyCodegen {
|
|||||||
if (Boolean.TRUE.equals(bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, descriptor))) {
|
if (Boolean.TRUE.equals(bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, descriptor))) {
|
||||||
fv = generateBackingFieldAccess(p, descriptor);
|
fv = generateBackingFieldAccess(p, descriptor);
|
||||||
}
|
}
|
||||||
else if (p instanceof JetProperty && ((JetProperty) p).getDelegateExpression() != null) {
|
else if (p instanceof JetProperty && ((JetProperty) p).hasDelegate()) {
|
||||||
fv = generatePropertyDelegateAccess((JetProperty) p, descriptor);
|
fv = generatePropertyDelegateAccess((JetProperty) p, descriptor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -288,7 +288,7 @@ public class PropertyCodegen {
|
|||||||
|
|
||||||
FunctionGenerationStrategy strategy;
|
FunctionGenerationStrategy strategy;
|
||||||
if (isDefaultAccessor) {
|
if (isDefaultAccessor) {
|
||||||
if (p instanceof JetProperty && ((JetProperty) p).getDelegate() != null) {
|
if (p instanceof JetProperty && ((JetProperty) p).hasDelegate()) {
|
||||||
strategy = new DelegatedPropertyAccessorStrategy(state, accessorDescriptor, indexOfDelegatedProperty((JetProperty) p));
|
strategy = new DelegatedPropertyAccessorStrategy(state, accessorDescriptor, indexOfDelegatedProperty((JetProperty) p));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -318,7 +318,7 @@ public class PropertyCodegen {
|
|||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (JetDeclaration declaration : container.getDeclarations()) {
|
for (JetDeclaration declaration : container.getDeclarations()) {
|
||||||
if (declaration instanceof JetProperty && ((JetProperty) declaration).getDelegate() != null) {
|
if (declaration instanceof JetProperty && ((JetProperty) declaration).hasDelegate()) {
|
||||||
if (declaration == property) {
|
if (declaration == property) {
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,11 +146,19 @@ public class JetProperty extends JetTypeParameterListOwnerStub<PsiJetPropertyStu
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasDelegate() {
|
||||||
|
return getDelegate() != null;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public JetPropertyDelegate getDelegate() {
|
public JetPropertyDelegate getDelegate() {
|
||||||
return (JetPropertyDelegate) findChildByType(PROPERTY_DELEGATE);
|
return (JetPropertyDelegate) findChildByType(PROPERTY_DELEGATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasDelegateExpression() {
|
||||||
|
return getDelegateExpression() != null;
|
||||||
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public JetExpression getDelegateExpression() {
|
public JetExpression getDelegateExpression() {
|
||||||
JetPropertyDelegate delegate = getDelegate();
|
JetPropertyDelegate delegate = getDelegate();
|
||||||
|
|||||||
@@ -984,7 +984,7 @@ public class DescriptorResolver {
|
|||||||
) {
|
) {
|
||||||
JetTypeReference propertyTypeRef = variable.getTypeRef();
|
JetTypeReference propertyTypeRef = variable.getTypeRef();
|
||||||
|
|
||||||
boolean hasDelegate = variable instanceof JetProperty && ((JetProperty) variable).getDelegateExpression() != null;
|
boolean hasDelegate = variable instanceof JetProperty && ((JetProperty) variable).hasDelegateExpression();
|
||||||
if (propertyTypeRef == null) {
|
if (propertyTypeRef == null) {
|
||||||
final JetExpression initializer = variable.getInitializer();
|
final JetExpression initializer = variable.getInitializer();
|
||||||
if (initializer == null) {
|
if (initializer == null) {
|
||||||
@@ -1186,7 +1186,7 @@ public class DescriptorResolver {
|
|||||||
trace.record(BindingContext.PROPERTY_ACCESSOR, setter, setterDescriptor);
|
trace.record(BindingContext.PROPERTY_ACCESSOR, setter, setterDescriptor);
|
||||||
}
|
}
|
||||||
else if (property.isVar()) {
|
else if (property.isVar()) {
|
||||||
setterDescriptor = DescriptorFactory.createSetter(propertyDescriptor, property.getDelegateExpression() == null);
|
setterDescriptor = DescriptorFactory.createSetter(propertyDescriptor, !property.hasDelegate());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!property.isVar()) {
|
if (!property.isVar()) {
|
||||||
@@ -1230,7 +1230,7 @@ public class DescriptorResolver {
|
|||||||
trace.record(BindingContext.PROPERTY_ACCESSOR, getter, getterDescriptor);
|
trace.record(BindingContext.PROPERTY_ACCESSOR, getter, getterDescriptor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
getterDescriptor = DescriptorFactory.createGetter(propertyDescriptor, property.getDelegateExpression() == null);
|
getterDescriptor = DescriptorFactory.createGetter(propertyDescriptor, !property.hasDelegate());
|
||||||
getterDescriptor.initialize(propertyDescriptor.getType());
|
getterDescriptor.initialize(propertyDescriptor.getType());
|
||||||
}
|
}
|
||||||
return getterDescriptor;
|
return getterDescriptor;
|
||||||
|
|||||||
Reference in New Issue
Block a user