Skip to content

Commit 4599bb9

Browse files
authored
Merge pull request #185 from bci-oss/bug/#182-java-code-generation
Fixes bug in java code generation in case an entity has no property
2 parents a75cf2f + 8580dd5 commit 4599bb9

File tree

4 files changed

+73
-6
lines changed

4 files changed

+73
-6
lines changed

core/sds-aspect-model-java-generator/src/main/java/io/openmanufacturing/sds/aspectmodel/java/AspectModelJavaUtil.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,15 @@ public static String objectEqualsExpression( final StructureElement element ) {
535535
.collect( Collectors.joining( " && " ) );
536536
}
537537

538-
public static String objectsHashCodeExpression( final StructureElement element ) {
539-
return element.getProperties().stream()
538+
public static String objectsHashCodeExpression( final StructureElement element, final boolean needsLeadingComma ) {
539+
final String elementString = element.getProperties().stream()
540540
.filter( property -> !property.isAbstract() )
541541
.map( Property::getPayloadName )
542542
.collect( Collectors.joining( ", " ) );
543+
if ( StringUtils.isNotBlank( elementString ) && needsLeadingComma ) {
544+
return ", " + elementString;
545+
}
546+
return elementString;
543547
}
544548

545549
/**
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
#macro( javaPojoHashCodeMethod )
22
@Override
33
public int hashCode() {
4-
return Objects.hash(
4+
return Objects.hash(
55
#if ( $element.is( $ComplexType ) )
66
#set( $complexElement = $ComplexType.cast( $element ) )
77
#if ( $complexElement.getExtends().isPresent() )
8-
super.hashCode(),
8+
super.hashCode()
9+
${util.objectsHashCodeExpression( $element, true )}
10+
#else
11+
${util.objectsHashCodeExpression( $element, false )}
912
#end
13+
#else
14+
${util.objectsHashCodeExpression( $element, false )}
1015
#end
11-
${util.objectsHashCodeExpression( $element )}
12-
);
16+
);
1317
}
1418
#end

core/sds-test-aspect-models/src/main/java/io/openmanufacturing/sds/test/TestAspect.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public enum TestAspect implements TestModel {
7070
ASPECT_WITH_ENGLISH_AND_GERMAN_DESCRIPTION,
7171
ASPECT_WITH_ENGLISH_DESCRIPTION,
7272
ASPECT_WITH_ENTITY,
73+
ASPECT_WITH_ENTITY_WITHOUT_PROPERTY,
7374
ASPECT_WITH_ENTITY_COLLECTION,
7475
ASPECT_WITH_ENTITY_ENUMERATION,
7576
ASPECT_WITH_ENTITY_ENUMERATION_AND_LANG_STRING,
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright (c) 2021 Robert Bosch Manufacturing Solutions GmbH
2+
#
3+
# See the AUTHORS file(s) distributed with this work for additional
4+
# information regarding authorship.
5+
#
6+
# This Source Code Form is subject to the terms of the Mozilla Public
7+
# License, v. 2.0. If a copy of the MPL was not distributed with this
8+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
9+
#
10+
# SPDX-License-Identifier: MPL-2.0
11+
12+
@prefix : <urn:bamm:io.openmanufacturing.test:1.0.0#> .
13+
@prefix bamm: <urn:bamm:io.openmanufacturing:meta-model:2.0.0#> .
14+
@prefix bamm-c: <urn:bamm:io.openmanufacturing:characteristic:2.0.0#> .
15+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
16+
@prefix unit: <urn:bamm:io.openmanufacturing:unit:2.0.0#> .
17+
18+
:AspectWithEntity
19+
a bamm:Aspect ;
20+
bamm:preferredName "Test Aspect"@en ;
21+
bamm:description "This is a test description"@en ;
22+
bamm:see <http://example.com/omp> ;
23+
bamm:properties ( :testProperty ) ;
24+
bamm:operations ( ) .
25+
26+
:testProperty
27+
a bamm:Property ;
28+
bamm:preferredName "Test Property"@en ;
29+
bamm:description "This is a test property."@en ;
30+
bamm:see <http://example.com/omp> ;
31+
bamm:see <http://example.com/me> ;
32+
bamm:characteristic :EntityCharacteristic .
33+
34+
:EntityCharacteristic
35+
a bamm-c:SingleEntity ;
36+
bamm:preferredName "Test Entity Characteristic"@en ;
37+
bamm:description "This is a test Entity Characteristic"@en ;
38+
bamm:see <http://example.com/omp> ;
39+
bamm:dataType :TestEntity .
40+
41+
:TestEntity
42+
a bamm:Entity ;
43+
bamm:extends :AbstractEntity ;
44+
bamm:preferredName "Test Entity"@en ;
45+
bamm:description "This is a test entity"@en ;
46+
bamm:properties ( ) .
47+
48+
:AbstractEntity
49+
a bamm:AbstractEntity ;
50+
bamm:preferredName "Abstract test Entity"@en ;
51+
bamm:description "This is an abstract test entity"@en ;
52+
bamm:properties ( :entityProperty ) .
53+
54+
:entityProperty
55+
a bamm:Property ;
56+
bamm:preferredName "Entity Property"@en ;
57+
bamm:description "This is a property for the test entity."@en ;
58+
bamm:characteristic bamm-c:Text .

0 commit comments

Comments
 (0)