Minor, simplify code in PropertyCodegen

This commit is contained in:
Alexander Udalov
2019-04-24 12:31:33 +02:00
parent 967a6bd80d
commit c13bec0e41
@@ -113,11 +113,17 @@ public class PropertyCodegen {
public void generateInPackageFacade(@NotNull DeserializedPropertyDescriptor deserializedProperty) { public void generateInPackageFacade(@NotNull DeserializedPropertyDescriptor deserializedProperty) {
assert context instanceof MultifileClassFacadeContext : "should be called only for generating facade: " + context; assert context instanceof MultifileClassFacadeContext : "should be called only for generating facade: " + context;
gen(null, deserializedProperty, null, null);
genBackingFieldAndAnnotations(deserializedProperty);
if (!isConstOrHasJvmFieldAnnotation(deserializedProperty)) {
generateGetter(deserializedProperty, null);
generateSetter(deserializedProperty, null);
}
} }
private void gen( private void gen(
@Nullable KtProperty declaration, @NotNull KtProperty declaration,
@NotNull PropertyDescriptor descriptor, @NotNull PropertyDescriptor descriptor,
@Nullable KtPropertyAccessor getter, @Nullable KtPropertyAccessor getter,
@Nullable KtPropertyAccessor setter @Nullable KtPropertyAccessor setter
@@ -169,7 +175,7 @@ public class PropertyCodegen {
* @see JvmCodegenUtil#couldUseDirectAccessToProperty * @see JvmCodegenUtil#couldUseDirectAccessToProperty
*/ */
private boolean isAccessorNeeded( private boolean isAccessorNeeded(
@Nullable KtProperty declaration, @NotNull KtProperty declaration,
@NotNull PropertyDescriptor descriptor, @NotNull PropertyDescriptor descriptor,
@Nullable KtPropertyAccessor accessor, @Nullable KtPropertyAccessor accessor,
boolean isDefaultGetterAndSetter boolean isDefaultGetterAndSetter
@@ -181,8 +187,6 @@ public class PropertyCodegen {
// Don't generate accessors for interface properties with default accessors in DefaultImpls // Don't generate accessors for interface properties with default accessors in DefaultImpls
if (kind == OwnerKind.DEFAULT_IMPLS && isDefaultAccessor) return false; if (kind == OwnerKind.DEFAULT_IMPLS && isDefaultAccessor) return false;
if (declaration == null) return true;
// Delegated or extension properties can only be referenced via accessors // Delegated or extension properties can only be referenced via accessors
if (declaration.hasDelegate() || declaration.getReceiverTypeReference() != null) return true; if (declaration.hasDelegate() || declaration.getReceiverTypeReference() != null) return true;
@@ -198,7 +202,7 @@ public class PropertyCodegen {
} }
// Non-const properties from multifile classes have accessors regardless of visibility // Non-const properties from multifile classes have accessors regardless of visibility
if (isNonConstTopLevelPropertyInMultifileClass(declaration, descriptor)) return true; if (isTopLevelPropertyInMultifileClass(declaration, descriptor)) return true;
// Private class properties have accessors only in cases when those accessors are non-trivial // Private class properties have accessors only in cases when those accessors are non-trivial
if (Visibilities.isPrivate(descriptor.getVisibility())) { if (Visibilities.isPrivate(descriptor.getVisibility())) {
@@ -207,6 +211,7 @@ public class PropertyCodegen {
// Non-private properties with private setter should not be generated for trivial properties // Non-private properties with private setter should not be generated for trivial properties
// as the class will use direct field access instead // as the class will use direct field access instead
//noinspection ConstantConditions
if (accessor != null && accessor.isSetter() && Visibilities.isPrivate(descriptor.getSetter().getVisibility())) { if (accessor != null && accessor.isSetter() && Visibilities.isPrivate(descriptor.getSetter().getVisibility())) {
return !isDefaultAccessor; return !isDefaultAccessor;
} }
@@ -214,12 +219,11 @@ public class PropertyCodegen {
return true; return true;
} }
private static boolean isNonConstTopLevelPropertyInMultifileClass( private static boolean isTopLevelPropertyInMultifileClass(
@NotNull KtProperty declaration, @NotNull KtProperty declaration,
@NotNull PropertyDescriptor descriptor @NotNull PropertyDescriptor descriptor
) { ) {
return !descriptor.isConst() && return descriptor.getContainingDeclaration() instanceof PackageFragmentDescriptor &&
descriptor.getContainingDeclaration() instanceof PackageFragmentDescriptor &&
JvmFileClassUtilKt.isInsideJvmMultifileClassFile(declaration); JvmFileClassUtilKt.isInsideJvmMultifileClassFile(declaration);
} }