Ejemplo n.º 1
0
 @Override
 public boolean doTypeVarsMatch(Type sourceType, Type targetType) {
   boolean match = false;
   if (sourceType.getTypeParameters().size() == 1) {
     match = sourceType.getTypeParameters().get(0).isAssignableTo(targetType);
   }
   return match;
 }
Ejemplo n.º 2
0
  public Type getSourceElementType() {
    Type sourceParameterType = getSourceParameter().getType();

    if (sourceParameterType.isArrayType()) {
      return sourceParameterType.getComponentType();
    } else {
      return sourceParameterType.getTypeParameters().get(0).getTypeBound();
    }
  }
Ejemplo n.º 3
0
    public IterableMappingMethod build() {

      Type sourceParameterType = first(method.getSourceParameters()).getType();
      Type resultType = method.getResultType();

      Type sourceElementType =
          sourceParameterType.isArrayType()
              ? sourceParameterType.getComponentType()
              : first(sourceParameterType.getTypeParameters()).getTypeBound();
      Type targetElementType =
          resultType.isArrayType()
              ? resultType.getComponentType()
              : first(resultType.getTypeParameters()).getTypeBound();

      String loopVariableName =
          Strings.getSaveVariableName(sourceElementType.getName(), method.getParameterNames());

      Assignment assignment =
          ctx.getMappingResolver()
              .getTargetAssignment(
                  method,
                  "collection element",
                  sourceElementType,
                  targetElementType,
                  null, // there is no targetPropertyName
                  formattingParameters,
                  selectionParameters,
                  loopVariableName,
                  false);

      if (assignment == null) {
        if (method instanceof ForgedMethod) {
          // leave messaging to calling property mapping
          return null;
        } else {
          ctx.getMessager()
              .printMessage(method.getExecutable(), Message.ITERABLEMAPPING_MAPPING_NOT_FOUND);
        }
      } else {
        if (method instanceof ForgedMethod) {
          ForgedMethod forgedMethod = (ForgedMethod) method;
          forgedMethod.addThrownTypes(assignment.getThrownTypes());
        }
      }
      // target accessor is setter, so decorate assignment as setter
      if (resultType.isArrayType()) {
        assignment = new LocalVarWrapper(assignment, method.getThrownTypes());
      } else {
        assignment = new SetterWrapper(assignment, method.getThrownTypes());
      }

      // mapNullToDefault
      boolean mapNullToDefault = false;
      if (method.getMapperConfiguration() != null) {
        mapNullToDefault = method.getMapperConfiguration().isMapToDefault(nullValueMappingStrategy);
      }

      MethodReference factoryMethod = null;
      if (!method.isUpdateMethod()) {
        factoryMethod =
            ctx.getMappingResolver().getFactoryMethod(method, method.getResultType(), null);
      }

      List<LifecycleCallbackMethodReference> beforeMappingMethods =
          LifecycleCallbackFactory.beforeMappingMethods(method, selectionParameters, ctx);
      List<LifecycleCallbackMethodReference> afterMappingMethods =
          LifecycleCallbackFactory.afterMappingMethods(method, selectionParameters, ctx);

      return new IterableMappingMethod(
          method,
          assignment,
          factoryMethod,
          mapNullToDefault,
          loopVariableName,
          beforeMappingMethods,
          afterMappingMethods);
    }