Allow rendering Any in all positions and using Function0 etc instead of "() -> ..."
This commit is contained in:
committed by
Alexander Udalov
parent
5b8d41cc36
commit
af415d160f
@@ -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(" : ");
|
||||
|
||||
@@ -47,17 +47,23 @@ import java.util.List;
|
||||
import static org.jetbrains.jet.test.util.DescriptorValidator.ValidationVisitor.FORBID_ERROR_TYPES;
|
||||
|
||||
public class NamespaceComparator {
|
||||
public static final Configuration DONT_INCLUDE_METHODS_OF_OBJECT = new Configuration(false, false, false, Predicates.<FqNameUnsafe>alwaysTrue(),
|
||||
FORBID_ERROR_TYPES);
|
||||
public static final Configuration RECURSIVE = new Configuration(false, false, true, Predicates.<FqNameUnsafe>alwaysTrue(), FORBID_ERROR_TYPES);
|
||||
public static final Configuration RECURSIVE_ALL = new Configuration(true, true, true, Predicates.<FqNameUnsafe>alwaysTrue(), FORBID_ERROR_TYPES);
|
||||
|
||||
private static final DescriptorRenderer RENDERER = new DescriptorRendererBuilder()
|
||||
private static final DescriptorRenderer DEFAULT_RENDERER = new DescriptorRendererBuilder()
|
||||
.setWithDefinedIn(false)
|
||||
.setExcludedAnnotationClasses(Arrays.asList(new FqName(ExpectedLoadErrorsUtil.ANNOTATION_CLASS_NAME)))
|
||||
.setOverrideRenderingPolicy(DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE)
|
||||
.setVerbose(true).build();
|
||||
|
||||
public static final Configuration DONT_INCLUDE_METHODS_OF_OBJECT = new Configuration(false, false, false,
|
||||
Predicates.<FqNameUnsafe>alwaysTrue(),
|
||||
FORBID_ERROR_TYPES, DEFAULT_RENDERER);
|
||||
public static final Configuration RECURSIVE = new Configuration(false, false, true,
|
||||
Predicates.<FqNameUnsafe>alwaysTrue(),
|
||||
FORBID_ERROR_TYPES, DEFAULT_RENDERER);
|
||||
|
||||
public static final Configuration RECURSIVE_ALL = new Configuration(true, true, true,
|
||||
Predicates.<FqNameUnsafe>alwaysTrue(),
|
||||
FORBID_ERROR_TYPES, DEFAULT_RENDERER);
|
||||
|
||||
private static final ImmutableSet<String> JAVA_OBJECT_METHOD_NAMES = ImmutableSet.of(
|
||||
"equals", "hashCode", "finalize", "wait", "notify", "notifyAll", "toString", "clone", "getClass");
|
||||
|
||||
@@ -79,7 +85,7 @@ public class NamespaceComparator {
|
||||
}
|
||||
|
||||
boolean isPrimaryConstructor = descriptor instanceof ConstructorDescriptor && ((ConstructorDescriptor) descriptor).isPrimary();
|
||||
printer.print(isPrimaryConstructor && conf.checkPrimaryConstructors ? "/*primary*/ " : "", RENDERER.render(descriptor));
|
||||
printer.print(isPrimaryConstructor && conf.checkPrimaryConstructors ? "/*primary*/ " : "", conf.renderer.render(descriptor));
|
||||
|
||||
if (descriptor instanceof ClassOrNamespaceDescriptor) {
|
||||
if (!topLevel) {
|
||||
@@ -109,12 +115,12 @@ public class NamespaceComparator {
|
||||
PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
|
||||
PropertyGetterDescriptor getter = propertyDescriptor.getGetter();
|
||||
if (getter != null) {
|
||||
printer.println(RENDERER.render(getter));
|
||||
printer.println(conf.renderer.render(getter));
|
||||
}
|
||||
|
||||
PropertySetterDescriptor setter = propertyDescriptor.getSetter();
|
||||
if (setter != null) {
|
||||
printer.println(RENDERER.render(setter));
|
||||
printer.println(conf.renderer.render(setter));
|
||||
}
|
||||
|
||||
printer.popIndent();
|
||||
@@ -241,6 +247,7 @@ public class NamespaceComparator {
|
||||
private final boolean checkPropertyAccessors;
|
||||
private final boolean includeMethodsOfJavaObject;
|
||||
private final Predicate<FqNameUnsafe> recurseIntoPackage;
|
||||
private final DescriptorRenderer renderer;
|
||||
|
||||
private final DescriptorValidator.ValidationVisitor validationStrategy;
|
||||
|
||||
@@ -249,33 +256,40 @@ public class NamespaceComparator {
|
||||
boolean checkPropertyAccessors,
|
||||
boolean includeMethodsOfJavaObject,
|
||||
Predicate<FqNameUnsafe> recurseIntoPackage,
|
||||
DescriptorValidator.ValidationVisitor validationStrategy
|
||||
DescriptorValidator.ValidationVisitor validationStrategy,
|
||||
DescriptorRenderer renderer
|
||||
) {
|
||||
this.checkPrimaryConstructors = checkPrimaryConstructors;
|
||||
this.checkPropertyAccessors = checkPropertyAccessors;
|
||||
this.includeMethodsOfJavaObject = includeMethodsOfJavaObject;
|
||||
this.recurseIntoPackage = recurseIntoPackage;
|
||||
this.validationStrategy = validationStrategy;
|
||||
this.renderer = renderer;
|
||||
}
|
||||
|
||||
public Configuration filterRecursion(@NotNull Predicate<FqNameUnsafe> recurseIntoPackage) {
|
||||
return new Configuration(checkPrimaryConstructors, checkPropertyAccessors, includeMethodsOfJavaObject, recurseIntoPackage,
|
||||
validationStrategy);
|
||||
validationStrategy, renderer);
|
||||
}
|
||||
|
||||
public Configuration checkPrimaryConstructors(boolean checkPrimaryConstructors) {
|
||||
return new Configuration(checkPrimaryConstructors, checkPropertyAccessors, includeMethodsOfJavaObject, recurseIntoPackage,
|
||||
validationStrategy);
|
||||
validationStrategy, renderer);
|
||||
}
|
||||
|
||||
public Configuration checkPropertyAccessors(boolean checkPropertyAccessors) {
|
||||
return new Configuration(checkPrimaryConstructors, checkPropertyAccessors, includeMethodsOfJavaObject, recurseIntoPackage,
|
||||
validationStrategy);
|
||||
validationStrategy, renderer);
|
||||
}
|
||||
|
||||
public Configuration withValidationStrategy(@NotNull DescriptorValidator.ValidationVisitor validationStrategy) {
|
||||
return new Configuration(checkPrimaryConstructors, checkPropertyAccessors, includeMethodsOfJavaObject, recurseIntoPackage,
|
||||
validationStrategy);
|
||||
validationStrategy, renderer);
|
||||
}
|
||||
|
||||
public Configuration withRenderer(@NotNull DescriptorRenderer renderer) {
|
||||
return new Configuration(checkPrimaryConstructors, checkPropertyAccessors, includeMethodsOfJavaObject, recurseIntoPackage,
|
||||
validationStrategy, renderer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user