Пример #1
0
 Type tupleFromParameterList() {
   if (params.getParameters().isEmpty()) {
     return n.getUnit().getEmptyType();
   }
   List<Type> types = new ArrayList<>(params.getParameters().size());
   int firstDefaulted = -1;
   int count = 0;
   for (Tree.Parameter p : params.getParameters()) {
     types.add(p.getParameterModel().getType());
     if (p.getParameterModel().isDefaulted()) firstDefaulted = count;
     count++;
   }
   return n.getUnit()
       .getTupleType(
           types,
           params
               .getParameters()
               .get(params.getParameters().size() - 1)
               .getParameterModel()
               .isSequenced(),
           params
               .getParameters()
               .get(params.getParameters().size() - 1)
               .getParameterModel()
               .isAtLeastOne(),
           firstDefaulted);
 }
  public JCNewClass build() {
    // Generate a subclass of Callable
    ListBuffer<JCTree> classBody = new ListBuffer<JCTree>();
    int numParams = paramLists.getParameters().size();
    int minimumParams = 0;
    for (Parameter p : paramLists.getParameters()) {
      if (p.isDefaulted() || p.isSequenced()) break;
      minimumParams++;
    }
    boolean isVariadic = minimumParams != numParams;
    if (parameterListTree != null) {
      // generate a method for each defaulted param
      for (Tree.Parameter p : parameterListTree.getParameters()) {
        if (p.getDefaultArgument() != null || p.getDeclarationModel().isSequenced()) {
          MethodDefinitionBuilder methodBuilder =
              gen.classGen().makeParamDefaultValueMethod(false, null, parameterListTree, p);
          classBody.append(methodBuilder.build());
        }
      }
    }

    // collect each parameter type from the callable type model rather than the declarations to get
    // them all bound
    java.util.List<ProducedType> parameterTypes = new ArrayList<ProducedType>(numParams);
    if (forwardCallTo != null) {
      for (int i = 0; i < numParams; i++)
        parameterTypes.add(gen.getParameterTypeOfCallable(typeModel, i));
    } else {
      // get them from our declaration
      for (Parameter p : paramLists.getParameters()) parameterTypes.add(p.getType());
    }

    // now generate a method for each supported minimum number of parameters below 4
    // which delegates to the $call$typed method if required
    for (int i = minimumParams, max = Math.min(numParams, 4); i < max; i++) {
      classBody.append(makeDefaultedCall(i, isVariadic, parameterTypes));
    }
    // generate the $call method for the max number of parameters,
    // which delegates to the $call$typed method if required
    classBody.append(makeDefaultedCall(numParams, isVariadic, parameterTypes));
    // generate the $call$typed method if required
    if (isVariadic && forwardCallTo == null)
      classBody.append(makeCallTypedMethod(body, parameterTypes));

    JCClassDecl classDef =
        gen.make().AnonymousClassDef(gen.make().Modifiers(0), classBody.toList());

    JCNewClass instance =
        gen.make()
            .NewClass(
                null,
                null,
                gen.makeJavaType(typeModel, JT_EXTENDS | JT_CLASS_NEW),
                List.<JCExpression>of(gen.make().Literal(typeModel.getProducedTypeName(true))),
                classDef);
    return instance;
  }
Пример #3
0
 @Override
 public void visit(Tree.Parameter that) {
   super.visit(that);
   if (that.getParameterModel().getModel() == declaration) {
     specify();
   }
 }
 private static void parameters(Tree.ParameterList pl, StyledString label) {
   if (pl == null || pl.getParameters().isEmpty()) {
     label.append("()");
   } else {
     label.append("(");
     int len = pl.getParameters().size(), i = 0;
     for (Tree.Parameter p : pl.getParameters()) {
       if (p != null) {
         label
             .append(type(p.getType()), TYPE_STYLER)
             .append(" ")
             .append(name(p.getIdentifier()), ID_STYLER);
         if (p instanceof Tree.FunctionalParameterDeclaration) {
           Tree.FunctionalParameterDeclaration fp = (Tree.FunctionalParameterDeclaration) p;
           for (Tree.ParameterList ipl : fp.getParameterLists()) {
             parameters(ipl, label);
           }
         }
       }
       if (++i < len) label.append(", ");
     }
     label.append(")");
   }
 }
  @Override
  public void visit(Tree.Parameter p) {

    if (annotationConstructor != null) {
      AnnotationConstructorParameter acp = new AnnotationConstructorParameter();
      acp.setParameter(p.getParameterModel());
      instantiation.getConstructorParameters().add(acp);
      push(acp);
      // super.visit(p);
      Tree.SpecifierOrInitializerExpression defaultArgument = Decl.getDefaultArgument(p);
      if (defaultArgument != null) {
        defaultedParameter(defaultArgument);
      }
      pop();
      Tree.ValueParameterDeclaration vp;
    }
    // Ignore statements in parameters
  }