Cls stubs and decompiled text: Do not render parameter names in decompiled text and do not load ParameterName annotation in stubs

Add tests for decompiled text and stubs
This commit is contained in:
Pavel V. Talanov
2016-09-20 16:38:34 +03:00
committed by Valentin Kipyatkov
parent 86495fd136
commit 14f3e4c758
9 changed files with 67 additions and 3 deletions
@@ -41,6 +41,9 @@ import org.jetbrains.kotlin.serialization.js.DynamicTypeDeserializer
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
import java.util.*
// TODO: see DescriptorRendererOptions.excludedTypeAnnotationClasses for decompiler
private val ANNOTATIONS_NOT_LOADED_FOR_TYPES = (ANNOTATIONS_COPIED_TO_TYPES + KotlinBuiltIns.FQ_NAMES.parameterName).toSet()
class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
fun createTypeReferenceStub(parent: StubElement<out PsiElement>, type: Type) {
@@ -49,7 +52,7 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
val annotations = c.components.annotationLoader.loadTypeAnnotations(type, c.nameResolver).filterNot {
val isTopLevelClass = !it.isNestedClass
isTopLevelClass && it.asSingleFqName() in ANNOTATIONS_COPIED_TO_TYPES
isTopLevelClass && it.asSingleFqName() in ANNOTATIONS_NOT_LOADED_FOR_TYPES
}
val effectiveParent =
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.idea.decompiler.textBuilder
import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.decompiler.navigation.ByDescriptorIndexer
import org.jetbrains.kotlin.name.FqName
@@ -38,8 +39,9 @@ fun DescriptorRendererOptions.defaultDecompilerRendererOptions() {
classWithPrimaryConstructor = true
secondaryConstructorsAsPrimary = false
modifiers = DescriptorRendererModifier.ALL
excludedTypeAnnotationClasses = ExcludedTypeAnnotations.annotationsForNullabilityAndMutability
excludedTypeAnnotationClasses = (ExcludedTypeAnnotations.annotationsForNullabilityAndMutability + KotlinBuiltIns.FQ_NAMES.parameterName).toSet()
alwaysRenderModifiers = true
parameterNamesInFunctionalTypes = false // to support parameters names in decompiled text we need to load annotation arguments
}
fun buildDecompiledText(
@@ -0,0 +1,9 @@
// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available
package test
public final class FunctionalTypeWithNamedArguments public constructor() {
public final fun f(ftype: (kotlin.String, kotlin.Any?) -> kotlin.Any?): kotlin.String { /* compiled code */ }
}
@@ -0,0 +1,5 @@
package test
class FunctionalTypeWithNamedArguments {
public fun f(ftype: (key: String, value: Any?) -> Any?): String = ""
}
+2
View File
@@ -22,4 +22,6 @@ abstract class Types {
abstract val extFun: @ExtensionFunctionType Function2<Int, Int, Unit>
abstract val listExtStarFun: List<@ExtensionFunctionType Function1<*, *>>
abstract val funTypeWithStarAndNonStar: Function1<*, Int>
abstract fun functionTypeWithNamedArgs(fType: (first: String, second: Any?) -> Int)
}
+30
View File
@@ -380,6 +380,36 @@ PsiJetFileStubImpl[package=test]
REFERENCE_EXPRESSION:[referencedName=List]
TYPE_ARGUMENT_LIST:
TYPE_PROJECTION:[projectionKind=STAR]
FUN:[fqName=test.Types.functionTypeWithNamedArgs, hasBlockBody=true, hasBody=false, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=functionTypeWithNamedArgs]
MODIFIER_LIST:[abstract public]
VALUE_PARAMETER_LIST:
VALUE_PARAMETER:[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=fType]
TYPE_REFERENCE:
FUNCTION_TYPE:
VALUE_PARAMETER_LIST:
VALUE_PARAMETER:[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=null]
TYPE_REFERENCE:
USER_TYPE:
USER_TYPE:
REFERENCE_EXPRESSION:[referencedName=kotlin]
REFERENCE_EXPRESSION:[referencedName=String]
VALUE_PARAMETER:[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=null]
TYPE_REFERENCE:
NULLABLE_TYPE:
USER_TYPE:
USER_TYPE:
REFERENCE_EXPRESSION:[referencedName=kotlin]
REFERENCE_EXPRESSION:[referencedName=Any]
TYPE_REFERENCE:
USER_TYPE:
USER_TYPE:
REFERENCE_EXPRESSION:[referencedName=kotlin]
REFERENCE_EXPRESSION:[referencedName=Int]
TYPE_REFERENCE:
USER_TYPE:
USER_TYPE:
REFERENCE_EXPRESSION:[referencedName=kotlin]
REFERENCE_EXPRESSION:[referencedName=Unit]
FUN:[fqName=test.Types.extOnFunctionType, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=true, isExtension=true, isTopLevel=false, name=extOnFunctionType]
MODIFIER_LIST:[public final]
TYPE_PARAMETER_LIST:
@@ -23,13 +23,14 @@ import org.jetbrains.kotlin.idea.decompiler.js.buildDecompiledTextFromJsMetadata
import org.jetbrains.kotlin.idea.test.KotlinStdJSProjectDescriptor
import org.jetbrains.kotlin.idea.vfilefinder.JsVirtualFileFinder
import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
class KotlinJavaScriptStubConsistencyTest : StubConsistencyBaseTest() {
override fun getFileIds() = listOf(
"java.util", "jquery", "jquery.ui",
"kotlin", "kotlin.browser", "kotlin.dom", "kotlin.js"
).map { OldPackageFacadeClassUtils.getPackageClassId(FqName(it)) }
).map { OldPackageFacadeClassUtils.getPackageClassId(FqName(it)) } + ClassId.topLevel(FqName("kotlin.js.JsonClass"))
override fun getVirtualFileFinder(): VirtualFileFinder =
JsVirtualFileFinder.SERVICE.getInstance(project)
@@ -125,6 +125,12 @@ public class CommonDecompiledTextFromJsMetadataTestGenerated extends AbstractCom
doTest(fileName);
}
@TestMetadata("FunctionalTypeWithNamedArguments")
public void testFunctionalTypeWithNamedArguments() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/FunctionalTypeWithNamedArguments/");
doTest(fileName);
}
@TestMetadata("Inherited")
public void testInherited() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/Inherited/");
@@ -95,6 +95,12 @@ public class CommonDecompiledTextTestGenerated extends AbstractCommonDecompiledT
doTest(fileName);
}
@TestMetadata("FunctionalTypeWithNamedArguments")
public void testFunctionalTypeWithNamedArguments() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/FunctionalTypeWithNamedArguments/");
doTest(fileName);
}
@TestMetadata("Inherited")
public void testInherited() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/Inherited/");