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:
committed by
Valentin Kipyatkov
parent
86495fd136
commit
14f3e4c758
+4
-1
@@ -41,6 +41,9 @@ import org.jetbrains.kotlin.serialization.js.DynamicTypeDeserializer
|
|||||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||||
import java.util.*
|
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) {
|
class TypeClsStubBuilder(private val c: ClsStubBuilderContext) {
|
||||||
|
|
||||||
fun createTypeReferenceStub(parent: StubElement<out PsiElement>, type: Type) {
|
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 annotations = c.components.annotationLoader.loadTypeAnnotations(type, c.nameResolver).filterNot {
|
||||||
val isTopLevelClass = !it.isNestedClass
|
val isTopLevelClass = !it.isNestedClass
|
||||||
isTopLevelClass && it.asSingleFqName() in ANNOTATIONS_COPIED_TO_TYPES
|
isTopLevelClass && it.asSingleFqName() in ANNOTATIONS_NOT_LOADED_FOR_TYPES
|
||||||
}
|
}
|
||||||
|
|
||||||
val effectiveParent =
|
val effectiveParent =
|
||||||
|
|||||||
+3
-1
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.idea.decompiler.textBuilder
|
package org.jetbrains.kotlin.idea.decompiler.textBuilder
|
||||||
|
|
||||||
import com.intellij.openapi.util.TextRange
|
import com.intellij.openapi.util.TextRange
|
||||||
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.idea.decompiler.navigation.ByDescriptorIndexer
|
import org.jetbrains.kotlin.idea.decompiler.navigation.ByDescriptorIndexer
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
@@ -38,8 +39,9 @@ fun DescriptorRendererOptions.defaultDecompilerRendererOptions() {
|
|||||||
classWithPrimaryConstructor = true
|
classWithPrimaryConstructor = true
|
||||||
secondaryConstructorsAsPrimary = false
|
secondaryConstructorsAsPrimary = false
|
||||||
modifiers = DescriptorRendererModifier.ALL
|
modifiers = DescriptorRendererModifier.ALL
|
||||||
excludedTypeAnnotationClasses = ExcludedTypeAnnotations.annotationsForNullabilityAndMutability
|
excludedTypeAnnotationClasses = (ExcludedTypeAnnotations.annotationsForNullabilityAndMutability + KotlinBuiltIns.FQ_NAMES.parameterName).toSet()
|
||||||
alwaysRenderModifiers = true
|
alwaysRenderModifiers = true
|
||||||
|
parameterNamesInFunctionalTypes = false // to support parameters names in decompiled text we need to load annotation arguments
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildDecompiledText(
|
fun buildDecompiledText(
|
||||||
|
|||||||
+9
@@ -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 */ }
|
||||||
|
}
|
||||||
|
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
class FunctionalTypeWithNamedArguments {
|
||||||
|
public fun f(ftype: (key: String, value: Any?) -> Any?): String = ""
|
||||||
|
}
|
||||||
@@ -22,4 +22,6 @@ abstract class Types {
|
|||||||
abstract val extFun: @ExtensionFunctionType Function2<Int, Int, Unit>
|
abstract val extFun: @ExtensionFunctionType Function2<Int, Int, Unit>
|
||||||
abstract val listExtStarFun: List<@ExtensionFunctionType Function1<*, *>>
|
abstract val listExtStarFun: List<@ExtensionFunctionType Function1<*, *>>
|
||||||
abstract val funTypeWithStarAndNonStar: Function1<*, Int>
|
abstract val funTypeWithStarAndNonStar: Function1<*, Int>
|
||||||
|
|
||||||
|
abstract fun functionTypeWithNamedArgs(fType: (first: String, second: Any?) -> Int)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -380,6 +380,36 @@ PsiJetFileStubImpl[package=test]
|
|||||||
REFERENCE_EXPRESSION:[referencedName=List]
|
REFERENCE_EXPRESSION:[referencedName=List]
|
||||||
TYPE_ARGUMENT_LIST:
|
TYPE_ARGUMENT_LIST:
|
||||||
TYPE_PROJECTION:[projectionKind=STAR]
|
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]
|
FUN:[fqName=test.Types.extOnFunctionType, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=true, isExtension=true, isTopLevel=false, name=extOnFunctionType]
|
||||||
MODIFIER_LIST:[public final]
|
MODIFIER_LIST:[public final]
|
||||||
TYPE_PARAMETER_LIST:
|
TYPE_PARAMETER_LIST:
|
||||||
|
|||||||
+2
-1
@@ -23,13 +23,14 @@ import org.jetbrains.kotlin.idea.decompiler.js.buildDecompiledTextFromJsMetadata
|
|||||||
import org.jetbrains.kotlin.idea.test.KotlinStdJSProjectDescriptor
|
import org.jetbrains.kotlin.idea.test.KotlinStdJSProjectDescriptor
|
||||||
import org.jetbrains.kotlin.idea.vfilefinder.JsVirtualFileFinder
|
import org.jetbrains.kotlin.idea.vfilefinder.JsVirtualFileFinder
|
||||||
import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder
|
import org.jetbrains.kotlin.load.kotlin.VirtualFileFinder
|
||||||
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
|
||||||
class KotlinJavaScriptStubConsistencyTest : StubConsistencyBaseTest() {
|
class KotlinJavaScriptStubConsistencyTest : StubConsistencyBaseTest() {
|
||||||
override fun getFileIds() = listOf(
|
override fun getFileIds() = listOf(
|
||||||
"java.util", "jquery", "jquery.ui",
|
"java.util", "jquery", "jquery.ui",
|
||||||
"kotlin", "kotlin.browser", "kotlin.dom", "kotlin.js"
|
"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 =
|
override fun getVirtualFileFinder(): VirtualFileFinder =
|
||||||
JsVirtualFileFinder.SERVICE.getInstance(project)
|
JsVirtualFileFinder.SERVICE.getInstance(project)
|
||||||
|
|||||||
+6
@@ -125,6 +125,12 @@ public class CommonDecompiledTextFromJsMetadataTestGenerated extends AbstractCom
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("FunctionalTypeWithNamedArguments")
|
||||||
|
public void testFunctionalTypeWithNamedArguments() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/FunctionalTypeWithNamedArguments/");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("Inherited")
|
@TestMetadata("Inherited")
|
||||||
public void testInherited() throws Exception {
|
public void testInherited() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/Inherited/");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/Inherited/");
|
||||||
|
|||||||
+6
@@ -95,6 +95,12 @@ public class CommonDecompiledTextTestGenerated extends AbstractCommonDecompiledT
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("FunctionalTypeWithNamedArguments")
|
||||||
|
public void testFunctionalTypeWithNamedArguments() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/FunctionalTypeWithNamedArguments/");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("Inherited")
|
@TestMetadata("Inherited")
|
||||||
public void testInherited() throws Exception {
|
public void testInherited() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/Inherited/");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/decompiledText/Inherited/");
|
||||||
|
|||||||
Reference in New Issue
Block a user