Skip to content

Commit 39010ab

Browse files
committed
Fix broken isReferenceTo checking code for Android extensions
#KT-16132 Fixed
1 parent 25c1828 commit 39010ab

File tree

29 files changed

+408
-26
lines changed

29 files changed

+408
-26
lines changed

idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/KtSimpleNameReference.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,8 @@ class KtSimpleNameReference(expression: KtSimpleNameExpression) : KtSimpleRefere
7272
}
7373

7474
override fun isReferenceTo(element: PsiElement?): Boolean {
75-
if (element != null) {
76-
if (!canBeReferenceTo(element)) return false
77-
78-
for (extension in Extensions.getArea(element.project).getExtensionPoint(SimpleNameReferenceExtension.EP_NAME).extensions) {
79-
if (extension.isReferenceTo(this, element)) return true
80-
}
75+
if (element != null && !canBeReferenceTo(element)) {
76+
return false
8177
}
8278

8379
return super.isReferenceTo(element)

idea/idea-analysis/src/org/jetbrains/kotlin/plugin/references/SimpleNameReferenceExtension.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,5 @@ interface SimpleNameReferenceExtension {
2727
ExtensionPointName.create("org.jetbrains.kotlin.simpleNameReferenceExtension")
2828
}
2929

30-
fun isReferenceTo(reference: KtSimpleNameReference, element: PsiElement): Boolean
3130
fun handleElementRename(reference: KtSimpleNameReference, psiFactory: KtPsiFactory, newElementName: String): PsiElement?
3231
}

plugins/android-extensions/android-extensions-idea/src/org/jetbrains/kotlin/android/synthetic/idea/AndroidSimpleNameReferenceExtension.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,11 @@ import org.jetbrains.kotlin.android.synthetic.androidIdToName
2525
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
2626
import org.jetbrains.kotlin.plugin.references.SimpleNameReferenceExtension
2727
import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
28+
import org.jetbrains.kotlin.psi.KtProperty
2829
import org.jetbrains.kotlin.psi.KtPsiFactory
2930

3031
class AndroidSimpleNameReferenceExtension : SimpleNameReferenceExtension {
3132

32-
override fun isReferenceTo(reference: KtSimpleNameReference, element: PsiElement) = when {
33-
element is ValueResourceElementWrapper && AndroidResourceUtil.isIdDeclaration(element) -> true
34-
isLayoutPackageIdentifier(reference) -> true
35-
else -> false
36-
}
37-
3833
private fun isLayoutPackageIdentifier(reference: KtSimpleNameReference): Boolean {
3934
val probablyVariant = reference.element?.parent as? KtDotQualifiedExpression ?: return false
4035
val probablyKAS = probablyVariant.receiverExpression as? KtDotQualifiedExpression ?: return false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.myapp
2+
3+
import android.app.Activity
4+
import android.os.Bundle
5+
import java.io.File
6+
import kotlinx.android.synthetic.main.layout.*
7+
8+
// KT-16132 Renaming property provided by kotlinx leads to renaming another members
9+
10+
object Loginer {
11+
fun login() { }
12+
}
13+
14+
public class MyActivity : Activity() {
15+
override fun onCreate(savedInstanceState: Bundle?) {
16+
<caret>login.setOnClickListener {
17+
Loginer.login()
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.myapp
2+
3+
import android.app.Activity
4+
import android.os.Bundle
5+
import java.io.File
6+
import kotlinx.android.synthetic.main.layout.*
7+
8+
// KT-16132 Renaming property provided by kotlinx leads to renaming another members
9+
10+
object Loginer {
11+
fun login() { }
12+
}
13+
14+
public class MyActivity : Activity() {
15+
override fun onCreate(savedInstanceState: Bundle?) {
16+
NEWNAME.setOnClickListener {
17+
Loginer.login()
18+
}
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:id="@+id/item_detail_container"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
tools:context=".ItemDetailActivity"
7+
tools:ignore="MergeRootFrame" >
8+
9+
10+
11+
<Button
12+
android:id="@+id/NEWNAME"
13+
android:layout_width="match_parent"
14+
android:layout_height="wrap_content"
15+
android:text="Sign in" />
16+
17+
</FrameLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:id="@+id/item_detail_container"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
tools:context=".ItemDetailActivity"
7+
tools:ignore="MergeRootFrame" >
8+
9+
10+
11+
<Button
12+
android:id="@+id/login"
13+
android:layout_width="match_parent"
14+
android:layout_height="wrap_content"
15+
android:text="Sign in" />
16+
17+
</FrameLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.myapp
2+
3+
import android.app.Activity
4+
import kotlinx.android.synthetic.main.layout.*
5+
6+
class MyActivity: Activity() {
7+
val button = this.NEWNAME
8+
}
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
tools:context=".ItemDetailActivity"
6+
tools:ignore="MergeRootFrame" >
7+
8+
<view
9+
class="org.my.cool.Button"
10+
android:id="@+id/NEWNAME"
11+
android:layout_width="match_parent"
12+
android:layout_height="wrap_content"
13+
android:text="Sign in" />
14+
15+
</FrameLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.myapp
2+
3+
import android.app.Fragment
4+
import kotlinx.android.synthetic.main.layout.*
5+
6+
class MyFragment: Fragment() {
7+
val button = this.NEWNAME
8+
}
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
tools:context=".ItemDetailActivity"
6+
tools:ignore="MergeRootFrame" >
7+
8+
<view
9+
class="org.my.cool.Button"
10+
android:id="@+id/NEWNAME"
11+
android:layout_width="match_parent"
12+
android:layout_height="wrap_content"
13+
android:text="Sign in" />
14+
15+
</FrameLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.myapp
2+
3+
import android.app.Activity
4+
import kotlinx.android.synthetic.main.layout.*
5+
6+
class MyActivity: Activity() {
7+
val button = this.NEWNAME
8+
}
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
tools:context=".ItemDetailActivity"
6+
tools:ignore="MergeRootFrame" >
7+
8+
<org.my.cool.Button
9+
android:id="@+id/NEWNAME"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"
12+
android:text="Sign in" />
13+
14+
</FrameLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.myapp
2+
3+
import android.app.Fragment
4+
import kotlinx.android.synthetic.main.layout.*
5+
6+
class MyFragment: Fragment() {
7+
val button = this.NEWNAME
8+
}
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
tools:context=".ItemDetailActivity"
6+
tools:ignore="MergeRootFrame" >
7+
8+
<org.my.cool.Button
9+
android:id="@+id/NEWNAME"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"
12+
android:text="Sign in" />
13+
14+
</FrameLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.myapp
2+
3+
import android.app.Activity
4+
import kotlinx.android.synthetic.main.layout.*
5+
6+
class MyActivity: Activity() {
7+
val button = this.NEWNAME
8+
val button1 = this.loginButton
9+
}
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:id="@+id/item_detail_container"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
tools:context=".ItemDetailActivity"
7+
tools:ignore="MergeRootFrame" >
8+
9+
10+
<TextView
11+
android:id="@+id/textView1"
12+
android:layout_width="wrap_content"
13+
android:layout_height="wrap_content"
14+
android:text="Enter your password" />
15+
16+
<EditText
17+
android:id="@+id/password"
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
android:ems="10"
21+
android:inputType="textPassword" />
22+
23+
<Button
24+
android:id="@+id/NEWNAME"
25+
android:layout_width="match_parent"
26+
android:layout_height="wrap_content"
27+
android:text="Sign in" />
28+
29+
</FrameLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:id="@+id/frameLayout"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
tools:context=".ItemDetailActivity"
7+
tools:ignore="MergeRootFrame" >
8+
9+
10+
<TextView
11+
android:id="@+id/passwordField"
12+
android:layout_width="wrap_content"
13+
android:layout_height="wrap_content"
14+
android:text="Enter your password" />
15+
16+
<EditText
17+
android:id="@+id/passwordCaption"
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
android:ems="10"
21+
android:inputType="textPassword" />
22+
23+
<Button
24+
android:id="@+id/loginButton"
25+
android:layout_width="match_parent"
26+
android:layout_height="wrap_content"
27+
android:text="Sign in" />
28+
29+
</FrameLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.myapp
2+
3+
import android.app.Fragment
4+
import kotlinx.android.synthetic.main.layout.*
5+
6+
class MyFragment: Fragment() {
7+
val button = this.NEWNAME
8+
val button1 = this.loginButton
9+
}
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:id="@+id/item_detail_container"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
tools:context=".ItemDetailActivity"
7+
tools:ignore="MergeRootFrame" >
8+
9+
10+
<TextView
11+
android:id="@+id/textView1"
12+
android:layout_width="wrap_content"
13+
android:layout_height="wrap_content"
14+
android:text="Enter your password" />
15+
16+
<EditText
17+
android:id="@+id/password"
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
android:ems="10"
21+
android:inputType="textPassword" />
22+
23+
<Button
24+
android:id="@+id/NEWNAME"
25+
android:layout_width="match_parent"
26+
android:layout_height="wrap_content"
27+
android:text="Sign in" />
28+
29+
</FrameLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:id="@+id/frameLayout"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
tools:context=".ItemDetailActivity"
7+
tools:ignore="MergeRootFrame" >
8+
9+
10+
<TextView
11+
android:id="@+id/passwordField"
12+
android:layout_width="wrap_content"
13+
android:layout_height="wrap_content"
14+
android:text="Enter your password" />
15+
16+
<EditText
17+
android:id="@+id/passwordCaption"
18+
android:layout_width="match_parent"
19+
android:layout_height="wrap_content"
20+
android:ems="10"
21+
android:inputType="textPassword" />
22+
23+
<Button
24+
android:id="@+id/loginButton"
25+
android:layout_width="match_parent"
26+
android:layout_height="wrap_content"
27+
android:text="Sign in" />
28+
29+
</FrameLayout>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:id="@+id/item_detail_container"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
tools:context=".ItemDetailActivity"
7+
tools:ignore="MergeRootFrame" >
8+
9+
10+
11+
<Button
12+
android:id="@+id/NEWNAME"
13+
android:layout_width="match_parent"
14+
android:layout_height="wrap_content"
15+
android:text="Sign in" />
16+
17+
</FrameLayout>

0 commit comments

Comments
 (0)