Package org.jrubyparser.ast

Examples of org.jrubyparser.ast.FCallNode


      if(n.getNodeType() == NodeType.NEWLINENODE)
        n = ((NewlineNode) n).getNextNode();

      switch(n.getNodeType()) {
        case FCALLNODE:
          FCallNode callNode = (FCallNode) n;
          if("setparameters".equals(callNode.getName()))
            for(String name : getArgs(callNode))
              parameterMap.put(name, getEntry(callNode));
          break;
        case VCALLNODE:
          VCallNode vcallNode = (VCallNode) n;
View Full Code Here


      if(n.getNodeType() == NodeType.NEWLINENODE)
        n = ((NewlineNode) n).getNextNode();

      switch(n.getNodeType()) {
        case FCALLNODE:
          FCallNode callNode = (FCallNode) n;
          if(NEWPARAM.equals(callNode.getName()))
            parameterMap.put(getFirstArg(callNode), getEntry(callNode));
          else if(NEWCHECK.equals(callNode.getName()))
            parameterMap.put(getFirstArg(callNode), getEntry(callNode));
          else if(NEWPROPERTY.equals(callNode.getName()))
            propertyMap.put(getFirstArg(callNode), getEntry(callNode));
          else if(ENSURABLE.equals(callNode.getName()))
            parameterMap.put("ensure", getEntry(callNode));
          break;
        case VCALLNODE:
          VCallNode vcallNode = (VCallNode) n;
          // A call to 'ensurable' adds 'ensure' parameter
View Full Code Here

            NodeType.BLOCKNODE, NodeType.FCALLNODE });
        if(calls.isEmpty())
          calls = RubyParserUtils.findNodes(call.getIter(), new NodeType[] { NodeType.FCALLNODE });
        if(!calls.isEmpty()) {
          for(Node snode : calls) {
            FCallNode subCall = (FCallNode) snode;
            if("desc".equals(subCall.getName())) {
              List<Node> strArgs = RubyParserUtils.findNodes(
                subCall.getArgs(), new NodeType[] { NodeType.STRNODE });
              if(strArgs.size() >= 1)
                provider.setDocumentation(((StrNode) strArgs.get(0)).getValue());
              break;
            }
          }
View Full Code Here

        // Try syntax found in iptables.rb. Not sure it's correct
        // but it seems to be parsed
        // OK by the puppet-tool
        nodes = RubyParserUtils.findNodes(puppetModule.getBody(), new NodeType[] { NodeType.FCALLNODE });
        for(Node node : nodes) {
          FCallNode call = (FCallNode) node;
          if("newtype".equals(call.getName())) {
            newtypeNode = call;
            break;
          }
        }
      }
    }
    else {
      // The call might be a CallNode at the top level
      nodes = RubyParserUtils.findNodes((root).getBody(), new NodeType[] { NodeType.CALLNODE });
      for(Node node : nodes) {
        CallNode call = (CallNode) node;
        if("newtype".equals(call.getName())) {
          Node receiver = call.getReceiver();
          if(receiver instanceof Colon2ConstNode) {
            Colon2ConstNode c2cNode = (Colon2ConstNode) receiver;
            if("Type".equals(c2cNode.getName()) && c2cNode.getLeftNode() instanceof ConstNode &&
                "Puppet".equals(((ConstNode) c2cNode.getLeftNode()).getName())) {
              newtypeNode = call;
              break;
            }
          }
        }
      }
    }

    if(newtypeNode == null)
      throw new IOException("Unable to find newtype call in " + typeFileStr);

    // Find the parameter that is passed in the call to newtype. It must
    // be one
    // single parameter in the form of a Symbol. This Symbol denotes the
    // name of
    // the new type.
    Node argsNode = ((IArgumentNode) newtypeNode).getArgs();
    nodes = RubyParserUtils.findNodes(argsNode, new NodeType[] { NodeType.SYMBOLNODE });
    if(nodes.size() != 1)
      throw new IOException("The newtype call does not take exactly one symbol parameter in " + typeFileStr);

    SymbolNode typeName = (SymbolNode) nodes.get(0);
    type.setName(typeName.getName());

    // Find the assignment of the @doc instance variable
    Node iterNode = newtypeNode.getIter();
    nodes = RubyParserUtils.findNodes(iterNode, new NodeType[] { NodeType.BLOCKNODE, NodeType.INSTASGNNODE });
    if(nodes.isEmpty())
      // No block when there's just one assignment
      nodes = RubyParserUtils.findNodes(iterNode, new NodeType[] { NodeType.INSTASGNNODE });

    for(Node node : nodes) {
      InstAsgnNode asgnNode = (InstAsgnNode) node;
      if(!"@doc".equals(asgnNode.getName()))
        continue;

      Node valueNode = asgnNode.getValue();
      if(valueNode instanceof StrNode)
        type.setDocumentation(((StrNode) valueNode).getValue());
      break;
    }

    // Find the calls to newparam (receiver is the instance returned by
    // newtype)
    nodes = RubyParserUtils.findNodes(iterNode, new NodeType[] { NodeType.BLOCKNODE, NodeType.FCALLNODE });
    if(nodes.isEmpty())
      // No block when there's just one call
      nodes = RubyParserUtils.findNodes(iterNode, new NodeType[] { NodeType.FCALLNODE });

    ArrayList<NamedTypeItem> parameters = null;
    ArrayList<NamedTypeItem> properties = null;

    for(Node node : nodes) {
      FCallNode callNode = (FCallNode) node;
      boolean isParam = "newparam".equals(callNode.getName());
      if(!isParam && !"newproperty".equals(callNode.getName()))
        continue;

      List<Node> pnodes = RubyParserUtils.findNodes(callNode.getArgs(), new NodeType[] { NodeType.SYMBOLNODE });
      if(pnodes.size() != 1)
        throw new IOException("A newparam or newproperty call does not take exactly one symbol parameter in " +
            typeFileStr);

      NamedTypeItem elem = new NamedTypeItem();
      if(isParam) {
        if(parameters == null)
          parameters = new ArrayList<NamedTypeItem>();
        parameters.add(elem);
      }
      else {
        if(properties == null)
          properties = new ArrayList<NamedTypeItem>();
        properties.add(elem);
      }

      elem.setName(((SymbolNode) pnodes.get(0)).getName());
      iterNode = callNode.getIter();
      pnodes = RubyParserUtils.findNodes(iterNode, new NodeType[] { NodeType.BLOCKNODE, NodeType.FCALLNODE });
      if(pnodes.isEmpty())
        // No block when there's just one call
        pnodes = RubyParserUtils.findNodes(iterNode, new NodeType[] { NodeType.FCALLNODE });

      for(Node pnode : pnodes) {
        FCallNode pcallNode = (FCallNode) pnode;
        if("desc".equals(pcallNode.getName())) {
          List<Node> args = pcallNode.getArgs().childNodes();
          if(args.size() != 1)
            throw new IOException(
              "A newparam or newproperty desc call does not take exactly one parameter in " + typeFileStr);
          elem.setDocumentation(RubyParserUtils.stringValue(args.get(0)));
          break;
View Full Code Here

        // classNode.getCPath();
        for(Node bn : classNode.getBody().childNodes()) {
          if(bn.getNodeType() == NodeType.NEWLINENODE)
            bn = ((NewlineNode) bn).getNextNode();
          if(bn.getNodeType() == NodeType.FCALLNODE) {
            FCallNode callNode = (FCallNode) bn;
            if("newmetaparam".equals(callNode.getName())) {
              parameterMap.put(getFirstArg(callNode), getEntry(callNode));

            }
          }
View Full Code Here

    if(bodyNode != null)
      for(Node n : bodyNode.childNodes()) {
        if(n.getNodeType() == NodeType.NEWLINENODE)
          n = ((NewlineNode) n).getNextNode();
        if(n.getNodeType() == NodeType.FCALLNODE) {
          FCallNode cn = (FCallNode) n;
          if("desc".equals(cn.getName()))
            desc = getFirstArgDefault(cn, "");
          // return new PPTypeInfo.Entry(getFirstArgDefault(cn, ""),
          // false);
        }
        else if(n.getNodeType() == NodeType.VCALLNODE) {
View Full Code Here

    nameSeen = false;
    versionSeen = false;
    fullName = null;
    File file = null;
    for(Node node : RubyParserUtils.findNodes(root.getBody(), new NodeType[] { NodeType.FCALLNODE })) {
      FCallNode call = (FCallNode) node;
      SourcePosition pos = call.getPosition();
      if(file == null)
        file = new File(pos.getFile());

      String key = call.getName();
      List<Node> args = getStringArguments(call);
      int nargs = args.size();
      if(nargs > 3 || !isValidCall(key)) {
        noResponse(key, pos, nargs);
        continue;
View Full Code Here

          pop(root); // clear the pushed names
          push(root); // push it again
          break; // continue search inside the function

        case FCALLNODE:
          FCallNode fcallNode = (FCallNode) root;
          if(!fcallNode.getName().equals(qualifiedName.get(0)))
            break SEARCH;
          if(inWantedScope())
            return Lists.newArrayList(new GenericCallNode(fcallNode));
          break; // continue search inside the function
        default:
View Full Code Here

TOP

Related Classes of org.jrubyparser.ast.FCallNode

Copyright © 2018 www.massapicom. 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.