mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
replace constructor with builder: do not suggest to default chain constructor params
This commit is contained in:
+5
-1
@@ -61,8 +61,12 @@ public class ParameterData {
|
||||
int i = 0;
|
||||
for (final PsiParameter parameter : chainedConstructor.getParameterList().getParameters()) {
|
||||
if (!parameter.isVarArgs()) {
|
||||
final PsiExpression arg = args[i];
|
||||
final ParameterData parameterData = initParameterData(parameter, result);
|
||||
parameterData.setDefaultValue(args[i++].getText());
|
||||
if (!(arg instanceof PsiReferenceExpression && ((PsiReferenceExpression)arg).resolve() instanceof PsiParameter)) {
|
||||
parameterData.setDefaultValue(arg.getText());
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
public class Builder {
|
||||
private int i = 2;
|
||||
private int j;
|
||||
|
||||
public Builder setI(int i) {
|
||||
this.i = i;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setJ(int j) {
|
||||
this.j = j;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Test createTest() {
|
||||
return new Test(i, j);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
public class Test {
|
||||
public Test(int i, int j){}
|
||||
public Test(int j){
|
||||
this(2, j);
|
||||
}
|
||||
void foo(){}
|
||||
public static void main(String[] args){
|
||||
new Builder().setJ(1).createTest().foo();
|
||||
new Builder().setI(2).setJ(3).createTest().foo();
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
public class Test {
|
||||
public Test(int i, int j){}
|
||||
public Test(int j){
|
||||
this(2, j);
|
||||
}
|
||||
void foo(){}
|
||||
public static void main(String[] args){
|
||||
new Test(1).foo();
|
||||
new Test(2, 3).foo();
|
||||
}
|
||||
}
|
||||
+7
@@ -50,6 +50,13 @@ public class ReplaceConstructorWithBuilderTest extends MultiFileTestCase {
|
||||
doTest(true, defaults);
|
||||
}
|
||||
|
||||
public void testConstructorChainWithoutDefaults() throws Exception {
|
||||
final HashMap<String, String> defaults = new HashMap<String, String>();
|
||||
defaults.put("i", "2");
|
||||
defaults.put("j", null);
|
||||
doTest(true, defaults);
|
||||
}
|
||||
|
||||
public void testConstructorTree() throws Exception {
|
||||
doTest(true, null, "Found constructors are not reducible to simple chain");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user