@Override public RefactoringStatus checkInitialConditions(final IProgressMonitor monitor) throws CoreException { final SubMonitor progress = SubMonitor.convert(monitor, 6); try { if (fSelectionRegion != null) { fSourceUnit.connect(progress.newChild(1)); try { final AbstractDocument document = fSourceUnit.getDocument(monitor); final IRModelInfo modelInfo = (IRModelInfo) fSourceUnit.getModelInfo( RModel.TYPE_ID, IRModelManager.MODEL_FILE, progress.newChild(1)); if (modelInfo != null) { final IRegion region = fAdapter.trimToAstRegion(document, fSelectionRegion); ISourceStructElement element = LTKUtil.getCoveringSourceElement(modelInfo.getSourceElement(), region); while (element != null) { if (element instanceof IRMethod) { fFunction = (IRMethod) element; break; } element = element.getSourceParent(); } } if (fFunction != null) { final ISourceStructElement source = (ISourceStructElement) fFunction; fOperationRegion = fAdapter.expandSelectionRegion(document, source.getSourceRange(), fSelectionRegion); } } finally { fSourceUnit.disconnect(progress.newChild(1)); } } if (fFunction == null) { return RefactoringStatus.createFatalErrorStatus( Messages.FunctionToS4Method_error_InvalidSelection_message); } final RefactoringStatus result = new RefactoringStatus(); fAdapter.checkInitialForModification(result, fElementSet); progress.worked(1); if (result.hasFatalError()) { return result; } checkFunction(result); progress.worked(2); return result; } finally { progress.done(); } }
@Override public RefactoringStatus checkInitialConditions(final IProgressMonitor monitor) throws CoreException { final SubMonitor progress = SubMonitor.convert(monitor, 6); RAstNode rootNode = null; try { if (fSelectionRegion != null) { fSourceUnit.connect(progress.newChild(1)); try { final AbstractDocument document = fSourceUnit.getDocument(monitor); final RHeuristicTokenScanner scanner = fAdapter.getScanner(fSourceUnit); final IRModelInfo modelInfo = (IRModelInfo) fSourceUnit.getModelInfo( RModel.TYPE_ID, IRModelManager.MODEL_FILE, progress.newChild(1)); if (modelInfo != null) { final IRegion region = fAdapter.trimToAstRegion(document, fSelectionRegion, scanner); final AstInfo ast = modelInfo.getAst(); if (ast != null) { rootNode = (RAstNode) AstSelection.search( ast.root, region.getOffset(), region.getOffset() + region.getLength(), AstSelection.MODE_COVERING_SAME_LAST) .getCovering(); } } } finally { fSourceUnit.disconnect(progress.newChild(1)); } } if (rootNode == null) { return RefactoringStatus.createFatalErrorStatus( Messages.ExtractTemp_error_InvalidSelection_message); } final RefactoringStatus result = new RefactoringStatus(); fAdapter.checkInitialToModify(result, fElementSet); progress.worked(1); if (result.hasFatalError()) { return result; } searchVariables(rootNode, result); progress.worked(2); return result; } finally { progress.done(); } }