Skip to content

Commit

Permalink
Fixed getter name generator according to JavaBeans specification
Browse files Browse the repository at this point in the history
Fixes #375
  • Loading branch information
ysrbo committed Nov 2, 2023
1 parent 6f5177a commit 0f429cc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions core/esmf-aspect-model-java-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
<artifactId>record-builder-processor</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0f429cc

Please sign in to comment.