Skip to content

Commit f1bc5bd

Browse files
authored
support java expressions in Mapping#conditionExpression (#154)
1 parent 14393d1 commit f1bc5bd

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/main/java/org/mapstruct/intellij/expression/JavaExpressionInjector.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public class JavaExpressionInjector implements MultiHostInjector {
5454
private static final ElementPattern<PsiElement> PATTERN =
5555
StandardPatterns.or(
5656
MapstructElementUtils.mappingElementPattern( "expression" ),
57-
MapstructElementUtils.mappingElementPattern( "defaultExpression" )
57+
MapstructElementUtils.mappingElementPattern( "defaultExpression" ),
58+
MapstructElementUtils.mappingElementPattern( "conditionExpression" )
5859
);
5960

6061
private void importIfNecessary(PsiClass cls, @NotNull Set<String> imports) {

src/test/java/org/mapstruct/intellij/expression/JavaExpressionInjectionTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ protected void setUp() throws Exception {
192192
public void testExpressionWithNoTargetDefinedMapper() {
193193
noTargetDefinedMapper( "expression" );
194194
noTargetDefinedMapper( "defaultExpression" );
195+
noTargetDefinedMapper( "conditionExpression" );
195196
}
196197

197198
protected void noTargetDefinedMapper(String attribute) {
@@ -215,6 +216,7 @@ protected void noTargetDefinedMapper(String attribute) {
215216
public void testExpressionWithoutJavaExpression() {
216217
withoutJavaExpression( "expression" );
217218
withoutJavaExpression( "defaultExpression" );
219+
withoutJavaExpression( "conditionExpression" );
218220
}
219221

220222
protected void withoutJavaExpression(String attribute) {
@@ -233,6 +235,7 @@ protected void withoutJavaExpression(String attribute) {
233235
public void testExpressionWithTargetDefinedMapper() {
234236
withTargetDefinedMapper( "expression" );
235237
withTargetDefinedMapper( "defaultExpression" );
238+
withTargetDefinedMapper( "conditionExpression" );
236239
}
237240

238241
protected void withTargetDefinedMapper(String attribute) {
@@ -268,6 +271,7 @@ protected void withTargetDefinedMapper(String attribute) {
268271
public void testExpressionWithTargetDefinedMapperInMappings() {
269272
withTargetDefinedMapperInMappings( "expression" );
270273
withTargetDefinedMapperInMappings( "defaultExpression" );
274+
withTargetDefinedMapperInMappings( "conditionExpression" );
271275
}
272276

273277
protected void withTargetDefinedMapperInMappings(String attribute) {
@@ -305,6 +309,7 @@ protected void withTargetDefinedMapperInMappings(String attribute) {
305309
public void testExpressionWithMapperWithImports() {
306310
withMapperWithImports( "expression" );
307311
withMapperWithImports( "defaultExpression" );
312+
withMapperWithImports( "conditionExpression" );
308313
}
309314

310315
protected void withMapperWithImports(String attribute) {
@@ -333,6 +338,7 @@ protected void withMapperWithImports(String attribute) {
333338
public void testExpressionWithMapperWithCustomImports() {
334339
withMapperWithCustomImports( "expression" );
335340
withMapperWithCustomImports( "defaultExpression" );
341+
withMapperWithCustomImports( "conditionExpression" );
336342
}
337343

338344
protected void withMapperWithCustomImports(String attribute) {
@@ -360,6 +366,7 @@ protected void withMapperWithCustomImports(String attribute) {
360366
public void testExpressionWithMapperWithoutImports() {
361367
withMapperWithoutImports( "expression" );
362368
withMapperWithoutImports( "defaultExpression" );
369+
withMapperWithoutImports( "conditionExpression" );
363370
}
364371

365372
protected void withMapperWithoutImports(String attribute) {
@@ -387,6 +394,7 @@ protected void withMapperWithoutImports(String attribute) {
387394
public void testExpressionWithMultiSourceParameters() {
388395
withMultiSourceParameters( "expression" );
389396
withMultiSourceParameters( "defaultExpression" );
397+
withMultiSourceParameters( "conditionExpression" );
390398
}
391399

392400
protected void withMultiSourceParameters(String attribute) {
@@ -414,6 +422,7 @@ protected void withMultiSourceParameters(String attribute) {
414422
public void testExpressionWithGenericSourceParameters() {
415423
withGenericSourceParameters( "expression" );
416424
withGenericSourceParameters( "defaultExpression" );
425+
withGenericSourceParameters( "conditionExpression" );
417426
}
418427

419428
protected void withGenericSourceParameters(String attribute) {
@@ -442,6 +451,7 @@ protected void withGenericSourceParameters(String attribute) {
442451
public void testExpressionWithSourceParameterWithAnnotations() {
443452
withExpressionWithSourceParameterWithAnnotations( "expression" );
444453
withExpressionWithSourceParameterWithAnnotations( "defaultExpression" );
454+
withExpressionWithSourceParameterWithAnnotations( "conditionExpression" );
445455
}
446456

447457
protected void withExpressionWithSourceParameterWithAnnotations(String attribute) {
@@ -471,6 +481,7 @@ protected void withExpressionWithSourceParameterWithAnnotations(String attribute
471481
public void testExpressionWithSourceParameterWithMultipleGenerics() {
472482
withExpressionWithSourceParameterWithMultipleGenerics( "expression" );
473483
withExpressionWithSourceParameterWithMultipleGenerics( "defaultExpression" );
484+
withExpressionWithSourceParameterWithMultipleGenerics( "conditionExpression" );
474485
}
475486

476487
protected void withExpressionWithSourceParameterWithMultipleGenerics(String attribute) {
@@ -500,6 +511,7 @@ protected void withExpressionWithSourceParameterWithMultipleGenerics(String attr
500511
public void testExpressionWithGenericMethod() {
501512
withExpressionWithGenericMethod( "expression" );
502513
withExpressionWithGenericMethod( "defaultExpression" );
514+
withExpressionWithGenericMethod( "conditionExpression" );
503515
}
504516

505517
protected void withExpressionWithGenericMethod(String attribute) {
@@ -526,6 +538,7 @@ protected void withExpressionWithGenericMethod(String attribute) {
526538
public void testExpressionWithGenericMapper() {
527539
withGenericMapper( "expression" );
528540
withGenericMapper( "defaultExpression" );
541+
withGenericMapper( "conditionExpression" );
529542
}
530543

531544
protected void withGenericMapper(String attribute) {
@@ -553,6 +566,7 @@ protected void withGenericMapper(String attribute) {
553566
public void testExpressionWithClassMapper() {
554567
withClassMapper( "expression" );
555568
withClassMapper( "defaultExpression" );
569+
withClassMapper( "conditionExpression" );
556570
}
557571

558572
protected void withClassMapper(String attribute) {
@@ -587,6 +601,7 @@ protected void withClassMapper(String attribute) {
587601
public void testExpressionWithTargetUsingStaticString() {
588602
withTargetUsingStaticString( "expression" );
589603
withTargetUsingStaticString( "defaultExpression" );
604+
withTargetUsingStaticString( "conditionExpression" );
590605
}
591606

592607
protected void withTargetUsingStaticString(String attribute) {
@@ -622,6 +637,7 @@ protected void withTargetUsingStaticString(String attribute) {
622637
public void testExpressionWithMapperToDtoWithoutAccessors() {
623638
withMapperToDtoWithoutAccessors( "expression" );
624639
withMapperToDtoWithoutAccessors( "defaultExpression" );
640+
withMapperToDtoWithoutAccessors( "conditionExpression" );
625641
}
626642

627643
protected void withMapperToDtoWithoutAccessors(String attribute) {

0 commit comments

Comments
 (0)