コード例 #1
0
  /**
   * The resource parameters for a root resource include the constructor params.
   *
   * @param delegate The declaration.
   * @return The resource params.
   */
  @Override
  protected List<ResourceParameter> getResourceParameters(TypeDeclaration delegate) {
    List<ResourceParameter> resourceParams = super.getResourceParameters(delegate);

    if (getDelegate() == delegate && delegate instanceof ClassDeclaration) {
      // root resources also include constructor params.

      Collection<ConstructorDeclaration> constructors =
          ((ClassDeclaration) delegate).getConstructors();
      ConstructorDeclaration chosen = null;
      CONSTRUCTOR_LOOP:
      for (ConstructorDeclaration constructor : constructors) {
        // the one with the most params is the chosen one.
        if (chosen == null || constructor.getParameters().size() > chosen.getParameters().size()) {
          // Has more constructor parameters.  See if they're all Jersey-provided.
          for (ParameterDeclaration param : constructor.getParameters()) {
            if (!ResourceParameter.isResourceParameter(param)) {
              continue CONSTRUCTOR_LOOP;
            }
          }
          chosen = constructor;
        }
      }

      if (chosen != null) {
        chosen = DeclarationDecorator.decorate(chosen);
        for (ParameterDeclaration param : chosen.getParameters()) {
          resourceParams.add(new ResourceParameter(param));
        }
      }
    }

    return resourceParams;
  }
コード例 #2
0
 @Override
 public List<Parameter> getParameters() {
   return declaration
       .getParameters()
       .stream()
       .map(
           (parameter) ->
               new Parameter(
                   getContext().resolve(parameter.getType()), parameter.getId().getName()))
       .collect(Collectors.toList());
 }