use of org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring in project xtext-xtend by eclipse.
the class ExtractMethodIntegrationTest method testSwapParameterNames.
@Test
public void testSwapParameterNames() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("def foo(int i, int j) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("$i-j$");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<ExtractMethodRefactoring> _function = (ExtractMethodRefactoring it) -> {
ParameterInfo _get = it.getParameterInfos().get(0);
_get.setNewName("j");
ParameterInfo _get_1 = it.getParameterInfos().get(1);
_get_1.setNewName("i");
};
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("class Foo {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def foo(int i, int j) {");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("bar(i, j)");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def bar(int j, int i) {");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("j-i");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
this.assertAfterExtract(_builder, _function, _builder_1);
}
use of org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring in project xtext-xtend by eclipse.
the class ExtractMethodIntegrationTest method testTypeParameter_1.
@Test
public void testTypeParameter_1() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("def <T, U> foo() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("if(true) ");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("$<T>newArrayList$");
_builder.newLine();
_builder.append("\t\t");
_builder.append("else");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("<U>newArrayList");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<ExtractMethodRefactoring> _function = (ExtractMethodRefactoring it) -> {
};
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("class Foo {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def <T, U> foo() {");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("if(true) ");
_builder_1.newLine();
_builder_1.append("\t\t\t");
_builder_1.append("bar()");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("else");
_builder_1.newLine();
_builder_1.append("\t\t\t");
_builder_1.append("<U>newArrayList");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def <T> bar() {");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("<T>newArrayList");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
this.assertAfterExtract(_builder, _function, _builder_1);
}
use of org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring in project xtext-xtend by eclipse.
the class ExtractMethodIntegrationTest method testFailOnDuplicateParameterName.
@Test
public void testFailOnDuplicateParameterName() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("def foo() {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val x = 4");
_builder.newLine();
_builder.append("\t\t");
_builder.append("val y = 2");
_builder.newLine();
_builder.append("\t\t");
_builder.append("$x+y$");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<ExtractMethodRefactoring> _function = (ExtractMethodRefactoring it) -> {
ParameterInfo _get = it.getParameterInfos().get(1);
_get.setNewName("x");
};
this.assertExtractForbidden(_builder, _function, "duplicate");
}
use of org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring in project xtext-xtend by eclipse.
the class ExtractMethodIntegrationTest method testVoidStatements.
@Test
public void testVoidStatements() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("def foo(int x) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("$for (i : x..45) {");
_builder.newLine();
_builder.append("\t\t\t");
_builder.append("println(i)");
_builder.newLine();
_builder.append("\t\t");
_builder.append("}$");
_builder.newLine();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<ExtractMethodRefactoring> _function = (ExtractMethodRefactoring it) -> {
it.setExplicitlyDeclareReturnType(true);
};
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("class Foo {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def foo(int x) {");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("bar(x)");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def void bar(int x) {");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("for (i : x..45) {");
_builder_1.newLine();
_builder_1.append("\t\t\t");
_builder_1.append("println(i)");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
this.assertAfterExtract(_builder, _function, _builder_1);
}
use of org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring in project xtext-xtend by eclipse.
the class ExtractMethodIntegrationTest method testTemplateExpression_06.
@Test
public void testTemplateExpression_06() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("class Foo {");
_builder.newLine();
_builder.append("\t");
_builder.append("def foo(String value) \'");
_builder.append("\'\'");
_builder.newLine();
_builder.append("\t\t");
_builder.append("Hello ");
_builder.append("�", "\t\t");
_builder.append("$ /* prefix */ value /* postfix */ ");
_builder.append("�", "\t\t");
_builder.append("$!");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("\'");
_builder.append("\'\'");
_builder.newLine();
_builder.append("}");
_builder.newLine();
final Procedure1<ExtractMethodRefactoring> _function = (ExtractMethodRefactoring it) -> {
};
StringConcatenation _builder_1 = new StringConcatenation();
_builder_1.append("class Foo {");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def foo(String value) \'");
_builder_1.append("\'\'");
_builder_1.newLine();
_builder_1.append("\t\t");
_builder_1.append("Hello ");
_builder_1.append("�", "\t\t");
_builder_1.append("bar(value)");
_builder_1.append("�", "\t\t");
_builder_1.append("!");
_builder_1.newLineIfNotEmpty();
_builder_1.append("\t");
_builder_1.append("\'");
_builder_1.append("\'\'");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("def bar(String value) {");
_builder_1.newLine();
_builder_1.append("\t\t ");
_builder_1.append("/* prefix */ value /* postfix */ ");
_builder_1.newLine();
_builder_1.append("\t");
_builder_1.append("}");
_builder_1.newLine();
_builder_1.append("}");
_builder_1.newLine();
this.assertAfterExtract(_builder, _function, _builder_1);
}
Aggregations