Example #1
0
  public static List<Node> getArgumentNodesFromFunctionCall(IArgumentNode iVisited) {
    List<Node> arguments = new ArrayList<Node>();
    Node argsNode = iVisited.getArgsNode();

    Iterator<Node> iter = null;
    if (argsNode != null) {
      iter = argsNode.childNodes().iterator();
    } else {
      // block?
      Node iterNode = null;
      if (iVisited instanceof FCallNode) {
        iterNode = ((FCallNode) iVisited).getIterNode();
      } else if (iVisited instanceof CallNode) {
        iterNode = ((CallNode) iVisited).getIterNode();
      }

      if (iterNode == null) {
        return arguments;
      }
      if (iterNode instanceof IterNode) {
        // yup, it has a block
        IterNode yeah = (IterNode) iterNode;
        Node varNode = yeah.getVarNode();
        if (varNode instanceof DAsgnNode) {
          // single variable in the block
          arguments.add(varNode);
        } else if (varNode instanceof MultipleAsgnNode) {
          // multiple variables in the block
          MultipleAsgnNode multi = (MultipleAsgnNode) varNode;
          ListNode list = multi.getHeadNode();
          if (list != null) {
            iter = list.childNodes().iterator();
          } else {
            Node multiArgsNode = multi.getArgsNode();
            if (multiArgsNode instanceof DAsgnNode) {
              arguments.add(multiArgsNode);
            }
          }
        }
      }
    }
    if (iter == null) {
      return arguments;
    }
    while (iter.hasNext()) {
      arguments.add(iter.next());
    }
    return arguments;
  }
Example #2
0
 public static String getStringRepresentation(Node node) {
   if (node == null) {
     return ""; //$NON-NLS-1$
   }
   if (node instanceof HashNode) {
     return "{}"; //$NON-NLS-1$
   }
   if (node instanceof SelfNode) {
     return "self"; //$NON-NLS-1$
   }
   if (node instanceof NilNode) {
     return "nil"; //$NON-NLS-1$
   }
   if (node instanceof TrueNode) {
     return "true"; //$NON-NLS-1$
   }
   if (node instanceof FalseNode) {
     return "false"; //$NON-NLS-1$
   }
   if (node instanceof SymbolNode) {
     return ':' + ((SymbolNode) node).getName();
   }
   if (node instanceof INameNode) {
     return ((INameNode) node).getName();
   }
   if (node instanceof ZArrayNode) {
     return "[]"; //$NON-NLS-1$
   }
   if (node instanceof FixnumNode) {
     return String.valueOf(((FixnumNode) node).getValue());
   }
   if (node instanceof StrNode) {
     return '"' + ((StrNode) node).getValue().toString() + '"';
   }
   if (node instanceof DStrNode) {
     List<Node> children = node.childNodes();
     StringBuilder text = new StringBuilder();
     text.append("\""); // $NON-NLS-1$
     for (Node child : children) {
       text.append(getStringRepresentation(child));
     }
     text.append("\""); // $NON-NLS-1$
     return text.toString();
   }
   return node.toString();
 }