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;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user