Remove @annotation from stdlib and compiler

This commit is contained in:
Alexey Tsvetkov
2015-10-14 18:13:21 +03:00
parent 28ca2e8b84
commit f2c69e56d2
10 changed files with 9 additions and 52 deletions
@@ -20,7 +20,6 @@ import com.google.protobuf.MessageLite;
import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
@@ -62,14 +61,6 @@ public class JvmSerializerExtension extends SerializerExtension {
return useTypeTable;
}
@Override
public void serializeClass(@NotNull ClassDescriptor descriptor, @NotNull ProtoBuf.Class.Builder proto) {
AnnotationDescriptor annotation = descriptor.getAnnotations().findAnnotation(KotlinBuiltIns.FQ_NAMES.annotation);
if (annotation != null) {
proto.addExtension(JvmProtoBuf.classAnnotation, annotationSerializer.serializeAnnotation(annotation));
}
}
@Override
public void serializeValueParameter(@NotNull ValueParameterDescriptor descriptor, @NotNull ProtoBuf.ValueParameter.Builder proto) {
Integer index = bindings.get(INDEX_FOR_VALUE_PARAMETER, descriptor);
@@ -218,7 +218,7 @@ public interface JetTokens {
// Please synchronize this array with org.jetbrains.kotlin.descriptors.annotations.ANNOTATION_MODIFIERS_FQ_NAMES
JetModifierKeywordToken[] ANNOTATION_MODIFIERS_KEYWORDS_ARRAY = new JetModifierKeywordToken[] {
INLINE_KEYWORD, NOINLINE_KEYWORD, TAILREC_KEYWORD, EXTERNAL_KEYWORD, ANNOTATION_KEYWORD, CROSSINLINE_KEYWORD
INLINE_KEYWORD, NOINLINE_KEYWORD, TAILREC_KEYWORD, EXTERNAL_KEYWORD, CROSSINLINE_KEYWORD
};
TokenSet MODIFIER_KEYWORDS = TokenSet.create(MODIFIER_KEYWORDS_ARRAY);
@@ -26,7 +26,6 @@ import com.intellij.psi.impl.source.codeStyle.CodeEditUtil
import com.intellij.psi.stubs.IStubElementType
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.JetNodeTypes
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.lexer.JetTokens
import org.jetbrains.kotlin.psi.stubs.KotlinClassOrObjectStub
import org.jetbrains.kotlin.psi.stubs.elements.JetStubElementTypes
@@ -108,17 +107,7 @@ abstract public class JetClassOrObject :
public fun getSecondaryConstructors(): List<JetSecondaryConstructor> = getBody()?.getSecondaryConstructors().orEmpty()
public fun isAnnotation(): Boolean =
getAnnotation(KotlinBuiltIns.FQ_NAMES.annotation.shortName().asString()) != null || hasModifier(JetTokens.ANNOTATION_KEYWORD)
private fun getAnnotation(name: String): JetAnnotationEntry? {
return getAnnotationEntries().firstOrNull() { entry ->
val typeReference = entry.getTypeReference()
val userType = typeReference?.getStubOrPsiChild(JetStubElementTypes.USER_TYPE)
name == userType?.getReferencedName()
}
}
public fun isAnnotation(): Boolean = hasModifier(JetTokens.ANNOTATION_KEYWORD)
public override fun delete() {
CheckUtil.checkWritable(this);
@@ -165,7 +165,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
this.kind = storageManager.createLazyValue(new Function0<ClassKind>() {
@Override
public ClassKind invoke() {
return (syntaxKind == ClassKind.CLASS && KotlinBuiltIns.isAnnotation(descriptor)) ? ClassKind.ANNOTATION_CLASS : syntaxKind;
return (syntaxKind == ClassKind.CLASS && modifierList != null && modifierList.hasModifier(JetTokens.ANNOTATION_KEYWORD)) ? ClassKind.ANNOTATION_CLASS : syntaxKind;
}
});
@@ -76,15 +76,6 @@ public enum class AnnotationRetention {
@MustBeDocumented
public annotation class Target(vararg val allowedTargets: AnnotationTarget)
/**
* This special meta-annotation is used to declare an annotation.
* So a class in Kotlin is an annotation if and only if it has the "annotation" meta-annotation.
*/
@Target(AnnotationTarget.ANNOTATION_CLASS)
@Retention(AnnotationRetention.SOURCE)
@MustBeDocumented
private annotation class annotation
/**
* This meta-annotation determines whether an annotation is stored in binary output and visible for reflection. By default, both are true.
*
@@ -45,7 +45,6 @@ class LazyJavaAnnotations(
override fun iterator() =
(annotationOwner.annotations.asSequence().map(annotationDescriptors)
+ JavaAnnotationMapper.findMappedJavaAnnotation(KotlinBuiltIns.FQ_NAMES.annotation, annotationOwner, c)
+ JavaAnnotationMapper.findMappedJavaAnnotation(KotlinBuiltIns.FQ_NAMES.deprecated, annotationOwner, c)).filterNotNull().iterator()
override fun isEmpty() = !iterator().hasNext()
@@ -145,7 +145,6 @@ public abstract class KotlinBuiltIns {
public final FqName crossinline = fqName("crossinline");
public final FqName extension = fqName("Extension");
public final FqName target = annotationName("Target");
public final FqName annotation = annotationName("annotation");
public final FqName annotationTarget = annotationName("AnnotationTarget");
public final FqName annotationRetention = annotationName("AnnotationRetention");
public final FqName retention = annotationName("Retention");
@@ -428,11 +427,6 @@ public abstract class KotlinBuiltIns {
return result instanceof ClassDescriptor ? (ClassDescriptor) result : null;
}
@NotNull
public ClassDescriptor getAnnotationAnnotation() {
return getAnnotationClassByName(FQ_NAMES.annotation.shortName());
}
@NotNull
public ClassDescriptor getString() {
return getBuiltInClassByName("String");
@@ -1019,11 +1013,6 @@ public abstract class KotlinBuiltIns {
return FQ_NAMES.array.equals(getFqName(descriptor));
}
public static boolean isAnnotation(@NotNull ClassDescriptor descriptor) {
return DescriptorUtils.getFqName(descriptor) == FQ_NAMES.annotation.toUnsafe()
|| containsAnnotation(descriptor, FQ_NAMES.annotation);
}
public static boolean isCloneable(@NotNull ClassDescriptor descriptor) {
return FQ_NAMES.cloneable.equals(getFqName(descriptor));
}
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.types.Variance
// Please synchronize this set with JetTokens.ANNOTATION_MODIFIERS_KEYWORDS_ARRAY
public val ANNOTATION_MODIFIERS_FQ_NAMES: Set<FqName> =
arrayOf("inline", "noinline", "tailrec", "external", "annotation.annotation", "crossinline").map { FqName("kotlin.$it") }.toSet()
arrayOf("inline", "noinline", "tailrec", "external", "crossinline").map { FqName("kotlin.$it") }.toSet()
public fun KotlinBuiltIns.createDeprecatedAnnotation(message: String, replaceWith: String): AnnotationDescriptor {
val deprecatedAnnotation = deprecatedAnnotation
@@ -26,11 +26,11 @@ import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.diagnostics.Diagnostic;
import org.jetbrains.kotlin.idea.JetBundle;
import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil;
import org.jetbrains.kotlin.idea.references.ReferenceUtilKt;
import org.jetbrains.kotlin.lexer.JetTokens;
import org.jetbrains.kotlin.psi.*;
public class MakeClassAnAnnotationClassFix extends KotlinQuickFixAction<JetAnnotationEntry> {
@@ -84,14 +84,13 @@ public class MakeClassAnAnnotationClassFix extends KotlinQuickFixAction<JetAnnot
public void invoke(@NotNull Project project, Editor editor, @NotNull JetFile file) throws IncorrectOperationException {
JetPsiFactory factory = new JetPsiFactory(annotationClass.getProject());
JetModifierList list = annotationClass.getModifierList();
String annotation = KotlinBuiltIns.FQ_NAMES.annotation.shortName().asString();
PsiElement added;
if (list == null) {
JetModifierList newModifierList = factory.createModifierList(annotation);
JetModifierList newModifierList = factory.createModifierList(JetTokens.ANNOTATION_KEYWORD);
added = annotationClass.addBefore(newModifierList, annotationClass.getClassOrInterfaceKeyword());
}
else {
JetAnnotationEntry entry = factory.createAnnotationEntry(annotation);
PsiElement entry = factory.createModifier(JetTokens.ANNOTATION_KEYWORD);
added = list.addBefore(entry, list.getFirstChild());
}
annotationClass.addAfter(factory.createWhiteSpace(), added);
@@ -58,7 +58,6 @@ import com.intellij.util.VisibilityUtil
import com.intellij.util.containers.MultiMap
import org.jetbrains.kotlin.asJava.KotlinLightMethod
import org.jetbrains.kotlin.asJava.LightClassUtil
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
@@ -450,8 +449,8 @@ private fun copyModifierListItems(from: PsiModifierList, to: PsiModifierList, wi
}
for (annotation in from.getAnnotations()) {
val annotationName = annotation.getQualifiedName()!!
if (KotlinBuiltIns.FQ_NAMES.annotation.asString() != annotationName
&& javaClass<Retention>().getName() != annotationName) {
if (javaClass<Retention>().getName() != annotationName) {
to.addAnnotation(annotationName)
}
}