Add renderAccessors flag to DescriptorRenderer to render property accessors as "setter for …"

This commit is contained in:
Ilya Ryzhenkov
2015-04-20 17:46:31 +03:00
parent c2b3bcc95f
commit aec37a35dc
2 changed files with 36 additions and 3 deletions
@@ -59,6 +59,7 @@ public class DescriptorRendererBuilder {
private Collection<FqName> excludedAnnotationClasses = Collections.emptyList();
private boolean receiverAfterName = false;
private boolean renderCompanionObjectName = false;
private boolean renderAccessors = false;
public DescriptorRendererBuilder() {
}
@@ -224,6 +225,12 @@ public class DescriptorRendererBuilder {
return this;
}
@NotNull
public DescriptorRendererBuilder setRenderAccessors(boolean renderAccessors) {
this.renderAccessors = renderAccessors;
return this;
}
@NotNull
public DescriptorRenderer build() {
return new DescriptorRendererImpl(
@@ -231,8 +238,8 @@ public class DescriptorRendererBuilder {
normalizedVisibilities, showInternalKeyword, prettyFunctionTypes, uninferredTypeParameterAsName,
overrideRenderingPolicy, valueParametersHandler, textFormat, excludedAnnotationClasses, includePropertyConstant,
parameterNameRenderingPolicy, withoutTypeParameters, receiverAfterName, renderCompanionObjectName, withoutSuperTypes,
typeNormalizer, renderDefaultValues, flexibleTypesForCode, secondaryConstructorsAsPrimary
);
typeNormalizer, renderDefaultValues, flexibleTypesForCode, secondaryConstructorsAsPrimary,
renderAccessors);
}
}
@@ -70,6 +70,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
private final boolean includePropertyConstant;
private final boolean secondaryConstructorsAsPrimary;
private final Set<FqName> excludedAnnotationClasses;
private final boolean renderAccessors;
/* package */ DescriptorRendererImpl(
NameShortness nameShortness,
@@ -97,7 +98,8 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
@NotNull Function1<JetType, JetType> typeNormalizer,
boolean renderDefaultValues,
boolean flexibleTypesForCode,
boolean secondaryConstructorsAsPrimary
boolean secondaryConstructorsAsPrimary,
boolean renderAccessors
) {
this.nameShortness = nameShortness;
this.withDefinedIn = withDefinedIn;
@@ -114,6 +116,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
this.textFormat = textFormat;
this.includePropertyConstant = includePropertyConstant;
this.secondaryConstructorsAsPrimary = secondaryConstructorsAsPrimary;
this.renderAccessors = renderAccessors;
this.excludedAnnotationClasses = new HashSet<FqName>(excludedAnnotationClasses);
this.prettyFunctionTypes = prettyFunctionTypes;
this.uninferredTypeParameterAsName = uninferredTypeParameterAsName;
@@ -1107,6 +1110,29 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
return null;
}
@Override
public Void visitPropertyGetterDescriptor(PropertyGetterDescriptor descriptor, StringBuilder builder) {
if (renderAccessors) {
builder.append("getter for ");
renderProperty(descriptor.getCorrespondingProperty(), builder);
return null;
} else {
return super.visitPropertyGetterDescriptor(descriptor, builder);
}
}
@Override
public Void visitPropertySetterDescriptor(PropertySetterDescriptor descriptor, StringBuilder builder) {
if (renderAccessors) {
builder.append("setter for ");
renderProperty(descriptor.getCorrespondingProperty(), builder);
return null;
} else {
return super.visitPropertySetterDescriptor(descriptor, builder);
}
}
@Override
public Void visitFunctionDescriptor(FunctionDescriptor descriptor, StringBuilder builder) {
renderFunction(descriptor, builder);