Extract TargetedAnnotations out of AnnotationsImpl
Minimize AnnotationsImpl to leave it usable in simple scenarios where there's no use-site targeted annotations, and use TargetedAnnotations in the only place in the frontend (AnnotationResolverImpl) where use-sites were needed. Also, delete kdoc on Annotations.isEmpty to prevent readers from putting too much thought into how it works. With the exception of a few places in the frontend where use-site targeted annotations are still accessed via the Annotations object, it's now an implementation detail and users (such as backends, IDE) should not care about them at all, and instead should just deal with the correct element when processing annotations
This commit is contained in:
+3
-5
@@ -108,11 +108,9 @@ class AnnotationSplitter(
|
||||
other.add(annotation)
|
||||
}
|
||||
|
||||
for ((annotation, useSiteTarget) in allAnnotations.getUseSiteTargetedAnnotations()) {
|
||||
if (useSiteTarget == null) continue
|
||||
|
||||
if (useSiteTarget in applicableTargets) {
|
||||
map.getOrPut(useSiteTarget) { arrayListOf() }.add(annotation)
|
||||
for ((annotation, target) in allAnnotations.getUseSiteTargetedAnnotations()) {
|
||||
if (target in applicableTargets) {
|
||||
map.getOrPut(target) { arrayListOf() }.add(annotation)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.descriptors.annotations
|
||||
|
||||
class TargetedAnnotations(
|
||||
private val standardAnnotations: List<AnnotationDescriptor>,
|
||||
private val targetedAnnotations: List<AnnotationWithTarget>
|
||||
) : Annotations {
|
||||
override fun isEmpty(): Boolean = standardAnnotations.isEmpty() && targetedAnnotations.isEmpty()
|
||||
|
||||
override fun getUseSiteTargetedAnnotations(): List<AnnotationWithTarget> = targetedAnnotations
|
||||
|
||||
override fun iterator(): Iterator<AnnotationDescriptor> = standardAnnotations.iterator()
|
||||
|
||||
override fun toString(): String = (standardAnnotations + targetedAnnotations).toString()
|
||||
}
|
||||
@@ -17,10 +17,14 @@
|
||||
package org.jetbrains.kotlin.resolve;
|
||||
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.TargetedAnnotations;
|
||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.calls.CallResolver;
|
||||
@@ -79,7 +83,9 @@ public class AnnotationResolverImpl extends AnnotationResolver {
|
||||
boolean shouldResolveArguments
|
||||
) {
|
||||
if (annotationEntryElements.isEmpty()) return Annotations.Companion.getEMPTY();
|
||||
List<AnnotationWithTarget> result = new ArrayList<>(0);
|
||||
|
||||
List<AnnotationDescriptor> standard = new ArrayList<>();
|
||||
List<AnnotationWithTarget> targeted = new ArrayList<>();
|
||||
|
||||
for (KtAnnotationEntry entryElement : annotationEntryElements) {
|
||||
AnnotationDescriptor descriptor = trace.get(BindingContext.ANNOTATION, entryElement);
|
||||
@@ -92,13 +98,13 @@ public class AnnotationResolverImpl extends AnnotationResolver {
|
||||
|
||||
KtAnnotationUseSiteTarget target = entryElement.getUseSiteTarget();
|
||||
if (target != null) {
|
||||
result.add(new AnnotationWithTarget(descriptor, target.getAnnotationUseSiteTarget()));
|
||||
targeted.add(new AnnotationWithTarget(descriptor, target.getAnnotationUseSiteTarget()));
|
||||
}
|
||||
else {
|
||||
result.add(new AnnotationWithTarget(descriptor, null));
|
||||
standard.add(descriptor);
|
||||
}
|
||||
}
|
||||
return AnnotationsImpl.create(result);
|
||||
return new TargetedAnnotations(CollectionsKt.toList(standard), CollectionsKt.toList(targeted));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user