@@ -28,6 +28,7 @@ public class JavaExpressionInjectionTest extends MapstructBaseCompletionTestCase
2828 "\n " +
2929 "import org.mapstruct.Mapper;\n " +
3030 "import org.mapstruct.Mapping;\n " +
31+ "import org.mapstruct.Mappings;\n " +
3132 "import org.example.dto.CarDto;\n " +
3233 "import org.example.dto.Car;\n " +
3334 "\n " +
@@ -126,6 +127,43 @@ protected void withTargetDefinedMapper(String attribute) {
126127 assertThat ( elementAt .getText () ).isEqualTo ( ";" );
127128 }
128129
130+ public void testExpressionWithTargetDefinedMapperInMappings () {
131+ withTargetDefinedMapperInMappings ( "expression" );
132+ withTargetDefinedMapperInMappings ( "defaultExpression" );
133+ }
134+
135+ protected void withTargetDefinedMapperInMappings (String attribute ) {
136+ String mapping = "@Mappings(\n " +
137+ "@Mapping(target = \" manufacturingYear\" , " + attribute + " = \" java(car.<caret>)\" )\n " +
138+ ")\n " ;
139+ @ Language ("java" )
140+ String mapper = String .format ( CAR_MAPPER , "" , mapping );
141+ PsiFile file = configureMapperByText ( mapper );
142+
143+ assertThat ( myFixture .completeBasic () )
144+ .extracting ( LookupElementPresentation ::renderElement )
145+ .extracting ( LookupElementPresentation ::getItemText )
146+ .contains (
147+ "getMake" ,
148+ "setMake" ,
149+ "getManufacturingDate" ,
150+ "setManufacturingDate" ,
151+ "getNumberOfSeats" ,
152+ "setNumberOfSeats"
153+ );
154+
155+ assertThat ( myFixture .complete ( CompletionType .SMART ) )
156+ .extracting ( LookupElementPresentation ::renderElement )
157+ .extracting ( LookupElementPresentation ::getItemText )
158+ .containsExactlyInAnyOrder ( "getMake" , "toString" );
159+
160+ PsiElement elementAt = file .findElementAt ( myFixture .getCaretOffset () );
161+ assertThat ( elementAt )
162+ .isNotNull ()
163+ .isInstanceOf ( PsiJavaToken .class );
164+ assertThat ( elementAt .getText () ).isEqualTo ( ";" );
165+ }
166+
129167 public void testExpressionWithMapperWithImports () {
130168 withMapperWithImports ( "expression" );
131169 withMapperWithImports ( "defaultExpression" );
0 commit comments