fix: Support multiple stereotypes on class diagrams (#6680)

- Modified JISON grammar to support consecutive annotations like <<interface>><<injected>>
- Updated addAnnotation method to create classes if they don't exist
- Added comprehensive tests for multiple annotation scenarios
- Maintains backward compatibility with existing single annotation syntax

Fixes #6680
This commit is contained in:
Justin Greywolf
2025-10-11 14:33:47 -07:00
parent d80a638e55
commit 274053ce7a
3 changed files with 29 additions and 1 deletions

View File

@@ -237,6 +237,7 @@ export class ClassDB implements DiagramDB {
* @public
*/
public addAnnotation(className: string, annotation: string) {
this.addClass(className);
const validatedClassName = this.splitClassNameAndType(className).className;
this.classes.get(validatedClassName)!.annotations.push(annotation);
}

View File

@@ -922,6 +922,28 @@ foo()
expect(actual.methods.length).toBe(1);
expect(actual.annotations[0]).toBe('interface');
});
it('should handle multiple consecutive annotations on a single class', function () {
const str = 'classDiagram\n' + '<<interface>><<injected>> Class1';
parser.parse(str);
const actual = parser.yy.getClass('Class1');
expect(actual.annotations.length).toBe(2);
expect(actual.annotations).toContain('interface');
expect(actual.annotations).toContain('injected');
});
it('should handle multiple separate annotations on a single class', function () {
const str = 'classDiagram\n' + '<<interface>> Class1\n' + '<<injected>> Class1';
parser.parse(str);
const actual = parser.yy.getClass('Class1');
expect(actual.annotations.length).toBe(2);
expect(actual.annotations).toContain('interface');
expect(actual.annotations).toContain('injected');
});
});
});

View File

@@ -310,7 +310,12 @@ emptyBody
;
annotationStatement
: ANNOTATION_START alphaNumToken ANNOTATION_END className { yy.addAnnotation($4,$2); }
: annotationList className { for(const annotation of $1) { yy.addAnnotation($2, annotation); } }
;
annotationList
: ANNOTATION_START alphaNumToken ANNOTATION_END { $$ = [$2]; }
| annotationList ANNOTATION_START alphaNumToken ANNOTATION_END { $1.push($3); $$ = $1; }
;
members