Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#151 rework inheritance and support auto inheritance #152

Merged
merged 8 commits into from
Sep 17, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import static org.mapstruct.intellij.util.TargetUtils.isBuilderEnabled;
import static org.mapstruct.intellij.util.TargetUtils.publicWriteAccessors;
import static org.mapstruct.intellij.util.TargetUtils.resolveBuilderOrSelfClass;
import static org.mapstruct.intellij.util.TypeUtils.firstParameterPsiType;

/**
* Reference for {@link org.mapstruct.Mapping#target()}.
Expand Down Expand Up @@ -227,19 +228,4 @@ else if ( psiMember instanceof PsiVariable ) {
}

}

/**
* Util function for extracting the type of the first parameter of a method.
*
* @param psiMethod the method to extract the parameter from
*
* @return the type of the first parameter of the method
*/
private static PsiType firstParameterPsiType(PsiMethod psiMethod) {
PsiParameter[] psiParameters = psiMethod.getParameterList().getParameters();
if ( psiParameters.length == 0) {
return null;
}
return psiParameters[0].getType();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import static com.intellij.codeInsight.AnnotationUtil.findAnnotation;
import static com.intellij.codeInsight.AnnotationUtil.getBooleanAttributeValue;
import static org.mapstruct.intellij.inspection.inheritance.InheritConfigurationUtils.findInheritedTargetProperties;
import static org.mapstruct.intellij.util.MapstructAnnotationUtils.addMappingAnnotation;
import static org.mapstruct.intellij.util.MapstructAnnotationUtils.getUnmappedTargetPolicy;
import static org.mapstruct.intellij.util.MapstructUtil.isInheritInverseConfiguration;
Expand All @@ -50,7 +51,6 @@
import static org.mapstruct.intellij.util.TargetUtils.findAllDefinedMappingTargets;
import static org.mapstruct.intellij.util.TargetUtils.findAllSourcePropertiesForCurrentTarget;
import static org.mapstruct.intellij.util.TargetUtils.findAllTargetProperties;
import static org.mapstruct.intellij.util.TargetUtils.findInheritedTargetProperties;
import static org.mapstruct.intellij.util.TargetUtils.getRelevantType;

/**
Expand Down Expand Up @@ -78,6 +78,10 @@ private MyJavaElementVisitor(ProblemsHolder holder, MapStructVersion mapStructVe
public void visitMethod(PsiMethod method) {
super.visitMethod( method );

if ( !MapstructUtil.isMapper( method.getContainingClass() ) ) {
return;
}

PsiType targetType = getTargetType( method );
if ( targetType == null ) {
return;
Expand All @@ -86,12 +90,12 @@ public void visitMethod(PsiMethod method) {
if ( isBeanMappingIgnoreByDefault( method ) ) {
return;
}

ReportingPolicy reportingPolicy = getUnmappedTargetPolicy( method );
if (reportingPolicy == ReportingPolicy.IGNORE) {
return;
}


Set<String> allTargetProperties = findAllTargetProperties( targetType, mapStructVersion, method );

// find and remove all defined mapping targets
Expand Down Expand Up @@ -204,6 +208,7 @@ private static PsiType getTargetType(PsiMethod method) {
}
return getRelevantType( method );
}

}

private static class UnmappedTargetPropertyFix extends LocalQuickFixOnPsiElement {
Expand Down
Loading
Loading