@Override
 protected void setASTField(int index, IASTNode value) {
   switch (index) {
     case 0:
       this.label = (org.eclipse.photran.internal.core.lexer.Token) value;
       if (value != null) value.setParent(this);
       return;
     case 1:
       this.hiddenTEnd = (org.eclipse.photran.internal.core.lexer.Token) value;
       if (value != null) value.setParent(this);
       return;
     case 2:
       this.hiddenTStructure = (org.eclipse.photran.internal.core.lexer.Token) value;
       if (value != null) value.setParent(this);
       return;
     case 3:
       this.hiddenTEndstructure = (org.eclipse.photran.internal.core.lexer.Token) value;
       if (value != null) value.setParent(this);
       return;
     case 4:
       this.hiddenTEos = (org.eclipse.photran.internal.core.lexer.Token) value;
       if (value != null) value.setParent(this);
       return;
     default:
       throw new IllegalArgumentException("Invalid index");
   }
 }
  @Override
  protected void doCheckInitialConditions(RefactoringStatus status, IProgressMonitor pm)
      throws PreconditionFailure {
    ensureProjectHasRefactoringEnabled(status);

    // ASTSubroutineSubprogramNode s = getNode(astOfFileInEditor, selectedRegionInEditor,
    // ASTSubroutineSubprogramNode.class);

    newParameterList = new ArrayList<ASTSubroutineParNode>();
    if (sigma == null) sigma = new ArrayList<Integer>();

    IASTNode temporaryNode = findEnclosingNode(astOfFileInEditor, selectedRegionInEditor);

    if (temporaryNode == null)
      fail(Messages.PermuteSubroutineArgsRefactoring_selectedTextNotSubroutine);

    if (temporaryNode instanceof ASTSubroutineSubprogramNode)
      selectedSubroutine = ((ASTSubroutineSubprogramNode) temporaryNode).getSubroutineStmt();
    else if (temporaryNode instanceof ASTSubroutineStmtNode) {
      if (temporaryNode.findNearestAncestor(ASTSubroutineSubprogramNode.class) == null)
        fail(Messages.PermuteSubroutineArgsRefactoring_selectSubroutineError);
      selectedSubroutine = (ASTSubroutineStmtNode) temporaryNode;
    } else fail(Messages.PermuteSubroutineArgsRefactoring_selectedTextNotSubroutine);

    oldParameterList = getSubroutineParameters();
    newParameterList = getSubroutineParameters();

    if (!matchingDeclarationsInInterfacesUniquelyBind())
      status.addWarning(
          Messages.PermuteSubroutineArgsRefactoring_matchingDeclarationsDoNotUniquelyBind);
  }
  @SuppressWarnings("unchecked")
  protected static <T extends IASTNode> T findEnclosingNode(
      IFortranAST ast, ITextSelection selection, Class<T> type) {
    IASTNode node = findEnclosingNode(ast, selection);
    if (node == null) return null;

    if (type.isAssignableFrom(node.getClass())) return (T) node;
    else return node.findNearestAncestor(type);
  }
  protected static IASTNode findEnclosingNode(IFortranAST ast, ITextSelection selection) {
    Token firstToken = findFirstTokenAfter(ast, selection.getOffset());
    Token lastToken =
        findLastTokenBefore(
            ast, OffsetLength.getPositionPastEnd(selection.getOffset(), selection.getLength()));
    if (firstToken == null || lastToken == null) return null;

    for (IASTNode parent = lastToken.getParent(); parent != null; parent = parent.getParent())
      if (contains(parent, firstToken)) return parent;

    return null;
  }
 @Override
 protected void setASTField(int index, IASTNode value) {
   switch (index) {
     case 0:
       this.hiddenTComma = (org.eclipse.photran.internal.core.lexer.Token) value;
       if (value != null) value.setParent(this);
       return;
     case 1:
       this.variable = (ASTVariableNode) value;
       if (value != null) value.setParent(this);
       return;
     default:
       throw new IllegalArgumentException("Invalid index");
   }
 }
  protected static boolean nodeExactlyEnclosesRegion(
      IASTNode node, IFortranAST ast, ITextSelection selection) {
    Token firstInNode = node.findFirstToken();
    Token lastInNode = node.findLastToken();

    Token firstInSel = findFirstTokenAfter(ast, selection.getOffset());
    Token lastInSel =
        findLastTokenBefore(
            ast, OffsetLength.getPositionPastEnd(selection.getOffset(), selection.getLength()));

    return firstInNode != null
        && lastInNode != null
        && firstInSel != null
        && lastInSel != null
        && firstInNode == firstInSel
        && lastInNode == lastInSel;
  }
示例#7
0
 @Override
 protected void setASTField(int index, IASTNode value) {
   switch (index) {
     case 0:
       this.objectName = (ASTObjectNameNode) value;
       if (value != null) value.setParent(this);
       return;
     case 1:
       this.hiddenAsterisk2 = (org.eclipse.photran.internal.core.lexer.Token) value;
       if (value != null) value.setParent(this);
       return;
     case 2:
       this.initialCharLength = (ASTCharLengthNode) value;
       if (value != null) value.setParent(this);
       return;
     case 3:
       this.hiddenLparen2 = (org.eclipse.photran.internal.core.lexer.Token) value;
       if (value != null) value.setParent(this);
       return;
     case 4:
       this.hiddenTLparen = (org.eclipse.photran.internal.core.lexer.Token) value;
       if (value != null) value.setParent(this);
       return;
     case 5:
       this.arraySpec = (ASTArraySpecNode) value;
       if (value != null) value.setParent(this);
       return;
     case 6:
       this.hiddenTRparen = (org.eclipse.photran.internal.core.lexer.Token) value;
       if (value != null) value.setParent(this);
       return;
     case 7:
       this.hiddenTLbracket = (org.eclipse.photran.internal.core.lexer.Token) value;
       if (value != null) value.setParent(this);
       return;
     case 8:
       this.coarraySpec = (ASTCoarraySpecNode) value;
       if (value != null) value.setParent(this);
       return;
     case 9:
       this.hiddenTRbracket = (org.eclipse.photran.internal.core.lexer.Token) value;
       if (value != null) value.setParent(this);
       return;
     case 10:
       this.hiddenTAsterisk = (org.eclipse.photran.internal.core.lexer.Token) value;
       if (value != null) value.setParent(this);
       return;
     case 11:
       this.charLength = (ASTCharLengthNode) value;
       if (value != null) value.setParent(this);
       return;
     case 12:
       this.hiddenTSlash = (org.eclipse.photran.internal.core.lexer.Token) value;
       if (value != null) value.setParent(this);
       return;
     case 13:
       this.dataStmtValueList = (IASTListNode<ASTDataStmtValueNode>) value;
       if (value != null) value.setParent(this);
       return;
     case 14:
       this.hiddenTSlash2 = (org.eclipse.photran.internal.core.lexer.Token) value;
       if (value != null) value.setParent(this);
       return;
     case 15:
       this.hiddenRparen2 = (org.eclipse.photran.internal.core.lexer.Token) value;
       if (value != null) value.setParent(this);
       return;
     case 16:
       this.initialization = (ASTInitializationNode) value;
       if (value != null) value.setParent(this);
       return;
     default:
       throw new IllegalArgumentException("Invalid index");
   }
 }
 private static boolean contains(IASTNode target, Token token) {
   for (IASTNode node = token.getParent(); node != null; node = node.getParent())
     if (node == target) return true;
   return false;
 }
 protected static boolean nodeExactlyEnclosesRegion(
     IASTNode parent, Token firstToken, Token lastToken) {
   return parent.findFirstToken() == firstToken && parent.findLastToken() == lastToken;
 }