From bb68483118e7704d6ac15c28cb3dfcbc162b06f3 Mon Sep 17 00:00:00 2001 From: Simon Brown Date: Wed, 18 Sep 2024 15:09:06 +0100 Subject: [PATCH] Allows !extend to be used hierarchically. --- .../structurizr/dsl/StructurizrDslParser.java | 2 +- .../java/com/structurizr/dsl/DslTests.java | 14 +++++++++ .../resources/dsl/extend-hierarchical.dsl | 31 +++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 structurizr-dsl/src/test/resources/dsl/extend-hierarchical.dsl diff --git a/structurizr-dsl/src/main/java/com/structurizr/dsl/StructurizrDslParser.java b/structurizr-dsl/src/main/java/com/structurizr/dsl/StructurizrDslParser.java index 6b7e307d..d5fa307c 100644 --- a/structurizr-dsl/src/main/java/com/structurizr/dsl/StructurizrDslParser.java +++ b/structurizr-dsl/src/main/java/com/structurizr/dsl/StructurizrDslParser.java @@ -326,7 +326,7 @@ void parse(List lines, File dslFile, boolean fragment, boolean includeIn startContext(new RelationshipsDslContext(getContext(), relationships)); } - } else if ((REF_TOKEN.equalsIgnoreCase(firstToken) || EXTEND_TOKEN.equalsIgnoreCase(firstToken)) && (inContext(ModelDslContext.class))) { + } else if ((REF_TOKEN.equalsIgnoreCase(firstToken) || EXTEND_TOKEN.equalsIgnoreCase(firstToken)) && (inContext(ModelItemDslContext.class) || inContext(ModelDslContext.class))) { ModelItem modelItem = new RefParser().parse(getContext(), tokens.withoutContextStartToken()); if (shouldStartContext(tokens)) { diff --git a/structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java b/structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java index e5f22175..0c72b1d7 100644 --- a/structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java +++ b/structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java @@ -1285,4 +1285,18 @@ void test_ImageView_WhenParserIsInRestrictedMode() { } } + @Test + void test_extendHierachical() throws Exception { + File dslFile = new File("src/test/resources/dsl/extend-hierarchical.dsl"); + + StructurizrDslParser parser = new StructurizrDslParser(); + parser.parse(dslFile); + + Component component = parser.getWorkspace().getModel().getSoftwareSystemWithName("A").getContainerWithName("B").getComponentWithName("C"); + assertEquals("Value1", component.getProperties().get("Name1")); + assertEquals("Value2", component.getProperties().get("Name2")); + assertEquals("Value3", component.getProperties().get("Name3")); + } + + } \ No newline at end of file diff --git a/structurizr-dsl/src/test/resources/dsl/extend-hierarchical.dsl b/structurizr-dsl/src/test/resources/dsl/extend-hierarchical.dsl new file mode 100644 index 00000000..c6ed6455 --- /dev/null +++ b/structurizr-dsl/src/test/resources/dsl/extend-hierarchical.dsl @@ -0,0 +1,31 @@ +workspace { + + !identifiers hierarchical + + model { + a = softwareSystem "A" { + b = container "B" { + c = component "C" + + !extend c { + properties { + "Name1" "Value1" + } + } + } + + !extend b.c { + properties { + "Name2" "Value2" + } + } + } + + !extend a.b.c { + properties { + "Name3" "Value3" + } + } + } + +} \ No newline at end of file