Skip to content

Commit

Permalink
Allows !extend to be used hierarchically.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Sep 18, 2024
1 parent 63cb000 commit bb68483
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ void parse(List<String> 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)) {
Expand Down
14 changes: 14 additions & 0 deletions structurizr-dsl/src/test/java/com/structurizr/dsl/DslTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}


}
31 changes: 31 additions & 0 deletions structurizr-dsl/src/test/resources/dsl/extend-hierarchical.dsl
Original file line number Diff line number Diff line change
@@ -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"
}
}
}

}

0 comments on commit bb68483

Please sign in to comment.