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);
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations