Search in sources :

Example 11 with ExtractMethodRefactoring

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

the class ExtractMethodIntegrationTest method testBug_404244.

@Test
public void testBug_404244() {
    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("\"foo\".contains($\"my string\"$)");
    _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 foo() {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("\"foo\".contains(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 bar() {");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("\"my string\"");
    _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 12 with ExtractMethodRefactoring

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

the class ExtractMethodIntegrationTest method testTypeParameter_0.

@Test
public void testTypeParameter_0() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def <T> foo() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("$<T>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> 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 <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);
}
Also used : ExtractMethodRefactoring(org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test)

Example 13 with ExtractMethodRefactoring

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

the class ExtractMethodIntegrationTest method assertExtractForbidden.

protected void assertExtractForbidden(final CharSequence input, final Procedure1<? super ExtractMethodRefactoring> initializer, final String messageFragment) {
    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<String, XtextResource> _function = (XtextResource it) -> {
                String _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.setMethodName("bar");
                    NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
                    final RefactoringStatus status = refactoring.checkInitialConditions(_nullProgressMonitor);
                    initializer.apply(refactoring);
                    NullProgressMonitor _nullProgressMonitor_1 = new NullProgressMonitor();
                    status.merge(refactoring.checkFinalConditions(_nullProgressMonitor_1));
                    Assert.assertTrue(status.toString(), status.hasError());
                    final String message = status.getMessageMatchingSeverity(RefactoringStatus.ERROR);
                    Assert.assertTrue(message, message.toLowerCase().contains(messageFragment.toLowerCase()));
                    _xblockexpression = "";
                }
                return _xblockexpression;
            };
            editor.getDocument().<String>readOnly(_function);
        } 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) ExtractMethodRefactoring(org.eclipse.xtend.ide.refactoring.ExtractMethodRefactoring) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 14 with ExtractMethodRefactoring

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

the class ExtractMethodIntegrationTest method testTemplateExpression_22.

@Test
public void testTemplateExpression_22() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Foo {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def foo(boolean a) \'");
    _builder.append("\'\'");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("�", "\t\t");
    _builder.append("IF a");
    _builder.append("�", "\t\t");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("$x\t");
    _builder.append("�", "\t\t");
    _builder.append("1");
    _builder.append("�", "\t\t");
    _builder.append("$");
    _builder.newLineIfNotEmpty();
    _builder.append("\t\t");
    _builder.append("�", "\t\t");
    _builder.append(" /* lalala */ ENDIF");
    _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(boolean a) \'");
    _builder_1.append("\'\'");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("�", "\t\t");
    _builder_1.append("IF a");
    _builder_1.append("�", "\t\t");
    _builder_1.append("�", "\t\t");
    _builder_1.append("bar()");
    _builder_1.append("�", "\t\t");
    _builder_1.newLineIfNotEmpty();
    _builder_1.append("\t\t");
    _builder_1.append("�", "\t\t");
    _builder_1.append(" /* lalala */ ENDIF");
    _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()");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("\'");
    _builder_1.append("\'\'");
    _builder_1.newLine();
    _builder_1.append("\t\t");
    _builder_1.append("x\t");
    _builder_1.append("�", "\t\t");
    _builder_1.append("1");
    _builder_1.append("�", "\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 15 with ExtractMethodRefactoring

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

the class ExtractMethodIntegrationTest method testTemplateExpression_16.

@Test
public void testTemplateExpression_16() {
    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 */ va$lue /* 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)

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