introduce parameter object: no need to change signature for overriders as they would be changed anyway; correct varargs method processing (IDEA-68920 )

This commit is contained in:
anna
2011-08-19 21:10:52 +02:00
parent 21b9055379
commit edcc4a17e0
6 changed files with 113 additions and 12 deletions
@@ -0,0 +1,17 @@
public class Param {
private final String a;
private final String b;
public Param(String a, String b) {
this.a = a;
this.b = b;
}
public String getA() {
return a;
}
public String getB() {
return b;
}
}
@@ -0,0 +1,30 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
interface Test {
void foo(Param param, String... v);
}
class TestImpl implements Test {
@Override
public void foo(Param param, String... v) {
}
void bar(){
foo(new Param("a", "b"), "c");
foo(new Param("a", "b"));
foo(new Param("a", "b"), "c", "d");
}
}
@@ -0,0 +1,30 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
interface Test {
void foo(String a, String b, String... v);
}
class TestImpl implements Test {
@Override
public void foo(String a, String b, String... v) {
}
void bar(){
foo("a", "b", "c");
foo("a", "b");
foo("a", "b", "c", "d");
}
}
@@ -115,6 +115,24 @@ public class IntroduceParameterObjectTest extends MultiFileTestCase{
doTest();
}
public void testSameTypeAndVarargs() throws Exception {
doTest(false, false, new Function<PsiMethod, ParameterTablePanel.VariableData[]>() {
@Override
public ParameterTablePanel.VariableData[] fun(PsiMethod method) {
final PsiParameter[] parameters = method.getParameterList().getParameters();
final ParameterTablePanel.VariableData[] datas = new ParameterTablePanel.VariableData[parameters.length - 1];
for (int i = 0; i < parameters.length - 1; i++) {
PsiParameter parameter = parameters[i];
datas[i] = new ParameterTablePanel.VariableData(parameter);
datas[i].name = parameter.getName();
datas[i].passAsParameter = true;
}
return datas;
}
});
}
public void testTypeParametersWithChosenSubtype() throws Exception {
doTest(false, true, new Function<PsiMethod, ParameterTablePanel.VariableData[]>() {
@Override