Refactor DescriptorRenderer's renderAccessors option
In some tests with txt (probably all except loadJava), property accessors are not rendered at all, so a third option value (NONE) will be useful to determine whether we need to render annotations on property accessors as get/set/sparam-targeted annotations on the property
This commit is contained in:
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.psi.KtClass
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.renderer.PropertyAccessorRenderingPolicy
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.MemberComparator
|
||||
import org.jetbrains.kotlin.resolve.MultiTargetPlatform
|
||||
@@ -50,7 +51,6 @@ import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringWriter
|
||||
import java.lang.AssertionError
|
||||
|
||||
object Renderers {
|
||||
|
||||
@@ -677,7 +677,7 @@ object Renderers {
|
||||
val DEPRECATION_RENDERER = DescriptorRenderer.ONLY_NAMES_WITH_SHORT_TYPES.withOptions {
|
||||
withoutTypeParameters = false
|
||||
receiverAfterName = false
|
||||
renderAccessors = true
|
||||
propertyAccessorRenderingPolicy = PropertyAccessorRenderingPolicy.PRETTY
|
||||
}.asRenderer()
|
||||
}
|
||||
|
||||
|
||||
+28
-3
@@ -43,6 +43,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static org.jetbrains.kotlin.resolve.DescriptorUtils.isEnumEntry;
|
||||
@@ -366,7 +367,7 @@ public class RecursiveDescriptorComparator {
|
||||
this.checkFunctionContracts = checkFunctionContracts;
|
||||
this.recursiveFilter = recursiveFilter;
|
||||
this.validationStrategy = validationStrategy;
|
||||
this.renderer = renderer;
|
||||
this.renderer = rendererWithPropertyAccessors(renderer, checkPropertyAccessors);
|
||||
}
|
||||
|
||||
public Configuration filterRecursion(@NotNull Predicate<DeclarationDescriptor> stepIntoFilter) {
|
||||
@@ -381,8 +382,11 @@ public class RecursiveDescriptorComparator {
|
||||
}
|
||||
|
||||
public Configuration checkPropertyAccessors(boolean checkPropertyAccessors) {
|
||||
return new Configuration(checkPrimaryConstructors, checkPropertyAccessors, includeMethodsOfKotlinAny,
|
||||
renderDeclarationsFromOtherModules, checkFunctionContracts, recursiveFilter, validationStrategy, renderer);
|
||||
return new Configuration(
|
||||
checkPrimaryConstructors, checkPropertyAccessors, includeMethodsOfKotlinAny, renderDeclarationsFromOtherModules,
|
||||
checkFunctionContracts, recursiveFilter, validationStrategy,
|
||||
rendererWithPropertyAccessors(renderer, checkPropertyAccessors)
|
||||
);
|
||||
}
|
||||
|
||||
public Configuration checkFunctionContracts(boolean checkFunctionContracts) {
|
||||
@@ -409,5 +413,26 @@ public class RecursiveDescriptorComparator {
|
||||
return new Configuration(checkPrimaryConstructors, checkPropertyAccessors, includeMethodsOfKotlinAny,
|
||||
renderDeclarationsFromOtherModules, checkFunctionContracts, recursiveFilter, validationStrategy, renderer);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static DescriptorRenderer rendererWithPropertyAccessors(
|
||||
@NotNull DescriptorRenderer renderer, boolean checkPropertyAccessors
|
||||
) {
|
||||
return newRenderer(renderer, options ->
|
||||
options.setPropertyAccessorRenderingPolicy(
|
||||
checkPropertyAccessors ? PropertyAccessorRenderingPolicy.DEBUG : PropertyAccessorRenderingPolicy.NONE
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static DescriptorRenderer newRenderer(
|
||||
@NotNull DescriptorRenderer renderer, @NotNull Consumer<DescriptorRendererOptions> configure
|
||||
) {
|
||||
return renderer.withOptions(options -> {
|
||||
configure.accept(options);
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ interface DescriptorRendererOptions {
|
||||
var typeNormalizer: (KotlinType) -> KotlinType
|
||||
var defaultParameterValueRenderer: ((ValueParameterDescriptor) -> String)?
|
||||
var secondaryConstructorsAsPrimary: Boolean
|
||||
var renderAccessors: Boolean
|
||||
var propertyAccessorRenderingPolicy: PropertyAccessorRenderingPolicy
|
||||
var renderDefaultAnnotationArguments: Boolean
|
||||
var alwaysRenderModifiers: Boolean
|
||||
var renderConstructorKeyword: Boolean
|
||||
@@ -251,6 +251,12 @@ enum class ParameterNameRenderingPolicy {
|
||||
NONE
|
||||
}
|
||||
|
||||
enum class PropertyAccessorRenderingPolicy {
|
||||
PRETTY,
|
||||
DEBUG,
|
||||
NONE
|
||||
}
|
||||
|
||||
enum class DescriptorRendererModifier(val includeByDefault: Boolean) {
|
||||
VISIBILITY(true),
|
||||
MODALITY(true),
|
||||
|
||||
@@ -985,25 +985,25 @@ internal class DescriptorRendererImpl(
|
||||
}
|
||||
|
||||
override fun visitPropertyGetterDescriptor(descriptor: PropertyGetterDescriptor, builder: StringBuilder) {
|
||||
if (renderAccessors) {
|
||||
renderAccessorModifiers(descriptor, builder)
|
||||
builder.append("getter for ")
|
||||
renderProperty(descriptor.correspondingProperty, builder)
|
||||
}
|
||||
else {
|
||||
visitFunctionDescriptor(descriptor, builder)
|
||||
}
|
||||
|
||||
visitPropertyAccessorDescriptor(descriptor, builder, "getter")
|
||||
}
|
||||
|
||||
override fun visitPropertySetterDescriptor(descriptor: PropertySetterDescriptor, builder: StringBuilder) {
|
||||
if (renderAccessors) {
|
||||
renderAccessorModifiers(descriptor, builder)
|
||||
builder.append("setter for ")
|
||||
renderProperty(descriptor.correspondingProperty, builder)
|
||||
}
|
||||
else {
|
||||
visitFunctionDescriptor(descriptor, builder)
|
||||
visitPropertyAccessorDescriptor(descriptor, builder, "setter")
|
||||
}
|
||||
|
||||
private fun visitPropertyAccessorDescriptor(descriptor: PropertyAccessorDescriptor, builder: StringBuilder, kind: String) {
|
||||
when (propertyAccessorRenderingPolicy) {
|
||||
PropertyAccessorRenderingPolicy.PRETTY -> {
|
||||
renderAccessorModifiers(descriptor, builder)
|
||||
builder.append("$kind for ")
|
||||
renderProperty(descriptor.correspondingProperty, builder)
|
||||
}
|
||||
PropertyAccessorRenderingPolicy.DEBUG -> {
|
||||
visitFunctionDescriptor(descriptor, builder)
|
||||
}
|
||||
PropertyAccessorRenderingPolicy.NONE -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ internal class DescriptorRendererOptionsImpl : DescriptorRendererOptions {
|
||||
override var parameterNameRenderingPolicy by property(ParameterNameRenderingPolicy.ALL)
|
||||
override var receiverAfterName by property(false)
|
||||
override var renderCompanionObjectName by property(false)
|
||||
override var renderAccessors by property(false)
|
||||
override var propertyAccessorRenderingPolicy by property(PropertyAccessorRenderingPolicy.DEBUG)
|
||||
override var renderDefaultAnnotationArguments by property(false)
|
||||
|
||||
override var eachAnnotationOnNewLine: Boolean by property(false)
|
||||
|
||||
+3
-2
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy
|
||||
import org.jetbrains.kotlin.renderer.PropertyAccessorRenderingPolicy
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||
import javax.swing.Icon
|
||||
|
||||
@@ -45,7 +46,7 @@ class KotlinMethodSmartStepTarget(
|
||||
private val renderer = IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_NO_ANNOTATIONS.withOptions {
|
||||
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.NONE
|
||||
withoutReturnType = true
|
||||
renderAccessors = true
|
||||
propertyAccessorRenderingPolicy = PropertyAccessorRenderingPolicy.PRETTY
|
||||
startFromName = true
|
||||
modifiers = emptySet()
|
||||
}
|
||||
@@ -75,4 +76,4 @@ class KotlinMethodSmartStepTarget(
|
||||
}
|
||||
return declaration!!.hashCode()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user