Some usages of JetClassOrObject.isAnnotation() are removed. Related test fixed.
This commit is contained in:
@@ -21,10 +21,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import org.jetbrains.kotlin.backend.common.bridges.BridgesPackage;
|
import org.jetbrains.kotlin.backend.common.bridges.BridgesPackage;
|
||||||
import org.jetbrains.kotlin.codegen.context.ClassContext;
|
import org.jetbrains.kotlin.codegen.context.ClassContext;
|
||||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
import org.jetbrains.kotlin.descriptors.*;
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
|
|
||||||
import org.jetbrains.kotlin.psi.*;
|
import org.jetbrains.kotlin.psi.*;
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||||
@@ -80,7 +77,7 @@ public abstract class ClassBodyCodegen extends MemberCodegen<JetClassOrObject> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
generatePrimaryConstructorProperties(propertyCodegen, myClass);
|
generatePrimaryConstructorProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean shouldProcessFirst(JetDeclaration declaration) {
|
private static boolean shouldProcessFirst(JetDeclaration declaration) {
|
||||||
@@ -101,8 +98,8 @@ public abstract class ClassBodyCodegen extends MemberCodegen<JetClassOrObject> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generatePrimaryConstructorProperties(PropertyCodegen propertyCodegen, JetClassOrObject origin) {
|
private void generatePrimaryConstructorProperties() {
|
||||||
boolean isAnnotation = origin instanceof JetClass && ((JetClass) origin).isAnnotation();
|
boolean isAnnotation = descriptor.getKind() == ClassKind.ANNOTATION_CLASS;
|
||||||
for (JetParameter p : getPrimaryConstructorParameters()) {
|
for (JetParameter p : getPrimaryConstructorParameters()) {
|
||||||
if (p.hasValOrVar()) {
|
if (p.hasValOrVar()) {
|
||||||
PropertyDescriptor propertyDescriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, p);
|
PropertyDescriptor propertyDescriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, p);
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
isAbstract = true;
|
isAbstract = true;
|
||||||
isInterface = true;
|
isInterface = true;
|
||||||
}
|
}
|
||||||
else if (jetClass.isAnnotation()) {
|
else if (descriptor.getKind() == ClassKind.ANNOTATION_CLASS) {
|
||||||
isAbstract = true;
|
isAbstract = true;
|
||||||
isInterface = true;
|
isInterface = true;
|
||||||
isAnnotation = true;
|
isAnnotation = true;
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.resolve
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors
|
import org.jetbrains.kotlin.diagnostics.Errors
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
@@ -53,9 +54,9 @@ public object AnnotationTargetChecker {
|
|||||||
|
|
||||||
private val ALL_TARGET_LIST = Target.values().map { it.name() }
|
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
|
if (annotated is JetTypeParameter) return // TODO: support type parameter annotations
|
||||||
val actualTargets = getActualTargetList(annotated)
|
val actualTargets = getActualTargetList(annotated, descriptor)
|
||||||
for (entry in annotated.getAnnotationEntries()) {
|
for (entry in annotated.getAnnotationEntries()) {
|
||||||
checkAnnotationEntry(entry, actualTargets, trace)
|
checkAnnotationEntry(entry, actualTargets, trace)
|
||||||
}
|
}
|
||||||
@@ -110,10 +111,15 @@ public object AnnotationTargetChecker {
|
|||||||
trace.report(Errors.WRONG_ANNOTATION_TARGET.on(entry, actualTargets.firstOrNull()?.description ?: "unidentified target"))
|
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 JetClassOrObject) {
|
||||||
if (annotated is JetEnumEntry) return listOf(Target.PROPERTY, Target.FIELD)
|
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) {
|
if (annotated is JetProperty) {
|
||||||
return if (annotated.isLocal()) listOf(Target.LOCAL_VARIABLE) else listOf(Target.PROPERTY, Target.FIELD)
|
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) {
|
public void process(@NotNull BodiesResolveContext bodiesResolveContext) {
|
||||||
for (JetFile file : bodiesResolveContext.getFiles()) {
|
for (JetFile file : bodiesResolveContext.getFiles()) {
|
||||||
checkModifiersAndAnnotationsInPackageDirective(file);
|
checkModifiersAndAnnotationsInPackageDirective(file);
|
||||||
AnnotationTargetChecker.INSTANCE$.check(file, trace);
|
AnnotationTargetChecker.INSTANCE$.check(file, trace, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<JetClassOrObject, ClassDescriptorWithResolutionScopes> classes = bodiesResolveContext.getDeclaredClasses();
|
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);
|
ModifiersChecker.reportIllegalModifiers(modifierList, Arrays.asList(JetTokens.MODIFIER_KEYWORDS_ARRAY), trace);
|
||||||
}
|
}
|
||||||
@@ -254,7 +254,7 @@ public class DeclarationsChecker {
|
|||||||
checkTraitModifiers(aClass);
|
checkTraitModifiers(aClass);
|
||||||
checkConstructorInTrait(aClass);
|
checkConstructorInTrait(aClass);
|
||||||
}
|
}
|
||||||
else if (aClass.isAnnotation()) {
|
else if (classDescriptor.getKind() == ClassKind.ANNOTATION_CLASS) {
|
||||||
checkAnnotationClassWithBody(aClass);
|
checkAnnotationClassWithBody(aClass);
|
||||||
checkValOnAnnotationParameter(aClass);
|
checkValOnAnnotationParameter(aClass);
|
||||||
}
|
}
|
||||||
@@ -304,7 +304,7 @@ public class DeclarationsChecker {
|
|||||||
if (typeParameter != null) {
|
if (typeParameter != null) {
|
||||||
DescriptorResolver.checkConflictingUpperBounds(trace, typeParameter, jetTypeParameter);
|
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()) {
|
if (supertypes.isEmpty()) {
|
||||||
JetType defaultSupertype = getDefaultSupertype(jetClass, trace);
|
JetType defaultSupertype = getDefaultSupertype(jetClass, trace, classDescriptor.getKind() == ClassKind.ANNOTATION_CLASS);
|
||||||
addValidSupertype(supertypes, defaultSupertype);
|
addValidSupertype(supertypes, defaultSupertype);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ public class DescriptorResolver {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JetType getDefaultSupertype(JetClassOrObject jetClass, BindingTrace trace) {
|
private JetType getDefaultSupertype(JetClassOrObject jetClass, BindingTrace trace, boolean isAnnotation) {
|
||||||
// TODO : beautify
|
// TODO : beautify
|
||||||
if (jetClass instanceof JetEnumEntry) {
|
if (jetClass instanceof JetEnumEntry) {
|
||||||
JetClassOrObject parent = JetStubbedPsiUtil.getContainingDeclaration(jetClass, JetClassOrObject.class);
|
JetClassOrObject parent = JetStubbedPsiUtil.getContainingDeclaration(jetClass, JetClassOrObject.class);
|
||||||
@@ -167,7 +167,7 @@ public class DescriptorResolver {
|
|||||||
return ErrorUtils.createErrorType("Supertype not specified");
|
return ErrorUtils.createErrorType("Supertype not specified");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (jetClass instanceof JetClass && ((JetClass) jetClass).isAnnotation()) {
|
else if (isAnnotation) {
|
||||||
return builtIns.getAnnotationType();
|
return builtIns.getAnnotationType();
|
||||||
}
|
}
|
||||||
return builtIns.getAnyType();
|
return builtIns.getAnyType();
|
||||||
|
|||||||
@@ -150,7 +150,8 @@ public class ModifiersChecker {
|
|||||||
}
|
}
|
||||||
checkPlatformNameApplicability(descriptor);
|
checkPlatformNameApplicability(descriptor);
|
||||||
runDeclarationCheckers(modifierListOwner, 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) {
|
private void checkVarargsModifiers(@NotNull JetDeclaration owner, @NotNull MemberDescriptor descriptor) {
|
||||||
@@ -164,7 +165,8 @@ public class ModifiersChecker {
|
|||||||
reportIllegalVisibilityModifiers(modifierListOwner);
|
reportIllegalVisibilityModifiers(modifierListOwner);
|
||||||
checkPlatformNameApplicability(descriptor);
|
checkPlatformNameApplicability(descriptor);
|
||||||
runDeclarationCheckers(modifierListOwner, 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) {
|
public void reportIllegalModalityModifiers(@NotNull JetModifierListOwner modifierListOwner) {
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
annotation class B
|
annotation class B
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
annotation companion object {}
|
<!WRONG_ANNOTATION_TARGET!>annotation<!> companion object {}
|
||||||
}
|
}
|
||||||
|
|
||||||
annotation object O {}
|
<!WRONG_ANNOTATION_TARGET!>annotation<!> object O {}
|
||||||
|
|
||||||
annotation interface T {}
|
<!WRONG_ANNOTATION_TARGET!>annotation<!> interface T {}
|
||||||
|
|
||||||
<!WRONG_ANNOTATION_TARGET!>annotation<!> fun f() = 0
|
<!WRONG_ANNOTATION_TARGET!>annotation<!> fun f() = 0
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ kotlin.annotation.annotation() internal object O {
|
|||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlin.annotation.annotation() internal interface T : kotlin.Annotation {
|
kotlin.annotation.annotation() internal interface T {
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
|||||||
Reference in New Issue
Block a user