Support secondary constructors in decompiled text

Build cls stubs for secondary constructors
This commit is contained in:
Pavel V. Talanov
2015-03-12 13:06:38 +03:00
parent 026e35b6d0
commit c0a031eafe
15 changed files with 351 additions and 28 deletions
@@ -53,6 +53,7 @@ public class DescriptorRendererBuilder {
};
private boolean renderDefaultValues = true;
private boolean flexibleTypesForCode = false;
private boolean secondaryConstructorsAsPrimary = true;
@NotNull
private DescriptorRenderer.OverrideRenderingPolicy overrideRenderingPolicy = DescriptorRenderer.OverrideRenderingPolicy.RENDER_OPEN;
@@ -211,6 +212,7 @@ public class DescriptorRendererBuilder {
return this;
}
@NotNull
public DescriptorRendererBuilder setRenderDefaultValues(boolean renderDefaultValues) {
this.renderDefaultValues = renderDefaultValues;
return this;
@@ -222,11 +224,18 @@ public class DescriptorRendererBuilder {
return this;
}
@NotNull
public DescriptorRendererBuilder setFlexibleTypesForCode(boolean flexibleTypesForCode) {
this.flexibleTypesForCode = flexibleTypesForCode;
return this;
}
@NotNull
public DescriptorRendererBuilder setSecondaryConstructorsAsPrimary(boolean secondaryConstructorsAsPrimary) {
this.secondaryConstructorsAsPrimary = secondaryConstructorsAsPrimary;
return this;
}
@NotNull
public DescriptorRenderer build() {
return new DescriptorRendererImpl(
@@ -234,7 +243,8 @@ public class DescriptorRendererBuilder {
normalizedVisibilities, showInternalKeyword, prettyFunctionTypes, uninferredTypeParameterAsName,
overrideRenderingPolicy, valueParametersHandler, textFormat, excludedAnnotationClasses, includePropertyConstant,
includeSynthesizedParameterNames, withoutFunctionParameterNames, withoutTypeParameters, receiverAfterName,
renderDefaultObjectName, withoutSuperTypes, typeNormalizer, renderDefaultValues, flexibleTypesForCode);
renderDefaultObjectName, withoutSuperTypes, typeNormalizer, renderDefaultValues, flexibleTypesForCode,
secondaryConstructorsAsPrimary);
}
}
@@ -76,6 +76,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
@NotNull
private final TextFormat textFormat;
private final boolean includePropertyConstant;
private final boolean secondaryConstructorsAsPrimary;
@NotNull
private final Set<FqName> excludedAnnotationClasses;
@@ -105,7 +106,8 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
boolean withoutSuperTypes,
@NotNull Function1<JetType, JetType> typeNormalizer,
boolean renderDefaultValues,
boolean flexibleTypesForCode
boolean flexibleTypesForCode,
boolean secondaryConstructorsAsPrimary
) {
this.nameShortness = nameShortness;
this.withDefinedIn = withDefinedIn;
@@ -121,6 +123,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
this.debugMode = debugMode;
this.textFormat = textFormat;
this.includePropertyConstant = includePropertyConstant;
this.secondaryConstructorsAsPrimary = secondaryConstructorsAsPrimary;
this.excludedAnnotationClasses = new HashSet<FqName>(excludedAnnotationClasses);
this.prettyFunctionTypes = prettyFunctionTypes;
this.uninferredTypeParameterAsName = uninferredTypeParameterAsName;
@@ -802,14 +805,19 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
renderVisibility(constructor.getVisibility(), builder);
renderMemberKind(constructor, builder);
builder.append(renderKeyword("constructor")).append(" ");
builder.append(renderKeyword("constructor"));
if (secondaryConstructorsAsPrimary) {
ClassDescriptor classDescriptor = constructor.getContainingDeclaration();
builder.append(" ");
renderName(classDescriptor, builder);
renderTypeParameters(classDescriptor.getTypeConstructor().getParameters(), builder, false);
}
ClassDescriptor classDescriptor = constructor.getContainingDeclaration();
renderName(classDescriptor, builder);
renderTypeParameters(classDescriptor.getTypeConstructor().getParameters(), builder, false);
renderValueParameters(constructor, builder);
renderWhereSuffix(constructor.getTypeParameters(), builder);
if (secondaryConstructorsAsPrimary) {
renderWhereSuffix(constructor.getTypeParameters(), builder);
}
}
private void renderWhereSuffix(@NotNull List<TypeParameterDescriptor> typeParameters, @NotNull StringBuilder builder) {