Add layout file name in completion for Android Extension properties

#KT-11051 Fixed
This commit is contained in:
Vyacheslav Gerasimov
2017-07-06 18:25:19 +03:00
parent f59859842a
commit 4cef8728d7
16 changed files with 99 additions and 11 deletions
@@ -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" />
@@ -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)")
}
}
}
@@ -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!" }
@@ -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!" }
@@ -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!" }
@@ -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!" }
@@ -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!" }
@@ -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!" }
@@ -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!" }
@@ -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!" }
@@ -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!" }
@@ -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!" }