Skip to content

Commit 36f1804

Browse files
committed
Introduce common StringArtifact class and clean up
1 parent 71d2d2a commit 36f1804

File tree

10 files changed

+57
-50
lines changed

10 files changed

+57
-50
lines changed

core/esmf-aspect-model-document-generators/src/main/java/org/eclipse/esmf/aspectmodel/generator/docu/DocumentationArtifact.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,10 @@
1313

1414
package org.eclipse.esmf.aspectmodel.generator.docu;
1515

16-
import org.eclipse.esmf.aspectmodel.generator.Artifact;
17-
18-
public class DocumentationArtifact implements Artifact<String, String> {
19-
private final String id;
20-
private final String content;
16+
import org.eclipse.esmf.aspectmodel.generator.StringArtifact;
2117

18+
public class DocumentationArtifact extends StringArtifact {
2219
public DocumentationArtifact( final String id, final String content ) {
23-
this.id = id;
24-
this.content = content;
25-
}
26-
27-
@Override
28-
public String getId() {
29-
return "";
30-
}
31-
32-
@Override
33-
public String getContent() {
34-
return "";
20+
super( id, content );
3521
}
3622
}

core/esmf-aspect-model-document-generators/src/main/java/org/eclipse/esmf/aspectmodel/generator/sql/SqlArtifact.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,13 @@
1313

1414
package org.eclipse.esmf.aspectmodel.generator.sql;
1515

16-
import org.eclipse.esmf.aspectmodel.generator.Artifact;
16+
import org.eclipse.esmf.aspectmodel.generator.StringArtifact;
1717

1818
/**
1919
* Represents a generated SQL script.
2020
*/
21-
public class SqlArtifact implements Artifact<String, String> {
22-
private final String id;
23-
private final String content;
24-
21+
public class SqlArtifact extends StringArtifact {
2522
public SqlArtifact( final String id, final String content ) {
26-
this.id = id;
27-
this.content = content;
28-
}
29-
30-
@Override
31-
public String getId() {
32-
return id;
33-
}
34-
35-
@Override
36-
public String getContent() {
37-
return content;
23+
super( id, content );
3824
}
3925
}

core/esmf-aspect-model-document-generators/src/main/java/org/eclipse/esmf/aspectmodel/generator/zip/AspectModelNamespacePackageCreator.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@
1616
import org.eclipse.esmf.aspectmodel.serializer.AspectSerializer;
1717
import org.eclipse.esmf.metamodel.AspectModel;
1818

19+
/**
20+
* Generator for Namespace Packages as described in <a
21+
* href="https://github.com/eclipse-esmf/esmf-semantic-aspect-meta-model/blob/main/documentation/decisions/0009-namespace-packages.md">
22+
* ADR-0009</a>.
23+
*/
1924
public class AspectModelNamespacePackageCreator
2025
extends Generator<AspectModel, String, byte[], NamespacePackageGenerationConfig, NamespacePackageArtifact> {
2126
public static final NamespacePackageGenerationConfig DEFAULT_CONFIG = NamespacePackageGenerationConfigBuilder.builder().build();
27+
/**
28+
* @deprecated Use {@link #AspectModelNamespacePackageCreator(AspectModel, NamespacePackageGenerationConfig)} instead
29+
*/
2230
@Deprecated( forRemoval = true )
2331
public static final AspectModelNamespacePackageCreator INSTANCE = new AspectModelNamespacePackageCreator( null );
2432
private static final String BASE_ARCHIVE_FORMAT_PATH = "aspect-models/";

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@
2424
*
2525
* @param <I> the type that uniquely identifies the artifact in the scope of the generation process
2626
* @param <T> the artifact's content type, e.g. String or byte[]
27-
* @param <C> the config object for the genererator
27+
* @param <C> the config object for the generator
2828
* @param <A> the type of the artifact that is generated
2929
*/
3030
public abstract class AspectGenerator<I, T, C extends GenerationConfig, A extends Artifact<I, T>>
3131
extends Generator<Aspect, I, T, C, A> {
32-
3332
protected AspectGenerator( final Aspect aspect, final C config ) {
3433
super( aspect, config );
3534
}
@@ -46,7 +45,7 @@ protected <E extends ModelElement> Stream<E> elements( final Class<E> clazz ) {
4645
.distinct();
4746
}
4847

49-
protected <E extends ModelElement> Stream<A> applyTemplate(
48+
protected <E extends ModelElement> Stream<A> applyArtifactGenerator(
5049
final Class<E> clazz, final ArtifactGenerator<I, T, E, C, A> artifactGenerator, final C config ) {
5150
return elements( clazz ).map( element -> artifactGenerator.apply( element, config ) );
5251
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
package org.eclipse.esmf.aspectmodel.generator;
66

7+
/**
8+
* Abstract base class for {@link Artifact}s that have content represented as byte[]
9+
*/
710
public abstract class BinaryArtifact implements Artifact<String, byte[]> {
811
private final String id;
912
private final byte[] content;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @param <F> the focus type, e.g. Aspect or AspectModel
2323
* @param <I> the type that uniquely identifies the artifact in the scope of the generation process
2424
* @param <T> the artifact's content type, e.g. String or byte[]
25-
* @param <C> the config object for the genererator
25+
* @param <C> the config object for the generator
2626
* @param <A> the type of the artifact that is generated
2727
*/
2828
public abstract class Generator<F, I, T, C extends GenerationConfig, A extends Artifact<I, T>> {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2024 Bosch Software Innovations GmbH. All rights reserved.
3+
*/
4+
5+
package org.eclipse.esmf.aspectmodel.generator;
6+
7+
public abstract class StringArtifact implements Artifact<String, String> {
8+
protected final String id;
9+
protected final String content;
10+
11+
public StringArtifact( final String id, final String content ) {
12+
this.id = id;
13+
this.content = content;
14+
}
15+
16+
@Override
17+
public String getId() {
18+
return id;
19+
}
20+
21+
@Override
22+
public String getContent() {
23+
return content;
24+
}
25+
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static String getPropertyType( final Property property, final JavaCodeGen
114114
*/
115115
public static boolean hasContainerType( final Property property ) {
116116
return property.isOptional()
117-
|| (property.getEffectiveCharacteristic().map( characteristic -> characteristic.is( Collection.class ) ).orElse( false ));
117+
|| ( property.getEffectiveCharacteristic().map( characteristic -> characteristic.is( Collection.class ) ).orElse( false ) );
118118
}
119119

120120
/**
@@ -313,8 +313,8 @@ public static String getDataType( final Optional<Type> dataType, final ImportTra
313313
return dataType.map( type -> {
314314
final Type actualDataType = dataType.get();
315315
if ( actualDataType instanceof ComplexType ) {
316-
final String complexDataType = ((ComplexType) actualDataType).getName();
317-
if ( (!codeGenerationConfig.namePrefix().isBlank() || !codeGenerationConfig.namePostfix().isBlank()) ) {
316+
final String complexDataType = ( (ComplexType) actualDataType ).getName();
317+
if ( ( !codeGenerationConfig.namePrefix().isBlank() || !codeGenerationConfig.namePostfix().isBlank() ) ) {
318318
return codeGenerationConfig.namePrefix() + complexDataType + codeGenerationConfig.namePostfix();
319319
}
320320
return complexDataType;
@@ -338,7 +338,7 @@ public static String getDataType( final Optional<Type> dataType, final ImportTra
338338

339339
public static Class<?> getDataTypeClass( final Type dataType ) {
340340
if ( dataType instanceof ComplexType ) {
341-
return ((ComplexType) dataType).getClass();
341+
return ( (ComplexType) dataType ).getClass();
342342
}
343343

344344
final Resource typeResource = ResourceFactory.createResource( dataType.getUrn() );
@@ -515,7 +515,7 @@ public static String printStructuredValueElement( final Object object ) {
515515
if ( object instanceof String ) {
516516
return createLiteral( object.toString() );
517517
}
518-
return toConstant( ((Property) object).getName() );
518+
return toConstant( ( (Property) object ).getName() );
519519
}
520520

521521
public static boolean isXmlDatatypeFactoryRequired( final StructureElement element ) {
@@ -570,7 +570,7 @@ public static String genericClassSignature( final StructureElement element ) {
570570
}
571571

572572
public static String generateClassName( final StructureElement element, final JavaCodeGenerationConfig config ) {
573-
if ( (!config.namePrefix().isBlank() || !config.namePostfix().isBlank()) && element.is( StructureElement.class ) ) {
573+
if ( ( !config.namePrefix().isBlank() || !config.namePostfix().isBlank() ) && element.is( StructureElement.class ) ) {
574574
return config.namePrefix() + element.getName() + config.namePostfix();
575575
}
576576
return element.getName();
@@ -666,6 +666,6 @@ public static String getterName( final Property property ) {
666666
.filter( Type::isScalar )
667667
.map( type -> XSD.xboolean.getURI().equals( type.getUrn() ) )
668668
.orElse( false );
669-
return (isBooleanType ? "is" : "get") + StringUtils.capitalize( property.getPayloadName() );
669+
return ( isBooleanType ? "is" : "get" ) + StringUtils.capitalize( property.getPayloadName() );
670670
}
671671
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public StaticMetaModelJavaGenerator( final Aspect aspect, final JavaCodeGenerati
3333
@Override
3434
public Stream<Artifact<QualifiedName, String>> generate() {
3535
final StaticMetaModelJavaArtifactGenerator<StructureElement> template = new StaticMetaModelJavaArtifactGenerator<>();
36-
return applyTemplate( StructureElement.class, template, config )
36+
return applyArtifactGenerator( StructureElement.class, template, config )
3737
.collect( Collectors.toSet() )
3838
.stream();
3939
}

core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/pojo/AspectModelJavaGenerator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public Stream<Artifact<QualifiedName, String>> generate() {
3939
final Set<ComplexType> structureElements = elements( ComplexType.class ).filter( element ->
4040
element.getExtends().isPresent() ).collect( Collectors.toSet() );
4141
return Stream.of(
42-
applyTemplate( Aspect.class, new StructureElementJavaArtifactGenerator<>(), config ),
43-
applyTemplate( ComplexType.class, new StructureElementJavaArtifactGenerator<>( structureElements ), config ),
44-
applyTemplate( Event.class, new StructureElementJavaArtifactGenerator<>(), config ),
45-
applyTemplate( Enumeration.class, new EnumerationJavaArtifactGenerator<>(), config ) )
42+
applyArtifactGenerator( Aspect.class, new StructureElementJavaArtifactGenerator<>(), config ),
43+
applyArtifactGenerator( ComplexType.class, new StructureElementJavaArtifactGenerator<>( structureElements ), config ),
44+
applyArtifactGenerator( Event.class, new StructureElementJavaArtifactGenerator<>(), config ),
45+
applyArtifactGenerator( Enumeration.class, new EnumerationJavaArtifactGenerator<>(), config ) )
4646
.flatMap( Function.identity() )
4747
.collect( Collectors.toSet() )
4848
.stream();

0 commit comments

Comments
 (0)