Change logic of loading "suppress" annotation class descriptor
Instead of loading the descriptor and checking equals(), we now check if the annotation is in fact "suppress" by simply comparing its FQ name. This allows us to suppress warnings while compiling built-ins: the problem is that built-ins have its own "suppress" annotation class (defined in the sources) which differs from the one loaded by the compiler (from kotlin-compiler.jar)
This commit is contained in:
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.PlatformToKotlinClassMap;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.ValueParameterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
@@ -103,6 +104,8 @@ public class KotlinBuiltIns {
|
||||
private final Map<JetType, JetType> primitiveJetTypeToJetArrayType;
|
||||
private final Map<JetType, JetType> jetArrayTypeToPrimitiveJetType;
|
||||
|
||||
private final FqNames fqNames = new FqNames();
|
||||
|
||||
private KotlinBuiltIns() {
|
||||
builtInsModule = new ModuleDescriptorImpl(Name.special("<built-ins lazy module>"),
|
||||
Collections.<ImportPath>emptyList(),
|
||||
@@ -139,6 +142,15 @@ public class KotlinBuiltIns {
|
||||
jetArrayTypeToPrimitiveJetType.put(arrayType, type);
|
||||
}
|
||||
|
||||
private static class FqNames {
|
||||
public final FqNameUnsafe suppress = fqName("suppress");
|
||||
|
||||
@NotNull
|
||||
private static FqNameUnsafe fqName(@NotNull String simpleName) {
|
||||
return BUILT_INS_PACKAGE_FQ_NAME.child(Name.identifier(simpleName)).toUnsafe();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@NotNull
|
||||
@@ -295,11 +307,6 @@ public class KotlinBuiltIns {
|
||||
return getBuiltInClassByName("inline");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getSuppressAnnotationClass() {
|
||||
return getBuiltInClassByName("suppress");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getTailRecursiveAnnotationClass() {
|
||||
return getBuiltInClassByName("tailRecursive");
|
||||
@@ -831,6 +838,11 @@ public class KotlinBuiltIns {
|
||||
return containsAnnotation(declarationDescriptor, getTailRecursiveAnnotationClass());
|
||||
}
|
||||
|
||||
public boolean isSuppressAnnotation(@NotNull AnnotationDescriptor annotationDescriptor) {
|
||||
ClassifierDescriptor classifier = annotationDescriptor.getType().getConstructor().getDeclarationDescriptor();
|
||||
return classifier != null && fqNames.suppress.equals(DescriptorUtils.getFqName(classifier));
|
||||
}
|
||||
|
||||
static boolean containsAnnotation(DeclarationDescriptor descriptor, ClassDescriptor annotationClass) {
|
||||
FqName fqName = DescriptorUtils.getFqName(annotationClass).toSafe();
|
||||
return descriptor.getOriginal().getAnnotations().findAnnotation(fqName) != null;
|
||||
|
||||
Reference in New Issue
Block a user