コード例 #1
0
ファイル: TreeBuilder27.java プロジェクト: conbon/Pydev
  private argumentsType makeArguments(DefaultArg[] def, NameTok varg, NameTok kwarg)
      throws Exception {
    exprType fpargs[] = new exprType[def.length];
    exprType defaults[] = new exprType[def.length];
    int startofdefaults = 0;
    boolean defaultsSet = false;
    for (int i = 0; i < def.length; i++) {
      DefaultArg node = def[i];
      exprType parameter = node.parameter;
      fpargs[i] = parameter;

      if (node.specialsBefore != null && node.specialsBefore.size() > 0) {
        parameter.getSpecialsBefore().addAll(node.specialsBefore);
      }
      if (node.specialsAfter != null && node.specialsAfter.size() > 0) {
        parameter.getSpecialsAfter().addAll(node.specialsAfter);
      }

      ctx.setParam(fpargs[i]);
      defaults[i] = node.value;
      if (node.value != null && defaultsSet == false) {
        defaultsSet = true;
        startofdefaults = i;
      }
    }

    // System.out.println("start "+ startofdefaults + " " + l);
    exprType[] newdefs = new exprType[def.length - startofdefaults];
    System.arraycopy(defaults, startofdefaults, newdefs, 0, newdefs.length);
    return new argumentsType(fpargs, varg, kwarg, newdefs, null, null, null, null, null, null);
  }
コード例 #2
0
  protected final SimpleNode makeDecorator(java.util.List<SimpleNode> nodes) {
    exprType starargs = null;
    exprType kwargs = null;

    exprType func = null;
    ArrayList<SimpleNode> keywordsl = new ArrayList<SimpleNode>();
    ArrayList<SimpleNode> argsl = new ArrayList<SimpleNode>();
    for (Iterator<SimpleNode> iter = nodes.iterator(); iter.hasNext(); ) {
      SimpleNode node = iter.next();

      if (node.getId() == JJTEXTRAKEYWORDVALUELIST) {
        final ExtraArgValue extraArg = (ExtraArgValue) node;
        kwargs = (extraArg).value;
        this.addSpecialsAndClearOriginal(extraArg, kwargs);
        extraArg.specialsBefore = kwargs.getSpecialsBefore();
        extraArg.specialsAfter = kwargs.getSpecialsAfter();

      } else if (node.getId() == JJTEXTRAARGVALUELIST) {
        final ExtraArgValue extraArg = (ExtraArgValue) node;
        starargs = extraArg.value;
        this.addSpecialsAndClearOriginal(extraArg, starargs);
        extraArg.specialsBefore = starargs.getSpecialsBefore();
        extraArg.specialsAfter = starargs.getSpecialsAfter();

      } else if (node instanceof keywordType) {
        // keyword
        keywordsl.add(node);

      } else if (isArg(node)) {
        // default
        argsl.add(node);

      } else if (node instanceof Comprehension) {
        argsl.add(
            new ListComp(
                (exprType) iter.next(), new comprehensionType[] {(comprehensionType) node}));

      } else if (node instanceof ComprehensionCollection) {
        // list comp (2 nodes: comp type and the elt -- what does elt mean by the way?)
        argsl.add(
            new ListComp((exprType) iter.next(), ((ComprehensionCollection) node).getGenerators()));

      } else if (node instanceof decoratorsType) {
        func = (exprType) stack.popNode(); // the func is the last thing in the stack
        decoratorsType d = (decoratorsType) node;
        d.func = func;
        d.args = (exprType[]) argsl.toArray(new exprType[0]);
        d.keywords = (keywordType[]) keywordsl.toArray(new keywordType[0]);
        d.starargs = starargs;
        d.kwargs = kwargs;
        return d;

      } else {
        argsl.add(node);
      }
    }
    throw new RuntimeException("Something wrong happened while making the decorators...");
  }