use of org.mapstruct.ap.internal.model.common.Type in project mapstruct by mapstruct.
the class MapperCreationProcessor method getDecorator.
private Decorator getDecorator(TypeElement element, List<SourceMethod> methods, MapperOptions mapperOptions) {
DecoratedWithGem decoratedWith = DecoratedWithGem.instanceOn(element);
if (decoratedWith == null) {
return null;
}
TypeElement decoratorElement = (TypeElement) typeUtils.asElement(decoratedWith.value().get());
if (!typeUtils.isAssignable(decoratorElement.asType(), element.asType())) {
messager.printMessage(element, decoratedWith.mirror(), Message.DECORATOR_NO_SUBTYPE);
}
List<MappingMethod> mappingMethods = new ArrayList<>(methods.size());
for (SourceMethod mappingMethod : methods) {
boolean implementationRequired = true;
for (ExecutableElement method : ElementFilter.methodsIn(decoratorElement.getEnclosedElements())) {
if (elementUtils.overrides(method, mappingMethod.getExecutable(), decoratorElement)) {
implementationRequired = false;
break;
}
}
Type declaringMapper = mappingMethod.getDeclaringMapper();
if (implementationRequired && !(mappingMethod.isDefault() || mappingMethod.isStatic())) {
if ((declaringMapper == null) || declaringMapper.equals(typeFactory.getType(element))) {
mappingMethods.add(new DelegatingMethod(mappingMethod));
}
}
}
boolean hasDelegateConstructor = false;
boolean hasDefaultConstructor = false;
for (ExecutableElement constructor : ElementFilter.constructorsIn(decoratorElement.getEnclosedElements())) {
if (constructor.getParameters().isEmpty()) {
hasDefaultConstructor = true;
} else if (constructor.getParameters().size() == 1) {
if (typeUtils.isAssignable(element.asType(), first(constructor.getParameters()).asType())) {
hasDelegateConstructor = true;
}
}
}
if (!hasDelegateConstructor && !hasDefaultConstructor) {
messager.printMessage(element, decoratedWith.mirror(), Message.DECORATOR_CONSTRUCTOR);
}
Decorator decorator = new Decorator.Builder().elementUtils(elementUtils).typeFactory(typeFactory).mapperElement(element).decoratedWith(decoratedWith).methods(mappingMethods).hasDelegateConstructor(hasDelegateConstructor).options(options).versionInformation(versionInformation).implName(mapperOptions.implementationName()).implPackage(mapperOptions.implementationPackage()).extraImports(getExtraImports(element, mapperOptions)).suppressGeneratorTimestamp(mapperOptions.suppressTimestampInGenerated()).build();
return decorator;
}
Aggregations