Drop Annotations.getAllAnnotations
This commit is contained in:
@@ -245,7 +245,7 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
|
||||
private void genTypeAliasAnnotationsMethodIfRequired(TypeAliasDescriptor typeAliasDescriptor) {
|
||||
boolean isAnnotationsMethodOwner = CodegenContextUtil.isImplClassOwner(context);
|
||||
Annotations annotations = typeAliasDescriptor.getAnnotations();
|
||||
if (!isAnnotationsMethodOwner || annotations.getAllAnnotations().isEmpty()) return;
|
||||
if (!isAnnotationsMethodOwner || annotations.isEmpty()) return;
|
||||
|
||||
String name = JvmAbi.getSyntheticMethodNameForAnnotatedTypeAlias(typeAliasDescriptor.getName());
|
||||
generateSyntheticAnnotationsMethod(typeAliasDescriptor, new Method(name, "()V"), annotations);
|
||||
|
||||
@@ -335,7 +335,7 @@ public class PropertyCodegen {
|
||||
// accessible via reflection, and 'deprecated' and 'synthetic' flags prevent this method from being called accidentally
|
||||
private void generateSyntheticMethodIfNeeded(@NotNull PropertyDescriptor descriptor, boolean isBackingFieldOwner) {
|
||||
Annotations annotations = descriptor.getAnnotations();
|
||||
if (annotations.getAllAnnotations().isEmpty()) return;
|
||||
if (annotations.isEmpty()) return;
|
||||
|
||||
Method signature = getSyntheticMethodSignature(descriptor);
|
||||
if (kind != OwnerKind.DEFAULT_IMPLS && CodegenContextUtil.isImplClassOwner(context)) {
|
||||
|
||||
+12
-10
@@ -92,14 +92,7 @@ class AnnotationSplitter(
|
||||
val applicableTargets = applicableTargetsLazy()
|
||||
val applicableTargetsWithoutUseSiteTarget = applicableTargets.intersect(TARGET_PRIORITIES)
|
||||
|
||||
outer@ for ((annotation, useSiteTarget) in allAnnotations.getAllAnnotations()) {
|
||||
if (useSiteTarget != null) {
|
||||
if (useSiteTarget in applicableTargets)
|
||||
map.getOrPut(useSiteTarget) { arrayListOf() }.add(annotation)
|
||||
|
||||
continue@outer
|
||||
}
|
||||
|
||||
outer@ for (annotation in allAnnotations) {
|
||||
for (target in TARGET_PRIORITIES) {
|
||||
if (target !in applicableTargetsWithoutUseSiteTarget) continue
|
||||
|
||||
@@ -115,6 +108,14 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
map to AnnotationsImpl(other)
|
||||
}
|
||||
|
||||
@@ -137,14 +138,15 @@ class AnnotationSplitter(
|
||||
}
|
||||
|
||||
override fun forceResolveAllContents() {
|
||||
getAllAnnotations()
|
||||
for (annotation in this) {
|
||||
// TODO: probably we should do ForceResolveUtil.forceResolveAllContents(annotation) here
|
||||
}
|
||||
}
|
||||
|
||||
override fun isEmpty() = annotations.isEmpty()
|
||||
override fun hasAnnotation(fqName: FqName) = annotations.hasAnnotation(fqName)
|
||||
override fun findAnnotation(fqName: FqName) = annotations.findAnnotation(fqName)
|
||||
override fun getUseSiteTargetedAnnotations() = annotations.getUseSiteTargetedAnnotations()
|
||||
override fun getAllAnnotations() = annotations.getAllAnnotations()
|
||||
override fun iterator() = annotations.iterator()
|
||||
override fun toString() = annotations.toString()
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
@@ -64,8 +64,8 @@ public class ForceResolveUtil {
|
||||
|
||||
public static void forceResolveAllContents(@NotNull Annotations annotations) {
|
||||
doForceResolveAllContents(annotations);
|
||||
for (AnnotationWithTarget annotationWithTarget : annotations.getAllAnnotations()) {
|
||||
doForceResolveAllContents(annotationWithTarget.getAnnotation());
|
||||
for (AnnotationDescriptor annotation : annotations) {
|
||||
doForceResolveAllContents(annotation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-4
@@ -56,7 +56,6 @@ class LazyAnnotations(
|
||||
override fun isEmpty() = annotationEntries.isEmpty()
|
||||
|
||||
private val annotation = c.storageManager.createMemoizedFunction { entry: KtAnnotationEntry ->
|
||||
|
||||
val descriptor = LazyAnnotationDescriptor(c, entry)
|
||||
val target = entry.useSiteTarget?.getAnnotationUseSiteTarget()
|
||||
AnnotationWithTarget(descriptor, target)
|
||||
@@ -70,8 +69,6 @@ class LazyAnnotations(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getAllAnnotations() = annotationEntries.map(annotation)
|
||||
|
||||
override fun iterator(): Iterator<AnnotationDescriptor> {
|
||||
return annotationEntries
|
||||
.asSequence()
|
||||
@@ -83,7 +80,9 @@ class LazyAnnotations(
|
||||
|
||||
override fun forceResolveAllContents() {
|
||||
// To resolve all entries
|
||||
getAllAnnotations()
|
||||
for (annotation in this) {
|
||||
// TODO: probably we should do ForceResolveUtil.forceResolveAllContents(annotation) here
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,10 +109,7 @@ class TypeTranslator(
|
||||
}
|
||||
|
||||
private fun translateTypeAnnotations(annotations: Annotations): List<IrCall> =
|
||||
annotations.getAllAnnotations().map {
|
||||
// TODO filter out annotation targets
|
||||
constantValueGenerator.generateAnnotationConstructorCall(it.annotation)
|
||||
}
|
||||
annotations.map(constantValueGenerator::generateAnnotationConstructorCall)
|
||||
|
||||
private fun translateTypeArguments(arguments: List<TypeProjection>) =
|
||||
arguments.map {
|
||||
@@ -121,4 +118,4 @@ class TypeTranslator(
|
||||
else
|
||||
translateType(it.type, it.projectionKind)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-6
@@ -32,7 +32,6 @@ import org.jetbrains.kotlin.resolve.constants.EnumValue
|
||||
import org.jetbrains.kotlin.resolve.constants.IntValue
|
||||
import org.jetbrains.kotlin.resolve.constants.NullValue
|
||||
import org.jetbrains.kotlin.resolve.constants.StringValue
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isSourceAnnotation
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.nonSourceAnnotations
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ProtoEnumFlags
|
||||
import org.jetbrains.kotlin.types.*
|
||||
@@ -752,11 +751,8 @@ class DescriptorSerializer private constructor(
|
||||
Variance.OUT_VARIANCE -> ProtoBuf.Type.Argument.Projection.OUT
|
||||
}
|
||||
|
||||
private fun hasAnnotations(descriptor: Annotated): Boolean {
|
||||
// Sadly, we can't just return `descriptor.nonSourceAnnotations.isNotEmpty()` because that would not
|
||||
// consider use-site-targeted annotations
|
||||
return descriptor.annotations.getAllAnnotations().filterNot { it.annotation.isSourceAnnotation }.isNotEmpty()
|
||||
}
|
||||
private fun hasAnnotations(descriptor: Annotated): Boolean =
|
||||
descriptor.nonSourceAnnotations.isNotEmpty()
|
||||
|
||||
fun <T : DeclarationDescriptor> sort(descriptors: Collection<T>): List<T> =
|
||||
ArrayList(descriptors).apply {
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
package
|
||||
|
||||
public final class A {
|
||||
public constructor A(/*0*/ @Ann @Ann x: kotlin.Int, /*1*/ @RepeatableAnn @Ann y: kotlin.Int)
|
||||
@Ann @RepeatableAnn @RepeatableAnn @field:Ann public final val a: kotlin.Int = 0
|
||||
public constructor A(/*0*/ @Ann @Ann x: kotlin.Int, /*1*/ @Ann @RepeatableAnn y: kotlin.Int)
|
||||
@RepeatableAnn @Ann @RepeatableAnn @field:Ann public final val a: kotlin.Int = 0
|
||||
@Ann @Ann @field:Ann public final val b: kotlin.Int = 0
|
||||
@field:RepeatableAnn @field:RepeatableAnn public final val c: kotlin.Int = 0
|
||||
@RepeatableAnn @RepeatableAnn public final val d: kotlin.Int = 0
|
||||
|
||||
+5
-22
@@ -153,7 +153,7 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends KotlinTest
|
||||
}
|
||||
|
||||
private static void checkAnnotationsOnProperty(String expectedAnnotation, PropertyDescriptor prop) {
|
||||
checkDescriptorWithTarget(expectedAnnotation, prop, AnnotationUseSiteTarget.FIELD);
|
||||
checkDescriptor(expectedAnnotation, prop);
|
||||
checkDescriptor(expectedAnnotation, prop.getGetter());
|
||||
PropertySetterDescriptor propSetter = prop.getSetter();
|
||||
assertNotNull(propSetter);
|
||||
@@ -361,32 +361,15 @@ public abstract class AbstractAnnotationDescriptorResolveTest extends KotlinTest
|
||||
return KotlinTestUtils.doLoadFile(file).replaceAll("ANNOTATION", annotationText);
|
||||
}
|
||||
|
||||
private static String renderAnnotations(Annotations annotations, @Nullable AnnotationUseSiteTarget defaultTarget) {
|
||||
return StringUtil.join(annotations.getAllAnnotations(), annotationWithTarget -> {
|
||||
AnnotationUseSiteTarget targetToRender = annotationWithTarget.getTarget();
|
||||
if (targetToRender == defaultTarget) {
|
||||
targetToRender = null;
|
||||
}
|
||||
|
||||
return WITH_ANNOTATION_ARGUMENT_TYPES.renderAnnotation(annotationWithTarget.getAnnotation(), targetToRender);
|
||||
}, " ");
|
||||
public static String renderAnnotations(Annotations annotations) {
|
||||
return StringUtil.join(annotations, annotation -> WITH_ANNOTATION_ARGUMENT_TYPES.renderAnnotation(annotation, null), " ");
|
||||
}
|
||||
|
||||
protected static void checkDescriptor(String expectedAnnotation, DeclarationDescriptor member) {
|
||||
String actual = getAnnotations(member);
|
||||
private static void checkDescriptor(String expectedAnnotation, DeclarationDescriptor member) {
|
||||
String actual = renderAnnotations(member.getAnnotations());
|
||||
assertEquals("Failed to resolve annotation descriptor for " + member.toString(), expectedAnnotation, actual);
|
||||
}
|
||||
|
||||
private static void checkDescriptorWithTarget(String expectedAnnotation, DeclarationDescriptor member, AnnotationUseSiteTarget target) {
|
||||
String actual = renderAnnotations(member.getAnnotations(), target);
|
||||
assertEquals("Failed to resolve annotation descriptor for " + member.toString(), expectedAnnotation, actual);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static String getAnnotations(DeclarationDescriptor member) {
|
||||
return renderAnnotations(member.getAnnotations(), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
analysisResult = null;
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ abstract class AbstractAnnotationParameterTest : AbstractAnnotationDescriptorRes
|
||||
val classDescriptor = AbstractAnnotationDescriptorResolveTest.getClassDescriptor(packageView, "MyClass")
|
||||
|
||||
val expected = InTextDirectivesUtils.findListWithPrefixes(fileText, "// EXPECTED: ").joinToString(", ")
|
||||
val actual = AbstractAnnotationDescriptorResolveTest.getAnnotations(classDescriptor)
|
||||
val actual = AbstractAnnotationDescriptorResolveTest.renderAnnotations(classDescriptor.annotations)
|
||||
|
||||
KotlinTestUtils.assertEqualsToFile(File(path), fileText.replace(expected, actual))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user