Search in sources :

Example 1 with Section

use of org.eclipse.xtext.xbase.ui.document.DocumentRewriter.Section in project xtext-xtend by eclipse.

the class ExtractMethodRefactoring method checkFinalConditions.

@Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm) throws CoreException, OperationCanceledException {
    StatusWrapper status = statusProvider.get();
    try {
        status.merge(validateMethodName(methodName));
        status.merge(validateParameters());
        ITextRegion expressionsRegion = getExpressionsRegion();
        ITextRegion predecessorRegion = locationInFileProvider.getFullTextRegion(originalMethod);
        if (pm.isCanceled()) {
            throw new OperationCanceledException();
        }
        Section expressionSection = rewriter.newSection(expressionsRegion.getOffset(), expressionsRegion.getLength());
        Section declarationSection = rewriter.newSection(predecessorRegion.getOffset() + predecessorRegion.getLength(), 0);
        createMethodCallEdit(expressionSection, expressionsRegion);
        if (pm.isCanceled()) {
            throw new OperationCanceledException();
        }
        createMethodDeclarationEdit(declarationSection, expressionSection.getBaseIndentLevel(), expressionsRegion);
        if (pm.isCanceled()) {
            throw new OperationCanceledException();
        }
        textEdit = replaceConverter.convertToTextEdit(rewriter.getChanges());
    } catch (OperationCanceledException e) {
        throw e;
    } catch (Exception exc) {
        handleException(exc, status);
    }
    return status.getRefactoringStatus();
}
Also used : ITextRegion(org.eclipse.xtext.util.ITextRegion) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) StatusWrapper(org.eclipse.xtext.ui.refactoring.impl.StatusWrapper) Section(org.eclipse.xtext.xbase.ui.document.DocumentRewriter.Section) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

CoreException (org.eclipse.core.runtime.CoreException)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 StatusWrapper (org.eclipse.xtext.ui.refactoring.impl.StatusWrapper)1 ITextRegion (org.eclipse.xtext.util.ITextRegion)1 Section (org.eclipse.xtext.xbase.ui.document.DocumentRewriter.Section)1