change method signature from usage text tweaks

This commit is contained in:
anna
2011-08-03 19:25:45 +04:00
parent b890d3d12e
commit b973627301
32 changed files with 50 additions and 54 deletions

View File

@@ -99,32 +99,28 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction, HighP
@Nullable
private String getShortText() {
if (myNewParametersInfo.length > 4 || myTargetMethod.getParameterList().getParametersCount() > 4) {
final StringBuilder buf = new StringBuilder();
final HashSet<ParameterInfoImpl> newParams = new HashSet<ParameterInfoImpl>();
final HashSet<ParameterInfoImpl> removedParams = new HashSet<ParameterInfoImpl>();
final HashSet<ParameterInfoImpl> changedParams = new HashSet<ParameterInfoImpl>();
getNewParametersInfo(myExpressions, myTargetMethod, mySubstitutor, buf, newParams, removedParams, changedParams);
final StringBuilder buf = new StringBuilder();
final HashSet<ParameterInfoImpl> newParams = new HashSet<ParameterInfoImpl>();
final HashSet<ParameterInfoImpl> removedParams = new HashSet<ParameterInfoImpl>();
final HashSet<ParameterInfoImpl> changedParams = new HashSet<ParameterInfoImpl>();
getNewParametersInfo(myExpressions, myTargetMethod, mySubstitutor, buf, newParams, removedParams, changedParams);
final String targetMethodName = myTargetMethod.getName();
if (myTargetMethod.getContainingClass().findMethodsByName(targetMethodName, true).length == 1) {
if (newParams.size() == 1) {
final ParameterInfoImpl p = newParams.iterator().next();
return "Add " + p.getTypeText() + " as " + (ArrayUtil.find(myNewParametersInfo, p) + 1) + "nd parameter to method " + targetMethodName;
}
if (removedParams.size() == 1) {
final ParameterInfoImpl p = removedParams.iterator().next();
return "Remove " + (p.getOldIndex() + 1) + "nd parameter from method " + targetMethodName;
}
if (changedParams.size() == 1) {
final ParameterInfoImpl p = changedParams.iterator().next();
return "Change " + (p.getOldIndex() + 1)+ "nd parameter type of method " +targetMethodName + " from " + myTargetMethod.getParameterList().getParameters()[p.getOldIndex()].getType().getPresentableText() + " to " + p.getTypeText();
}
final String targetMethodName = myTargetMethod.getName();
if (myTargetMethod.getContainingClass().findMethodsByName(targetMethodName, true).length == 1) {
if (newParams.size() == 1) {
final ParameterInfoImpl p = newParams.iterator().next();
return "Add " + p.getTypeText() + " as " + (ArrayUtil.find(myNewParametersInfo, p) + 1) + " parameter to method " + targetMethodName;
}
if (removedParams.size() == 1) {
final ParameterInfoImpl p = removedParams.iterator().next();
return "Remove " + (p.getOldIndex() + 1) + " parameter from method " + targetMethodName;
}
if (changedParams.size() == 1) {
final ParameterInfoImpl p = changedParams.iterator().next();
return "Change " + (p.getOldIndex() + 1)+ " parameter of method " +targetMethodName + " from " + myTargetMethod.getParameterList().getParameters()[p.getOldIndex()].getType().getPresentableText() + " to " + p.getTypeText();
}
return "<html> Change signature of " + targetMethodName + "(" + buf.toString() + ")</html>";
}
return null;
return "<html> Change signature of " + targetMethodName + "(" + buf.toString() + ")</html>";
}
private static String formatTypesList(ParameterInfoImpl[] infos, PsiElement context) {

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(int)' to 'f()'" "true"
// "Remove 1 parameter from method f" "true"
class A {
void f() {}
public void foo() {

View File

@@ -1,4 +1,4 @@
// "Change signature of 'set(List<T>)' to 'set(List<T>, String)'" "true"
// "Add String as 2 parameter to method set" "true"
import java.util.List;
public class X<T> {

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(int, String)' to 'f()'" "true"
// "<html> Change signature of f(<s>int</s>, <s>String</s>)</html>" "true"
class A {
void f() {}
public void foo() {

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(int, String)' to 'f(int, char, String)'" "true"
// "Add char as 2 parameter to method f" "true"
class A {
void f(int i, char c, String s) {}
public void foo() {

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(int, String, int)' to 'f(int, int)'" "true"
// "Remove 2 parameter from method f" "true"
class A {
void f(int i, int i2) {}
public void foo() {

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(int, String, int)' to 'f(int, int, int)'" "true"
// "Change 2 parameter of method f from String to int" "true"
class A {
void f(int i, int s, int i2) {}
public void foo() {

View File

@@ -1,4 +1,4 @@
// "Change signature of 'A()' to 'A(int, int, String)'" "true"
// "<html> Change signature of A(<b>int</b>, <b>int</b>, <b>String</b>)</html>" "true"
class A {
A(int i, int i1, String s) {
new A<caret>(1,1,"4");

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(int, int...)' to 'f(int, int, int...)'" "true"
// "Add int as 2 parameter to method f" "true"
public class S {
void f(int k, int i, int... args) {
f(1,1,null)<caret>;// -> f(1,1,null)

View File

@@ -1,4 +1,4 @@
// "Change signature of 'Bar(String)' to 'Bar(Foo<TypeParamName>, String)'" "true"
// "Add Foo<TypeParamName> as 1 parameter to method Bar" "true"
public class Bar {
Bar(Foo<TypeParamName> typeParamNameFoo, String args) {

View File

@@ -1,4 +1,4 @@
// "Change signature of 'bar(String)' to 'bar(Foo<TypeParamName>, String)'" "true"
// "Add Foo<TypeParamName> as 1 parameter to method bar" "true"
public class Bar {
static void bar(Foo<TypeParamName> typeParamNameFoo, String args) {

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(String)' to 'f(int, String)'" "true"
// "Add int as 1 parameter to method f" "true"
public class S {
void f(int i, String args) {

View File

@@ -1,4 +1,4 @@
// "Change signature of 'Inner2()' to 'Inner2(CoolTest.Inner1)'" "true"
// "Add Inner1 as 1 parameter to method Inner2" "true"
class CoolTest {
class Inner1 {}

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(int...)' to 'f(String, int...)'" "true"
// "Add String as 1 parameter to method f" "true"
public class S {
void f(String s, int... args) {
f("",1,1);

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(int...)' to 'f(String, int...)'" "true"
// "Add String as 1 parameter to method f" "true"
public class S {
void f(String s, int... args) {
f("",null);

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(int)' to 'f()'" "true"
// "Remove 1 parameter from method f" "true"
class A {
void f(int i) {}
public void foo() {

View File

@@ -1,4 +1,4 @@
// "Change signature of 'set(List<T>)' to 'set(List<T>, String)'" "true"
// "Add String as 2 parameter to method set" "true"
import java.util.List;
public class X<T> {

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(int, String)' to 'f()'" "true"
// "<html> Change signature of f(<s>int</s>, <s>String</s>)</html>" "true"
class A {
void f(int i,String s) {}
public void foo() {

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(int, String)' to 'f(int, char, String)'" "true"
// "Add char as 2 parameter to method f" "true"
class A {
void f(int i,String s) {}
public void foo() {

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(int, String, int)' to 'f(int, int)'" "true"
// "Remove 2 parameter from method f" "true"
class A {
void f(int i, String s, int i2) {}
public void foo() {

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(int, String, int)' to 'f(int, int, int)'" "true"
// "Change 2 parameter of method f from String to int" "true"
class A {
void f(int i, String s, int i2) {}
public void foo() {

View File

@@ -1,4 +1,4 @@
// "Change signature of 'A()' to 'A(int, int, String)'" "true"
// "<html> Change signature of A(<b>int</b>, <b>int</b>, <b>String</b>)</html>" "true"
class A {
A() {
new A<caret>(1,1,"4");

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(int, int...)' to 'f(int, int, int...)'" "true"
// "Add int as 2 parameter to method f" "true"
public class S {
void f(int k, int... args) {
f(1,1,null)<caret>;// -> f(1,1,null)

View File

@@ -1,4 +1,4 @@
// "Change signature of 'Bar(String)' to 'Bar(Foo<TypeParamName>, String)'" "true"
// "Add Foo<TypeParamName> as 1 parameter to method Bar" "true"
public class Bar {
Bar(String args) {

View File

@@ -1,4 +1,4 @@
// "Change signature of 'bar(String)' to 'bar(Foo<TypeParamName>, String)'" "true"
// "Add Foo<TypeParamName> as 1 parameter to method bar" "true"
public class Bar {
static void bar(String args) {

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(String)' to 'f(int)'" "false"
// "Add int as 1 parameter to method f" "false"
public class Foo {
void foo(Bar f) {
f.f<caret>(2);

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(String)' to 'f(int, String)'" "true"
// "Add int as 1 parameter to method f" "true"
public class S {
void f(String args) {

View File

@@ -1,4 +1,4 @@
// "Change signature of 'parseInt(String)' to 'parseInt(int)'" "false"
// "Change 1 parameter of method parseInt from String to int" "false"
class A {
public void foo() {
<caret>Integer.parseInt(1);

View File

@@ -1,4 +1,4 @@
// "Change signature of 'Inner2()' to 'Inner2(CoolTest.Inner1)'" "true"
// "Add Inner1 as 1 parameter to method Inner2" "true"
class CoolTest {
class Inner1 {}

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(int...)' to 'f(String, int...)'" "true"
// "Add String as 1 parameter to method f" "true"
public class S {
void f(int... args) {
f("",1,1)<caret>;

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(int...)' to 'f(String, int...)'" "true"
// "Add String as 1 parameter to method f" "true"
public class S {
void f(int... args) {
f("",null)<caret>;

View File

@@ -1,4 +1,4 @@
// "Change signature of 'f(int...)' to 'f(int..., String)'" "false"
// "Add String as 2nd parameter to method f" "false"
public class S {
void f(int... args) {
f(1,1, "")<caret>;