mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
Co-authored-by: Ben Zegveld <Ben.Zegveld@gmail.com>
This commit is contained in:
parent
6604617730
commit
437a70d6df
@ -5,11 +5,9 @@
|
||||
*/
|
||||
package org.mapstruct.ap.internal.model;
|
||||
|
||||
import static org.mapstruct.ap.internal.util.Strings.getSafeVariableName;
|
||||
import static org.mapstruct.ap.internal.util.Strings.join;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -21,6 +19,9 @@ import org.mapstruct.ap.internal.model.common.Parameter;
|
||||
import org.mapstruct.ap.internal.model.common.Type;
|
||||
import org.mapstruct.ap.internal.model.source.Method;
|
||||
|
||||
import static org.mapstruct.ap.internal.util.Strings.getSafeVariableName;
|
||||
import static org.mapstruct.ap.internal.util.Strings.join;
|
||||
|
||||
/**
|
||||
* A method implemented or referenced by a {@link Mapper} class.
|
||||
*
|
||||
@ -70,7 +71,7 @@ public abstract class MappingMethod extends ModelElement {
|
||||
this.resultName = initResultName( existingVariableNames );
|
||||
this.beforeMappingReferencesWithMappingTarget = filterMappingTarget( beforeMappingReferences, true );
|
||||
this.beforeMappingReferencesWithoutMappingTarget = filterMappingTarget( beforeMappingReferences, false );
|
||||
this.afterMappingReferences = afterMappingReferences;
|
||||
this.afterMappingReferences = afterMappingReferences == null ? Collections.emptyList() : afterMappingReferences;
|
||||
}
|
||||
|
||||
protected MappingMethod(Method method, List<Parameter> parameters) {
|
||||
@ -153,6 +154,16 @@ public abstract class MappingMethod extends ModelElement {
|
||||
types.addAll( type.getImportTypes() );
|
||||
}
|
||||
|
||||
for ( LifecycleCallbackMethodReference reference : beforeMappingReferencesWithMappingTarget ) {
|
||||
types.addAll( reference.getImportTypes() );
|
||||
}
|
||||
for ( LifecycleCallbackMethodReference reference : beforeMappingReferencesWithoutMappingTarget ) {
|
||||
types.addAll( reference.getImportTypes() );
|
||||
}
|
||||
for ( LifecycleCallbackMethodReference reference : afterMappingReferences ) {
|
||||
types.addAll( reference.getImportTypes() );
|
||||
}
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
@ -178,7 +189,7 @@ public abstract class MappingMethod extends ModelElement {
|
||||
private List<LifecycleCallbackMethodReference> filterMappingTarget(List<LifecycleCallbackMethodReference> methods,
|
||||
boolean mustHaveMappingTargetParameter) {
|
||||
if ( methods == null ) {
|
||||
return null;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<LifecycleCallbackMethodReference> result =
|
||||
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.bugs._2807;
|
||||
|
||||
import org.mapstruct.ap.test.bugs._2807.after.AfterMethod;
|
||||
import org.mapstruct.ap.test.bugs._2807.before.BeforeMethod;
|
||||
import org.mapstruct.ap.test.bugs._2807.beforewithtarget.BeforeWithTarget;
|
||||
import org.mapstruct.ap.testutil.IssueKey;
|
||||
import org.mapstruct.ap.testutil.ProcessorTest;
|
||||
import org.mapstruct.ap.testutil.WithClasses;
|
||||
import org.mapstruct.ap.testutil.WithSpring;
|
||||
|
||||
/**
|
||||
* @author Ben Zegveld
|
||||
*/
|
||||
@IssueKey( "2807" )
|
||||
public class Issue2807Test {
|
||||
|
||||
@ProcessorTest
|
||||
@WithSpring
|
||||
@WithClasses( { SpringLifeCycleMapper.class, BeforeMethod.class, BeforeWithTarget.class, AfterMethod.class } )
|
||||
void shouldCompile() {
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.bugs._2807;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
import org.mapstruct.ap.test.bugs._2807.after.AfterMethod;
|
||||
import org.mapstruct.ap.test.bugs._2807.before.BeforeMethod;
|
||||
import org.mapstruct.ap.test.bugs._2807.beforewithtarget.BeforeWithTarget;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
/**
|
||||
* @author Ben Zegveld
|
||||
*/
|
||||
@Mapper( componentModel = "spring", uses = { BeforeMethod.class, AfterMethod.class,
|
||||
BeforeWithTarget.class }, unmappedTargetPolicy = ReportingPolicy.IGNORE )
|
||||
public interface SpringLifeCycleMapper {
|
||||
SpringLifeCycleMapper INSTANCE = Mappers.getMapper( SpringLifeCycleMapper.class );
|
||||
|
||||
List<String> map(List<Integer> list);
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.bugs._2807.after;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.mapstruct.AfterMapping;
|
||||
import org.mapstruct.MappingTarget;
|
||||
|
||||
/**
|
||||
* @author Ben Zegveld
|
||||
*/
|
||||
public class AfterMethod {
|
||||
private AfterMethod() {
|
||||
}
|
||||
|
||||
@AfterMapping
|
||||
public static <D> void doNothing(@MappingTarget List<D> source) {
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 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.bugs._2807.before;
|
||||
|
||||
import org.mapstruct.BeforeMapping;
|
||||
|
||||
/**
|
||||
* @author Ben Zegveld
|
||||
*/
|
||||
public class BeforeMethod {
|
||||
private BeforeMethod() {
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public static <T> void doNothing(Iterable<T> source) {
|
||||
return;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.bugs._2807.beforewithtarget;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.mapstruct.BeforeMapping;
|
||||
import org.mapstruct.MappingTarget;
|
||||
|
||||
/**
|
||||
* @author Ben Zegveld
|
||||
*/
|
||||
public class BeforeWithTarget {
|
||||
private BeforeWithTarget() {
|
||||
}
|
||||
|
||||
@BeforeMapping
|
||||
public static <T, D> void doNothingBeforeWithTarget(Iterable<T> source, @MappingTarget List<D> target) {
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user