Ejemplo n.º 1
0
  public Parameter getSingleParameter(TypeElement includingType, ExecutableElement method) {
    List<? extends VariableElement> parameters = method.getParameters();

    if (parameters.size() != 1) {
      // TODO: Log error
      return null;
    }

    return Collections.first(getParameters(includingType, method));
  }
Ejemplo n.º 2
0
  public static class Builder {

    private Type declaringMapper = null;
    private Type definingType = null;
    private ExecutableElement executable;
    private List<Parameter> parameters;
    private Type returnType = null;
    private List<Type> exceptionTypes;
    private Map<String, List<Mapping>> mappings;
    private IterableMapping iterableMapping = null;
    private MapMapping mapMapping = null;
    private BeanMapping beanMapping = null;
    private Types typeUtils;
    private TypeFactory typeFactory = null;
    private FormattingMessager messager = null;
    private MapperConfiguration mapperConfig = null;
    private List<SourceMethod> prototypeMethods = Collections.emptyList();
    private List<ValueMapping> valueMappings;

    public Builder() {}

    public Builder setDeclaringMapper(Type declaringMapper) {
      this.declaringMapper = declaringMapper;
      return this;
    }

    public Builder setExecutable(ExecutableElement executable) {
      this.executable = executable;
      return this;
    }

    public Builder setParameters(List<Parameter> parameters) {
      this.parameters = parameters;
      return this;
    }

    public Builder setReturnType(Type returnType) {
      this.returnType = returnType;
      return this;
    }

    public Builder setExceptionTypes(List<Type> exceptionTypes) {
      this.exceptionTypes = exceptionTypes;
      return this;
    }

    public Builder setMappings(Map<String, List<Mapping>> mappings) {
      this.mappings = mappings;
      return this;
    }

    public Builder setIterableMapping(IterableMapping iterableMapping) {
      this.iterableMapping = iterableMapping;
      return this;
    }

    public Builder setMapMapping(MapMapping mapMapping) {
      this.mapMapping = mapMapping;
      return this;
    }

    public Builder setBeanMapping(BeanMapping beanMapping) {
      this.beanMapping = beanMapping;
      return this;
    }

    public Builder setValueMappings(List<ValueMapping> valueMappings) {
      this.valueMappings = valueMappings;
      return this;
    }

    public Builder setTypeUtils(Types typeUtils) {
      this.typeUtils = typeUtils;
      return this;
    }

    public Builder setTypeFactory(TypeFactory typeFactory) {
      this.typeFactory = typeFactory;
      return this;
    }

    public Builder setMessager(FormattingMessager messager) {
      this.messager = messager;
      return this;
    }

    public Builder setMapperConfiguration(MapperConfiguration mapperConfig) {
      this.mapperConfig = mapperConfig;
      return this;
    }

    public Builder setPrototypeMethods(List<SourceMethod> prototypeMethods) {
      this.prototypeMethods = prototypeMethods;
      return this;
    }

    public Builder setDefininingType(Type definingType) {
      this.definingType = definingType;
      return this;
    }

    public SourceMethod build() {

      MappingOptions mappingOptions =
          new MappingOptions(mappings, iterableMapping, mapMapping, beanMapping, valueMappings);

      SourceMethod sourceMethod =
          new SourceMethod(
              declaringMapper,
              executable,
              parameters,
              returnType,
              exceptionTypes,
              mappingOptions,
              typeUtils,
              typeFactory,
              mapperConfig,
              prototypeMethods,
              definingType);

      if (mappings != null) {
        for (Map.Entry<String, List<Mapping>> entry : mappings.entrySet()) {
          for (Mapping mapping : entry.getValue()) {
            mapping.init(sourceMethod, messager, typeFactory, false);
          }
        }
      }
      return sourceMethod;
    }
  }
 @Override
 public Set<Type> getImportTypes() {
   return declaringType != null
       ? Collections.asSet(declaringType)
       : java.util.Collections.<Type>emptySet();
 }