Move all annotation FQ names to JvmAnnotationNames

Delete reflected usages of annotation classes (JetValueParameter.class,
KotlinSignature.class, etc.). It's wrong: this is a dependency on the old
runtime, whereas the compiler should work with the new one
This commit is contained in:
Alexander Udalov
2014-02-27 20:30:53 +04:00
parent a6a31878a7
commit 33a9f3abd1
11 changed files with 51 additions and 80 deletions
@@ -1,45 +0,0 @@
/*
* Copyright 2010-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.jet.lang.resolve.java;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
import static org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils.fqNameByClass;
public final class AnnotationLoadingUtil {
public static final Name DEFAULT_ANNOTATION_MEMBER_NAME = Name.identifier("value");
public static final FqName JETBRAINS_NOT_NULL_ANNOTATION = fqNameByClass(NotNull.class);
public static final FqName JETBRAINS_NULLABLE_ANNOTATION = fqNameByClass(Nullable.class);
public static final FqName JETBRAINS_MUTABLE_ANNOTATION = new FqName("org.jetbrains.annotations.Mutable");
public static final FqName JETBRAINS_READONLY_ANNOTATION = new FqName("org.jetbrains.annotations.ReadOnly");
public static final FqName JL_CLASS_FQ_NAME = new FqName("java.lang.Class");
@SuppressWarnings("deprecation")
public static boolean isSpecialAnnotation(@NotNull FqName fqName) {
return fqName.asString().startsWith("jet.runtime.typeinfo.")
|| fqName.equals(JETBRAINS_NOT_NULL_ANNOTATION)
|| fqName.equals(JvmAnnotationNames.OLD_KOTLIN_CLASS)
|| fqName.equals(JvmAnnotationNames.OLD_KOTLIN_PACKAGE)
|| fqName.equals(JvmAnnotationNames.KOTLIN_CLASS)
|| fqName.equals(JvmAnnotationNames.KOTLIN_PACKAGE);
}
private AnnotationLoadingUtil() {}
}
@@ -16,7 +16,9 @@
package org.jetbrains.jet.lang.resolve.java;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
public final class JvmAnnotationNames {
public static final FqName KOTLIN_CLASS = new FqName("kotlin.jvm.internal.KotlinClass");
@@ -24,14 +26,24 @@ public final class JvmAnnotationNames {
public static final FqName KOTLIN_PACKAGE_PART = new FqName("kotlin.jvm.internal.KotlinPackagePart");
public static final FqName KOTLIN_TRAIT_IMPL = new FqName("kotlin.jvm.internal.KotlinTraitImpl");
public static final FqName KOTLIN_SIGNATURE = new FqName("jet.runtime.typeinfo.KotlinSignature");
public static final String ABI_VERSION_FIELD_NAME = "abiVersion";
public static final String DATA_FIELD_NAME = "data";
public static final Name DEFAULT_ANNOTATION_MEMBER_NAME = Name.identifier("value");
public static final FqName JETBRAINS_NOT_NULL_ANNOTATION = new FqName("org.jetbrains.annotations.NotNull");
public static final FqName JETBRAINS_NULLABLE_ANNOTATION = new FqName("org.jetbrains.annotations.Nullable");
public static final FqName JETBRAINS_MUTABLE_ANNOTATION = new FqName("org.jetbrains.annotations.Mutable");
public static final FqName JETBRAINS_READONLY_ANNOTATION = new FqName("org.jetbrains.annotations.ReadOnly");
@Deprecated
public static final FqName OLD_JET_CLASS_ANNOTATION = new FqName("jet.runtime.typeinfo.JetClass");
@Deprecated
public static final FqName OLD_JET_PACKAGE_CLASS_ANNOTATION = new FqName("jet.runtime.typeinfo.JetPackageClass");
@Deprecated
public static final FqName OLD_JET_VALUE_PARAMETER_ANNOTATION = new FqName("jet.runtime.typeinfo.JetValueParameter");
@Deprecated
public static final FqName OLD_KOTLIN_CLASS = new FqName("jet.KotlinClass");
@Deprecated
public static final FqName OLD_KOTLIN_PACKAGE = new FqName("jet.KotlinPackage");
@@ -40,6 +52,16 @@ public final class JvmAnnotationNames {
@Deprecated
public static final FqName OLD_KOTLIN_TRAIT_IMPL = new FqName("jet.KotlinTraitImpl");
@SuppressWarnings("deprecation")
public static boolean isSpecialAnnotation(@NotNull FqName fqName) {
return fqName.asString().startsWith("jet.runtime.typeinfo.")
|| fqName.equals(JETBRAINS_NOT_NULL_ANNOTATION)
|| fqName.equals(OLD_KOTLIN_CLASS)
|| fqName.equals(OLD_KOTLIN_PACKAGE)
|| fqName.equals(KOTLIN_CLASS)
|| fqName.equals(KOTLIN_PACKAGE);
}
private JvmAnnotationNames() {
}
}
@@ -22,13 +22,13 @@ import org.jetbrains.jet.lang.resolve.name.FqName
import org.jetbrains.jet.lang.descriptors.annotations.Annotations
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.jet.lang.resolve.java.lazy.descriptors.LazyJavaAnnotationDescriptor
import org.jetbrains.jet.lang.resolve.java.AnnotationLoadingUtil
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames
class LazyJavaAnnotations(c: LazyJavaResolverContextWithTypes, val annotationOwner: JavaAnnotationOwner) : Annotations {
private val annotationDescriptors = c.storageManager.createMemoizedFunctionWithNullableValues {
(jAnnotation: JavaAnnotation) ->
val fqName = jAnnotation.getFqName()
if (fqName == null || AnnotationLoadingUtil.isSpecialAnnotation(fqName)) {
if (fqName == null || JvmAnnotationNames.isSpecialAnnotation(fqName)) {
null
}
else LazyJavaAnnotationDescriptor(c, jAnnotation)
@@ -54,6 +54,6 @@ fun LazyJavaResolverContextWithTypes.resolveAnnotations(annotationsOwner: JavaAn
private fun GlobalJavaResolverContext.hasAnnotation(owner: JavaAnnotationOwner, annotationFqName: FqName): Boolean
= owner.findAnnotation(annotationFqName) != null || externalAnnotationResolver.findExternalAnnotation(owner, annotationFqName) != null
fun GlobalJavaResolverContext.hasMutableAnnotation(owner: JavaAnnotationOwner): Boolean = hasAnnotation(owner, AnnotationLoadingUtil.JETBRAINS_MUTABLE_ANNOTATION)
fun GlobalJavaResolverContext.hasReadOnlyAnnotation(owner: JavaAnnotationOwner): Boolean = hasAnnotation(owner, AnnotationLoadingUtil.JETBRAINS_READONLY_ANNOTATION)
fun GlobalJavaResolverContext.hasNotNullAnnotation(owner: JavaAnnotationOwner): Boolean = hasAnnotation(owner, AnnotationLoadingUtil.JETBRAINS_NOT_NULL_ANNOTATION)
fun GlobalJavaResolverContext.hasMutableAnnotation(owner: JavaAnnotationOwner): Boolean = hasAnnotation(owner, JvmAnnotationNames.JETBRAINS_MUTABLE_ANNOTATION)
fun GlobalJavaResolverContext.hasReadOnlyAnnotation(owner: JavaAnnotationOwner): Boolean = hasAnnotation(owner, JvmAnnotationNames.JETBRAINS_READONLY_ANNOTATION)
fun GlobalJavaResolverContext.hasNotNullAnnotation(owner: JavaAnnotationOwner): Boolean = hasAnnotation(owner, JvmAnnotationNames.JETBRAINS_NOT_NULL_ANNOTATION)
@@ -13,7 +13,7 @@ import org.jetbrains.jet.lang.resolve.name.FqName
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
import org.jetbrains.jet.lang.descriptors.VariableDescriptor
import org.jetbrains.jet.lang.resolve.java.AnnotationLoadingUtil.*
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.*
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames
import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils
import org.jetbrains.jet.lang.resolve.DescriptorUtils
@@ -33,7 +33,6 @@ import org.jetbrains.jet.renderer.DescriptorRenderer
import org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap
import org.jetbrains.jet.lang.types.TypeUtils
import org.jetbrains.jet.lang.resolve.java.resolver.resolveCompileTimeConstantValue
import org.jetbrains.jet.lang.resolve.java.AnnotationLoadingUtil
private object DEPRECATED_IN_JAVA : JavaLiteralAnnotationArgument {
override fun getName(): Name? = null
@@ -107,7 +106,7 @@ class LazyJavaAnnotationDescriptor(
val fqName = javaAnnotation.getFqName()
if (fqName == null) return null
if (AnnotationLoadingUtil.isSpecialAnnotation(fqName)) {
if (JvmAnnotationNames.isSpecialAnnotation(fqName)) {
return null
}
@@ -146,7 +145,7 @@ class LazyJavaAnnotationDescriptor(
private fun resolveFromJavaClassObjectType(javaType: JavaType): CompileTimeConstant<*>? {
// Class type is never nullable in 'Foo.class' in Java
val `type` = TypeUtils.makeNotNullable(c.typeResolver.transformJavaType(javaType, TypeUsage.MEMBER_SIGNATURE_INVARIANT.toAttributes()))
val jlClass = c.javaClassResolver.resolveClassByFqName(JL_CLASS_FQ_NAME)
val jlClass = c.javaClassResolver.resolveClassByFqName(FqName("java.lang.Class"))
if (jlClass == null) return null
val arguments = listOf(TypeProjectionImpl(`type`))
@@ -26,7 +26,6 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptorImpl;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.constants.StringValue;
import org.jetbrains.jet.lang.resolve.java.AnnotationLoadingUtil;
import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType;
import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils;
import org.jetbrains.jet.lang.resolve.java.resolver.TypeUsage;
@@ -38,6 +37,7 @@ import org.jetbrains.jet.lang.types.lang.PrimitiveType;
import java.util.*;
import static org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME;
import static org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils.fqNameByClass;
public class JavaToKotlinClassMap extends JavaToKotlinClassMapBuilder implements PlatformToKotlinClassMap {
@@ -108,8 +108,8 @@ public class JavaToKotlinClassMap extends JavaToKotlinClassMapBuilder implements
private static AnnotationDescriptor getAnnotationDescriptorForJavaLangDeprecated(@NotNull ClassDescriptor annotationClass) {
AnnotationDescriptorImpl annotation = new AnnotationDescriptorImpl();
annotation.setAnnotationType(annotationClass.getDefaultType());
ValueParameterDescriptor value = DescriptorResolverUtils.getAnnotationParameterByName(
AnnotationLoadingUtil.DEFAULT_ANNOTATION_MEMBER_NAME, annotationClass);
ValueParameterDescriptor value =
DescriptorResolverUtils.getAnnotationParameterByName(DEFAULT_ANNOTATION_MEMBER_NAME, annotationClass);
assert value != null : "kotlin.deprecated must have one parameter called value";
annotation.setValueArgument(value, new StringValue("Deprecated in Java", true));
return annotation;
@@ -28,13 +28,11 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptorImpl;
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationsImpl;
import org.jetbrains.jet.lang.resolve.java.AnnotationLoadingUtil;
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.constants.EnumValue;
import org.jetbrains.jet.lang.resolve.constants.ErrorValue;
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.java.PackageClassUtils;
import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils;
@@ -52,6 +50,7 @@ import java.util.*;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isClassObject;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isTrait;
import static org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.*;
import static org.jetbrains.jet.lang.resolve.kotlin.DeserializedResolverUtils.kotlinFqNameToJavaFqName;
import static org.jetbrains.jet.lang.resolve.kotlin.DeserializedResolverUtils.naiveKotlinFqName;
@@ -148,10 +147,10 @@ public class AnnotationDescriptorDeserializer implements AnnotationDeserializer
}
private static boolean ignoreAnnotation(@NotNull JvmClassName className) {
return className.equals(JvmClassName.byFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_CLASS))
|| className.equals(JvmClassName.byFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_PACKAGE))
|| className.equals(JvmClassName.byFqNameWithoutInnerClasses(AnnotationLoadingUtil.JETBRAINS_NOT_NULL_ANNOTATION))
|| className.equals(JvmClassName.byFqNameWithoutInnerClasses(AnnotationLoadingUtil.JETBRAINS_NULLABLE_ANNOTATION))
return className.equals(JvmClassName.byFqNameWithoutInnerClasses(KOTLIN_CLASS))
|| className.equals(JvmClassName.byFqNameWithoutInnerClasses(KOTLIN_PACKAGE))
|| className.equals(JvmClassName.byFqNameWithoutInnerClasses(JETBRAINS_NOT_NULL_ANNOTATION))
|| className.equals(JvmClassName.byFqNameWithoutInnerClasses(JETBRAINS_NULLABLE_ANNOTATION))
|| className.getInternalName().startsWith("jet/runtime/typeinfo/");
}