From 95dddadb3641723b40e2a784299cf0db79f5fd48 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 28 Aug 2012 18:31:09 +0400 Subject: [PATCH] Present "data" annotation to standard library --- compiler/frontend/src/jet/Library.jet | 1 + .../lang/types/lang/JetStandardLibrary.java | 26 +++++++++++++++++-- compiler/testData/builtin-classes.txt | 3 +++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/compiler/frontend/src/jet/Library.jet b/compiler/frontend/src/jet/Library.jet index 49acab798c7..b132b00d588 100644 --- a/compiler/frontend/src/jet/Library.jet +++ b/compiler/frontend/src/jet/Library.jet @@ -4,6 +4,7 @@ public trait Annotation public annotation class volatile : Annotation public annotation class atomic : Annotation +public annotation class data : Annotation public fun synchronized(lock: Any, block : () -> R) : R diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardLibrary.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardLibrary.java index 30ffa7cb81a..b9c8babd32f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardLibrary.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/lang/JetStandardLibrary.java @@ -99,6 +99,7 @@ public class JetStandardLibrary { private ClassDescriptor enumClass; private ClassDescriptor annotationClass; private ClassDescriptor volatileClass; + private ClassDescriptor dataClass; private JetType stringType; private JetType annotationType; @@ -170,7 +171,9 @@ public class JetStandardLibrary { this.arrayClass = getStdClassByName("Array"); this.throwableClass = getStdClassByName("Throwable"); this.enumClass = getStdClassByName("Enum"); + this.volatileClass = getStdClassByName("volatile"); + this.dataClass = getStdClassByName("data"); this.iterableClass = getStdClassByName("Iterable"); this.iteratorClass = getStdClassByName("Iterator"); @@ -498,6 +501,11 @@ public class JetStandardLibrary { return getEnumType(Variance.INVARIANT, argument); } + @NotNull + public ClassDescriptor getDataClassAnnotation() { + return dataClass; + } + @NotNull public JetType getArrayType(@NotNull Variance projectionType, @NotNull JetType argument) { List types = Collections.singletonList(new TypeProjection(projectionType, argument)); @@ -559,10 +567,24 @@ public class JetStandardLibrary { } public boolean isVolatile(@NotNull PropertyDescriptor descriptor) { + return containsAnnotation(descriptor, volatileClass); + } + + public static boolean isData(@NotNull ClassDescriptor descriptor) { + if (initializing) { + // This is a hack to make this method callable while resolving standard library + // (otherwise getInstance() would throw an Exception) + // This also means that "data" annotation has no effect in standard library + return false; + } + return containsAnnotation(descriptor, getInstance().dataClass); + } + + private static boolean containsAnnotation(DeclarationDescriptor descriptor, ClassDescriptor annotationClass) { List annotations = descriptor.getOriginal().getAnnotations(); if (annotations != null) { - for(AnnotationDescriptor annotation: annotations) { - if (volatileClass.equals(annotation.getType().getConstructor().getDeclarationDescriptor())) { + for (AnnotationDescriptor annotation : annotations) { + if (annotationClass.equals(annotation.getType().getConstructor().getDeclarationDescriptor())) { return true; } } diff --git a/compiler/testData/builtin-classes.txt b/compiler/testData/builtin-classes.txt index fdbee57a4d5..de94d925422 100644 --- a/compiler/testData/builtin-classes.txt +++ b/compiler/testData/builtin-classes.txt @@ -1447,6 +1447,9 @@ public final class jet.Tuple9(): jet.atomic } +public final annotation class jet.data : jet.Annotation { + public final /*constructor*/ fun (): jet.data +} public final annotation class jet.volatile : jet.Annotation { public final /*constructor*/ fun (): jet.volatile }