Search in sources :

Example 31 with ExtractMethodRefactoring

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

the class ExtractMethodIntegrationTest method testStatic.

@Test
public void testStatic() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def static foo() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("$val x = 1$");
    _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 static foo() {");
    _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 static bar() {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("val x = 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)

Example 32 with ExtractMethodRefactoring

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

the class ExtractMethodIntegrationTest method testReturnStatements_0.

@Test
public void testReturnStatements_0() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo(int i) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("$switch i {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("case 0: return 0");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("switch i {");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("case 2: return \'\'");
    _builder.newLine();
    _builder.append("\t\t\t");
    _builder.append("case 3: return null");
    _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 i) {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("bar(i)");
    _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 Object bar(int i) {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("switch i {");
    _builder_1.newLine();
    _builder_1.append("\t\t\t");
    _builder_1.append("case 0: return 0");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("switch i {");
    _builder_1.newLine();
    _builder_1.append("\t\t\t");
    _builder_1.append("case 2: return \'\'");
    _builder_1.newLine();
    _builder_1.append("\t\t\t");
    _builder_1.append("case 3: return null");
    _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);
}
Also used : ExtractMethodRefactoring(org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 33 with ExtractMethodRefactoring

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

the class ExtractMethodIntegrationTest method assertAfterExtract.

protected void assertAfterExtract(final CharSequence input, final Procedure1<? super ExtractMethodRefactoring> initializer, final CharSequence expected) {
    try {
        final String inputString = input.toString();
        final IFile file = this.workbenchTestHelper.createFile("Foo", inputString.replace("$", ""));
        final XtextEditor editor = this.workbenchTestHelper.openEditor(file);
        try {
            final IUnitOfWork<Change, XtextResource> _function = (XtextResource it) -> {
                Change _xblockexpression = null;
                {
                    int _indexOf = inputString.indexOf("$");
                    int _lastIndexOf = inputString.lastIndexOf("$");
                    int _indexOf_1 = inputString.indexOf("$");
                    int _minus = (_lastIndexOf - _indexOf_1);
                    int _minus_1 = (_minus - 1);
                    TextSelection _textSelection = new TextSelection(_indexOf, _minus_1);
                    final List<XExpression> selection = this.util.findSelectedSiblingExpressions(it, _textSelection);
                    final ExtractMethodRefactoring refactoring = this.refactoringProvider.get();
                    refactoring.initialize(editor, selection, true);
                    refactoring.setExplicitlyDeclareReturnType(false);
                    refactoring.setVisibility(JvmVisibility.PUBLIC);
                    refactoring.setMethodName("bar");
                    NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
                    RefactoringStatus status = refactoring.checkInitialConditions(_nullProgressMonitor);
                    Assert.assertTrue(status.toString(), status.isOK());
                    initializer.apply(refactoring);
                    NullProgressMonitor _nullProgressMonitor_1 = new NullProgressMonitor();
                    status = refactoring.checkFinalConditions(_nullProgressMonitor_1);
                    Assert.assertTrue(status.toString(), status.isOK());
                    NullProgressMonitor _nullProgressMonitor_2 = new NullProgressMonitor();
                    Change _createChange = refactoring.createChange(_nullProgressMonitor_2);
                    NullProgressMonitor _nullProgressMonitor_3 = new NullProgressMonitor();
                    _xblockexpression = _createChange.perform(_nullProgressMonitor_3);
                }
                return _xblockexpression;
            };
            editor.getDocument().<Change>readOnly(_function);
            Assert.assertEquals(expected.toString(), editor.getDocument().get());
        } finally {
            editor.close(false);
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) TextSelection(org.eclipse.jface.text.TextSelection) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) XtextResource(org.eclipse.xtext.resource.XtextResource) Change(org.eclipse.ltk.core.refactoring.Change) ExtractMethodRefactoring(org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 34 with ExtractMethodRefactoring

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

the class ExtractMethodIntegrationTest method testTemplateExpression_15.

@Test
public void testTemplateExpression_15() {
    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.append("\'\'");
    _builder_1.newLineIfNotEmpty();
    _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.append("�", "\t\t");
    _builder_1.append(" /* prefix */ value /* postfix */ ");
    _builder_1.append("�", "\t\t");
    _builder_1.append("!");
    _builder_1.newLineIfNotEmpty();
    _builder_1.append("\t\t\t");
    _builder_1.append("\'");
    _builder_1.append("\'\'");
    _builder_1.newLine();
    _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 35 with ExtractMethodRefactoring

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

the class ExtractMethodIntegrationTest method testTemplateExpression_07.

@Test
public void testTemplateExpression_07() {
    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);
}
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