Beispiel #1
0
 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();
 }
  @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;
  }