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 @@ -14,6 +14,7 @@
import org.mapstruct.ap.internal.util.Strings;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand Down Expand Up @@ -121,6 +122,9 @@ public ForgedMethodHistory getDescription() {
}

public List<Annotation> getMethodAnnotations() {
if ( method instanceof ForgedMethod ) {
return Collections.emptyList();
}
AdditionalAnnotationsBuilder additionalAnnotationsBuilder =
new AdditionalAnnotationsBuilder(
ctx.getElementUtils(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.mapstruct.ap.internal.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -117,13 +118,20 @@ else if ( sourceType.isString() && targetType.isEnumType() ) {
LifecycleMethodResolver.beforeMappingMethods( method, selectionParameters, ctx, existingVariables );
List<LifecycleCallbackMethodReference> afterMappingMethods =
LifecycleMethodResolver.afterMappingMethods( method, selectionParameters, ctx, existingVariables );
AdditionalAnnotationsBuilder additionalAnnotationsBuilder =
List<Annotation> annotations;
if ( method instanceof ForgedMethod ) {
annotations = Collections.emptyList();
}
else {
annotations = new ArrayList<>();
AdditionalAnnotationsBuilder additionalAnnotationsBuilder =
new AdditionalAnnotationsBuilder(
ctx.getElementUtils(),
ctx.getTypeFactory(),
ctx.getMessager() );
List<Annotation> annotations = new ArrayList<>();
annotations.addAll( additionalAnnotationsBuilder.getProcessedAnnotations( method.getExecutable() ) );
ctx.getElementUtils(),
ctx.getTypeFactory(),
ctx.getMessager() );

annotations.addAll( additionalAnnotationsBuilder.getProcessedAnnotations( method.getExecutable() ) );
}
// finally return a mapping
return new ValueMappingMethod( method,
annotations,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* 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._3015;

import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

import org.mapstruct.AnnotateWith;
import org.mapstruct.Mapper;
import org.mapstruct.ap.test.annotatewith.CustomMethodOnlyAnnotation;

/**
* @author orange add
*/
@Mapper
public interface Issue3015Mapper {

@AnnotateWith( CustomMethodOnlyAnnotation.class )
Target map(Source source);

class Source {

private NestedSource nested;
private List<String> list;
private Stream<String> stream;
private AnnotateSourceEnum annotateWithEnum;
private Map<String, Integer> map;

public NestedSource getNested() {
return nested;
}

public void setNested(NestedSource nested) {
this.nested = nested;
}

public List<String> getList() {
return list;
}

public void setList(List<String> list) {
this.list = list;
}

public Stream<String> getStream() {
return stream;
}

public void setStream(Stream<String> stream) {
this.stream = stream;
}

public AnnotateSourceEnum getAnnotateWithEnum() {
return annotateWithEnum;
}

public void setAnnotateWithEnum(AnnotateSourceEnum annotateWithEnum) {
this.annotateWithEnum = annotateWithEnum;
}

public Map<String, Integer> getMap() {
return map;
}

public void setMap(Map<String, Integer> map) {
this.map = map;
}
}

class Target {
private NestedTarget nested;
private List<Integer> list;
private Stream<Integer> stream;
private AnnotateTargetEnum annotateWithEnum;
private Map<String, String> map;

public NestedTarget getNested() {
return nested;
}

public void setNested(NestedTarget nested) {
this.nested = nested;
}

public List<Integer> getList() {
return list;
}

public void setList(List<Integer> list) {
this.list = list;
}

public Stream<Integer> getStream() {
return stream;
}

public void setStream(Stream<Integer> stream) {
this.stream = stream;
}

public AnnotateTargetEnum getAnnotateWithEnum() {
return annotateWithEnum;
}

public void setAnnotateWithEnum(AnnotateTargetEnum annotateWithEnum) {
this.annotateWithEnum = annotateWithEnum;
}

public Map<String, String> getMap() {
return map;
}

public void setMap(Map<String, String> map) {
this.map = map;
}
}

enum AnnotateSourceEnum {
EXISTING;
}

enum AnnotateTargetEnum {
EXISTING;
}

class NestedSource {
private String value;

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}
}

class NestedTarget {
private Integer value;

public Integer getValue() {
return value;
}

public void setValue(Integer value) {
this.value = value;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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._3015;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.mapstruct.ap.test.annotatewith.CustomMethodOnlyAnnotation;
import org.mapstruct.ap.testutil.ProcessorTest;
import org.mapstruct.ap.testutil.WithClasses;
import org.mapstruct.factory.Mappers;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author orange add
*/
@WithClasses({
Issue3015Mapper.class,
CustomMethodOnlyAnnotation.class
})
class Issue3015Test {

@ProcessorTest
void noNeedPassAnnotationToForgeMethod() {
Issue3015Mapper mapper = Mappers.getMapper( Issue3015Mapper.class );
Method[] declaredMethods = mapper.getClass().getDeclaredMethods();
List<Method> annotationMethods = Arrays.stream( declaredMethods )
.filter( method -> method.getAnnotation( CustomMethodOnlyAnnotation.class ) != null )
.collect( Collectors.toList() );
assertThat( annotationMethods ).hasSize( 1 );
}
}