@@ -90,20 +90,21 @@ public static PsiType getRelevantType(@NotNull PsiMethod mappingMethod) {
9090 public static Map <String , Pair <? extends PsiElement , PsiSubstitutor >> publicWriteAccessors (@ NotNull PsiType psiType ,
9191 MapStructVersion mapStructVersion ) {
9292 boolean builderSupportPresent = mapStructVersion .isBuilderSupported ();
93- Pair <PsiClass , PsiType > classAndType = resolveBuilderOrSelfClass ( psiType , builderSupportPresent );
93+ Pair <PsiClass , TargetType > classAndType = resolveBuilderOrSelfClass ( psiType , builderSupportPresent );
9494 if ( classAndType == null ) {
9595 return Collections .emptyMap ();
9696 }
9797
9898 Map <String , Pair <? extends PsiElement , PsiSubstitutor >> publicWriteAccessors = new LinkedHashMap <>();
9999
100100 PsiClass psiClass = classAndType .getFirst ();
101- PsiType typeToUse = classAndType .getSecond ();
101+ TargetType targetType = classAndType .getSecond ();
102+ PsiType typeToUse = targetType .type ();
102103
103104 publicWriteAccessors .putAll ( publicSetters ( psiClass , typeToUse , builderSupportPresent ) );
104105 publicWriteAccessors .putAll ( publicFields ( psiClass ) );
105106
106- if ( mapStructVersion .isConstructorSupported () ) {
107+ if ( mapStructVersion .isConstructorSupported () && ! targetType . builder () ) {
107108 publicWriteAccessors .putAll ( constructorParameters ( psiClass ) );
108109 }
109110
@@ -195,6 +196,9 @@ private static Map<String, Pair<? extends PsiMember, PsiSubstitutor>> publicSett
195196 Map <String , Pair <? extends PsiMember , PsiSubstitutor >> publicSetters = new LinkedHashMap <>();
196197 for ( Pair <PsiMethod , PsiSubstitutor > pair : psiClass .getAllMethodsAndTheirSubstitutors () ) {
197198 PsiMethod method = pair .getFirst ();
199+ if ( method .isConstructor () ) {
200+ continue ;
201+ }
198202 String propertyName = extractPublicSetterPropertyName ( method , typeToUse , builderSupportPresent );
199203
200204 if ( propertyName != null &&
@@ -253,26 +257,26 @@ else if ( methodName.startsWith( "set" ) ) {
253257 *
254258 * @return the pair containing the {@link PsiClass} and the corresponding {@link PsiType}
255259 */
256- public static Pair <PsiClass , PsiType > resolveBuilderOrSelfClass (@ NotNull PsiType psiType ,
260+ public static Pair <PsiClass , TargetType > resolveBuilderOrSelfClass (@ NotNull PsiType psiType ,
257261 boolean builderSupportPresent ) {
258262 PsiClass psiClass = PsiUtil .resolveClassInType ( psiType );
259263 if ( psiClass == null ) {
260264 return null ;
261265 }
262- PsiType typeToUse = psiType ;
266+ TargetType targetType = TargetType . defaultType ( psiType ) ;
263267
264268 if ( builderSupportPresent ) {
265269 for ( PsiMethod classMethod : psiClass .getMethods () ) {
266- if ( MapstructUtil .isPossibleBuilderCreationMethod ( classMethod , typeToUse ) &&
270+ if ( MapstructUtil .isPossibleBuilderCreationMethod ( classMethod , targetType . type () ) &&
267271 hasBuildMethod ( classMethod .getReturnType (), psiType ) ) {
268- typeToUse = classMethod .getReturnType ();
272+ targetType = TargetType . builder ( classMethod .getReturnType () );
269273 break ;
270274 }
271275 }
272276 }
273277
274- psiClass = PsiUtil .resolveClassInType ( typeToUse );
275- return psiClass == null ? null : Pair .createNonNull ( psiClass , typeToUse );
278+ psiClass = PsiUtil .resolveClassInType ( targetType . type () );
279+ return psiClass == null ? null : Pair .createNonNull ( psiClass , targetType );
276280 }
277281
278282 /**
0 commit comments