public static ITextSelection createSelectionExtension( AbstractScopeNode<?> scope, ITextSelection selection) { SelectionExtenderVisitor visitor = null; try { visitor = new SelectionExtenderVisitor(scope.getModule(), selection); scope.getASTNode().accept(visitor); } catch (Exception e) { throw new RuntimeException(e); } return visitor.getSelection(); }
private void deduce() { ModuleAdapter module = scopeAdapter.getModule(); List<SimpleAdapter> selected = module.getWithinSelection(selection, scopeAdapter.getUsedVariables()); List<SimpleAdapter> before = new ArrayList<SimpleAdapter>(); List<SimpleAdapter> after = new ArrayList<SimpleAdapter>(); extractBeforeAfterVariables(selected, before, after); deduceParameters(before, selected); deduceReturns(after, selected); }
@Override public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException { AbstractScopeNode<?> scope = info.getScopeAdapter(); ITextSelection selection = info.getUserSelection(); SimpleNode node = scope.getASTNode(); LocalVariablesVisitor visitor = new LocalVariablesVisitor(); try { node.accept(visitor); } catch (Exception e) { throw new RuntimeException(e); } List<Name> variables = visitor.getVariables(); Name selectedVariable = findSelectedVariable(selection, variables); if (selectedVariable == null) { status.addFatalError(Messages.validationNoNameSelected); return status; } List<Name> relatedVariables = findAllRelatedVariables(variables, selectedVariable); Assign assignment = findAssignment(relatedVariables); if (assignment == null) { String id = selectedVariable.id; status.addFatalError(Messages.format(Messages.inlinelocalNoAssignment, id)); return status; } if (!isValid(relatedVariables)) { return status; } requestProcessor.setAssign(assignment); requestProcessor.setVariables(relatedVariables); return status; }
private void extractBeforeAfterVariables( List<SimpleAdapter> selectedVariables, List<SimpleAdapter> before, List<SimpleAdapter> after) { List<SimpleAdapter> scopeVariables = scopeAdapter.getUsedVariables(); if (selectedVariables.isEmpty()) { return; } SimpleAdapter firstSelectedVariable = selectedVariables.get(0); SimpleAdapter lastSelectedVariable = selectedVariables.get(selectedVariables.size() - 1); for (SimpleAdapter adapter : scopeVariables) { if (isBeforeSelectedLine(firstSelectedVariable, adapter) || isBeforeOnSameLine(firstSelectedVariable, adapter)) { before.add(adapter); } else if (isAfterSelectedLine(lastSelectedVariable, adapter) || isAfterOnSameLine(lastSelectedVariable, adapter)) { after.add(adapter); } } }