Skip to content
Open
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 @@ -5,6 +5,7 @@
*/
package org.mapstruct.intellij.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -297,9 +298,12 @@ public static Stream<PsiAnnotation> findAllDefinedMappingAnnotations(@NotNull Ps
private static Stream<PsiAnnotation> findAllDefinedMappingAnnotations(@NotNull PsiModifierListOwner owner,
boolean includeMetaAnnotations) {
//TODO cache
Stream<PsiAnnotation> mappingAnnotations = findMappingAnnotations( owner, includeMetaAnnotations );
if ( includeMetaAnnotations ) {
return mappingAnnotations;
}
PsiAnnotation mappings = findAnnotation( owner, true, MapstructUtil.MAPPINGS_ANNOTATION_FQN );
Stream<PsiAnnotation> mappingsAnnotations = extractMappingAnnotationsFromMappings( mappings );
Stream<PsiAnnotation> mappingAnnotations = findMappingAnnotations( owner, includeMetaAnnotations );

return Stream.concat( mappingAnnotations, mappingsAnnotations );
}
Expand Down Expand Up @@ -330,10 +334,10 @@ private static Stream<PsiAnnotation> findMappingAnnotations(@NotNull PsiModifier
}

@NotNull
private static Set<PsiAnnotation> findDirectAndMetaAnnotations(@NotNull PsiModifierListOwner owner,
private static List<PsiAnnotation> findDirectAndMetaAnnotations(@NotNull PsiModifierListOwner owner,
Set<? super PsiClass> visited) {

Set<PsiAnnotation> result = new HashSet<>();
List<PsiAnnotation> result = new ArrayList<>();

// to avoid infinite loops, do not include meta annotations at this point
findAllDefinedMappingAnnotations( owner, false ).forEach( result::add );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ public void testTargetPropertyMappedMoreThanOnce() {
Caret currentCaret = myFixture.getEditor().getCaretModel().getCurrentCaret();
assertThat( currentCaret.getSelectedText( ) ).isEqualTo( "testName" );
}

public void testTargetPropertyNotMappedMoreThanOnceFromAnnotation() {
doTest();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at https://www.apache.org/licenses/LICENSE-2.0
*/
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;


class TargetClass {
private String name;
private String value;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getValue() {
return value;
}

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

class SourceClass {
private String sourceName;

public String getSourceName() {
return sourceName;
}

public void setSourceName(String sourceName) {
this.sourceName = sourceName;
}
}

@Retention(RetentionPolicy.RUNTIME)
@Target( ElementType.METHOD )
@Mappings({
@Mapping(target = "name", source = "sourceName"),
@Mapping(target = "value", ignore = true)
})
@interface MyMappingAnnotation {
}

@Mapper
interface MyMappingAnnotationMapper {

@MyMappingAnnotation
TargetClass map(SourceClass source);
}
Loading