From 842734123fabccb7b0110439df4788b5e247d295 Mon Sep 17 00:00:00 2001 From: cofe Date: Wed, 18 Oct 2023 14:01:59 +0800 Subject: [PATCH] support java expressions in `Mapping#conditionExpression` --- .../expression/JavaExpressionInjector.java | 3 ++- .../expression/JavaExpressionInjectionTest.java | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/mapstruct/intellij/expression/JavaExpressionInjector.java b/src/main/java/org/mapstruct/intellij/expression/JavaExpressionInjector.java index a31b5d2d..386cfacd 100644 --- a/src/main/java/org/mapstruct/intellij/expression/JavaExpressionInjector.java +++ b/src/main/java/org/mapstruct/intellij/expression/JavaExpressionInjector.java @@ -54,7 +54,8 @@ public class JavaExpressionInjector implements MultiHostInjector { private static final ElementPattern PATTERN = StandardPatterns.or( MapstructElementUtils.mappingElementPattern( "expression" ), - MapstructElementUtils.mappingElementPattern( "defaultExpression" ) + MapstructElementUtils.mappingElementPattern( "defaultExpression" ), + MapstructElementUtils.mappingElementPattern( "conditionExpression" ) ); private void importIfNecessary(PsiClass cls, @NotNull Set imports) { diff --git a/src/test/java/org/mapstruct/intellij/expression/JavaExpressionInjectionTest.java b/src/test/java/org/mapstruct/intellij/expression/JavaExpressionInjectionTest.java index 4bcf22f6..1ec1d858 100644 --- a/src/test/java/org/mapstruct/intellij/expression/JavaExpressionInjectionTest.java +++ b/src/test/java/org/mapstruct/intellij/expression/JavaExpressionInjectionTest.java @@ -192,6 +192,7 @@ protected void setUp() throws Exception { public void testExpressionWithNoTargetDefinedMapper() { noTargetDefinedMapper( "expression" ); noTargetDefinedMapper( "defaultExpression" ); + noTargetDefinedMapper( "conditionExpression" ); } protected void noTargetDefinedMapper(String attribute) { @@ -215,6 +216,7 @@ protected void noTargetDefinedMapper(String attribute) { public void testExpressionWithoutJavaExpression() { withoutJavaExpression( "expression" ); withoutJavaExpression( "defaultExpression" ); + withoutJavaExpression( "conditionExpression" ); } protected void withoutJavaExpression(String attribute) { @@ -233,6 +235,7 @@ protected void withoutJavaExpression(String attribute) { public void testExpressionWithTargetDefinedMapper() { withTargetDefinedMapper( "expression" ); withTargetDefinedMapper( "defaultExpression" ); + withTargetDefinedMapper( "conditionExpression" ); } protected void withTargetDefinedMapper(String attribute) { @@ -268,6 +271,7 @@ protected void withTargetDefinedMapper(String attribute) { public void testExpressionWithTargetDefinedMapperInMappings() { withTargetDefinedMapperInMappings( "expression" ); withTargetDefinedMapperInMappings( "defaultExpression" ); + withTargetDefinedMapperInMappings( "conditionExpression" ); } protected void withTargetDefinedMapperInMappings(String attribute) { @@ -305,6 +309,7 @@ protected void withTargetDefinedMapperInMappings(String attribute) { public void testExpressionWithMapperWithImports() { withMapperWithImports( "expression" ); withMapperWithImports( "defaultExpression" ); + withMapperWithImports( "conditionExpression" ); } protected void withMapperWithImports(String attribute) { @@ -333,6 +338,7 @@ protected void withMapperWithImports(String attribute) { public void testExpressionWithMapperWithCustomImports() { withMapperWithCustomImports( "expression" ); withMapperWithCustomImports( "defaultExpression" ); + withMapperWithCustomImports( "conditionExpression" ); } protected void withMapperWithCustomImports(String attribute) { @@ -360,6 +366,7 @@ protected void withMapperWithCustomImports(String attribute) { public void testExpressionWithMapperWithoutImports() { withMapperWithoutImports( "expression" ); withMapperWithoutImports( "defaultExpression" ); + withMapperWithoutImports( "conditionExpression" ); } protected void withMapperWithoutImports(String attribute) { @@ -387,6 +394,7 @@ protected void withMapperWithoutImports(String attribute) { public void testExpressionWithMultiSourceParameters() { withMultiSourceParameters( "expression" ); withMultiSourceParameters( "defaultExpression" ); + withMultiSourceParameters( "conditionExpression" ); } protected void withMultiSourceParameters(String attribute) { @@ -414,6 +422,7 @@ protected void withMultiSourceParameters(String attribute) { public void testExpressionWithGenericSourceParameters() { withGenericSourceParameters( "expression" ); withGenericSourceParameters( "defaultExpression" ); + withGenericSourceParameters( "conditionExpression" ); } protected void withGenericSourceParameters(String attribute) { @@ -442,6 +451,7 @@ protected void withGenericSourceParameters(String attribute) { public void testExpressionWithSourceParameterWithAnnotations() { withExpressionWithSourceParameterWithAnnotations( "expression" ); withExpressionWithSourceParameterWithAnnotations( "defaultExpression" ); + withExpressionWithSourceParameterWithAnnotations( "conditionExpression" ); } protected void withExpressionWithSourceParameterWithAnnotations(String attribute) { @@ -471,6 +481,7 @@ protected void withExpressionWithSourceParameterWithAnnotations(String attribute public void testExpressionWithSourceParameterWithMultipleGenerics() { withExpressionWithSourceParameterWithMultipleGenerics( "expression" ); withExpressionWithSourceParameterWithMultipleGenerics( "defaultExpression" ); + withExpressionWithSourceParameterWithMultipleGenerics( "conditionExpression" ); } protected void withExpressionWithSourceParameterWithMultipleGenerics(String attribute) { @@ -500,6 +511,7 @@ protected void withExpressionWithSourceParameterWithMultipleGenerics(String attr public void testExpressionWithGenericMethod() { withExpressionWithGenericMethod( "expression" ); withExpressionWithGenericMethod( "defaultExpression" ); + withExpressionWithGenericMethod( "conditionExpression" ); } protected void withExpressionWithGenericMethod(String attribute) { @@ -526,6 +538,7 @@ protected void withExpressionWithGenericMethod(String attribute) { public void testExpressionWithGenericMapper() { withGenericMapper( "expression" ); withGenericMapper( "defaultExpression" ); + withGenericMapper( "conditionExpression" ); } protected void withGenericMapper(String attribute) { @@ -553,6 +566,7 @@ protected void withGenericMapper(String attribute) { public void testExpressionWithClassMapper() { withClassMapper( "expression" ); withClassMapper( "defaultExpression" ); + withClassMapper( "conditionExpression" ); } protected void withClassMapper(String attribute) { @@ -587,6 +601,7 @@ protected void withClassMapper(String attribute) { public void testExpressionWithTargetUsingStaticString() { withTargetUsingStaticString( "expression" ); withTargetUsingStaticString( "defaultExpression" ); + withTargetUsingStaticString( "conditionExpression" ); } protected void withTargetUsingStaticString(String attribute) { @@ -622,6 +637,7 @@ protected void withTargetUsingStaticString(String attribute) { public void testExpressionWithMapperToDtoWithoutAccessors() { withMapperToDtoWithoutAccessors( "expression" ); withMapperToDtoWithoutAccessors( "defaultExpression" ); + withMapperToDtoWithoutAccessors( "conditionExpression" ); } protected void withMapperToDtoWithoutAccessors(String attribute) {