ClsStubBuilder: fix stub builder in case of java types annotated with special annotations

This commit is contained in:
Pavel V. Talanov
2015-05-18 18:30:14 +03:00
parent 09e7e0da4d
commit 5b14d5be28
6 changed files with 76 additions and 2 deletions
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.psi.stubs.impl.KotlinFileStubImpl;
import java.io.IOException;
public class JetFileElementType extends IStubFileElementType<KotlinFileStub> {
public static final int STUB_VERSION = 44;
public static final int STUB_VERSION = 45;
private static final String NAME = "kotlin.FILE";
@@ -21,6 +21,7 @@ import com.intellij.psi.stubs.StubElement
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.lexer.JetModifierKeywordToken
import org.jetbrains.kotlin.lexer.JetTokens
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
@@ -43,7 +44,10 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
fun createTypeReferenceStub(parent: StubElement<out PsiElement>, typeProto: Type) {
val typeReference = KotlinPlaceHolderStubImpl<JetTypeReference>(parent, JetStubElementTypes.TYPE_REFERENCE)
val typeAnnotations = c.components.annotationLoader.loadTypeAnnotations(typeProto, c.nameResolver)
val typeAnnotations = c.components.annotationLoader.loadTypeAnnotations(typeProto, c.nameResolver).filterNot {
val isTopLevelClass = !it.isNestedClass()
isTopLevelClass && it.asSingleFqName() in JvmAnnotationNames.ANNOTATIONS_COPIED_TO_TYPES
}
if (typeAnnotations.isNotEmpty()) {
createAnnotationStubs(typeAnnotations, typeReference, needWrappingAnnotationEntries = true)
}
@@ -0,0 +1,7 @@
package test
public class AnnotatedFlexibleTypes(val javaClass: d.JavaClass) {
fun foo() = javaClass.foo()
val bar = javaClass.bar()
}
@@ -0,0 +1,44 @@
PsiJetFileStubImpl[package=test]
PACKAGE_DIRECTIVE:
REFERENCE_EXPRESSION:[referencedName=test]
CLASS:[fqName=test.AnnotatedFlexibleTypes, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=true, name=AnnotatedFlexibleTypes, superNames=[]]
MODIFIER_LIST:[public final]
PRIMARY_CONSTRUCTOR:
MODIFIER_LIST:[public]
VALUE_PARAMETER_LIST:
VALUE_PARAMETER:[fqName=null, hasDefaultValue=false, hasValOrVarNode=false, isMutable=false, name=javaClass]
TYPE_REFERENCE:
USER_TYPE:[isAbsoluteInRootPackage=false]
USER_TYPE:[isAbsoluteInRootPackage=false]
REFERENCE_EXPRESSION:[referencedName=d]
REFERENCE_EXPRESSION:[referencedName=JavaClass]
CLASS_BODY:
PROPERTY:[fqName=test.AnnotatedFlexibleTypes.bar, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=bar]
MODIFIER_LIST:[internal final]
TYPE_REFERENCE:
USER_TYPE:[isAbsoluteInRootPackage=false]
USER_TYPE:[isAbsoluteInRootPackage=false]
REFERENCE_EXPRESSION:[referencedName=kotlin]
REFERENCE_EXPRESSION:[referencedName=MutableCollection]
TYPE_ARGUMENT_LIST:
TYPE_PROJECTION:[projectionKind=NONE]
TYPE_REFERENCE:
USER_TYPE:[isAbsoluteInRootPackage=false]
USER_TYPE:[isAbsoluteInRootPackage=false]
REFERENCE_EXPRESSION:[referencedName=kotlin]
REFERENCE_EXPRESSION:[referencedName=Int]
PROPERTY:[fqName=test.AnnotatedFlexibleTypes.javaClass, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=javaClass]
MODIFIER_LIST:[internal final]
TYPE_REFERENCE:
USER_TYPE:[isAbsoluteInRootPackage=false]
USER_TYPE:[isAbsoluteInRootPackage=false]
REFERENCE_EXPRESSION:[referencedName=d]
REFERENCE_EXPRESSION:[referencedName=JavaClass]
FUN:[fqName=test.AnnotatedFlexibleTypes.foo, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=foo]
MODIFIER_LIST:[internal final]
VALUE_PARAMETER_LIST:
TYPE_REFERENCE:
USER_TYPE:[isAbsoluteInRootPackage=false]
USER_TYPE:[isAbsoluteInRootPackage=false]
REFERENCE_EXPRESSION:[referencedName=kotlin]
REFERENCE_EXPRESSION:[referencedName=Int]
@@ -0,0 +1,13 @@
package d
import org.jetbrains.annotations.*;
public abstract class JavaClass {
@NotNull
@Nullable
public abstract Integer foo();
@Mutable
@ReadOnly
public abstract java.util.Collection<Integer> bar();
}
@@ -35,6 +35,12 @@ public class ClsStubBuilderTestGenerated extends AbstractClsStubBuilderTest {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/decompiler/stubBuilder"), Pattern.compile("^([^\\.]+)$"), false);
}
@TestMetadata("AnnotatedFlexibleTypes")
public void testAnnotatedFlexibleTypes() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/stubBuilder/AnnotatedFlexibleTypes/");
doTest(fileName);
}
@TestMetadata("AnnotationClass")
public void testAnnotationClass() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/decompiler/stubBuilder/AnnotationClass/");