Additional Resolve: Use descriptor of constructor instead of class when resolving primary constructor annotations
#KT-6099
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
package rendererTest
|
package rendererTest
|
||||||
|
|
||||||
annotation class TheAnnotation
|
annotation class TheAnnotation
|
||||||
|
annotation class AnotherAnnotation
|
||||||
|
|
||||||
[TheAnnotation]
|
[TheAnnotation]
|
||||||
public open class TheClass<out T : Int, X> {
|
public open class TheClass<out T : Int, X> [AnotherAnnotation] () {
|
||||||
private val privateVal: Int = 5
|
private val privateVal: Int = 5
|
||||||
|
|
||||||
val shouldBeFinal: Int = 5
|
val shouldBeFinal: Int = 5
|
||||||
@@ -31,8 +32,10 @@ public trait TwoUpperBounds<T> where T : Number, T : Any
|
|||||||
//package rendererTest
|
//package rendererTest
|
||||||
//internal final annotation class TheAnnotation : kotlin.Annotation defined in rendererTest
|
//internal final annotation class TheAnnotation : kotlin.Annotation defined in rendererTest
|
||||||
//public constructor TheAnnotation() defined in rendererTest.TheAnnotation
|
//public constructor TheAnnotation() defined in rendererTest.TheAnnotation
|
||||||
|
//internal final annotation class AnotherAnnotation : kotlin.Annotation defined in rendererTest
|
||||||
|
//public constructor AnotherAnnotation() defined in rendererTest.AnotherAnnotation
|
||||||
//rendererTest.TheAnnotation public open class TheClass<out T : kotlin.Int, X> defined in rendererTest
|
//rendererTest.TheAnnotation public open class TheClass<out T : kotlin.Int, X> defined in rendererTest
|
||||||
//public constructor TheClass<out T : kotlin.Int, X>() defined in rendererTest.TheClass
|
//rendererTest.AnotherAnnotation public constructor TheClass<out T : kotlin.Int, X>() defined in rendererTest.TheClass
|
||||||
//<out T : kotlin.Int> defined in rendererTest.TheClass
|
//<out T : kotlin.Int> defined in rendererTest.TheClass
|
||||||
//<X> defined in rendererTest.TheClass
|
//<X> defined in rendererTest.TheClass
|
||||||
//private final val privateVal: kotlin.Int defined in rendererTest.TheClass
|
//private final val privateVal: kotlin.Int defined in rendererTest.TheClass
|
||||||
|
|||||||
@@ -234,10 +234,10 @@ public abstract class ElementResolver {
|
|||||||
private static void annotationAdditionalResolve(ResolveSession resolveSession, JetAnnotationEntry jetAnnotationEntry) {
|
private static void annotationAdditionalResolve(ResolveSession resolveSession, JetAnnotationEntry jetAnnotationEntry) {
|
||||||
Annotations annotations = null;
|
Annotations annotations = null;
|
||||||
|
|
||||||
JetDeclaration declaration = PsiTreeUtil.getParentOfType(jetAnnotationEntry, JetDeclaration.class);
|
JetModifierList modifierList = PsiTreeUtil.getParentOfType(jetAnnotationEntry, JetModifierList.class);
|
||||||
|
JetDeclaration declaration = PsiTreeUtil.getParentOfType(modifierList, JetDeclaration.class);
|
||||||
if (declaration != null) {
|
if (declaration != null) {
|
||||||
Annotated descriptor = resolveSession.resolveToDescriptor(declaration);
|
annotations = getAnnotationsByDeclaration(resolveSession, modifierList, declaration);
|
||||||
annotations = descriptor.getAnnotations();
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JetFileAnnotationList fileAnnotationList = PsiTreeUtil.getParentOfType(jetAnnotationEntry, JetFileAnnotationList.class);
|
JetFileAnnotationList fileAnnotationList = PsiTreeUtil.getParentOfType(jetAnnotationEntry, JetFileAnnotationList.class);
|
||||||
@@ -252,6 +252,20 @@ public abstract class ElementResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Annotations getAnnotationsByDeclaration(
|
||||||
|
ResolveSession resolveSession,
|
||||||
|
JetModifierList modifierList,
|
||||||
|
JetDeclaration declaration
|
||||||
|
) {
|
||||||
|
Annotations annotations;Annotated descriptor = resolveSession.resolveToDescriptor(declaration);
|
||||||
|
if (declaration instanceof JetClass && modifierList == ((JetClass) declaration).getPrimaryConstructorModifierList()) {
|
||||||
|
descriptor = ((ClassDescriptor)descriptor).getUnsubstitutedPrimaryConstructor();
|
||||||
|
assert descriptor != null : "No constructor found: " + declaration.getText();
|
||||||
|
}
|
||||||
|
annotations = descriptor.getAnnotations();
|
||||||
|
return annotations;
|
||||||
|
}
|
||||||
|
|
||||||
private static void typeParameterAdditionalResolve(KotlinCodeAnalyzer analyzer, JetTypeParameter typeParameter) {
|
private static void typeParameterAdditionalResolve(KotlinCodeAnalyzer analyzer, JetTypeParameter typeParameter) {
|
||||||
DeclarationDescriptor descriptor = analyzer.resolveToDescriptor(typeParameter);
|
DeclarationDescriptor descriptor = analyzer.resolveToDescriptor(typeParameter);
|
||||||
assert descriptor instanceof LazyEntity;
|
assert descriptor instanceof LazyEntity;
|
||||||
|
|||||||
Reference in New Issue
Block a user