create constructor params from field: do not reject next constructors if current one is chained (IDEA-131746)

This commit is contained in:
Anna Kozlova
2014-10-23 14:46:31 +02:00
parent 247fbc358f
commit 71d92723a8
3 changed files with 38 additions and 3 deletions
@@ -144,7 +144,9 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction {
}
for (PsiMethodMember member : elements) {
if (!addParameterToConstructor(project, file, editor, member.getElement(), new PsiField[] {getField()}, cleanupElements)) break;
if (!addParameterToConstructor(project, file, editor, member.getElement(), new PsiField[] {getField()}, cleanupElements)) {
break;
}
}
} else if (!constrs.isEmpty()) {
@@ -317,9 +319,9 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction {
assert constructor != null;
PsiParameter[] newParameters = constructor.getParameterList().getParameters();
if (newParameters == parameters) return false; //user must have canceled dialog
boolean created = false;
// do not introduce assignment in chanined constructor
if (JavaHighlightUtil.getChainedConstructors(constructor) == null) {
boolean created = false;
for (PsiField field : fields.keySet()) {
final String defaultParamName = fields.get(field);
PsiParameter parameter = findParamByName(defaultParamName, field.getType(), newParameters, parameterInfos);
@@ -334,8 +336,10 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction {
}
created = true;
}
return created;
} else {
return true;
}
return created;
}
private static void notNull(PsiField field, PsiParameter parameter) {
@@ -0,0 +1,16 @@
// "Add constructor parameter" "true"
abstract class FooBar {
protected final String myFoo;
public FooBar(String myFoo) {
this.myFoo = myFoo;
}
public FooBar(Integer interestingType, String myFoo) {
this(myFoo);
}
public FooBar(int i, String myFoo) {
this(myFoo);
}
}
@@ -0,0 +1,15 @@
// "Add constructor parameter" "true"
abstract class FooBar {
protected final String my<caret>Foo;
public FooBar() {
}
public FooBar(Integer interestingType) {
this();
}
public FooBar(int i) {
this();
}
}