Allow rendering Any in all positions and using Function0 etc instead of "() -> ..."

This commit is contained in:
Andrey Breslav
2013-05-31 16:32:44 +04:00
committed by Alexander Udalov
parent 5b8d41cc36
commit af415d160f
3 changed files with 51 additions and 19 deletions
@@ -33,6 +33,8 @@ public class DescriptorRendererBuilder {
private boolean unitReturnType = true;
private boolean normalizedVisibilities = false;
private boolean showInternalKeyword = true;
private boolean alwaysRenderAny = false;
private boolean prettyFunctionTypes = true;
@NotNull
private DescriptorRenderer.OverrideRenderingPolicy overrideRenderingPolicy = DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN;
@NotNull
@@ -115,10 +117,20 @@ public class DescriptorRendererBuilder {
return this;
}
public DescriptorRendererBuilder setAlwaysRenderAny(boolean alwaysRenderAny) {
this.alwaysRenderAny = alwaysRenderAny;
return this;
}
public DescriptorRendererBuilder setPrettyFunctionTypes(boolean prettyFunctionTypes) {
this.prettyFunctionTypes = prettyFunctionTypes;
return this;
}
public DescriptorRenderer build() {
return new DescriptorRendererImpl(shortNames, withDefinedIn, modifiers, startFromName, debugMode, classWithPrimaryConstructor,
verbose, unitReturnType, normalizedVisibilities, showInternalKeyword, overrideRenderingPolicy,
valueParametersHandler, textFormat, excludedAnnotationClasses);
verbose, unitReturnType, normalizedVisibilities, showInternalKeyword, alwaysRenderAny, prettyFunctionTypes,
overrideRenderingPolicy, valueParametersHandler, textFormat, excludedAnnotationClasses);
}
}
@@ -58,6 +58,8 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
private final boolean unitReturnType;
private final boolean normalizedVisibilities;
private final boolean showInternalKeyword;
private final boolean alwaysRenderAny;
private final boolean prettyFunctionTypes;
@NotNull
private final OverrideRenderingPolicy overrideRenderingPolicy;
@NotNull
@@ -78,6 +80,8 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
boolean unitReturnType,
boolean normalizedVisibilities,
boolean showInternalKeyword,
boolean alwaysRenderAny,
boolean prettyFunctionTypes,
@NotNull OverrideRenderingPolicy overrideRenderingPolicy,
@NotNull ValueParametersHandler handler,
@NotNull TextFormat textFormat,
@@ -97,6 +101,8 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
this.debugMode = debugMode;
this.textFormat = textFormat;
this.excludedAnnotationClasses = Sets.newHashSet(excludedAnnotationClasses);
this.alwaysRenderAny = alwaysRenderAny;
this.prettyFunctionTypes = prettyFunctionTypes;
}
@@ -218,7 +224,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
if (ErrorUtils.isErrorType(type)) {
return type.toString();
}
if (KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(type)) {
if (KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(type) && prettyFunctionTypes) {
return renderFunctionType(type);
}
return renderDefaultType(type);
@@ -411,7 +417,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
int upperBoundsCount = typeParameter.getUpperBounds().size();
if ((upperBoundsCount > 1 && !topLevel) || upperBoundsCount == 1) {
JetType upperBound = typeParameter.getUpperBounds().iterator().next();
if (!KotlinBuiltIns.getInstance().getDefaultBound().equals(upperBound)) {
if (!KotlinBuiltIns.getInstance().getDefaultBound().equals(upperBound) || alwaysRenderAny) {
builder.append(" : ").append(renderType(upperBound));
}
}
@@ -640,7 +646,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
if (!klass.equals(KotlinBuiltIns.getInstance().getNothing())) {
Collection<JetType> supertypes = klass.getTypeConstructor().getSupertypes();
if (supertypes.isEmpty() || supertypes.size() == 1 && KotlinBuiltIns.getInstance().isAny(supertypes.iterator().next())) {
if (supertypes.isEmpty() || !alwaysRenderAny && supertypes.size() == 1 && KotlinBuiltIns.getInstance().isAny(supertypes.iterator().next())) {
}
else {
builder.append(" : ");