Skip to content

Commit

Permalink
support java expressions in Mapping#conditionExpression (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
cofedream authored Oct 20, 2023
1 parent 14393d1 commit f1bc5bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public class JavaExpressionInjector implements MultiHostInjector {
private static final ElementPattern<PsiElement> PATTERN =
StandardPatterns.or(
MapstructElementUtils.mappingElementPattern( "expression" ),
MapstructElementUtils.mappingElementPattern( "defaultExpression" )
MapstructElementUtils.mappingElementPattern( "defaultExpression" ),
MapstructElementUtils.mappingElementPattern( "conditionExpression" )
);

private void importIfNecessary(PsiClass cls, @NotNull Set<String> imports) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ protected void setUp() throws Exception {
public void testExpressionWithNoTargetDefinedMapper() {
noTargetDefinedMapper( "expression" );
noTargetDefinedMapper( "defaultExpression" );
noTargetDefinedMapper( "conditionExpression" );
}

protected void noTargetDefinedMapper(String attribute) {
Expand All @@ -215,6 +216,7 @@ protected void noTargetDefinedMapper(String attribute) {
public void testExpressionWithoutJavaExpression() {
withoutJavaExpression( "expression" );
withoutJavaExpression( "defaultExpression" );
withoutJavaExpression( "conditionExpression" );
}

protected void withoutJavaExpression(String attribute) {
Expand All @@ -233,6 +235,7 @@ protected void withoutJavaExpression(String attribute) {
public void testExpressionWithTargetDefinedMapper() {
withTargetDefinedMapper( "expression" );
withTargetDefinedMapper( "defaultExpression" );
withTargetDefinedMapper( "conditionExpression" );
}

protected void withTargetDefinedMapper(String attribute) {
Expand Down Expand Up @@ -268,6 +271,7 @@ protected void withTargetDefinedMapper(String attribute) {
public void testExpressionWithTargetDefinedMapperInMappings() {
withTargetDefinedMapperInMappings( "expression" );
withTargetDefinedMapperInMappings( "defaultExpression" );
withTargetDefinedMapperInMappings( "conditionExpression" );
}

protected void withTargetDefinedMapperInMappings(String attribute) {
Expand Down Expand Up @@ -305,6 +309,7 @@ protected void withTargetDefinedMapperInMappings(String attribute) {
public void testExpressionWithMapperWithImports() {
withMapperWithImports( "expression" );
withMapperWithImports( "defaultExpression" );
withMapperWithImports( "conditionExpression" );
}

protected void withMapperWithImports(String attribute) {
Expand Down Expand Up @@ -333,6 +338,7 @@ protected void withMapperWithImports(String attribute) {
public void testExpressionWithMapperWithCustomImports() {
withMapperWithCustomImports( "expression" );
withMapperWithCustomImports( "defaultExpression" );
withMapperWithCustomImports( "conditionExpression" );
}

protected void withMapperWithCustomImports(String attribute) {
Expand Down Expand Up @@ -360,6 +366,7 @@ protected void withMapperWithCustomImports(String attribute) {
public void testExpressionWithMapperWithoutImports() {
withMapperWithoutImports( "expression" );
withMapperWithoutImports( "defaultExpression" );
withMapperWithoutImports( "conditionExpression" );
}

protected void withMapperWithoutImports(String attribute) {
Expand Down Expand Up @@ -387,6 +394,7 @@ protected void withMapperWithoutImports(String attribute) {
public void testExpressionWithMultiSourceParameters() {
withMultiSourceParameters( "expression" );
withMultiSourceParameters( "defaultExpression" );
withMultiSourceParameters( "conditionExpression" );
}

protected void withMultiSourceParameters(String attribute) {
Expand Down Expand Up @@ -414,6 +422,7 @@ protected void withMultiSourceParameters(String attribute) {
public void testExpressionWithGenericSourceParameters() {
withGenericSourceParameters( "expression" );
withGenericSourceParameters( "defaultExpression" );
withGenericSourceParameters( "conditionExpression" );
}

protected void withGenericSourceParameters(String attribute) {
Expand Down Expand Up @@ -442,6 +451,7 @@ protected void withGenericSourceParameters(String attribute) {
public void testExpressionWithSourceParameterWithAnnotations() {
withExpressionWithSourceParameterWithAnnotations( "expression" );
withExpressionWithSourceParameterWithAnnotations( "defaultExpression" );
withExpressionWithSourceParameterWithAnnotations( "conditionExpression" );
}

protected void withExpressionWithSourceParameterWithAnnotations(String attribute) {
Expand Down Expand Up @@ -471,6 +481,7 @@ protected void withExpressionWithSourceParameterWithAnnotations(String attribute
public void testExpressionWithSourceParameterWithMultipleGenerics() {
withExpressionWithSourceParameterWithMultipleGenerics( "expression" );
withExpressionWithSourceParameterWithMultipleGenerics( "defaultExpression" );
withExpressionWithSourceParameterWithMultipleGenerics( "conditionExpression" );
}

protected void withExpressionWithSourceParameterWithMultipleGenerics(String attribute) {
Expand Down Expand Up @@ -500,6 +511,7 @@ protected void withExpressionWithSourceParameterWithMultipleGenerics(String attr
public void testExpressionWithGenericMethod() {
withExpressionWithGenericMethod( "expression" );
withExpressionWithGenericMethod( "defaultExpression" );
withExpressionWithGenericMethod( "conditionExpression" );
}

protected void withExpressionWithGenericMethod(String attribute) {
Expand All @@ -526,6 +538,7 @@ protected void withExpressionWithGenericMethod(String attribute) {
public void testExpressionWithGenericMapper() {
withGenericMapper( "expression" );
withGenericMapper( "defaultExpression" );
withGenericMapper( "conditionExpression" );
}

protected void withGenericMapper(String attribute) {
Expand Down Expand Up @@ -553,6 +566,7 @@ protected void withGenericMapper(String attribute) {
public void testExpressionWithClassMapper() {
withClassMapper( "expression" );
withClassMapper( "defaultExpression" );
withClassMapper( "conditionExpression" );
}

protected void withClassMapper(String attribute) {
Expand Down Expand Up @@ -587,6 +601,7 @@ protected void withClassMapper(String attribute) {
public void testExpressionWithTargetUsingStaticString() {
withTargetUsingStaticString( "expression" );
withTargetUsingStaticString( "defaultExpression" );
withTargetUsingStaticString( "conditionExpression" );
}

protected void withTargetUsingStaticString(String attribute) {
Expand Down Expand Up @@ -622,6 +637,7 @@ protected void withTargetUsingStaticString(String attribute) {
public void testExpressionWithMapperToDtoWithoutAccessors() {
withMapperToDtoWithoutAccessors( "expression" );
withMapperToDtoWithoutAccessors( "defaultExpression" );
withMapperToDtoWithoutAccessors( "conditionExpression" );
}

protected void withMapperToDtoWithoutAccessors(String attribute) {
Expand Down

0 comments on commit f1bc5bd

Please sign in to comment.