@@ -160,6 +160,23 @@ public class JavaExpressionInjectionTest extends MapstructBaseCompletionTestCase
160160 " CarDto carToCarDto(Car car, String make);\n " +
161161 "}" ;
162162
163+ @ Language ("java" )
164+ private static final String MAPPER_TO_DTO_WITHOUT_ACCESSORS = "" +
165+ "import java.util.List;\n " +
166+ "\n " +
167+ "import org.mapstruct.Mapper;\n " +
168+ "import org.mapstruct.Mapping;\n " +
169+ "import org.mapstruct.Mappings;\n " +
170+ "import org.example.dto.CarPlainDto;\n " +
171+ "import org.example.dto.Car;\n " +
172+ "\n " +
173+ "@Mapper(" + MAPPER + ")\n " +
174+ "public interface CarMapper {\n " +
175+ "\n " +
176+ " " + MAPPING + "\n " +
177+ " CarPlainDto carToCarPlainDto(Car car);\n " +
178+ "}" ;
179+
163180 @ Override
164181 protected String getTestDataPath () {
165182 return "testData/expression" ;
@@ -602,6 +619,41 @@ protected void withTargetUsingStaticString(String attribute) {
602619 "}" );
603620 }
604621
622+ public void testExpressionWithMapperToDtoWithoutAccessors () {
623+ withMapperToDtoWithoutAccessors ( "expression" );
624+ withMapperToDtoWithoutAccessors ( "defaultExpression" );
625+ }
626+
627+ protected void withMapperToDtoWithoutAccessors (String attribute ) {
628+ String mapping = "@Mapping(target = \" manufacturingYear\" , " + attribute + " = \" java(car.<caret>)\" )\n " ;
629+ @ Language ("java" )
630+ String mapper = formatMapper ( MAPPER_TO_DTO_WITHOUT_ACCESSORS , mapping );
631+ PsiFile file = configureMapperByText ( mapper );
632+
633+ assertThat ( myFixture .completeBasic () )
634+ .extracting ( LookupElementPresentation ::renderElement )
635+ .extracting ( LookupElementPresentation ::getItemText )
636+ .contains (
637+ "getMake" ,
638+ "setMake" ,
639+ "getManufacturingDate" ,
640+ "setManufacturingDate" ,
641+ "getNumberOfSeats" ,
642+ "setNumberOfSeats"
643+ );
644+
645+ assertThat ( myFixture .complete ( CompletionType .SMART ) )
646+ .extracting ( LookupElementPresentation ::renderElement )
647+ .extracting ( LookupElementPresentation ::getItemText )
648+ .containsExactlyInAnyOrder ( "getMake" , "toString" );
649+
650+ PsiElement elementAt = file .findElementAt ( myFixture .getCaretOffset () );
651+ assertThat ( elementAt )
652+ .isNotNull ()
653+ .isInstanceOf ( PsiJavaToken .class );
654+ assertThat ( elementAt .getText () ).isEqualTo ( ";" );
655+ }
656+
605657 private PsiFile configureMapperByText (@ Language ("java" ) String text ) {
606658 return myFixture .configureByText ( JavaFileType .INSTANCE , text );
607659 }
0 commit comments