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
@@ -19,7 +19,6 @@ package org.jetbrains.jet.codegen;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.psi.PsiElement;
import jet.runtime.typeinfo.JetValueParameter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.asm4.AnnotationVisitor;
@@ -56,7 +55,7 @@ import static org.jetbrains.jet.lang.resolve.BindingContextUtils.callableDescrip
import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDeclaration;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isFunctionLiteral;
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
import static org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils.fqNameByClass;
import static org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.OLD_JET_VALUE_PARAMETER_ANNOTATION;
public class FunctionCodegen extends ParentCodegenAwareImpl {
private final CodegenContext owner;
@@ -213,7 +212,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl {
}
AnnotationVisitor av =
mv.visitParameterAnnotation(i, asmDescByFqNameWithoutInnerClasses(fqNameByClass(JetValueParameter.class)), true);
mv.visitParameterAnnotation(i, asmDescByFqNameWithoutInnerClasses(OLD_JET_VALUE_PARAMETER_ANNOTATION), true);
if (av != null) {
av.visit("name", name);
if (nullableType) {
@@ -17,20 +17,16 @@
package org.jetbrains.jet.lang.resolve.java.kotlinSignature;
import com.intellij.openapi.util.text.StringUtil;
import jet.runtime.typeinfo.KotlinSignature;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.resolver.ExternalAnnotationResolver;
import org.jetbrains.jet.lang.resolve.java.structure.*;
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;
import static org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME;
import static org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.KOTLIN_SIGNATURE;
public class SignaturesUtil {
public static final FqName KOTLIN_SIGNATURE = fqNameByClass(KotlinSignature.class);
public static final Name KOTLIN_SIGNATURE_VALUE_FIELD_NAME = Name.identifier("value");
private SignaturesUtil() {
}
@@ -39,7 +35,7 @@ public class SignaturesUtil {
JavaAnnotation annotation = findAnnotationWithExternal(externalAnnotationResolver, member, KOTLIN_SIGNATURE);
if (annotation != null) {
JavaAnnotationArgument argument = annotation.findArgument(KOTLIN_SIGNATURE_VALUE_FIELD_NAME);
JavaAnnotationArgument argument = annotation.findArgument(DEFAULT_ANNOTATION_MEMBER_NAME);
if (argument instanceof JavaLiteralAnnotationArgument) {
Object value = ((JavaLiteralAnnotationArgument) argument).getValue();
if (value instanceof String) {
@@ -30,7 +30,7 @@ import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.TestJdkKind;
import org.jetbrains.jet.cli.jvm.compiler.CoreExternalAnnotationsManager;
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
import org.jetbrains.jet.lang.resolve.java.kotlinSignature.SignaturesUtil;
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames;
import org.jetbrains.jet.lang.resolve.lazy.KotlinTestWithEnvironment;
import org.jetbrains.jet.lang.resolve.name.FqName;
@@ -166,9 +166,9 @@ public class IdeaJdkAnnotationsReflectedTest extends KotlinTestWithEnvironment {
}
private enum AnnotationsKind {
KOTLIN_SIGNATURE(SignaturesUtil.KOTLIN_SIGNATURE.asString()),
KOTLIN_SIGNATURE(JvmAnnotationNames.KOTLIN_SIGNATURE.asString()),
NOT_NULL(AnnotationUtil.NOT_NULL),
ANY(AnnotationUtil.NOT_NULL, SignaturesUtil.KOTLIN_SIGNATURE.asString());
ANY(AnnotationUtil.NOT_NULL, JvmAnnotationNames.KOTLIN_SIGNATURE.asString());
public final String[] annotationNames;
@@ -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/");
}
@@ -33,13 +33,14 @@ import org.jetbrains.jet.lang.resolve.DescriptorUtils;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.java.AnnotationLoadingUtil;
import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils;
import org.jetbrains.jet.lang.types.TypeUtils;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import static org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME;
public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisitor {
private static final TokenSet PROPERTY_SET_OPERATIONS =
@@ -231,8 +232,8 @@ public class DeprecatedAnnotationVisitor extends AfterAnalysisHighlightingVisito
private static String getMessageFromAnnotationDescriptor(@NotNull AnnotationDescriptor descriptor) {
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(descriptor.getType());
assert classDescriptor != null : "ClassDescriptor for kotlin.deprecated mustn't be null";
ValueParameterDescriptor parameter = DescriptorResolverUtils.getAnnotationParameterByName(
AnnotationLoadingUtil.DEFAULT_ANNOTATION_MEMBER_NAME, classDescriptor);
ValueParameterDescriptor parameter =
DescriptorResolverUtils.getAnnotationParameterByName(DEFAULT_ANNOTATION_MEMBER_NAME, classDescriptor);
assert parameter != null : "kotlin.deprecated must have one parameter called value";
CompileTimeConstant<?> valueArgument = descriptor.getValueArgument(parameter);
assert valueArgument != null : "kotlin.deprecated must have value argument";
@@ -28,7 +28,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.java.resolver.PsiBasedExternalAnnotationResolver;
import static org.jetbrains.jet.lang.resolve.java.kotlinSignature.SignaturesUtil.KOTLIN_SIGNATURE;
import static org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames.KOTLIN_SIGNATURE;
class KotlinSignatureUtil {
static final String KOTLIN_SIGNATURE_ANNOTATION = KOTLIN_SIGNATURE.asString();