Java type annotations supported in LazyJavaTypeResolver

This commit is contained in:
Andrey Breslav
2015-05-07 21:58:22 +03:00
committed by Denis Zharkov
parent eaae88133c
commit c6b91b0f81
6 changed files with 45 additions and 2 deletions
@@ -32,7 +32,7 @@ public abstract class JavaClassifierImpl<Psi extends PsiClass> extends JavaEleme
super(psiClass);
}
@NotNull
@Nullable
@Override
public PsiAnnotationOwner getAnnotationOwnerPsi() {
return getPsi().getModifierList();
@@ -0,0 +1,16 @@
package test;
import java.lang.annotation.*;
@Target(ElementType.TYPE_USE)
@interface A {
String value() default "";
}
interface G<T> {}
interface G2<A, B> {}
public interface TypeAnnotations<TT> {
void f(G<@A String> p);
void f(G2<@A String, @A Integer> p);
}
@@ -0,0 +1,6 @@
package test
public interface TypeAnnotations</*0*/ TT> {
public abstract fun f(/*0*/ p: test.G2<@[test.A()] kotlin.String!, @[test.A()] kotlin.Int!>!): kotlin.Unit
public abstract fun f(/*0*/ p: test.G<@[test.A()] kotlin.String!>!): kotlin.Unit
}
@@ -5156,6 +5156,12 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
doTestSourceJava(fileName);
}
@TestMetadata("TypeAnnotations.java")
public void testTypeAnnotations() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/sourceJava/TypeAnnotations.java");
doTestSourceJava(fileName);
}
@TestMetadata("WrongNumberOfGenericParameters.java")
public void testWrongNumberOfGenericParameters() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/sourceJava/WrongNumberOfGenericParameters.java");
@@ -20,10 +20,12 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.annotations.CompositeAnnotations
import org.jetbrains.kotlin.descriptors.annotations.FilteredAnnotations
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.*
import org.jetbrains.kotlin.load.java.components.TypeUsage
import org.jetbrains.kotlin.load.java.components.TypeUsage.*
import org.jetbrains.kotlin.load.java.lazy.LazyJavaAnnotations
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
import org.jetbrains.kotlin.load.java.lazy.TypeParameterResolver
import org.jetbrains.kotlin.load.java.lazy.types.JavaTypeFlexibility.FLEXIBLE_LOWER_BOUND
@@ -110,6 +112,7 @@ class LazyJavaTypeResolver(
private val javaType: JavaClassifierType,
private val attr: JavaTypeAttributes
) : AbstractLazyType(c.storageManager) {
private val annotations = CompositeAnnotations(listOf(LazyJavaAnnotations(c, javaType), attr.typeAnnotations))
private val classifier = c.storageManager.createNullableLazyValue { javaType.getClassifier() }
@@ -291,7 +294,7 @@ class LazyJavaTypeResolver(
override fun isMarkedNullable(): Boolean = nullable()
override fun getAnnotations() = attr.typeAnnotations
override fun getAnnotations() = annotations
}
public object FlexibleJavaClassifierTypeCapabilities : FlexibleTypeCapabilities {
@@ -65,3 +65,15 @@ class FilteredAnnotations(
override fun isEmpty() = !iterator().hasNext()
}
class CompositeAnnotations(
private val delegates: List<Annotations>
) : Annotations {
override fun isEmpty() = delegates.all { it.isEmpty() }
override fun findAnnotation(fqName: FqName) = delegates.asSequence().map { it.findAnnotation(fqName) }.filterNotNull().firstOrNull()
override fun findExternalAnnotation(fqName: FqName) = delegates.asSequence().map { it.findExternalAnnotation(fqName) }.filterNotNull().firstOrNull()
override fun iterator() = delegates.asSequence().flatMap { it.asSequence() }.iterator()
}