Skip to content

Commit 03336e5

Browse files
committed
More fixes
1 parent 719b4fb commit 03336e5

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import java.lang.reflect.InvocationTargetException;
99
import java.lang.reflect.Method;
10+
import java.util.ArrayList;
11+
import java.util.Collection;
1012

1113
import com.intellij.codeInsight.AnnotationUtil;
1214
import com.intellij.codeInsight.daemon.impl.quickfix.RemoveUnusedVariableFix;
@@ -100,15 +102,22 @@ public void visitMethodCallExpression(PsiMethodCallExpression expression) {
100102
PsiClass mapperClass = (PsiClass) mapperElement;
101103
PsiAnnotation mapperAnnotation = mapperClass.getAnnotation( MapstructUtil.MAPPER_ANNOTATION_FQN );
102104
if ( mapperAnnotation == null ) {
103-
problemsHolder.registerProblem(
104-
expression,
105-
MapStructBundle.message( "inspection.wrong.usage.mappers.factory.non.mapstruct" ),
105+
Collection<LocalQuickFix> fixes = new ArrayList<>( 2 );
106+
fixes.add(
106107
new AddAnnotationPsiFix(
107108
MapstructUtil.MAPPER_ANNOTATION_FQN,
108109
mapperClass,
109110
PsiNameValuePair.EMPTY_ARRAY
110-
),
111-
createRemoveMappersFix( expression )
111+
)
112+
);
113+
LocalQuickFix removeMappersFix = createRemoveMappersFix( expression );
114+
if ( removeMappersFix != null ) {
115+
fixes.add( removeMappersFix );
116+
}
117+
problemsHolder.registerProblem(
118+
expression,
119+
MapStructBundle.message( "inspection.wrong.usage.mappers.factory.non.mapstruct" ),
120+
fixes.toArray( LocalQuickFix[]::new )
112121
);
113122
}
114123
else {

0 commit comments

Comments
 (0)