Extract JetProperty#hasDelegate() and hasDelegateExpression() and use it where appropriate

This commit is contained in:
Pavel V. Talanov
2014-04-09 15:23:11 +04:00
parent e424b89d82
commit 58651d02c2
4 changed files with 15 additions and 7 deletions
@@ -317,7 +317,7 @@ public abstract class MemberCodegen<T extends JetElement/* TODO: & JetDeclaratio
for (JetDeclaration declaration : ((JetDeclarationContainer) element).getDeclarations()) {
if (declaration instanceof JetProperty) {
JetProperty property = (JetProperty) declaration;
if (property.getDelegate() != null) {
if (property.hasDelegate()) {
delegatedProperties.add(property);
}
}
@@ -148,7 +148,7 @@ public class PropertyCodegen {
if (Boolean.TRUE.equals(bindingContext.get(BindingContext.BACKING_FIELD_REQUIRED, 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);
}
else {
@@ -288,7 +288,7 @@ public class PropertyCodegen {
FunctionGenerationStrategy strategy;
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));
}
else {
@@ -318,7 +318,7 @@ public class PropertyCodegen {
int index = 0;
for (JetDeclaration declaration : container.getDeclarations()) {
if (declaration instanceof JetProperty && ((JetProperty) declaration).getDelegate() != null) {
if (declaration instanceof JetProperty && ((JetProperty) declaration).hasDelegate()) {
if (declaration == property) {
return index;
}
@@ -146,11 +146,19 @@ public class JetProperty extends JetTypeParameterListOwnerStub<PsiJetPropertyStu
return null;
}
public boolean hasDelegate() {
return getDelegate() != null;
}
@Nullable
public JetPropertyDelegate getDelegate() {
return (JetPropertyDelegate) findChildByType(PROPERTY_DELEGATE);
}
public boolean hasDelegateExpression() {
return getDelegateExpression() != null;
}
@Nullable
public JetExpression getDelegateExpression() {
JetPropertyDelegate delegate = getDelegate();
@@ -984,7 +984,7 @@ public class DescriptorResolver {
) {
JetTypeReference propertyTypeRef = variable.getTypeRef();
boolean hasDelegate = variable instanceof JetProperty && ((JetProperty) variable).getDelegateExpression() != null;
boolean hasDelegate = variable instanceof JetProperty && ((JetProperty) variable).hasDelegateExpression();
if (propertyTypeRef == null) {
final JetExpression initializer = variable.getInitializer();
if (initializer == null) {
@@ -1186,7 +1186,7 @@ public class DescriptorResolver {
trace.record(BindingContext.PROPERTY_ACCESSOR, setter, setterDescriptor);
}
else if (property.isVar()) {
setterDescriptor = DescriptorFactory.createSetter(propertyDescriptor, property.getDelegateExpression() == null);
setterDescriptor = DescriptorFactory.createSetter(propertyDescriptor, !property.hasDelegate());
}
if (!property.isVar()) {
@@ -1230,7 +1230,7 @@ public class DescriptorResolver {
trace.record(BindingContext.PROPERTY_ACCESSOR, getter, getterDescriptor);
}
else {
getterDescriptor = DescriptorFactory.createGetter(propertyDescriptor, property.getDelegateExpression() == null);
getterDescriptor = DescriptorFactory.createGetter(propertyDescriptor, !property.hasDelegate());
getterDescriptor.initialize(propertyDescriptor.getType());
}
return getterDescriptor;