From 0f429cc7cd41090682dd253438ec468b4e0ae17e Mon Sep 17 00:00:00 2001 From: Yuriy Shevtsov Date: Tue, 10 Oct 2023 14:34:19 +0100 Subject: [PATCH] Fixed getter name generator according to JavaBeans specification Fixes #375 --- core/esmf-aspect-model-java-generator/pom.xml | 4 ++++ .../esmf/aspectmodel/java/AspectModelJavaUtil.java | 9 +++++++++ .../src/main/resources/java-pojo-getter-lib.vm | 11 ++++------- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/core/esmf-aspect-model-java-generator/pom.xml b/core/esmf-aspect-model-java-generator/pom.xml index 43575a63a..1c8c3d921 100644 --- a/core/esmf-aspect-model-java-generator/pom.xml +++ b/core/esmf-aspect-model-java-generator/pom.xml @@ -57,6 +57,10 @@ record-builder-processor provided + + org.apache.jena + jena-core + diff --git a/core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/AspectModelJavaUtil.java b/core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/AspectModelJavaUtil.java index 03d7f2429..beee67eaf 100644 --- a/core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/AspectModelJavaUtil.java +++ b/core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/AspectModelJavaUtil.java @@ -622,4 +622,13 @@ public static AbstractEntity castToAbstractEntity( final ComplexType complexType public static Quantifiable castToQuantifiable( final Characteristic characteristic ) { return (Quantifiable) characteristic; } + + public static String getterName( final Property property ) { + final boolean isBooleanType = !property.isOptional() + && property.getDataType() + .filter( Type::isScalar ) + .map( type -> XSD.xboolean.getURI().equals( type.getUrn() ) ) + .orElse( false ); + return (isBooleanType ? "is" : "get") + StringUtils.capitalize( property.getPayloadName() ); + } } diff --git a/core/esmf-aspect-model-java-generator/src/main/resources/java-pojo-getter-lib.vm b/core/esmf-aspect-model-java-generator/src/main/resources/java-pojo-getter-lib.vm index 411779884..0205ad136 100644 --- a/core/esmf-aspect-model-java-generator/src/main/resources/java-pojo-getter-lib.vm +++ b/core/esmf-aspect-model-java-generator/src/main/resources/java-pojo-getter-lib.vm @@ -10,26 +10,23 @@ ~ ~ SPDX-License-Identifier: MPL-2.0 *# -#macro( methodName ) - #if( $property.getDataType().isPresent() ) - #set( $type = $property.dataType.get() ) - #if( $type.isScalar() && $type.getUrn().equals( $XSD.xboolean.getURI() ) )is#{else}get#{end} - #{else}get#{end}${StringUtils.capitalize( $property.getPayloadName() )}#{end} #macro( javaPojoGetter $property $propertyIndex ) +#set( $methodName = $util.getterName( $property ) ) + /** * Returns $property.getPreferredName( $localeEn ) * * @return {@link #$property.getPayloadName()} */ #if( $property.isAbstract() ) - public abstract T${propertyIndex} #methodName()(); + public abstract T${propertyIndex} $methodName(); #else #set( $propertyType = $util.getPropertyType( $property, false, $codeGenerationConfig ) ) #if( $property.getExtends().isPresent() )@Override #end #if( $util.isPropertyNotInPayload( $property, $codeGenerationConfig ) )@JsonIgnore #end -public $propertyType #methodName()() { +public $propertyType $methodName() { return this.$property.getPayloadName(); } #end