Skip to content

Commit dd13840

Browse files
committed
#236: Do not register problems when on mapping composition annotations
1 parent e99789c commit dd13840

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

src/main/java/org/mapstruct/intellij/inspection/MapstructReferenceInspection.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
*/
66
package org.mapstruct.intellij.inspection;
77

8+
import java.util.Optional;
9+
810
import com.intellij.codeInspection.ProblemHighlightType;
911
import com.intellij.codeInspection.ProblemsHolder;
1012
import com.intellij.openapi.util.TextRange;
1113
import com.intellij.psi.ContributedReferenceHost;
14+
import com.intellij.psi.PsiClass;
1215
import com.intellij.psi.PsiElement;
1316
import com.intellij.psi.PsiElementVisitor;
1417
import com.intellij.psi.PsiLanguageInjectionHost;
1518
import com.intellij.psi.PsiReference;
19+
import com.intellij.psi.util.PsiTreeUtil;
1620
import org.jetbrains.annotations.NotNull;
1721
import org.mapstruct.intellij.codeinsight.references.BaseReference;
1822
import org.mapstruct.intellij.codeinsight.references.BaseValueMappingReference;
@@ -64,7 +68,14 @@ private boolean shouldRegisterProblem(BaseReference reference) {
6468
if ( reference instanceof BaseValueMappingReference valueMappingReference ) {
6569
return valueMappingReference.getEnumClass() != null;
6670
}
67-
return true;
71+
72+
return !containingClassIsAnnotationType( reference.getElement() );
73+
}
74+
75+
private boolean containingClassIsAnnotationType(PsiElement element) {
76+
return Optional.ofNullable( PsiTreeUtil.getParentOfType( element, PsiClass.class ) )
77+
.map( PsiClass::isAnnotationType )
78+
.orElse( false );
6879
}
6980
}
7081
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at https://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
package org.mapstruct.intellij.bugs._236;
7+
8+
import org.jetbrains.annotations.NotNull;
9+
import org.mapstruct.intellij.inspection.BaseInspectionTest;
10+
import org.mapstruct.intellij.inspection.MapstructReferenceInspection;
11+
12+
/**
13+
* @author Oliver Erhart
14+
*/
15+
public class DisableSourceAndTargetPropertyInspectionOnAnnotationsTest extends BaseInspectionTest {
16+
17+
@Override
18+
protected String getTestDataPath() {
19+
return "testData/bugs/_236";
20+
}
21+
22+
@NotNull
23+
@Override
24+
protected Class<MapstructReferenceInspection> getInspection() {
25+
return MapstructReferenceInspection.class;
26+
}
27+
28+
public void testDisableSourceAndTargetPropertyInspectionOnAnnotations() {
29+
doTest();
30+
}
31+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright MapStruct Authors.
3+
*
4+
* Licensed under the Apache License version 2.0, available at https://www.apache.org/licenses/LICENSE-2.0
5+
*/
6+
7+
import java.lang.annotation.Retention;
8+
import java.lang.annotation.RetentionPolicy;
9+
10+
import org.mapstruct.Mapping;
11+
12+
@Retention(RetentionPolicy.CLASS)
13+
@Mapping(target = "id", ignore = true)
14+
@Mapping(target = "creationDate", expression = "java(new java.util.Date())")
15+
@Mapping(target = "name", source = "groupName")
16+
@interface ToEntity { }

0 commit comments

Comments
 (0)