Skip to content

Commit ac4d165

Browse files
committed
Update functionality
1 parent 2435be0 commit ac4d165

File tree

4 files changed

+21
-31
lines changed

4 files changed

+21
-31
lines changed

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/loader/MetaModelBaseAttributes.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,20 @@ public class MetaModelBaseAttributes implements HasDescription {
4141
private final boolean isAnonymous;
4242
private final AspectModelFile sourceFile;
4343

44-
private final ScalarValue exampleValue;
45-
4644
private MetaModelBaseAttributes(
4745
final AspectModelUrn urn,
4846
final Set<LangString> preferredNames,
4947
final Set<LangString> descriptions,
5048
final List<String> see,
5149
final boolean isAnonymous,
52-
final AspectModelFile sourceFile,
53-
final ScalarValue exampleValue
50+
final AspectModelFile sourceFile
5451
) {
5552
this.urn = urn;
5653
this.preferredNames = preferredNames;
5754
this.descriptions = descriptions;
5855
this.see = see;
5956
this.isAnonymous = isAnonymous;
6057
this.sourceFile = sourceFile;
61-
this.exampleValue = exampleValue;
6258
}
6359

6460
public AspectModelUrn urn() {
@@ -93,10 +89,6 @@ public AspectModelFile getSourceFile() {
9389
return sourceFile;
9490
}
9591

96-
public ScalarValue getExampleValue() {
97-
return exampleValue;
98-
}
99-
10092
public static Builder builder() {
10193
return new Builder();
10294
}
@@ -116,7 +108,7 @@ public boolean equals( final Object o ) {
116108

117109
@Override
118110
public int hashCode() {
119-
return Objects.hash( urn, preferredNames, descriptions, see, isAnonymous, exampleValue );
111+
return Objects.hash( urn, preferredNames, descriptions, see, isAnonymous );
120112
}
121113

122114
/**
@@ -127,8 +119,7 @@ public int hashCode() {
127119
*/
128120
public static MetaModelBaseAttributes fromModelElement( final ModelElement modelElement ) {
129121
return new MetaModelBaseAttributes( modelElement.urn(), modelElement.getPreferredNames(),
130-
modelElement.getDescriptions(), modelElement.getSee(), modelElement.isAnonymous(), modelElement.getSourceFile(),
131-
new DefaultScalarValue( "", new DefaultScalar( "http://www.w3.org/2001/XMLSchema#string" ) ) );
122+
modelElement.getDescriptions(), modelElement.getSee(), modelElement.isAnonymous(), modelElement.getSourceFile() );
132123
}
133124

134125
public static class Builder {
@@ -139,8 +130,6 @@ public static class Builder {
139130
private boolean isAnonymous = true;
140131
private AspectModelFile sourceFile;
141132

142-
private ScalarValue exampleValue;
143-
144133
public Builder withUrn( final String urn ) {
145134
return withUrn( AspectModelUrn.fromUrn( urn ) );
146135
}
@@ -204,13 +193,8 @@ public Builder isAnonymous( final boolean isAnonymous ) {
204193
return this;
205194
}
206195

207-
public Builder withExampleValue( final ScalarValue exampleValue ) {
208-
this.exampleValue = exampleValue;
209-
return this;
210-
}
211-
212196
public MetaModelBaseAttributes build() {
213-
return new MetaModelBaseAttributes( urn, preferredNames, descriptions, see, isAnonymous, sourceFile, exampleValue );
197+
return new MetaModelBaseAttributes( urn, preferredNames, descriptions, see, isAnonymous, sourceFile );
214198
}
215199
}
216200
}

core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/metamodel/StaticMetaModelVisitor.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,12 @@ private <T> String getOptionalStaticDeclarationValue( final Type type, final Opt
544544
return "Optional.of(" + valueInitializer.apply( xsdType, valueExpression ) + ")";
545545
}
546546

547+
public String exampleValue(final Property property, final StaticCodeGenerationContext context) {
548+
return property.getExampleValue()
549+
.map(exampleValue -> "Optional.of(" + this.visitScalarValue(exampleValue, context) + ")")
550+
.orElse("Optional.empty()");
551+
}
552+
547553
/*
548554
* This method is a crutch because velocity is not able to call the parameterized actual method
549555
*/
@@ -575,14 +581,6 @@ public String getMetaModelBaseAttributes( final ModelElement element, final Stat
575581
element.getSee().stream().sorted()
576582
.forEach( see -> builder.append( ".withSee(" ).append( AspectModelJavaUtil.createLiteral( see ) ).append( ")" ) );
577583

578-
if ( element instanceof final Property property ) {
579-
property.getExampleValue().ifPresent( exampleValue ->
580-
builder.append( ".withExampleValue(" )
581-
.append( this.visitScalarValue( property.getExampleValue().get(), context ) )
582-
.append( ")" )
583-
);
584-
}
585-
586584
builder.append( ".build()" );
587585
return builder.toString();
588586
}

core/esmf-aspect-model-java-generator/src/main/resources/java-static-class-property-lib.vm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
## $arg1, $arg2, ... ) {
132132
$modelVisitor.metaModelBaseAttributes( $property, $context ),
133133
#propertyCharacteristic( $property.getCharacteristic().get(), $propertyType ),
134-
Optional.empty(),
134+
$modelVisitor.exampleValue( $property, $context ),
135135
$property.isOptional(),
136136
$property.isNotInPayload(),
137137
Optional.of("$property.getPayloadName()"),

core/esmf-aspect-model-java-generator/src/test/java/org/eclipse/esmf/aspectmodel/java/StaticMetaModelJavaGeneratorTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,19 @@ void testCharacteristicInstantiationForPropertyWithExampleValue() throws IOExcep
514514
"withPreferredName(Locale.forLanguageTag(\"en\"), \"Test Property\")",
515515
"withDescription(Locale.forLanguageTag(\"en\"), \"This is a test property.\")",
516516
"withSee(\"http://example.com/\")",
517-
"withSee(\"http://example.com/me\")",
518-
"withExampleValue(new DefaultScalarValue(\"Example Value\", new DefaultScalar(\"http://www.w3.org/2001/XMLSchema#string\")))"
517+
"withSee(\"http://example.com/me\")"
519518
) );
520519

521520
result.assertMetaModelBaseAttributesForProperties( "MetaAspectWithCollection", expectedBaseAttributes );
521+
522+
final String expectedTestPropertyCharacteristicConstructorCall =
523+
"new DefaultCollection(MetaModelBaseAttributes.builder().withUrn(AspectModelUrn.fromUrn(NAMESPACE + \"TestCollection\"))"
524+
+ ".withPreferredName(Locale.forLanguageTag(\"en\"), \"Test Collection\").withDescription(Locale.forLanguageTag(\"en\")"
525+
+ ", \"This is a test collection.\").withSee(\"http://example.com/\").build(), Optional.of(new DefaultScalar"
526+
+ "(\"http://www.w3.org/2001/XMLSchema#string\")), Optional.empty())";
527+
528+
result.assertConstructorArgumentForProperties( "MetaAspectWithCollection",
529+
ImmutableMap.<String, String> builder().put( "TEST_PROPERTY", expectedTestPropertyCharacteristicConstructorCall ).build(), 1 );
522530
}
523531

524532
@Test

0 commit comments

Comments
 (0)