Search in sources :

Example 21 with ExtractMethodRefactoring

use of org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring in project xtext-xtend by eclipse.

the class ExtractMethodIntegrationTest method test_Issue_107_a.

@Test
public void test_Issue_107_a() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("import java.util.ArrayList");
    _builder.newLine();
    _builder.newLine();
    _builder.append("class Test {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def void test() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("$val int a = 5");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("new ArrayList<Integer>.addAll(#[a])$");
    _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("import java.util.ArrayList");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("class Test {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def void test() {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("bar()");
    _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 boolean bar() {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("val int a = 5");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("new ArrayList<Integer>.addAll(#[a])");
    _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);
}
Also used : ExtractMethodRefactoring(org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 22 with ExtractMethodRefactoring

use of org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring in project xtext-xtend by eclipse.

the class ExtractMethodIntegrationTest method testRenameParameter.

@Test
public void testRenameParameter() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo(int shrinkMe, int expandMe) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("$shrinkMe + expandMe - shrinkMe-  expandMe$");
    _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("s");
        ParameterInfo _get_1 = it.getParameterInfos().get(1);
        _get_1.setNewName("expandMeMore");
    };
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("class Foo {");
    _builder_1.newLine();
    _builder_1.append("\t");
    _builder_1.append("def foo(int shrinkMe, int expandMe) {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("bar(shrinkMe, expandMe)");
    _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 s, int expandMeMore) {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("s + expandMeMore - s-  expandMeMore");
    _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);
}
Also used : ExtractMethodRefactoring(org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ParameterInfo(org.eclipse.jdt.internal.corext.refactoring.ParameterInfo) Test(org.junit.Test)

Example 23 with ExtractMethodRefactoring

use of org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring in project xtext-xtend by eclipse.

the class ExtractMethodIntegrationTest method testTemplateExpression_20.

@Test
public void testTemplateExpression_20() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo(int i) \'");
    _builder.append("\'\'");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("�", "\t\t");
    _builder.append("FOR j : 1 .. i");
    _builder.append("�", "\t\t");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t\t");
    _builder.append("$x   ");
    _builder.append("�", "\t\t\t");
    _builder.append("j");
    _builder.append("�", "\t\t\t");
    _builder.append("$");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("�", "\t\t");
    _builder.append("ENDFOR");
    _builder.append("�", "\t\t");
    _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(int i) \'");
    _builder_1.append("\'\'");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("�", "\t\t");
    _builder_1.append("FOR j : 1 .. i");
    _builder_1.append("�", "\t\t");
    _builder_1.append("�", "\t\t");
    _builder_1.append("bar(j)");
    _builder_1.append("�", "\t\t");
    _builder_1.newLineIfNotEmpty();
    _builder_1.append("\t\t");
    _builder_1.append("�", "\t\t");
    _builder_1.append("ENDFOR");
    _builder_1.append("�", "\t\t");
    _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(Integer j)");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("\'");
    _builder_1.append("\'\'");
    _builder_1.newLine();
    _builder_1.append("\t\t\t");
    _builder_1.append("x   ");
    _builder_1.append("�", "\t\t\t");
    _builder_1.append("j");
    _builder_1.append("�", "\t\t\t");
    _builder_1.append("\'");
    _builder_1.append("\'\'");
    _builder_1.newLineIfNotEmpty();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertAfterExtract(_builder, _function, _builder_1);
}
Also used : ExtractMethodRefactoring(org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 24 with ExtractMethodRefactoring

use of org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring in project xtext-xtend by eclipse.

the class ExtractMethodIntegrationTest method testTemplateExpression_09.

@Test
public void testTemplateExpression_09() {
    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.append("�", "\t");
    _builder_1.append("bar(value)");
    _builder_1.append("�", "\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("\'");
    _builder_1.append("\'\'");
    _builder_1.newLine();
    _builder_1.append("\t\t\t");
    _builder_1.append("Hello ");
    _builder_1.append("�", "\t\t\t");
    _builder_1.append(" /* prefix */ value /* postfix */ ");
    _builder_1.append("�", "\t\t\t");
    _builder_1.append("\'");
    _builder_1.append("\'\'");
    _builder_1.newLineIfNotEmpty();
    _builder_1.append("\t");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertAfterExtract(_builder, _function, _builder_1);
}
Also used : ExtractMethodRefactoring(org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 25 with ExtractMethodRefactoring

use of org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring in project xtext-xtend by eclipse.

the class ExtractMethodIntegrationTest method testReturnValue.

@Test
public void testReturnValue() {
    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 = 1$");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("val y = x");
    _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() {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("val x = bar()");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("val y = 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 int bar() {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("1");
    _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);
}
Also used : ExtractMethodRefactoring(org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Aggregations

ExtractMethodRefactoring (org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring)51 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)49 Test (org.junit.Test)49 ParameterInfo (org.eclipse.jdt.internal.corext.refactoring.ParameterInfo)3 IFile (org.eclipse.core.resources.IFile)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 TextSelection (org.eclipse.jface.text.TextSelection)2 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)2 XtextResource (org.eclipse.xtext.resource.XtextResource)2 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)2 XExpression (org.eclipse.xtext.xbase.XExpression)2 Change (org.eclipse.ltk.core.refactoring.Change)1