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 @@ -9,10 +9,12 @@
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.ContributedReferenceHost;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.PsiLanguageInjectionHost;
import com.intellij.psi.PsiReference;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import org.mapstruct.intellij.codeinsight.references.BaseReference;
import org.mapstruct.intellij.codeinsight.references.BaseValueMappingReference;
Expand Down Expand Up @@ -64,7 +66,19 @@ private boolean shouldRegisterProblem(BaseReference reference) {
if ( reference instanceof BaseValueMappingReference valueMappingReference ) {
return valueMappingReference.getEnumClass() != null;
}
return true;

return !containingClassIsAnnotationType( reference.getElement() );
}

private boolean containingClassIsAnnotationType(PsiElement element) {

PsiClass containingClass = PsiTreeUtil.getParentOfType( element, PsiClass.class );

if ( containingClass == null ) {
return false;
}

return containingClass.isAnnotationType();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.bugs._236;

import org.jetbrains.annotations.NotNull;
import org.mapstruct.intellij.inspection.BaseInspectionTest;
import org.mapstruct.intellij.inspection.MapstructReferenceInspection;

/**
* @author Oliver Erhart
*/
public class DisableSourceAndTargetPropertyInspectionOnAnnotationsTest extends BaseInspectionTest {

@Override
protected String getTestDataPath() {
return "testData/bugs/_236";
}

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

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

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

import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

@Retention(RetentionPolicy.CLASS)
@Mapping(target = "id", ignore = true)
@Mapping(target = "creationDate", expression = "java(new java.util.Date())")
@Mapping(target = "name", source = "groupName")
@interface ToEntity { }

@Retention(RetentionPolicy.CLASS)
@Mappings({
@Mapping(target = "id", ignore = true),
@Mapping(target = "creationDate", expression = "java(new java.util.Date())"),
@Mapping(target = "name", source = "groupName")
})
@interface ToEntityWithMappings { }