public static boolean areParametersValid()

in mapper-processor/src/main/java/com/datastax/oss/driver/internal/mapper/processor/dao/EntityUtils.java [104:184]


  public static boolean areParametersValid(
      TypeElement entityElement,
      EntityDefinition entityDefinition,
      List<? extends VariableElement> parameters,
      Class<? extends Annotation> annotationClass,
      ProcessorContext context,
      ExecutableElement methodElement,
      TypeElement processedType,
      String exceptionCondition) {

    if (exceptionCondition == null || exceptionCondition.isEmpty()) {
      exceptionCondition = "";
    } else {
      exceptionCondition = " that " + exceptionCondition;
    }

    List<TypeName> primaryKeyTypes =
        entityDefinition.getPrimaryKey().stream()
            .map(d -> d.getType().asTypeName())
            .collect(Collectors.toList());
    List<TypeName> partitionKeyTypes =
        entityDefinition.getPartitionKey().stream()
            .map(d -> d.getType().asTypeName())
            .collect(Collectors.toList());
    List<TypeName> parameterTypes =
        parameters.stream().map(p -> TypeName.get(p.asType())).collect(Collectors.toList());
    // if parameters are provided, we must have at least enough to match partition key.
    if (parameterTypes.size() < partitionKeyTypes.size()) {
      context
          .getMessager()
          .error(
              methodElement,
              "Invalid parameter list: %s methods%s "
                  + "must at least specify partition key components "
                  + "(expected partition key of %s: %s)",
              annotationClass.getSimpleName(),
              exceptionCondition,
              entityElement.getSimpleName(),
              partitionKeyTypes);
      return false;
    }

    if (parameterTypes.size() > primaryKeyTypes.size()) {
      context
          .getMessager()
          .error(
              methodElement,
              "Invalid parameter list: %s methods%s "
                  + "must match the primary key components in the exact order "
                  + "(expected primary key of %s: %s). Too many parameters provided",
              annotationClass.getSimpleName(),
              exceptionCondition,
              entityElement.getSimpleName(),
              primaryKeyTypes);
      return false;
    }

    // validate that each parameter type matches the primary key type
    for (int parameterIndex = 0; parameterIndex < parameterTypes.size(); parameterIndex++) {
      TypeName parameterType = parameterTypes.get(parameterIndex);
      TypeName primaryKeyParameterType = primaryKeyTypes.get(parameterIndex);
      if (!parameterType.equals(primaryKeyParameterType)) {
        context
            .getMessager()
            .error(
                methodElement,
                "Invalid parameter list: %s methods%s "
                    + "must match the primary key components in the exact order "
                    + "(expected primary key of %s: %s). Mismatch at index %d: %s should be %s",
                annotationClass.getSimpleName(),
                exceptionCondition,
                entityElement.getSimpleName(),
                primaryKeyTypes,
                parameterIndex,
                parameterType,
                primaryKeyParameterType);
        return false;
      }
    }
    return true;
  }