Examples of RefactoringStatusException


Examples of org.pdtextensions.core.ui.exception.RefactoringStatusException

  }

  private void parsePHPCode() throws RefactoringStatusException {
   
    if(fSourceModule == null) {
      throw new RefactoringStatusException("The script must be on the build path of a project.");
    }
   
    try {
      // parse the php code and create a program
      ASTParser parser = ASTParser.newParser(fSourceModule);
      fProgram = parser.createAST(null);
    } catch(Exception e) {
      throw new RefactoringStatusException(RefactoringMessages.ExtractMethodInputPage_errorCouldNotParseSourceCode);
    }
   
    // Get covering namespace/class/method/function declaration
    fCoveringDeclarationFinder = new CoveringDeclarationFinder();
    fCoveringDeclarationFinder.setRange(getSelectedRange());
    fProgram.accept(fCoveringDeclarationFinder);
   
    try {
      // retrieve method, which covers the selected code
      fSelectedMethodSourceRange = SourceRangeUtil.createFrom(fCoveringDeclarationFinder.getCoveringMethodDeclaration());
      // get the access modifiers from the covering method (e.g. public/protected/private) and ignore final/static etc.. modifiers
      fModifierAccessFlag = fCoveringDeclarationFinder.getCoveringMethodDeclaration().getModifier() & (Modifiers.AccPublic | Modifiers.AccProtected | Modifiers.AccPrivate | Modifiers.AccStatic);
     
      if(!SourceRangeUtil.covers(SourceRangeUtil.createFrom(fCoveringDeclarationFinder.getCoveringFunctionDeclaration().getBody()), fSelectedSourceRange)) {
        throw new Exception();
      }
     
    } catch(Exception e) {
      throw new RefactoringStatusException(RefactoringMessages.ExtractMethodInputPage_errorCouldNotRetrieveCoveringMethodDeclaration);
    }
   
    // compute source ranges before and after the selected code
    fPreSelectedSourceRange = new SourceRange(fSelectedMethodSourceRange.getOffset(), fSelectionStart - fSelectedMethodSourceRange.getOffset());
    fPostSelectedSourceRange = new SourceRange(fSelectionStart + fSelectionLength, fSelectedMethodSourceRange.getOffset() + fSelectedMethodSourceRange.getLength() - fSelectionStart + fSelectionLength);
   
    // find all variables used in the selected method
    LocalVariableFinder finder = new LocalVariableFinder();
    finder.setRange(fSelectedMethodSourceRange);
    fProgram.accept(finder);
   
    // those are the used variables, including method parameters
    fMethodVariables = finder.getFoundVariables();
    // those are only the method parameters, as FormalParameter
    fMethodParameters = finder.getParameters();
   
    // find all assignments in the selected method
    RangeAssignmentFinder assignmentFinder = new RangeAssignmentFinder();
    assignmentFinder.setRange(fSelectedMethodSourceRange);
    fProgram.accept(assignmentFinder);
   
    // those are all assignments in the selected method
    fMethodAssignments = assignmentFinder.getFoundAssignments();
   
    fSelectedNodesFinder = new RangeNodeFinder(fSelectedSourceRange);
    fProgram.accept(fSelectedNodesFinder);
   
    if(fSelectedNodesFinder.getNodes().size() == 0) {
      throw new RefactoringStatusException(RefactoringMessages.ExtractMethodInputPage_errorCouldNotParseSelectedCode);
    }
   
    ReturnStatementFinder returnFinder = new ReturnStatementFinder();
    returnFinder.setRange(fSelectedSourceRange);
    fProgram.accept(returnFinder);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.