Add layout file name in completion for Android Extension properties
#KT-11051 Fixed
This commit is contained in:
+11
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.synthetic.SamAdapterExtensionFunctionDescriptor
|
||||
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
|
||||
|
||||
class BasicLookupElementFactory(
|
||||
private val project: Project,
|
||||
@@ -246,6 +247,16 @@ class BasicLookupElementFactory(
|
||||
}
|
||||
|
||||
fun appendContainerAndReceiverInformation(descriptor: CallableDescriptor, appendTailText: (String) -> Unit) {
|
||||
|
||||
val information = CompletionInformationProvider.EP_NAME.extensions.firstNotNullResult {
|
||||
it.getContainerAndReceiverInformation(descriptor)
|
||||
}
|
||||
|
||||
if (information != null) {
|
||||
appendTailText(information)
|
||||
return
|
||||
}
|
||||
|
||||
val extensionReceiver = descriptor.original.extensionReceiverParameter
|
||||
when {
|
||||
descriptor is SyntheticJavaPropertyDescriptor -> {
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.completion
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
|
||||
interface CompletionInformationProvider {
|
||||
companion object {
|
||||
val EP_NAME: ExtensionPointName<CompletionInformationProvider> =
|
||||
ExtensionPointName.create("org.jetbrains.kotlin.completionInformationProvider")
|
||||
}
|
||||
|
||||
fun getContainerAndReceiverInformation(descriptor: DeclarationDescriptor): String?
|
||||
}
|
||||
@@ -77,6 +77,7 @@
|
||||
<quickFixContributor implementation="org.jetbrains.kotlin.android.quickfix.AndroidQuickFixRegistrar"/>
|
||||
<projectConfigurator implementation="org.jetbrains.kotlin.android.configure.KotlinAndroidGradleModuleConfigurator"/>
|
||||
<platformGradleDetector implementation="org.jetbrains.kotlin.android.configure.PlatformAndroidGradleDetector"/>
|
||||
<completionInformationProvider implementation="org.jetbrains.kotlin.AndroidExtensionsCompletionInformationProvider" />
|
||||
</extensions>
|
||||
|
||||
<project-components>
|
||||
|
||||
@@ -45,5 +45,7 @@
|
||||
interface="org.jetbrains.kotlin.idea.inspections.gradle.KotlinPlatformGradleDetector"/>
|
||||
<extensionPoint name="scriptHelper"
|
||||
interface="org.jetbrains.kotlin.script.ScriptHelper"/>
|
||||
<extensionPoint name="completionInformationProvider"
|
||||
interface="org.jetbrains.kotlin.idea.completion.CompletionInformationProvider" />
|
||||
</extensionPoints>
|
||||
</idea-plugin>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<orderEntry type="module" module-name="util" />
|
||||
<orderEntry type="module" module-name="tests-common" scope="TEST" />
|
||||
<orderEntry type="module" module-name="cli" scope="TEST" />
|
||||
<orderEntry type="module" module-name="idea-completion" scope="TEST" />
|
||||
<orderEntry type="module" module-name="idea-completion" />
|
||||
<orderEntry type="module" module-name="idea-test-framework" scope="TEST" />
|
||||
<orderEntry type="module" module-name="frontend.java" scope="TEST" />
|
||||
<orderEntry type="module" module-name="idea-live-templates" scope="TEST" />
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin
|
||||
|
||||
import com.intellij.psi.xml.XmlAttributeValue
|
||||
import org.jetbrains.kotlin.android.synthetic.res.AndroidSyntheticProperty
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.kotlin.idea.completion.CompletionInformationProvider
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
|
||||
|
||||
class AndroidExtensionsCompletionInformationProvider : CompletionInformationProvider {
|
||||
override fun getContainerAndReceiverInformation(descriptor: DeclarationDescriptor): String? {
|
||||
if (descriptor !is AndroidSyntheticProperty) {
|
||||
return null
|
||||
}
|
||||
|
||||
val propertyDescriptor = (descriptor as? PropertyDescriptor) ?: return null
|
||||
val attributeValue = (propertyDescriptor.source as? PsiSourceElement)?.psi as? XmlAttributeValue ?: return null
|
||||
val extensionReceiverType = propertyDescriptor.original.extensionReceiverParameter?.type
|
||||
|
||||
return buildString {
|
||||
append(" from ${attributeValue.containingFile.name}")
|
||||
extensionReceiverType?.let { append(" for " + DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(it)) }
|
||||
append(" (Android Extensions)")
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -7,4 +7,4 @@ class MyActivity: Activity() {
|
||||
val button = this.MyBu<caret>
|
||||
}
|
||||
|
||||
// EXIST: MyButton
|
||||
// EXIST: { lookupString:"MyButton", tailText: " from layout.xml for Activity (Android Extensions)", typeText:"View!" }
|
||||
|
||||
+1
-1
@@ -7,4 +7,4 @@ class MyFragment: Fragment() {
|
||||
val button = this.MyBu<caret>
|
||||
}
|
||||
|
||||
// EXIST: MyButton
|
||||
// EXIST: { lookupString:"MyButton", tailText: " from layout.xml for Fragment (Android Extensions)", typeText:"View!" }
|
||||
|
||||
+1
-1
@@ -7,4 +7,4 @@ class MyActivity: Activity() {
|
||||
val button = this.MyBu<caret>
|
||||
}
|
||||
|
||||
// EXIST: MyButton
|
||||
// EXIST: { lookupString:"MyButton", tailText: " from layout.xml for Activity (Android Extensions)", typeText:"View!" }
|
||||
|
||||
+1
-1
@@ -7,4 +7,4 @@ class MyFragment: Fragment() {
|
||||
val button = this.MyBu<caret>
|
||||
}
|
||||
|
||||
// EXIST: MyButton
|
||||
// EXIST: { lookupString:"MyButton", tailText: " from layout.xml for Fragment (Android Extensions)", typeText:"View!" }
|
||||
|
||||
+2
-1
@@ -8,4 +8,5 @@ class MyActivity: Activity() {
|
||||
val button = log<caret>
|
||||
}
|
||||
|
||||
// EXIST: login, loginButton
|
||||
// EXIST: { lookupString:"login", tailText: " from layout.xml for Activity (Android Extensions)", typeText:"Button!" }
|
||||
// EXIST: { lookupString:"loginButton", tailText: " from layout1.xml for Activity (Android Extensions)", typeText:"Button!" }
|
||||
|
||||
+2
-1
@@ -8,4 +8,5 @@ class MyFragment: Fragment() {
|
||||
val button = log<caret>
|
||||
}
|
||||
|
||||
// EXIST: login, loginButton
|
||||
// EXIST: { lookupString:"login", tailText: " from layout.xml for Fragment (Android Extensions)", typeText:"Button!" }
|
||||
// EXIST: { lookupString:"loginButton", tailText: " from layout1.xml for Fragment (Android Extensions)", typeText:"Button!" }
|
||||
+1
-1
@@ -7,4 +7,4 @@ class MyActivity: Activity() {
|
||||
val button = this.login<caret>
|
||||
}
|
||||
|
||||
// EXIST: login
|
||||
// EXIST: { lookupString:"login", tailText: " from layout.xml for Activity (Android Extensions)", typeText:"Button!" }
|
||||
|
||||
+1
-1
@@ -7,4 +7,4 @@ class MyFragment: Fragment() {
|
||||
val button = this.login<caret>
|
||||
}
|
||||
|
||||
// EXIST: login
|
||||
// EXIST: { lookupString:"login", tailText: " from layout.xml for Fragment (Android Extensions)", typeText:"Button!" }
|
||||
|
||||
+1
-1
@@ -7,4 +7,4 @@ fun View.a() {
|
||||
val button = this.login<caret>
|
||||
}
|
||||
|
||||
// EXIST: login
|
||||
// EXIST: { lookupString:"login", tailText: " from layout.xml for View (Android Extensions)", typeText:"Button!" }
|
||||
|
||||
+1
-1
@@ -6,4 +6,4 @@ class MyActivity: Activity() {
|
||||
val button = this.login<caret>
|
||||
}
|
||||
|
||||
// EXIST: login
|
||||
// EXIST: { lookupString:"login", tailText: " from layout.xml for Activity (Android Extensions)", typeText:"Button!" }
|
||||
|
||||
Reference in New Issue
Block a user