Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -295,20 +295,24 @@ && allowDirect( sourceType, targetType ) ) {
}

// 2 step method, then: method(conversion(source))
assignment = ConversionMethod.getBestMatch( this, sourceType, targetType );
if ( assignment != null ) {
usedSupportedMappings.addAll( supportingMethodCandidates );
return assignment;
if ( allowConversion() ) {
assignment = ConversionMethod.getBestMatch( this, sourceType, targetType );
if ( assignment != null ) {
usedSupportedMappings.addAll( supportingMethodCandidates );
return assignment;
}
}

// stop here when looking for update methods.
selectionCriteria.setPreferUpdateMapping( false );

// 2 step method, finally: conversion(method(source))
assignment = MethodConversion.getBestMatch( this, sourceType, targetType );
if ( assignment != null ) {
usedSupportedMappings.addAll( supportingMethodCandidates );
return assignment;
if ( allowConversion() ) {
assignment = MethodConversion.getBestMatch( this, sourceType, targetType );
if ( assignment != null ) {
usedSupportedMappings.addAll( supportingMethodCandidates );
return assignment;
}
}
}

Expand Down Expand Up @@ -763,22 +767,26 @@ static Assignment getBestMatch(ResolvingAttempt att, Type sourceType, Type targe
return mmAttempt.result;
}
}
MethodMethod<Method, BuiltInMethod> mbAttempt =
new MethodMethod<>( att, att.methods, att.builtIns, att::toMethodRef, att::toBuildInRef )
.getBestMatch( sourceType, targetType );
if ( mbAttempt.hasResult ) {
return mbAttempt.result;
}
MethodMethod<BuiltInMethod, Method> bmAttempt =
new MethodMethod<>( att, att.builtIns, att.methods, att::toBuildInRef, att::toMethodRef )
.getBestMatch( sourceType, targetType );
if ( bmAttempt.hasResult ) {
return bmAttempt.result;
if ( att.allowConversion() ) {
MethodMethod<Method, BuiltInMethod> mbAttempt =
new MethodMethod<>( att, att.methods, att.builtIns, att::toMethodRef, att::toBuildInRef )
.getBestMatch( sourceType, targetType );
if ( mbAttempt.hasResult ) {
return mbAttempt.result;
}
MethodMethod<BuiltInMethod, Method> bmAttempt =
new MethodMethod<>( att, att.builtIns, att.methods, att::toBuildInRef, att::toMethodRef )
.getBestMatch( sourceType, targetType );
if ( bmAttempt.hasResult ) {
return bmAttempt.result;
}
MethodMethod<BuiltInMethod, BuiltInMethod> bbAttempt =
new MethodMethod<>( att, att.builtIns, att.builtIns, att::toBuildInRef, att::toBuildInRef )
.getBestMatch( sourceType, targetType );
return bbAttempt.result;
}
MethodMethod<BuiltInMethod, BuiltInMethod> bbAttempt =
new MethodMethod<>( att, att.builtIns, att.builtIns, att::toBuildInRef, att::toBuildInRef )
.getBestMatch( sourceType, targetType );
return bbAttempt.result;

return null;
}

MethodMethod(ResolvingAttempt attempt, List<T1> xMethods, List<T2> yMethods,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.mappingcontrol;

import java.time.ZonedDateTime;
import java.util.Date;

import org.mapstruct.Mapper;

/**
* @author Filip Hrisafov
*/
@Mapper(mappingControl = NoConversion.class)
public interface ErroneousBuiltInAndBuiltInMapper {

Target map(Source source);

class Source {
private final ZonedDateTime time;

public Source(ZonedDateTime time) {
this.time = time;
}

public ZonedDateTime getTime() {
return time;
}
}

class Target {
private final Date time;

public Target(Date time) {
this.time = time;
}

public Date getTime() {
return time;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.mappingcontrol;

import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Calendar;

import org.mapstruct.Mapper;

/**
* @author Filip Hrisafov
*/
@Mapper(mappingControl = NoConversion.class)
public interface ErroneousBuiltInAndMethodMapper {

Target map(Source source);

default ZonedDateTime fromInt(int time) {
return ZonedDateTime.ofInstant( Instant.ofEpochMilli( time ), ZoneOffset.UTC );
}

class Source {
private final int time;

public Source(int time) {
this.time = time;
}

public int getTime() {
return time;
}
}

class Target {
private Calendar time;

public Target(Calendar time) {
this.time = time;
}

public Calendar getTime() {
return time;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.mappingcontrol;

import java.time.Instant;
import java.util.Date;

import org.mapstruct.Mapper;

/**
* @author Filip Hrisafov
*/
@Mapper(mappingControl = NoConversion.class)
public interface ErroneousConversionAndMethodMapper {

Target map(Source source);

default Instant fromDate(int time) {
return Instant.ofEpochMilli( time );
}

class Source {
private final int time;

public Source(int time) {
this.time = time;
}

public int getTime() {
return time;
}
}

class Target {
private Date time;

public Target(Date time) {
this.time = time;
}

public Date getTime() {
return time;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.mappingcontrol;

import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.Date;

import org.mapstruct.Mapper;

/**
* @author Filip Hrisafov
*/
@Mapper(mappingControl = NoConversion.class)
public interface ErroneousMethodAndBuiltInMapper {

Target map(Source source);

default Date fromCalendar(Calendar calendar) {
return calendar != null ? calendar.getTime() : null;
}

class Source {
private final ZonedDateTime time;

public Source(ZonedDateTime time) {
this.time = time;
}

public ZonedDateTime getTime() {
return time;
}
}

class Target {
private final Date time;

public Target(Date time) {
this.time = time;
}

public Date getTime() {
return time;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.ap.test.mappingcontrol;

import java.time.Instant;
import java.util.Date;

import org.mapstruct.Mapper;

/**
* @author Filip Hrisafov
*/
@Mapper(mappingControl = NoConversion.class)
public interface ErroneousMethodAndConversionMapper {

Target map(Source source);

default long fromInstant(Instant value) {
return value != null ? value.getEpochSecond() : null;
}

class Source {
private final Date time;

public Source(Date time) {
this.time = time;
}

public Date getTime() {
return time;
}
}

class Target {
private long time;

public Target(long time) {
this.time = time;
}

public long getTime() {
return time;
}
}
}
Loading