Fix extract refactoring for android extensions declarations (KT-11048)

Allow any target declarations in marking references. Otherwise conflicts
for references resolved to xml are not considered broken.

This also fix evaluate for extension fields.

 #KT-11048 Fixed
This commit is contained in:
Nikolay Krasko
2017-07-05 14:55:40 +03:00
parent a09b31b568
commit 72611d1337
11 changed files with 265 additions and 106 deletions
@@ -0,0 +1,14 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<org.my.cool.Button
android:id="@+id/MyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -0,0 +1,17 @@
// SUGGESTED_NAMES: view, getButton
// SUGGESTED_RETURN_TYPES: android.view.View?, android.view.View
// PARAM_DESCRIPTOR: public final class MyActivity : android.app.Activity defined in test in file toTopLevelFun.kt
// PARAM_TYPES: test.MyActivity, android.app.Activity
package test
import android.app.Activity
import kotlinx.android.synthetic.main.layout.*
// SIBLING:
class MyActivity: Activity() {
fun test() {
val button = <selection>MyButton</selection>
}
}
@@ -0,0 +1,20 @@
// SUGGESTED_NAMES: view, getButton
// SUGGESTED_RETURN_TYPES: android.view.View?, android.view.View
// PARAM_DESCRIPTOR: public final class MyActivity : android.app.Activity defined in test in file toTopLevelFun.kt
// PARAM_TYPES: test.MyActivity, android.app.Activity
package test
import android.app.Activity
import android.view.View
import kotlinx.android.synthetic.main.layout.*
// SIBLING:
class MyActivity: Activity() {
fun test() {
val button = view()
}
}
private fun MyActivity.view(): View? = MyButton
@@ -0,0 +1,35 @@
/*
* 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.android
import org.jetbrains.kotlin.idea.refactoring.introduce.ExtractTestFiles
import org.jetbrains.kotlin.idea.refactoring.introduce.checkExtract
import org.jetbrains.kotlin.idea.refactoring.introduce.doExtractFunction
import org.jetbrains.kotlin.psi.KtFile
abstract class AbstractAndroidExtractionTest: KotlinAndroidTestCase() {
fun doTest(path: String) {
copyResourceDirectoryForTest(path)
val testFilePath = path + getTestName(true) + ".kt"
val virtualFile = myFixture.copyFileToProject(testFilePath, "src/" + getTestName(true) + ".kt")
myFixture.configureFromExistingVirtualFile(virtualFile)
checkExtract(ExtractTestFiles(testFilePath, myFixture.file)) { file ->
doExtractFunction(myFixture, file as KtFile)
}
}
}
@@ -0,0 +1,44 @@
/*
* 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.android;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TargetBackend;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("plugins/android-extensions/android-extensions-idea/testData/android/extraction")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class AndroidExtractionTestGenerated extends AbstractAndroidExtractionTest {
public void testAllFilesPresentInExtraction() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("plugins/android-extensions/android-extensions-idea/testData/android/extraction"), Pattern.compile("^([^\\.]+)$"), TargetBackend.ANY, false);
}
@TestMetadata("toTopLevelFun")
public void testToTopLevelFun() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("plugins/android-extensions/android-extensions-idea/testData/android/extraction/toTopLevelFun/");
doTest(fileName);
}
}