Ejemplo n.º 1
0
 public ExtractMethodRefactoring(CompilationUnit unit, int selectionStart, int selectionLength) {
   this.unit = unit;
   this.selectionStart = selectionStart;
   this.selectionLength = selectionLength;
   this.selectionRange = SourceRangeFactory.forStartLength(selectionStart, selectionLength);
   this.methodName = "extracted"; // $NON-NLS-1$
 }
Ejemplo n.º 2
0
 /**
  * Checks if {@link #selectionRange} selects {@link DartExpression} or set of {@link
  * DartStatement}s which can be extracted, and location in AST allows extracting.
  */
 private RefactoringStatus checkSelection(IProgressMonitor pm) throws CoreException {
   Selection selection = Selection.createFromStartLength(selectionStart, selectionLength);
   selectionAnalyzer = new ExtractMethodAnalyzer(unit, selection);
   unitNode.accept(selectionAnalyzer);
   // may be fatal error
   {
     RefactoringStatus status = selectionAnalyzer.getStatus();
     if (status.hasFatalError()) {
       return status;
     }
   }
   // update selection
   selectionLength = selectionAnalyzer.getSelectionExclusiveEnd() - selectionStart;
   selectionRange = SourceRangeFactory.forStartLength(selectionStart, selectionLength);
   // check selected nodes
   DartNode[] selectedNodes = selectionAnalyzer.getSelectedNodes();
   if (selectedNodes.length > 0) {
     parentMember =
         ASTNodes.getParent(selectionAnalyzer.getLastCoveringNode(), DartClassMember.class);
     // single expression selected
     if (selectedNodes.length == 1
         && !utils.rangeIncludesNonWhitespaceOutsideNode(
             selectionRange, selectionAnalyzer.getFirstSelectedNode())) {
       DartNode selectedNode = selectionAnalyzer.getFirstSelectedNode();
       if (selectedNode instanceof DartExpression) {
         selectionExpression = (DartExpression) selectedNode;
         return new RefactoringStatus();
       }
     }
     // statements selected
     {
       List<DartStatement> selectedStatements = Lists.newArrayList();
       for (DartNode selectedNode : selectedNodes) {
         if (selectedNode instanceof DartStatement) {
           selectedStatements.add((DartStatement) selectedNode);
         }
       }
       if (selectedStatements.size() == selectedNodes.length) {
         selectionStatements = selectedStatements;
         return new RefactoringStatus();
       }
     }
   }
   // invalid selection
   return RefactoringStatus.createFatalErrorStatus(
       RefactoringCoreMessages.ExtractMethodAnalyzer_single_expression_or_set);
 }