Render flexible types with enhancement as enhanced in IDE (KT-25622)
Main targets for the fix is completion, parameters info, inlay hints and override/implement. Other IDE functions might be affected. #KT-24911 Fixed #KT-25616 Fixed #KT-25622 Fixed
This commit is contained in:
@@ -48,6 +48,7 @@ object IdeDescriptorRenderers {
|
|||||||
renderDefaultVisibility = false
|
renderDefaultVisibility = false
|
||||||
overrideRenderingPolicy = OverrideRenderingPolicy.RENDER_OVERRIDE
|
overrideRenderingPolicy = OverrideRenderingPolicy.RENDER_OVERRIDE
|
||||||
unitReturnType = false
|
unitReturnType = false
|
||||||
|
enhancedTypes = true
|
||||||
modifiers = DescriptorRendererModifier.ALL
|
modifiers = DescriptorRendererModifier.ALL
|
||||||
renderUnabbreviatedType = false
|
renderUnabbreviatedType = false
|
||||||
annotationArgumentsRenderingPolicy = AnnotationArgumentsRenderingPolicy.UNLESS_EMPTY
|
annotationArgumentsRenderingPolicy = AnnotationArgumentsRenderingPolicy.UNLESS_EMPTY
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ fun KotlinType.approximateFlexibleTypes(
|
|||||||
preferStarForRaw: Boolean = false
|
preferStarForRaw: Boolean = false
|
||||||
): KotlinType {
|
): KotlinType {
|
||||||
if (isDynamic()) return this
|
if (isDynamic()) return this
|
||||||
return approximateNonDynamicFlexibleTypes(preferNotNull, preferStarForRaw)
|
return unwrapEnhancement().approximateNonDynamicFlexibleTypes(preferNotNull, preferStarForRaw)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KotlinType.approximateNonDynamicFlexibleTypes(
|
private fun KotlinType.approximateNonDynamicFlexibleTypes(
|
||||||
|
|||||||
+5
-1
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.idea.completion.handlers.KotlinFunctionInsertHandler
|
|||||||
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
|
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
|
||||||
import org.jetbrains.kotlin.idea.core.completion.PackageLookupObject
|
import org.jetbrains.kotlin.idea.core.completion.PackageLookupObject
|
||||||
import org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension
|
import org.jetbrains.kotlin.idea.highlighter.dsl.DslHighlighterExtension
|
||||||
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
|
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
@@ -50,7 +51,10 @@ class BasicLookupElementFactory(
|
|||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
// we skip parameter names in functional types in most of cases for shortness
|
// we skip parameter names in functional types in most of cases for shortness
|
||||||
val SHORT_NAMES_RENDERER = DescriptorRenderer.SHORT_NAMES_IN_TYPES.withOptions { parameterNamesInFunctionalTypes = false }
|
val SHORT_NAMES_RENDERER = DescriptorRenderer.SHORT_NAMES_IN_TYPES.withOptions {
|
||||||
|
enhancedTypes = true
|
||||||
|
parameterNamesInFunctionalTypes = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createLookupElement(
|
fun createLookupElement(
|
||||||
|
|||||||
idea/idea-completion/testData/basic/multifile/EnhancementFlexibleTypes/EnhancementFlexibleTypes.java
Vendored
+12
@@ -0,0 +1,12 @@
|
|||||||
|
import androidx.annotation.RecentlyNonNull;
|
||||||
|
import androidx.annotation.RecentlyNullable;
|
||||||
|
|
||||||
|
public class EnhancementFlexibleTypes {
|
||||||
|
public static void testNullable(@RecentlyNullable String string) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void testNotNull(@RecentlyNonNull String string) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+6
@@ -0,0 +1,6 @@
|
|||||||
|
fun temp() {
|
||||||
|
EnhancementFlexibleTypes.test<caret>
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXIST: { lookupString: "testNotNull", tailText:"(string: String)" }
|
||||||
|
// EXIST: { lookupString: "testNullable", tailText:"(string: String?)" }
|
||||||
Vendored
+8
@@ -0,0 +1,8 @@
|
|||||||
|
package androidx.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Target({ElementType.PARAMETER, ElementType.TYPE})
|
||||||
|
public @interface RecentlyNonNull {
|
||||||
|
}
|
||||||
Vendored
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package androidx.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
import java.lang.reflect.Parameter;
|
||||||
|
|
||||||
|
@Target({ElementType.PARAMETER, ElementType.TYPE})
|
||||||
|
public @interface RecentlyNullable {
|
||||||
|
}
|
||||||
+5
@@ -74,6 +74,11 @@ public class MultiFileJvmBasicCompletionTestGenerated extends AbstractMultiFileJ
|
|||||||
runTest("idea/idea-completion/testData/basic/multifile/DoNotCompleteWithConstraints/");
|
runTest("idea/idea-completion/testData/basic/multifile/DoNotCompleteWithConstraints/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("EnhancementFlexibleTypes")
|
||||||
|
public void testEnhancementFlexibleTypes() throws Exception {
|
||||||
|
runTest("idea/idea-completion/testData/basic/multifile/EnhancementFlexibleTypes/");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("EntriesOfNotImportedEnumFromKotlin")
|
@TestMetadata("EntriesOfNotImportedEnumFromKotlin")
|
||||||
public void testEntriesOfNotImportedEnumFromKotlin() throws Exception {
|
public void testEntriesOfNotImportedEnumFromKotlin() throws Exception {
|
||||||
runTest("idea/idea-completion/testData/basic/multifile/EntriesOfNotImportedEnumFromKotlin/");
|
runTest("idea/idea-completion/testData/basic/multifile/EntriesOfNotImportedEnumFromKotlin/");
|
||||||
|
|||||||
+1
@@ -157,6 +157,7 @@ private val OVERRIDE_RENDERER = DescriptorRenderer.withOptions {
|
|||||||
classifierNamePolicy = ClassifierNamePolicy.SOURCE_CODE_QUALIFIED
|
classifierNamePolicy = ClassifierNamePolicy.SOURCE_CODE_QUALIFIED
|
||||||
overrideRenderingPolicy = OverrideRenderingPolicy.RENDER_OVERRIDE
|
overrideRenderingPolicy = OverrideRenderingPolicy.RENDER_OVERRIDE
|
||||||
unitReturnType = false
|
unitReturnType = false
|
||||||
|
enhancedTypes = true
|
||||||
typeNormalizer = IdeDescriptorRenderers.APPROXIMATE_FLEXIBLE_TYPES
|
typeNormalizer = IdeDescriptorRenderers.APPROXIMATE_FLEXIBLE_TYPES
|
||||||
renderUnabbreviatedType = false
|
renderUnabbreviatedType = false
|
||||||
annotationFilter = {
|
annotationFilter = {
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
|||||||
import org.jetbrains.kotlin.idea.core.OptionalParametersHelper
|
import org.jetbrains.kotlin.idea.core.OptionalParametersHelper
|
||||||
import org.jetbrains.kotlin.idea.core.resolveCandidates
|
import org.jetbrains.kotlin.idea.core.resolveCandidates
|
||||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||||
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||||
import org.jetbrains.kotlin.idea.util.ShadowedDeclarationsFilter
|
import org.jetbrains.kotlin.idea.util.ShadowedDeclarationsFilter
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.load.java.NULLABILITY_ANNOTATIONS
|
import org.jetbrains.kotlin.load.java.NULLABILITY_ANNOTATIONS
|
||||||
@@ -248,6 +249,7 @@ abstract class KotlinParameterInfoWithCallHandlerBase<TArgumentList : KtElement,
|
|||||||
override fun getParametersForDocumentation(item: FunctionDescriptor, context: ParameterInfoContext) = emptyArray<Any>()
|
override fun getParametersForDocumentation(item: FunctionDescriptor, context: ParameterInfoContext) = emptyArray<Any>()
|
||||||
|
|
||||||
private val RENDERER = DescriptorRenderer.SHORT_NAMES_IN_TYPES.withOptions {
|
private val RENDERER = DescriptorRenderer.SHORT_NAMES_IN_TYPES.withOptions {
|
||||||
|
enhancedTypes = true
|
||||||
renderUnabbreviatedType = false
|
renderUnabbreviatedType = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ class ImportAwareClassifierNamePolicy(
|
|||||||
|
|
||||||
fun getInlayHintsTypeRenderer(bindingContext: BindingContext, context: KtElement) =
|
fun getInlayHintsTypeRenderer(bindingContext: BindingContext, context: KtElement) =
|
||||||
DescriptorRenderer.COMPACT_WITH_SHORT_TYPES.withOptions {
|
DescriptorRenderer.COMPACT_WITH_SHORT_TYPES.withOptions {
|
||||||
|
enhancedTypes = true
|
||||||
textFormat = RenderingFormat.PLAIN
|
textFormat = RenderingFormat.PLAIN
|
||||||
renderUnabbreviatedType = false
|
renderUnabbreviatedType = false
|
||||||
classifierNamePolicy = ImportAwareClassifierNamePolicy(bindingContext, context)
|
classifierNamePolicy = ImportAwareClassifierNamePolicy(bindingContext, context)
|
||||||
|
|||||||
idea/testData/codeInsight/overrideImplement/androidxNotNull/androidx/annotation/RecentlyNonNull.java
Vendored
+8
@@ -0,0 +1,8 @@
|
|||||||
|
package androidx.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Target({ElementType.PARAMETER, ElementType.TYPE})
|
||||||
|
public @interface RecentlyNonNull {
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package androidx.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
import java.lang.reflect.Parameter;
|
||||||
|
|
||||||
|
@Target({ElementType.PARAMETER, ElementType.TYPE})
|
||||||
|
public @interface RecentlyNullable {
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package foo;
|
||||||
|
|
||||||
|
import androidx.annotation.RecentlyNonNull;
|
||||||
|
import androidx.annotation.RecentlyNullable;
|
||||||
|
|
||||||
|
public class A {
|
||||||
|
public @RecentlyNonNull String foo(@RecentlyNonNull String s1, @RecentlyNullable String s2) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import foo.A
|
||||||
|
|
||||||
|
class B : A() {
|
||||||
|
<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import foo.A
|
||||||
|
|
||||||
|
class B : A() {
|
||||||
|
override fun foo(s1: String, s2: String?): String {
|
||||||
|
return super.foo(s1, s2)
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -3,5 +3,5 @@ fun test() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Text: (<highlight>s1: String?</highlight>, s2: String, a: String!, b: String!, s3: String!), Disabled: false, Strikeout: false, Green: true
|
Text: (<highlight>s1: String?</highlight>, s2: String, a: String?, b: String, s3: String!), Disabled: false, Strikeout: false, Green: true
|
||||||
*/
|
*/
|
||||||
@@ -25,6 +25,10 @@ class OverrideImplementTest : AbstractOverrideImplementTest() {
|
|||||||
myFixture.testDataPath = PluginTestCaseBase.getTestDataPathBase() + "/codeInsight/overrideImplement"
|
myFixture.testDataPath = PluginTestCaseBase.getTestDataPathBase() + "/codeInsight/overrideImplement"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun testAndroidxNotNull() {
|
||||||
|
doOverrideDirectoryTest("foo")
|
||||||
|
}
|
||||||
|
|
||||||
fun testEmptyClassBodyFunctionMethod() {
|
fun testEmptyClassBodyFunctionMethod() {
|
||||||
doImplementFileTest()
|
doImplementFileTest()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user