Skip to content

Commit 7be368b

Browse files
committed
Update logic
1 parent 88e81da commit 7be368b

File tree

5 files changed

+41
-64
lines changed

5 files changed

+41
-64
lines changed

core/esmf-aspect-meta-model-interface/src/main/java/org/eclipse/esmf/metamodel/HasDescription.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import java.util.List;
1818
import java.util.Locale;
1919
import java.util.Set;
20-
import java.util.stream.Collectors;
2120

2221
import org.eclipse.esmf.metamodel.datatype.LangString;
2322

@@ -79,11 +78,4 @@ default String getDescription( final Locale locale ) {
7978
return getDescription( Locale.ENGLISH );
8079
} );
8180
}
82-
83-
default Set<String> getDescriptions( final Locale locale ) {
84-
return getDescriptions().stream()
85-
.filter( description -> description.getLanguageTag().equals( locale ) )
86-
.map( LangString::getValue )
87-
.collect( Collectors.toSet() );
88-
}
8981
}

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/utils/DescriptionsUtils.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,42 +45,42 @@ private DescriptionsUtils() {
4545
/**
4646
* Extracts all {@code NOTE} blocks from the given set of Markdown description strings.
4747
*
48-
* @param descriptions A set of multi-line Markdown descriptions.
48+
* @param description A line Markdown description.
4949
* @return A list of extracted NOTE block contents.
5050
*/
51-
public static List<String> notes( final Set<String> descriptions ) {
52-
return extractBlock( descriptions, "NOTE" );
51+
public static List<String> notes( final String description ) {
52+
return extractBlock( description, "NOTE" );
5353
}
5454

5555
/**
5656
* Extracts all {@code EXAMPLE} blocks from the given set of Markdown description strings.
5757
*
58-
* @param descriptions A set of multi-line Markdown descriptions.
58+
* @param description A line Markdown description.
5959
* @return A list of extracted EXAMPLE block contents.
6060
*/
61-
public static List<String> examples( final Set<String> descriptions ) {
62-
return extractBlock( descriptions, "EXAMPLE" );
61+
public static List<String> examples( final String description ) {
62+
return extractBlock( description, "EXAMPLE" );
6363
}
6464

6565
/**
6666
* Extracts all {@code SOURCE} blocks from the given set of Markdown description strings.
6767
*
68-
* @param descriptions A set of multi-line Markdown descriptions.
68+
* @param description A line Markdown description.
6969
* @return A list of extracted SOURCE block contents.
7070
*/
71-
public static List<String> sources( final Set<String> descriptions ) {
72-
return extractBlock( descriptions, "SOURCE" );
71+
public static List<String> sources( final String description ) {
72+
return extractBlock( description, "SOURCE" );
7373
}
7474

7575
/**
7676
* Renders the given set of Markdown description strings into semantic HTML.
7777
* Uses {@link MarkdownHtmlRenderer} to process both special blocks and general Markdown syntax.
7878
*
79-
* @param descriptions A set of Markdown description strings.
79+
* @param description A line of Markdown description string.
8080
* @return The HTML representation of the combined input.
8181
*/
82-
public static String toHtml( final Set<String> descriptions ) {
83-
return MarkdownHtmlRenderer.renderHtmlFromDescriptions( descriptions );
82+
public static String toHtml( final String description ) {
83+
return MarkdownHtmlRenderer.renderHtmlFromDescriptions( description );
8484
}
8585

8686
/**
@@ -93,11 +93,9 @@ public static String toHtml( final Set<String> descriptions ) {
9393
* @param type The type of block to extract ("NOTE", "EXAMPLE", or "SOURCE").
9494
* @return A list of extracted block contents for the specified type.
9595
*/
96-
private static List<String> extractBlock( final Set<String> descriptions, final String type ) {
96+
private static List<String> extractBlock( final String descriptions, final String type ) {
9797
List<String> result = new ArrayList<>();
98-
for ( String desc : descriptions ) {
99-
extractFromDescription( desc, type, result );
100-
}
98+
extractFromDescription( descriptions, type, result );
10199
return result;
102100
}
103101

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/utils/MarkdownHtmlRenderer.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,11 @@ private MarkdownHtmlRenderer() {
6060
* Converts a set of multi-line Markdown descriptions into a single HTML string.
6161
* Each entry in the set is processed independently and merged in the resulting output.
6262
*
63-
* @param descriptions A set of Markdown description blocks to render.
63+
* @param description A line of Markdown description blocks to render.
6464
* @return Combined HTML output representing all given descriptions.
6565
*/
66-
public static String renderHtmlFromDescriptions( final Set<String> descriptions ) {
67-
StringBuilder result = new StringBuilder();
68-
for ( String desc : descriptions ) {
69-
result.append( processSpecialBlocks( desc ) ).append( "\n" );
70-
}
71-
return result.toString();
66+
public static String renderHtmlFromDescriptions( final String description ) {
67+
return processSpecialBlocks( description ) + "\n";
7268
}
7369

7470
/**

core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/utils/DescriptionsUtilsTest.java

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,24 @@
44
import static org.junit.jupiter.api.Assertions.assertTrue;
55

66
import java.util.List;
7-
import java.util.Set;
87

98
import org.junit.jupiter.api.Test;
109

1110
class DescriptionsUtilsTest {
1211
@Test
1312
void testExtractNotes_singleNote() {
14-
Set<String> descriptions = Set.of(
15-
"> NOTE: This is a note.\n> Continued on the next line."
16-
);
17-
List<String> notes = DescriptionsUtils.notes( descriptions );
13+
String description = "> NOTE: This is a note.\n> Continued on the next line.";
14+
List<String> notes = DescriptionsUtils.notes( description );
1815
assertEquals( 1, notes.size() );
1916
assertEquals( "This is a note.\nContinued on the next line.", notes.get( 0 ) );
2017
}
2118

2219
@Test
2320
void testExtractExamples_multipleExamples() {
24-
Set<String> descriptions = Set.of(
25-
"> EXAMPLE 1: First example.\n> More detail.",
26-
"> EXAMPLE 2: Second example."
27-
);
28-
List<String> examples = DescriptionsUtils.examples( descriptions );
21+
String description =
22+
"> EXAMPLE 1: First example.\n> More detail.\n" +
23+
"> EXAMPLE 2: Second example.";
24+
List<String> examples = DescriptionsUtils.examples( description );
2925

3026
assertEquals( 2, examples.size() );
3127
assertEquals( "First example.\nMore detail.", examples.get( 0 ) );
@@ -34,39 +30,34 @@ void testExtractExamples_multipleExamples() {
3430

3531
@Test
3632
void testExtractSources_withLink() {
37-
Set<String> descriptions = Set.of(
38-
"> SOURCE: Source with [link](https://example.com)"
39-
);
40-
List<String> sources = DescriptionsUtils.sources( descriptions );
33+
String description = "> SOURCE: Source with [link](https://example.com)";
34+
List<String> sources = DescriptionsUtils.sources( description );
4135
assertEquals( 1, sources.size() );
4236
assertTrue( sources.get( 0 ).contains( "[link](https://example.com)" ) );
4337
}
4438

4539
@Test
4640
void testMixedBlockTypes() {
47-
Set<String> descriptions = Set.of(
48-
"> NOTE: A note block.",
49-
"> EXAMPLE: An example block.",
50-
"> SOURCE: A source block."
51-
);
52-
assertEquals( 1, DescriptionsUtils.notes( descriptions ).size() );
53-
assertEquals( 1, DescriptionsUtils.examples( descriptions ).size() );
54-
assertEquals( 1, DescriptionsUtils.sources( descriptions ).size() );
41+
String description =
42+
"> NOTE: A note block.\n" +
43+
"> EXAMPLE: An example block.\n" +
44+
"> SOURCE: A source block.";
45+
assertEquals( 1, DescriptionsUtils.notes( description ).size() );
46+
assertEquals( 1, DescriptionsUtils.examples( description ).size() );
47+
assertEquals( 1, DescriptionsUtils.sources( description ).size() );
5548
}
5649

5750
@Test
5851
void testNoBlocks() {
59-
Set<String> descriptions = Set.of(
60-
"This is a plain description without any special blocks."
61-
);
62-
assertTrue( DescriptionsUtils.notes( descriptions ).isEmpty() );
63-
assertTrue( DescriptionsUtils.examples( descriptions ).isEmpty() );
64-
assertTrue( DescriptionsUtils.sources( descriptions ).isEmpty() );
52+
String description = "This is a plain description without any special blocks.";
53+
assertTrue( DescriptionsUtils.notes( description ).isEmpty() );
54+
assertTrue( DescriptionsUtils.examples( description ).isEmpty() );
55+
assertTrue( DescriptionsUtils.sources( description ).isEmpty() );
6556
}
6657

6758
@Test
68-
public void testToHtml_withAllBlockTypes() {
69-
Set<String> descriptions = Set.of(
59+
void testToHtml_withAllBlockTypes() {
60+
final String description =
7061
"""
7162
> NOTE: This is a note.
7263
> With multiple lines.
@@ -82,9 +73,9 @@ public void testToHtml_withAllBlockTypes() {
8273
1. Ordered
8374
2. List
8475
"""
85-
);
76+
;
8677

87-
String html = DescriptionsUtils.toHtml( descriptions );
78+
final String html = DescriptionsUtils.toHtml( description );
8879

8980
assertTrue( html.contains( "<div class=\"note\">" ) );
9081
assertTrue( html.contains( "This is a note." ) );

core/esmf-aspect-model-document-generators/src/main/resources/docu/templates/html/property-documentation-lib.vm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#paragraph( $property.getPreferredName( $i18n.getLocale() ) "${aspectModelHelper.buildAnchor( $property, $parentElement, 'property' )}" $weight )
1818

1919
#if( $property.getDescription( $i18n.getLocale() ) )
20-
#description( $descriptionsUtils.toHtml( $property.getDescriptions( $i18n.getLocale() ) ) )
20+
#description( $descriptionsUtils.toHtml( $property.getDescription( $i18n.getLocale() ) ) )
2121
#end
2222

2323
<div class="flex border-b pb-1 py-4">

0 commit comments

Comments
 (0)