Change Signature: Search & process as-property usages of Java methods (This ixes some muted tests on Change Signature for properties).

Improve test data
This commit is contained in:
Alexey Sedunov
2015-10-21 18:24:10 +03:00
committed by Alexey Sedunov
parent ad0c12935b
commit 8d3296e08d
23 changed files with 283 additions and 116 deletions
@@ -23,6 +23,7 @@ import com.intellij.psi.*;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.searches.MethodReferencesSearch;
import com.intellij.psi.search.searches.OverridingMethodsSearch;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.util.PsiTreeUtil;
@@ -59,6 +60,8 @@ import org.jetbrains.kotlin.idea.refactoring.CallableRefactoringKt;
import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.*;
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference;
import org.jetbrains.kotlin.idea.references.ReferenceUtilKt;
import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinReferencesSearchOptions;
import org.jetbrains.kotlin.idea.search.ideaExtensions.KotlinReferencesSearchParameters;
import org.jetbrains.kotlin.idea.search.usagesSearch.UtilsKt;
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
import org.jetbrains.kotlin.idea.util.ScopeUtils;
@@ -253,6 +256,22 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
}
}
private static Set<PsiReference> findReferences(PsiElement functionPsi) {
Set<PsiReference> result = new LinkedHashSet<PsiReference>();
SearchScope searchScope = functionPsi.getUseScope();
KotlinReferencesSearchOptions options = new KotlinReferencesSearchOptions(true, false, false, false);
KotlinReferencesSearchParameters parameters = new KotlinReferencesSearchParameters(functionPsi, searchScope, false, null, options);
result.addAll(ReferencesSearch.search(parameters).findAll());
if (functionPsi instanceof KtProperty || functionPsi instanceof KtParameter) {
for (PsiMethod lightMethod : LightClassUtilsKt.toLightMethods(functionPsi)) {
result.addAll(MethodReferencesSearch.search(lightMethod, searchScope, true).findAll());
}
}
return result;
}
private static void findOneMethodUsages(
@NotNull final JetCallableDefinitionUsage<?> functionUsageInfo,
final JetChangeInfo changeInfo,
@@ -267,7 +286,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
PsiElement functionPsi = functionUsageInfo.getElement();
if (functionPsi == null) return;
for (PsiReference reference : ReferencesSearch.search(functionPsi, functionPsi.getUseScope())) {
for (PsiReference reference : findReferences(functionPsi)) {
PsiElement element = reference.getElement();
if (functionPsi instanceof KtClass && reference.resolve() != functionPsi) continue;
@@ -1,6 +1,6 @@
import java.lang.Override;
class J extends A {
public class J extends A {
private int p;
@Override
@@ -17,12 +17,15 @@ class J extends A {
class Test {
static void test() {
new A().getP("");
new A().setP("", 1);
new A().setP("", 3);
new B().getP("");
new B().setP("", 2);
new AA().getP("");
new AA().setP("", 3);
new J().getP("");
new J().setP("", 3);
new B().getP("");
new B().setP("", 3);
}
}
@@ -1,26 +1,35 @@
public inline fun <T, R> with(receiver: T, f: T.() -> R): R = receiver.f()
open class A {
open var <caret>String.p: Int = 1
open var String.p: Int = 1
}
class B: A() {
override var String.p: Int = 2
class AA : A() {
override var String.p: Int = 1
}
class B : J() {
override var String.p: Int = 1
}
fun test() {
with(A()) {
val t = "".p
"".p = 1
"".p = 3
}
with(AA()) {
val t = "".p
"".p = 3
}
with(J()) {
val t = "".p
"".p = 3
}
with(B()) {
val t = "".p
"".p = 2
}
with(J()) {
val t = getP("")
setP("", 3)
"".p = 3
}
}
@@ -1,6 +1,6 @@
import java.lang.Override;
class J extends A {
public class J extends A {
private int p;
@Override
@@ -17,12 +17,15 @@ class J extends A {
class Test {
static void test() {
new A().getP();
new A().setP(1);
new A().setP(3);
new B().getP();
new B().setP(2);
new AA().getP();
new AA().setP(3);
new J().getP();
new J().setP(3);
new B().getP();
new B().setP(3);
}
}
@@ -4,23 +4,32 @@ open class A {
open var <caret>p: Int = 1
}
class B: A() {
override var p: Int = 2
class AA : A() {
override var p: Int = 1
}
class B : J() {
override var p: Int = 1
}
fun test() {
with(A()) {
val t = p
p = 1
p = 3
}
with(AA()) {
val t = p
p = 3
}
with(J()) {
val t = p
p = 3
}
with(B()) {
val t = p
p = 2
}
with(J()) {
val t = getP()
setP(3)
p = 3
}
}
@@ -34,5 +34,11 @@ class Test {
new J().getS();
new J().setS(4);
new D().getS();
new D().setS(5);
new E().getS();
new E().setS(6);
}
}
@@ -6,6 +6,12 @@ class C: A(0) {
override var s: String = 1
}
class D(override var s: String) : J()
class E : J() {
override var s: String = 1
}
fun test() {
val t1 = A(0).s
A(0).s = 1
@@ -16,6 +22,12 @@ fun test() {
val t3 = C().s
C().s = 3
val t4 = J().getS()
J().setS(4)
val t4 = J().s
J().s = 4
val t5 = D().s
D().s = 5
val t6 = E().s
E().s = 6
}
@@ -31,5 +31,11 @@ class Test {
new J().getP();
new J().setP(4);
new D().getP();
new D().setP(5);
new E().getP();
new E().setP(6);
}
}
@@ -6,6 +6,12 @@ class C: A(0) {
override var p: Int = 1
}
class D(override var s: String) : J()
class E : J() {
override var s: String = 1
}
fun test() {
val t1 = A(0).p
A(0).p = 1
@@ -16,6 +22,12 @@ fun test() {
val t3 = C().p
C().p = 3
val t4 = J().getP()
J().setP(4)
val t4 = J().p
J().p = 4
val t5 = D().p
D().p = 5
val t6 = E().p
E().p = 6
}
@@ -2,7 +2,7 @@ import org.jetbrains.annotations.NotNull;
import java.lang.Override;
class J extends A {
public class J extends A {
private int p;
@NotNull
@@ -20,12 +20,15 @@ class J extends A {
class Test {
static void test() {
new A().getS();
new A().setS(1);
new A().setS(3);
new B().getS();
new B().setS(2);
new AA().getS();
new AA().setS(3);
new J().getS();
new J().setS(3);
new B().getS();
new B().setS(3);
}
}
@@ -1,18 +1,35 @@
public inline fun <T, R> with(receiver: T, f: T.() -> R): R = receiver.f()
open class A {
open var <caret>s: String = 1
open var s: String = 1
}
class B: A() {
override var s: String = 2
class AA : A() {
override var s: String = 1
}
class B : J() {
override var s: String = 1
}
fun test() {
val t1 = A().s
A().s = 1
with(A()) {
val t = s
s = 3
}
val t2 = B().s
B().s = 2
with(AA()) {
val t = s
s = 3
}
val t3 = J().getS()
J().setS(3)
with(J()) {
val t = s
s = 3
}
with(B()) {
val t = s
s = 3
}
}
@@ -1,6 +1,6 @@
import java.lang.Override;
class J extends A {
public class J extends A {
private int p;
@Override
@@ -17,12 +17,15 @@ class J extends A {
class Test {
static void test() {
new A().getP();
new A().setP(1);
new A().setP(3);
new B().getP();
new B().setP(2);
new AA().getP();
new AA().setP(3);
new J().getP();
new J().setP(3);
new B().getP();
new B().setP(3);
}
}
@@ -1,18 +1,35 @@
public inline fun <T, R> with(receiver: T, f: T.() -> R): R = receiver.f()
open class A {
open var <caret>p: Int = 1
}
class B: A() {
override var p: Int = 2
class AA : A() {
override var p: Int = 1
}
class B : J() {
override var p: Int = 1
}
fun test() {
val t1 = A().p
A().p = 1
with(A()) {
val t = p
p = 3
}
val t2 = B().p
B().p = 2
with(AA()) {
val t = p
p = 3
}
val t3 = J().getP()
J().setP(3)
with(J()) {
val t = p
p = 3
}
with(B()) {
val t = p
p = 3
}
}
@@ -1,6 +1,6 @@
import java.lang.Override;
class J extends A {
public class J extends A {
private int p;
@Override
@@ -17,12 +17,15 @@ class J extends A {
class Test {
static void test() {
new A().getP("");
new A().setP("", 1);
new A().setP("", 3);
new B().getP("");
new B().setP("", 2);
new AA().getP("");
new AA().setP("", 3);
new J().getP("");
new J().setP("", 3);
new B().getP("");
new B().setP("", 3);
}
}
@@ -4,23 +4,32 @@ open class A {
open var Int.<caret>p: Int = 1
}
class B: A() {
override var Int.p: Int = 2
class AA : A() {
override var Int.p: Int = 1
}
class B : J() {
override var Int.p: Int = 1
}
fun test() {
with(A()) {
val t = "".p
"".p = 1
"".p = 3
}
with(AA()) {
val t = "".p
"".p = 3
}
with(J()) {
val t = "".p
"".p = 3
}
with(B()) {
val t = "".p
"".p = 2
}
with(J()) {
val t = getP("")
setP("", 3)
"".p = 3
}
}
@@ -1,6 +1,6 @@
import java.lang.Override;
class J extends A {
public class J extends A {
private int p;
@Override
@@ -17,12 +17,15 @@ class J extends A {
class Test {
static void test() {
new A().getP("");
new A().setP("", 1);
new A().setP("", 3);
new B().getP("");
new B().setP("", 2);
new AA().getP("");
new AA().setP("", 3);
new J().getP("");
new J().setP("", 3);
new B().getP("");
new B().setP("", 3);
}
}
@@ -4,23 +4,32 @@ open class A {
open var String.<caret>p: Int = 1
}
class B: A() {
override var String.p: Int = 2
class AA : A() {
override var String.p: Int = 1
}
class B : J() {
override var String.p: Int = 1
}
fun test() {
with(A()) {
val t = "".p
"".p = 1
"".p = 3
}
with(AA()) {
val t = "".p
"".p = 3
}
with(J()) {
val t = "".p
"".p = 3
}
with(B()) {
val t = "".p
"".p = 2
}
with(J()) {
val t = getP("")
setP("", 3)
"".p = 3
}
}
@@ -1,17 +1,17 @@
open class X: A() {
fun foo(x: Int): String? {
override fun foo(x: Int): String? {
return super.foo(1) + 1
}
}
open class Y: B() {
fun foo(x: Int): String? {
override fun foo(x: Int): String? {
return s.length * 2
}
}
open class Z: X() {
fun foo(x: Int): String? {
override fun foo(x: Int): String? {
return s.length
}
}
@@ -1,17 +1,17 @@
open class X: A() {
fun foo(s: String): Int {
override fun foo(s: String): Int {
return super.foo(s) + 1
}
}
open class Y: B() {
fun foo(s: String): Int {
override fun foo(s: String): Int {
return s.length * 2
}
}
open class Z: X() {
fun foo(s: String): Int {
override fun foo(s: String): Int {
return s.length
}
}
@@ -1,6 +1,6 @@
import java.lang.Override;
class J extends A {
public class J extends A {
private int p;
@Override
@@ -17,12 +17,15 @@ class J extends A {
class Test {
static void test() {
new A().getP();
new A().setP(1);
new A().setP(3);
new B().getP();
new B().setP(2);
new AA().getP();
new AA().setP(3);
new J().getP();
new J().setP(3);
new B().getP();
new B().setP(3);
}
}
@@ -1,26 +1,35 @@
public inline fun <T, R> with(receiver: T, f: T.() -> R): R = receiver.f()
open class A {
open var <caret>p: Int = 1
open var p: Int = 1
}
class B: A() {
override var p: Int = 2
class AA : A() {
override var p: Int = 1
}
class B : J() {
override var p: Int = 1
}
fun test() {
with(A()) {
val t = p
p = 1
p = 3
}
with(AA()) {
val t = p
p = 3
}
with(J()) {
val t = p
p = 3
}
with(B()) {
val t = p
p = 2
}
with(J()) {
val t = getP()
setP(3)
p = 3
}
}
@@ -1,6 +1,6 @@
import java.lang.Override;
class J extends A {
public class J extends A {
private int p;
@Override
@@ -17,12 +17,15 @@ class J extends A {
class Test {
static void test() {
new A().getP("");
new A().setP("", 1);
new A().setP("", 3);
new B().getP("");
new B().setP("", 2);
new AA().getP("");
new AA().setP("", 3);
new J().getP("");
new J().setP("", 3);
new B().getP("");
new B().setP("", 3);
}
}
@@ -4,23 +4,32 @@ open class A {
open var String.<caret>p: Int = 1
}
class B: A() {
override var String.p: Int = 2
class AA : A() {
override var String.p: Int = 1
}
class B : J() {
override var String.p: Int = 1
}
fun test() {
with(A()) {
val t = "".p
"".p = 1
"".p = 3
}
with(AA()) {
val t = "".p
"".p = 3
}
with(J()) {
val t = "".p
"".p = 3
}
with(B()) {
val t = "".p
"".p = 2
}
with(J()) {
val t = getP("")
setP("", 3)
"".p = 3
}
}