Render property constant
This commit is contained in:
@@ -47,6 +47,7 @@ public class RecursiveDescriptorComparator {
|
||||
.setWithDefinedIn(false)
|
||||
.setExcludedAnnotationClasses(Arrays.asList(new FqName(ExpectedLoadErrorsUtil.ANNOTATION_CLASS_NAME)))
|
||||
.setOverrideRenderingPolicy(DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN_OVERRIDE)
|
||||
.setIncludePropertyConstant(true)
|
||||
.setVerbose(true).build();
|
||||
|
||||
public static final Configuration DONT_INCLUDE_METHODS_OF_OBJECT = new Configuration(false, false, false,
|
||||
|
||||
@@ -36,6 +36,7 @@ public class DescriptorRendererBuilder {
|
||||
private boolean normalizedVisibilities = false;
|
||||
private boolean showInternalKeyword = true;
|
||||
private boolean prettyFunctionTypes = true;
|
||||
private boolean includePropertyConstant = false;
|
||||
@NotNull
|
||||
private DescriptorRenderer.OverrideRenderingPolicy overrideRenderingPolicy = DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN;
|
||||
@NotNull
|
||||
@@ -143,11 +144,17 @@ public class DescriptorRendererBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public DescriptorRendererBuilder setIncludePropertyConstant(boolean includePropertyConstant) {
|
||||
this.includePropertyConstant = includePropertyConstant;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DescriptorRenderer build() {
|
||||
return new DescriptorRendererImpl(shortNames, withDefinedIn, modifiers, startFromName, debugMode, classWithPrimaryConstructor,
|
||||
verbose, unitReturnType, normalizedVisibilities, showInternalKeyword, prettyFunctionTypes,
|
||||
overrideRenderingPolicy, valueParametersHandler, textFormat, excludedAnnotationClasses);
|
||||
overrideRenderingPolicy, valueParametersHandler, textFormat, excludedAnnotationClasses,
|
||||
includePropertyConstant);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
private final ValueParametersHandler handler;
|
||||
@NotNull
|
||||
private final TextFormat textFormat;
|
||||
private final boolean includePropertyConstant;
|
||||
@NotNull
|
||||
private final Set<FqName> excludedAnnotationClasses;
|
||||
|
||||
@@ -80,7 +81,8 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
@NotNull OverrideRenderingPolicy overrideRenderingPolicy,
|
||||
@NotNull ValueParametersHandler handler,
|
||||
@NotNull TextFormat textFormat,
|
||||
@NotNull Collection<FqName> excludedAnnotationClasses
|
||||
@NotNull Collection<FqName> excludedAnnotationClasses,
|
||||
boolean includePropertyConstant
|
||||
) {
|
||||
this.shortNames = shortNames;
|
||||
this.withDefinedIn = withDefinedIn;
|
||||
@@ -95,6 +97,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
this.overrideRenderingPolicy = overrideRenderingPolicy;
|
||||
this.debugMode = debugMode;
|
||||
this.textFormat = textFormat;
|
||||
this.includePropertyConstant = includePropertyConstant;
|
||||
this.excludedAnnotationClasses = Sets.newHashSet(excludedAnnotationClasses);
|
||||
this.prettyFunctionTypes = prettyFunctionTypes;
|
||||
}
|
||||
@@ -663,6 +666,8 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
renderName(variable, builder);
|
||||
builder.append(": ").append(escape(renderType(typeToRender)));
|
||||
|
||||
renderInitializer(variable, builder);
|
||||
|
||||
if (verbose && varargElementType != null) {
|
||||
builder.append(" /*").append(escape(renderType(realType))).append("*/");
|
||||
}
|
||||
@@ -688,9 +693,19 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
|
||||
renderName(property, builder);
|
||||
builder.append(": ").append(escape(renderType(property.getType())));
|
||||
|
||||
renderInitializer(property, builder);
|
||||
|
||||
renderWhereSuffix(property.getTypeParameters(), builder);
|
||||
}
|
||||
|
||||
private void renderInitializer(@NotNull VariableDescriptor variable, @NotNull StringBuilder builder) {
|
||||
if (includePropertyConstant) {
|
||||
CompileTimeConstant<?> initializer = variable.getCompileTimeInitializer();
|
||||
if (initializer != null) {
|
||||
builder.append(" = ").append(escape(renderConstant(initializer)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* CLASSES */
|
||||
private void renderClass(@NotNull ClassDescriptor klass, @NotNull StringBuilder builder) {
|
||||
|
||||
Reference in New Issue
Block a user