add support for collection targets from getter by hduelme · Pull Request #149 · mapstruct/mapstruct-idea · GitHub
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
45 changes: 22 additions & 23 deletions src/main/java/org/mapstruct/intellij/util/TargetUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at https://www.apache.org/licenses/LICENSE-2.0
*/
package org.mapstruct.intellij.inspection;

import com.intellij.codeInsight.intention.IntentionAction;
import org.jetbrains.annotations.NotNull;

import java.util.List;

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

/**
* @author Filip Hrisafov
*/
public class UnmappedCollectionGetterPropertiesInspectionTest extends BaseInspectionTest {

@NotNull
@Override
protected Class<UnmappedTargetPropertiesInspection> getInspection() {
return UnmappedTargetPropertiesInspection.class;
}

@Override
protected void setUp() throws Exception {
super.setUp();
myFixture.copyFileToProject(
"UnmappedCollectionGetterPropertiesData.java",
"org/example/data/UnmappedCollectionGetterPropertiesData.java"
);
}

public void testUnmappedCollectionGetterProperties() {
doTest();
List<IntentionAction> allQuickFixes = myFixture.getAllQuickFixes();

assertThat( allQuickFixes )
.extracting( IntentionAction::getText )
.as( "Intent Text" )
.containsExactlyInAnyOrder(
"Ignore unmapped target property: 'listTarget'",
"Add unmapped target property: 'listTarget'",
"Ignore unmapped target property: 'setTarget'",
"Add unmapped target property: 'setTarget'",
"Ignore unmapped target property: 'mapTarget'",
"Add unmapped target property: 'mapTarget'",
"Ignore all unmapped target properties"
);

allQuickFixes.forEach( myFixture::launchAction );
}
}
36 changes: 36 additions & 0 deletions testData/inspection/UnmappedCollectionGetterProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright MapStruct Authors.
*
* Licensed under the Apache License version 2.0, available at https://www.apache.org/licenses/LICENSE-2.0
*/

import org.mapstruct.Context;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.Mappings;
import org.example.data.UnmappedCollectionGetterPropertiesData.Target;
import org.example.data.UnmappedCollectionGetterPropertiesData.Source;

interface NotMapStructMapper {

Target map(Source source);
}

@Mapper
interface NoMappingMapper {

Target <warning descr="Unmapped target properties: listTarget, mapTarget, setTarget">map</warning>(Source source);

@org.mapstruct.InheritInverseConfiguration
Source reverse(Target target);
}

@Mapper
interface AllMappingMapper {

@Mapping(target = "listTarget", source = "listSource")
@Mapping(target = "setTarget", source = "setSource")
@Mapping(target = "mapTarget", source = "mapSource")
Target mapWithAllMapping(Source source);
}
56 changes: 56 additions & 0 deletions testData/inspection/UnmappedCollectionGetterPropertiesData.java