Some usages of JetClassOrObject.isAnnotation() are removed. Related test fixed.

This commit is contained in:
Mikhail Glukhikh
2015-07-14 16:01:40 +03:00
parent 7f12965741
commit 2a1058ed63
8 changed files with 30 additions and 25 deletions
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.resolve
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.psi.*
@@ -53,9 +54,9 @@ public object AnnotationTargetChecker {
private val ALL_TARGET_LIST = Target.values().map { it.name() }
public fun check(annotated: JetAnnotated, trace: BindingTrace) {
public fun check(annotated: JetAnnotated, trace: BindingTrace, descriptor: ClassDescriptor? = null) {
if (annotated is JetTypeParameter) return // TODO: support type parameter annotations
val actualTargets = getActualTargetList(annotated)
val actualTargets = getActualTargetList(annotated, descriptor)
for (entry in annotated.getAnnotationEntries()) {
checkAnnotationEntry(entry, actualTargets, trace)
}
@@ -110,10 +111,15 @@ public object AnnotationTargetChecker {
trace.report(Errors.WRONG_ANNOTATION_TARGET.on(entry, actualTargets.firstOrNull()?.description ?: "unidentified target"))
}
private fun getActualTargetList(annotated: JetAnnotated): List<Target> {
private fun getActualTargetList(annotated: JetAnnotated, descriptor: ClassDescriptor?): List<Target> {
if (annotated is JetClassOrObject) {
if (annotated is JetEnumEntry) return listOf(Target.PROPERTY, Target.FIELD)
return if (annotated.isAnnotation()) listOf(Target.ANNOTATION_CLASS, Target.CLASSIFIER) else listOf(Target.CLASSIFIER)
return if (descriptor?.getKind() == ClassKind.ANNOTATION_CLASS) {
listOf(Target.ANNOTATION_CLASS, Target.CLASSIFIER)
}
else {
listOf(Target.CLASSIFIER)
}
}
if (annotated is JetProperty) {
return if (annotated.isLocal()) listOf(Target.LOCAL_VARIABLE) else listOf(Target.PROPERTY, Target.FIELD)
@@ -67,7 +67,7 @@ public class DeclarationsChecker {
public void process(@NotNull BodiesResolveContext bodiesResolveContext) {
for (JetFile file : bodiesResolveContext.getFiles()) {
checkModifiersAndAnnotationsInPackageDirective(file);
AnnotationTargetChecker.INSTANCE$.check(file, trace);
AnnotationTargetChecker.INSTANCE$.check(file, trace, null);
}
Map<JetClassOrObject, ClassDescriptorWithResolutionScopes> classes = bodiesResolveContext.getDeclaredClasses();
@@ -147,7 +147,7 @@ public class DeclarationsChecker {
}
}
}
AnnotationTargetChecker.INSTANCE$.check(packageDirective, trace);
AnnotationTargetChecker.INSTANCE$.check(packageDirective, trace, null);
ModifiersChecker.reportIllegalModifiers(modifierList, Arrays.asList(JetTokens.MODIFIER_KEYWORDS_ARRAY), trace);
}
@@ -254,7 +254,7 @@ public class DeclarationsChecker {
checkTraitModifiers(aClass);
checkConstructorInTrait(aClass);
}
else if (aClass.isAnnotation()) {
else if (classDescriptor.getKind() == ClassKind.ANNOTATION_CLASS) {
checkAnnotationClassWithBody(aClass);
checkValOnAnnotationParameter(aClass);
}
@@ -304,7 +304,7 @@ public class DeclarationsChecker {
if (typeParameter != null) {
DescriptorResolver.checkConflictingUpperBounds(trace, typeParameter, jetTypeParameter);
}
AnnotationTargetChecker.INSTANCE$.check(jetTypeParameter, trace);
AnnotationTargetChecker.INSTANCE$.check(jetTypeParameter, trace, null);
}
}
@@ -131,7 +131,7 @@ public class DescriptorResolver {
}
if (supertypes.isEmpty()) {
JetType defaultSupertype = getDefaultSupertype(jetClass, trace);
JetType defaultSupertype = getDefaultSupertype(jetClass, trace, classDescriptor.getKind() == ClassKind.ANNOTATION_CLASS);
addValidSupertype(supertypes, defaultSupertype);
}
@@ -154,7 +154,7 @@ public class DescriptorResolver {
return false;
}
private JetType getDefaultSupertype(JetClassOrObject jetClass, BindingTrace trace) {
private JetType getDefaultSupertype(JetClassOrObject jetClass, BindingTrace trace, boolean isAnnotation) {
// TODO : beautify
if (jetClass instanceof JetEnumEntry) {
JetClassOrObject parent = JetStubbedPsiUtil.getContainingDeclaration(jetClass, JetClassOrObject.class);
@@ -167,7 +167,7 @@ public class DescriptorResolver {
return ErrorUtils.createErrorType("Supertype not specified");
}
}
else if (jetClass instanceof JetClass && ((JetClass) jetClass).isAnnotation()) {
else if (isAnnotation) {
return builtIns.getAnnotationType();
}
return builtIns.getAnyType();
@@ -150,7 +150,8 @@ public class ModifiersChecker {
}
checkPlatformNameApplicability(descriptor);
runDeclarationCheckers(modifierListOwner, descriptor);
AnnotationTargetChecker.INSTANCE$.check(modifierListOwner, trace);
AnnotationTargetChecker.INSTANCE$.check(modifierListOwner, trace,
descriptor instanceof ClassDescriptor ? (ClassDescriptor) descriptor : null);
}
private void checkVarargsModifiers(@NotNull JetDeclaration owner, @NotNull MemberDescriptor descriptor) {
@@ -164,7 +165,8 @@ public class ModifiersChecker {
reportIllegalVisibilityModifiers(modifierListOwner);
checkPlatformNameApplicability(descriptor);
runDeclarationCheckers(modifierListOwner, descriptor);
AnnotationTargetChecker.INSTANCE$.check(modifierListOwner, trace);
AnnotationTargetChecker.INSTANCE$.check(modifierListOwner, trace,
descriptor instanceof ClassDescriptor ? (ClassDescriptor) descriptor : null);
}
public void reportIllegalModalityModifiers(@NotNull JetModifierListOwner modifierListOwner) {