Package org.jrubyparser.ast

Examples of org.jrubyparser.ast.CallNode


      for(Node n : nodeIterable) {
        if(n.getNodeType() == NodeType.NEWLINENODE)
          n = ((NewlineNode) n).getNextNode();

        if(n.getNodeType() == NodeType.CALLNODE) {
          CallNode callNode = (CallNode) n;
          if(NEWPROPERTY.equals(callNode.getName())) {
            CallNode typeCall = opCallVisitor.findOpCall(callNode.getReceiver(), "type", "Puppet", "Type");
            if(typeCall == null)
              continue;
            String typeName = getFirstArg(typeCall);
            if(typeName == null)
              continue;
            Map<String, PPTypeInfo.Entry> propertyMap = Maps.newHashMap();
            propertyMap.put(getFirstArg(callNode), getEntry(callNode));
            result.add(new PPTypeInfo(typeName, "", propertyMap, null));
            continue;
          }
          if(NEWPARAM.equals(callNode.getName())) {
            CallNode typeCall = opCallVisitor.findOpCall(callNode.getReceiver(), "type", "Puppet", "Type");
            if(typeCall == null)
              continue;
            String typeName = getFirstArg(typeCall);
            if(typeName == null)
              continue;
            Map<String, PPTypeInfo.Entry> parameterMap = Maps.newHashMap();
            parameterMap.put(getFirstArg(callNode), getEntry(callNode));
            result.add(new PPTypeInfo(typeName, "", null, parameterMap));
            continue;
          }
          if(NEWCHECK.equals(callNode.getName())) {
            CallNode typeCall = opCallVisitor.findOpCall(callNode.getReceiver(), "type", "Puppet", "Type");
            if(typeCall == null)
              continue;
            String typeName = getFirstArg(typeCall);
            if(typeName == null)
              continue;
            Map<String, PPTypeInfo.Entry> parameterMap = Maps.newHashMap();
            parameterMap.put(getFirstArg(callNode), getEntry(callNode));
            result.add(new PPTypeInfo(typeName, "", null, parameterMap));
          }
          // NOTE: this does probably never occur
          if(ENSURABLE.equals(callNode.getName())) {
            CallNode typeCall = opCallVisitor.findOpCall(callNode.getReceiver(), "type", "Puppet", "Type");
            if(typeCall == null)
              continue;
            String typeName = getFirstArg(typeCall);
            if(typeName == null)
              continue;
View Full Code Here


      if(!providerFileName.endsWith(".rb"))
        continue;

      for(Node node : RubyParserUtils.findNodes(
        RubyParserUtils.parseFile(providerFile).getBody(), new NodeType[] { NodeType.CALLNODE })) {
        CallNode call = (CallNode) node;
        if(!"provide".equals(call.getName()))
          continue;

        Node receiverNode = call.getReceiver();
        if(!(receiverNode instanceof CallNode))
          continue;

        CallNode receiver = (CallNode) receiverNode;
        if(!"type".equals(receiver.getName()))
          continue;
        Node recRecNode = receiver.getReceiver();
        if(!(recRecNode instanceof Colon2ConstNode))
          continue;
        Colon2ConstNode recRec = (Colon2ConstNode) recRecNode;
        if(!("Puppet".equals(((ConstNode) recRec.getLeftNode()).getName()) && "Type".equals(recRec.getName())))
          continue;

        // Receiver is Puppet::Type.type
        List<Node> symArgs = RubyParserUtils.findNodes(
          receiver.getArgs(), new NodeType[] { NodeType.SYMBOLNODE });
        if(!(symArgs.size() == 1 && type.getName().equals(((SymbolNode) symArgs.get(0)).getName())))
          // Not this type
          continue;

        symArgs = RubyParserUtils.findNodes(call.getArgs(), new NodeType[] { NodeType.SYMBOLNODE });
View Full Code Here

    BlockAcceptingNode newtypeNode = null;
    if(puppetModule != null) {
      // Find the newtype call
      nodes = RubyParserUtils.findNodes(puppetModule.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 ConstNode && "Type".equals(((ConstNode) receiver).getName())) {
            newtypeNode = call;
            break;
          }
        }
      }
      if(newtypeNode == null) {
        // 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;
View Full Code Here

        return "false";
      case TRUENODE:
        return "true";
      case CALLNODE: {
        // We can handle simple string concatenation
        CallNode argCall = (CallNode) node;
        if("+".equals(argCall.getName())) {
          StringBuilder bld = new StringBuilder();
          bld.append(stringValue(argCall.getReceiver()));
          for(Node arg : argCall.getArgs().childNodes())
            bld.append(stringValue(arg));
          return bld.toString();
        }
        throw new IOException("Unable to evaluate call node " + argCall.getName() + " into a string");
      }
      default:
        throw new IOException("Unable to evaluate node of type " + node.getNodeType() + " into a string");
    }
  }
View Full Code Here

          if(!inCompatibleScope())
            break SEARCH;
          break; // search children

        case CALLNODE:
          CallNode callNode = (CallNode) root;
          if(!callNode.getName().equals(qualifiedName.get(0)))
            break SEARCH;
          pushNames(constEvaluator.stringList(constEvaluator.eval(callNode.getReceiver())));
          if(inWantedScope())
            return Lists.newArrayList(new GenericCallNode(callNode));
          pop(root); // clear the pushed names
          push(root); // push it again
          break; // continue search inside the function
View Full Code Here

TOP

Related Classes of org.jrubyparser.ast.CallNode

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.