private void reportErrorWhenAmbigousReverseMapping(
      List<SourceMethod> candidates,
      SourceMethod method,
      InheritInverseConfigurationPrism reversePrism) {

    List<String> candidateNames = new ArrayList<String>();
    for (SourceMethod candidate : candidates) {
      candidateNames.add(candidate.getName());
    }

    String name = reversePrism.name();
    if (name.isEmpty()) {
      messager.printMessage(
          method.getExecutable(),
          reversePrism.mirror,
          Message.INHERITINVERSECONFIGURATION_DUPLICATES,
          Strings.join(candidateNames, "(), "));

    } else {
      messager.printMessage(
          method.getExecutable(),
          reversePrism.mirror,
          Message.INHERITINVERSECONFIGURATION_INVALID_NAME,
          Strings.join(candidateNames, "(), "),
          name);
    }
  }
  private void mergeInheritedOptions(
      SourceMethod method,
      MapperConfiguration mapperConfig,
      List<SourceMethod> availableMethods,
      List<SourceMethod> initializingMethods) {
    if (initializingMethods.contains(method)) {
      // cycle detected

      initializingMethods.add(method);

      messager.printMessage(
          method.getExecutable(),
          Message.INHERITCONFIGURATION_CYCLE,
          Strings.join(initializingMethods, " -> "));
      return;
    }

    initializingMethods.add(method);

    MappingOptions mappingOptions = method.getMappingOptions();
    List<SourceMethod> applicablePrototypeMethods = method.getApplicablePrototypeMethods();

    MappingOptions inverseMappingOptions =
        getInverseMappingOptions(availableMethods, method, initializingMethods, mapperConfig);

    MappingOptions templateMappingOptions =
        getTemplateMappingOptions(
            join(availableMethods, applicablePrototypeMethods),
            method,
            initializingMethods,
            mapperConfig);

    if (templateMappingOptions != null) {
      mappingOptions.applyInheritedOptions(
          templateMappingOptions, false, method, messager, typeFactory);
    } else if (inverseMappingOptions != null) {
      mappingOptions.applyInheritedOptions(
          inverseMappingOptions, true, method, messager, typeFactory);
    } else if (mapperConfig.getMappingInheritanceStrategy() == AUTO_INHERIT_FROM_CONFIG) {
      if (applicablePrototypeMethods.size() == 1) {
        mappingOptions.applyInheritedOptions(
            first(applicablePrototypeMethods).getMappingOptions(),
            false,
            method,
            messager,
            typeFactory);
      } else if (applicablePrototypeMethods.size() > 1) {
        messager.printMessage(
            method.getExecutable(),
            Message.INHERITCONFIGURATION_MULTIPLE_PROTOTYPE_METHODS_MATCH,
            Strings.join(applicablePrototypeMethods, ", "));
      }
    }

    mappingOptions.markAsFullyInitialized();
  }
  private void reportErrorWhenSeveralNamesMatch(
      List<SourceMethod> candidates, SourceMethod method, InheritConfigurationPrism prism) {

    messager.printMessage(
        method.getExecutable(),
        prism.mirror,
        Message.INHERITCONFIGURATION_DUPLICATE_MATCHES,
        prism.name(),
        Strings.join(candidates, ", "));
  }
示例#4
0
  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder(returnType.toString());
    sb.append(" ");

    if (declaringMapper != null) {
      sb.append(declaringMapper).append(".");
    }

    sb.append(getName()).append("(").append(Strings.join(parameters, ", ")).append(")");

    return sb.toString();
  }
示例#5
0
    public SourceReference build() {

      String sourceName = mapping.getSourceName();

      if (sourceName == null) {
        return null;
      }

      boolean isValid = true;
      boolean foundEntryMatch;

      String[] sourcePropertyNames = new String[0];
      String[] segments = sourceName.split("\\.");
      Parameter parameter = null;

      List<PropertyEntry> entries = new ArrayList<PropertyEntry>();

      if (method.getSourceParameters().size() > 1) {

        // parameterName is mandatory for multiple source parameters
        if (segments.length > 0) {
          String sourceParameterName = segments[0];
          parameter = method.getSourceParameter(sourceParameterName);
          if (parameter == null) {
            reportMappingError(Message.PROPERTYMAPPING_INVALID_PARAMETER_NAME, sourceParameterName);
            isValid = false;
          }
        }
        if (segments.length > 1 && parameter != null) {
          sourcePropertyNames = Arrays.copyOfRange(segments, 1, segments.length);
          entries = getSourceEntries(parameter.getType(), sourcePropertyNames);
          foundEntryMatch = (entries.size() == sourcePropertyNames.length);
        } else {
          // its only a parameter, no property
          foundEntryMatch = true;
        }

      } else {

        // parameter name is not mandatory for single source parameter
        sourcePropertyNames = segments;
        parameter = method.getSourceParameters().get(0);
        entries = getSourceEntries(parameter.getType(), sourcePropertyNames);
        foundEntryMatch = (entries.size() == sourcePropertyNames.length);

        if (!foundEntryMatch) {
          // Lets see if the expression contains the parameterName, so
          // parameterName.propName1.propName2
          if (parameter.getName().equals(segments[0])) {
            sourcePropertyNames = Arrays.copyOfRange(segments, 1, segments.length);
            entries = getSourceEntries(parameter.getType(), sourcePropertyNames);
            foundEntryMatch = (entries.size() == sourcePropertyNames.length);
          } else {
            // segment[0] cannot be attributed to the parameter name.
            parameter = null;
          }
        }
      }

      if (!foundEntryMatch) {

        if (parameter != null) {
          reportMappingError(
              Message.PROPERTYMAPPING_NO_PROPERTY_IN_PARAMETER,
              parameter.getName(),
              Strings.join(Arrays.asList(sourcePropertyNames), "."));
        } else {
          reportMappingError(
              Message.PROPERTYMAPPING_INVALID_PROPERTY_NAME, mapping.getSourceName());
        }
        isValid = false;
      }

      return new SourceReference(parameter, entries, isValid);
    }