Search in sources :

Example 1 with ExtractVariableRefactoring

use of org.eclipse.xtext.xbase.ui.refactoring.ExtractVariableRefactoring in project xtext-xtend by eclipse.

the class ExtractVariableIntegrationTest method assertAfterExtract.

protected void assertAfterExtract(final CharSequence input, final CharSequence expected, final boolean isFinal) {
    try {
        final String inputString = input.toString();
        final String model = inputString.replace("$", "");
        final IFile file = this.workbenchTestHelper.createFile("Foo", model);
        final XtextEditor editor = this.workbenchTestHelper.openEditor(file);
        try {
            final IUnitOfWork<Change, XtextResource> _function = (XtextResource it) -> {
                Change _xblockexpression = null;
                {
                    final int offset = inputString.indexOf("$");
                    int _lastIndexOf = inputString.lastIndexOf("$");
                    int _minus = (_lastIndexOf - 1);
                    final int length = (_minus - offset);
                    final TextSelection textSelection = new TextSelection(offset, length);
                    final XExpression selection = this.util.findSelectedExpression(it, textSelection);
                    final ExtractVariableRefactoring refactoring = this.refactoringProvider.get();
                    refactoring.setFinal(isFinal);
                    refactoring.initialize(editor, selection);
                    NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
                    final RefactoringStatus status = refactoring.checkAllConditions(_nullProgressMonitor);
                    Assert.assertTrue(status.toString(), status.isOK());
                    NullProgressMonitor _nullProgressMonitor_1 = new NullProgressMonitor();
                    Change _createChange = refactoring.createChange(_nullProgressMonitor_1);
                    NullProgressMonitor _nullProgressMonitor_2 = new NullProgressMonitor();
                    _xblockexpression = _createChange.perform(_nullProgressMonitor_2);
                }
                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) ExtractVariableRefactoring(org.eclipse.xtext.xbase.ui.refactoring.ExtractVariableRefactoring) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) XtextResource(org.eclipse.xtext.resource.XtextResource) Change(org.eclipse.ltk.core.refactoring.Change) XExpression(org.eclipse.xtext.xbase.XExpression)

Aggregations

IFile (org.eclipse.core.resources.IFile)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 TextSelection (org.eclipse.jface.text.TextSelection)1 Change (org.eclipse.ltk.core.refactoring.Change)1 RefactoringStatus (org.eclipse.ltk.core.refactoring.RefactoringStatus)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)1 XExpression (org.eclipse.xtext.xbase.XExpression)1 ExtractVariableRefactoring (org.eclipse.xtext.xbase.ui.refactoring.ExtractVariableRefactoring)1