Sort out "isSpecialAnnotation" method logic

Remove duplicate method, include all needed annotations (seems that some of
them were forgotten in either of the two methods)
This commit is contained in:
Alexander Udalov
2014-03-13 17:43:41 +04:00
parent 7b503bbe6f
commit 9bf0d014d5
2 changed files with 23 additions and 18 deletions
@@ -21,6 +21,10 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public final class JvmAnnotationNames {
public static final FqName KOTLIN_CLASS = new FqName("kotlin.jvm.internal.KotlinClass");
public static final FqName KOTLIN_PACKAGE = new FqName("kotlin.jvm.internal.KotlinPackage");
@@ -89,15 +93,21 @@ public final class JvmAnnotationNames {
@Deprecated
public static final FqName OLD_KOTLIN_TRAIT_IMPL = new FqName("jet.KotlinTraitImpl");
@SuppressWarnings("deprecation")
private static final Set<JvmClassName> SPECIAL_ANNOTATIONS = new HashSet<JvmClassName>();
static {
for (FqName fqName : Arrays.asList(KOTLIN_CLASS, KOTLIN_PACKAGE, KOTLIN_SIGNATURE, JETBRAINS_NOT_NULL_ANNOTATION,
JETBRAINS_NULLABLE_ANNOTATION)) {
SPECIAL_ANNOTATIONS.add(JvmClassName.byFqNameWithoutInnerClasses(fqName));
}
SPECIAL_ANNOTATIONS.add(KotlinSyntheticClass.CLASS_NAME);
}
public static boolean isSpecialAnnotation(@NotNull FqName fqName) {
return fqName.asString().startsWith("jet.runtime.typeinfo.")
|| fqName.equals(KOTLIN_SIGNATURE)
|| fqName.equals(JETBRAINS_NOT_NULL_ANNOTATION)
|| fqName.equals(OLD_KOTLIN_CLASS)
|| fqName.equals(OLD_KOTLIN_PACKAGE)
|| fqName.equals(KOTLIN_CLASS)
|| fqName.equals(KOTLIN_PACKAGE);
return isSpecialAnnotation(JvmClassName.byFqNameWithoutInnerClasses(fqName));
}
public static boolean isSpecialAnnotation(@NotNull JvmClassName name) {
return SPECIAL_ANNOTATIONS.contains(name) || name.getInternalName().startsWith("jet/runtime/typeinfo/");
}
private JvmAnnotationNames() {
@@ -27,7 +27,10 @@ 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.constants.*;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.constants.ConstantsPackage;
import org.jetbrains.jet.lang.resolve.constants.EnumValue;
import org.jetbrains.jet.lang.resolve.constants.ErrorValue;
import org.jetbrains.jet.lang.resolve.java.JvmAnnotationNames;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils;
@@ -107,21 +110,13 @@ public class AnnotationDescriptorDeserializer extends BaseDescriptorDeserializer
return new AnnotationsImpl(result);
}
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(JvmAnnotationNames.JETBRAINS_NOT_NULL_ANNOTATION))
|| className.equals(JvmClassName.byFqNameWithoutInnerClasses(JvmAnnotationNames.JETBRAINS_NULLABLE_ANNOTATION))
|| className.getInternalName().startsWith("jet/runtime/typeinfo/");
}
@Nullable
public static KotlinJvmBinaryClass.AnnotationArgumentVisitor resolveAnnotation(
@NotNull JvmClassName className,
@NotNull final List<AnnotationDescriptor> result,
@NotNull final DependencyClassByQualifiedNameResolver classResolver
) {
if (ignoreAnnotation(className)) return null;
if (JvmAnnotationNames.isSpecialAnnotation(className)) return null;
final ClassDescriptor annotationClass = resolveClass(className, classResolver);
final AnnotationDescriptorImpl annotation = new AnnotationDescriptorImpl();