SpecifyTypeExplicitlyIntention: remove annotations from result type
#KT-36930 Fixed
This commit is contained in:
@@ -17,7 +17,12 @@
|
|||||||
package org.jetbrains.kotlin.idea.util
|
package org.jetbrains.kotlin.idea.util
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.annotations.BuiltInAnnotationDescriptor
|
import org.jetbrains.kotlin.descriptors.annotations.BuiltInAnnotationDescriptor
|
||||||
import org.jetbrains.kotlin.renderer.*
|
import org.jetbrains.kotlin.renderer.AnnotationArgumentsRenderingPolicy
|
||||||
|
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy
|
||||||
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||||
|
import org.jetbrains.kotlin.renderer.DescriptorRenderer.Companion.FQ_NAMES_IN_TYPES
|
||||||
|
import org.jetbrains.kotlin.renderer.DescriptorRendererModifier
|
||||||
|
import org.jetbrains.kotlin.renderer.OverrideRenderingPolicy
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.isDynamic
|
import org.jetbrains.kotlin.types.isDynamic
|
||||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||||
@@ -62,6 +67,11 @@ object IdeDescriptorRenderers {
|
|||||||
typeNormalizer = { APPROXIMATE_FLEXIBLE_TYPES(unwrapAnonymousType(it)) }
|
typeNormalizer = { APPROXIMATE_FLEXIBLE_TYPES(unwrapAnonymousType(it)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
val FQ_NAMES_IN_TYPES_WITH_NORMALIZER: DescriptorRenderer = FQ_NAMES_IN_TYPES.withOptions {
|
||||||
|
typeNormalizer = { APPROXIMATE_FLEXIBLE_TYPES(unwrapAnonymousType(it)) }
|
||||||
|
}
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
val SOURCE_CODE_TYPES: DescriptorRenderer = BASE.withOptions {
|
val SOURCE_CODE_TYPES: DescriptorRenderer = BASE.withOptions {
|
||||||
classifierNamePolicy = ClassifierNamePolicy.SOURCE_CODE_QUALIFIED
|
classifierNamePolicy = ClassifierNamePolicy.SOURCE_CODE_QUALIFIED
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ class SpecifyTypeExplicitlyIntention : SelfTargetingRangeIntention<KtCallableDec
|
|||||||
IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_NO_ANNOTATIONS.renderType(element)
|
IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_NO_ANNOTATIONS.renderType(element)
|
||||||
|
|
||||||
override fun getResult(element: KotlinType): String {
|
override fun getResult(element: KotlinType): String {
|
||||||
val renderType = IdeDescriptorRenderers.SOURCE_CODE.renderType(element)
|
val renderType = IdeDescriptorRenderers.FQ_NAMES_IN_TYPES_WITH_NORMALIZER.renderType(element)
|
||||||
val descriptor = element.constructor.declarationDescriptor
|
val descriptor = element.constructor.declarationDescriptor
|
||||||
if (descriptor?.name?.asString() == renderType) {
|
if (descriptor?.name?.asString() == renderType) {
|
||||||
val className = (DescriptorToSourceUtils.descriptorToDeclaration(descriptor) as? KtClass)?.nameIdentifier?.text
|
val className = (DescriptorToSourceUtils.descriptorToDeclaration(descriptor) as? KtClass)?.nameIdentifier?.text
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package source;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
class A {
|
||||||
|
@NotNull
|
||||||
|
public String doSmth() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package org.jetbrains.annotations
|
||||||
|
|
||||||
|
annotation class NotNull
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package source
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
val myVar: String = A().doSmth()
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package source;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
class A {
|
||||||
|
@NotNull
|
||||||
|
public String doSmth() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package org.jetbrains.annotations
|
||||||
|
|
||||||
|
annotation class NotNull
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package source
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
val myVar<caret> = A().doSmth()
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"mainFile": "source/kt36930.kt",
|
||||||
|
"intentionClass": "org.jetbrains.kotlin.idea.intentions.SpecifyTypeExplicitlyIntention",
|
||||||
|
"withRuntime": true
|
||||||
|
}
|
||||||
+5
@@ -142,4 +142,9 @@ public class MultiFileIntentionTestGenerated extends AbstractMultiFileIntentionT
|
|||||||
public void testObjectLiteralToLambda_ObjectLiteralToLambda() throws Exception {
|
public void testObjectLiteralToLambda_ObjectLiteralToLambda() throws Exception {
|
||||||
runTest("idea/testData/multiFileIntentions/objectLiteralToLambda/objectLiteralToLambda.test");
|
runTest("idea/testData/multiFileIntentions/objectLiteralToLambda/objectLiteralToLambda.test");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("specifyTypeExplicitly/specifyTypeExplicitly.test")
|
||||||
|
public void testSpecifyTypeExplicitly_SpecifyTypeExplicitly() throws Exception {
|
||||||
|
runTest("idea/testData/multiFileIntentions/specifyTypeExplicitly/specifyTypeExplicitly.test");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user