Autoimport items from kotlinx.android.synthetic on completion

This commit is contained in:
Yan Zhulanow
2015-11-12 16:49:50 +03:00
parent 0dada9d13a
commit 3f97b384ef
11 changed files with 158 additions and 16 deletions
@@ -12,6 +12,7 @@
<orderEntry type="library" exported="" scope="PROVIDED" name="android-plugin" level="project" />
<orderEntry type="library" scope="PROVIDED" name="idea-full" level="project" />
<orderEntry type="module" module-name="idea" scope="PROVIDED" />
<orderEntry type="module" module-name="idea-core" scope="PROVIDED" />
<orderEntry type="module" module-name="compiler-tests" scope="TEST" />
<orderEntry type="module" module-name="cli" scope="TEST" />
<orderEntry type="module" module-name="light-classes" />
@@ -0,0 +1,59 @@
/*
* Copyright 2010-2015 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.android.synthetic.idea
import org.jetbrains.kotlin.android.synthetic.AndroidConst
import org.jetbrains.kotlin.android.synthetic.descriptors.AndroidSyntheticPackageFragmentDescriptor
import org.jetbrains.kotlin.android.synthetic.descriptors.PredefinedPackageFragmentDescriptor
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.idea.core.extension.KotlinIndicesHelperExtension
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
class AndroidIndicesHelperExtension : KotlinIndicesHelperExtension {
override fun appendExtensionCallables(
consumer: MutableList<in CallableDescriptor>,
moduleDescriptor: ModuleDescriptor,
receiverTypes: Collection<KotlinType>,
nameFilter: (String) -> Boolean
) {
for (packageFragment in moduleDescriptor.getPackage(FqName(AndroidConst.SYNTHETIC_PACKAGE)).fragments) {
if (packageFragment !is PredefinedPackageFragmentDescriptor) continue
fun handleScope(scope: MemberScope) {
val descriptors = scope.getContributedDescriptors(DescriptorKindFilter.CALLABLES) { nameFilter(it.asString()) }
for (descriptor in descriptors) {
val receiverType = (descriptor as CallableDescriptor).extensionReceiverParameter?.type ?: continue
if (receiverTypes.any { it.isSubtypeOf(receiverType) }) {
consumer += descriptor
}
}
}
handleScope(packageFragment.getMemberScope())
for (fragment in packageFragment.subpackages) {
if (fragment is AndroidSyntheticPackageFragmentDescriptor && fragment.packageData.isDeprecated) continue
handleScope(fragment.getMemberScope())
}
}
}
}
@@ -0,0 +1,10 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
@@ -0,0 +1,9 @@
package com.myapp
import android.app.Activity
class MyActivity: Activity() {
val button = this.login<caret>
}
// EXIST: login
@@ -88,4 +88,10 @@ public class AndroidCompletionTestGenerated extends AbstractAndroidCompletionTes
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-idea-plugin/testData/android/completion/propertiesSimpleView/");
doTest(fileName);
}
@TestMetadata("withoutImport")
public void testWithoutImport() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-idea-plugin/testData/android/completion/withoutImport/");
doTest(fileName);
}
}