Skip to content

Commit

Permalink
#151 rework inheritance and support auto inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderhook committed Sep 8, 2023
1 parent 5168fba commit 1d50fb8
Show file tree
Hide file tree
Showing 25 changed files with 1,359 additions and 256 deletions.
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 @@ -9,6 +9,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -41,16 +42,17 @@

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.MAPPER_CONFIG_ANNOTATION_FQN;
import static org.mapstruct.intellij.util.MapstructUtil.isInheritInverseConfiguration;
import static org.mapstruct.intellij.util.MapstructUtil.isMapper;
import static org.mapstruct.intellij.util.MapstructUtil.isMapperConfig;
import static org.mapstruct.intellij.util.SourceUtils.findAllSourceProperties;
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 @@ -86,11 +88,18 @@ public void visitMethod(PsiMethod method) {
if ( isBeanMappingIgnoreByDefault( method ) ) {
return;
}

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

if ( isPrototypeMethod( method )) {
// prototype methods can be incomplete and therefore should not provide errors or warnings
// that cannot be solved with quick fixes
return;
}


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

Expand Down Expand Up @@ -181,6 +190,14 @@ private static boolean isBeanMappingIgnoreByDefault(PsiMethod method) {
return false;
}

private static boolean isPrototypeMethod(@NotNull PsiMethod method) {

return Optional.ofNullable( method.getContainingClass() )
.map( containingClass -> findAnnotation( containingClass, MAPPER_CONFIG_ANNOTATION_FQN ) )
.stream().findFirst()
.isPresent();
}

/**
* @param method the method to be used
*
Expand Down
Loading

0 comments on commit 1d50fb8

Please sign in to comment.