Get rid of recordToTrace

recordToTrace is a bad practice as instance could be initialized out of
our control (e.g. in other plugins)

#KTIJ-22182
This commit is contained in:
Vladimir Dolzhenko
2023-01-31 11:32:07 +01:00
committed by Space Team
parent 79b8954814
commit d3fcd965ba
2 changed files with 5 additions and 6 deletions
@@ -96,7 +96,6 @@ public class AnnotationResolverImpl extends AnnotationResolver {
if (descriptor == null) {
LazyAnnotationDescriptor lazyAnnotationDescriptor =
new LazyAnnotationDescriptor(new LazyAnnotationsContextImpl(this, storageManager, trace, scope), entryElement);
lazyAnnotationDescriptor.recordToTrace();
descriptor = lazyAnnotationDescriptor;
}
if (shouldResolveArguments) {
@@ -60,7 +60,7 @@ class LazyAnnotations(
override fun isEmpty() = annotationEntries.isEmpty()
private val annotation = c.storageManager.createMemoizedFunction { entry: KtAnnotationEntry ->
c.trace.get(BindingContext.ANNOTATION, entry) ?: LazyAnnotationDescriptor(c, entry).also { it.recordToTrace() }
c.trace.get(BindingContext.ANNOTATION, entry) ?: LazyAnnotationDescriptor(c, entry)
}
override fun iterator(): Iterator<AnnotationDescriptor> = annotationEntries.asSequence().map(annotation).iterator()
@@ -121,6 +121,10 @@ class LazyAnnotationDescriptor(
valueArgumentsWithSourceInfo.mapValues { it.value.first }
}
init {
c.trace.record(BindingContext.ANNOTATION, annotationEntry, this)
}
fun getSourceForArgument(name: Name): SourceElement =
valueArgumentsWithSourceInfo[name]?.second ?: SourceElement.NO_SOURCE
@@ -129,10 +133,6 @@ class LazyAnnotationDescriptor(
allValueArguments
}
fun recordToTrace() {
c.trace.record(BindingContext.ANNOTATION, annotationEntry, this)
}
private class FileDescriptorForVisibilityChecks(
private val source: SourceElement,
private val containingDeclaration: PackageFragmentDescriptor