Skip to content

Commit aa6c734

Browse files
Adds support for a jump property on relationship styles.
1 parent 324bb7f commit aa6c734

File tree

7 files changed

+107
-1
lines changed

7 files changed

+107
-1
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- structurizr-dsl: Relationships to/from software system/container instances can be now defined by using the software system/container identifier.
1313
- structurizr-dsl: Fixes https://github.com/structurizr/java/issues/435 (Relationship archetype not applied to implicit-source relationships).
1414
- structurizr-dsl: Adds support for removing relationships between software system instance/container instances, with a view to redefining them via infrastructure nodes.
15+
- structurizr-dsl: Adds support for a `jump` property on relationship styles.
1516

1617
## v4.1.0 (28th May 2025)
1718

structurizr-core/src/main/java/com/structurizr/view/RelationshipStyle.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public final class RelationshipStyle extends AbstractStyle {
3939
@JsonInclude(value = JsonInclude.Include.NON_NULL)
4040
private Routing routing;
4141

42+
/** whether the line should jump over others */
43+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
44+
private Boolean jump;
45+
4246
/** the position of the annotation along the line; 0 (start) to 100 (end) */
4347
@JsonInclude(value = JsonInclude.Include.NON_NULL)
4448
private Integer position;
@@ -142,6 +146,19 @@ public RelationshipStyle routing(Routing routing) {
142146
return this;
143147
}
144148

149+
public Boolean getJump() {
150+
return jump;
151+
}
152+
153+
public void setJump(Boolean jump) {
154+
this.jump = jump;
155+
}
156+
157+
public RelationshipStyle jump(boolean jump) {
158+
setJump(jump);
159+
return this;
160+
}
161+
145162
public Integer getFontSize() {
146163
return fontSize;
147164
}

structurizr-core/src/main/java/com/structurizr/view/RelationshipView.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public final class RelationshipView implements PropertyHolder, Comparable<Relati
2929
@JsonInclude(value = JsonInclude.Include.NON_NULL)
3030
private Routing routing;
3131

32+
@JsonInclude(value = JsonInclude.Include.NON_NULL)
33+
private Boolean jump;
34+
3235
@JsonInclude(value = JsonInclude.Include.NON_NULL)
3336
private Integer position;
3437

@@ -222,6 +225,24 @@ public void setRouting(Routing routing) {
222225
this.routing = routing;
223226
}
224227

228+
/**
229+
* Gets whether this relationship should "jump" when crossing others.
230+
*
231+
* @return true if jumping is enabled, false otherwise
232+
*/
233+
public Boolean getJump() {
234+
return jump;
235+
}
236+
237+
/**
238+
* Sets whether this relationship should "jump" when crossing others.
239+
*
240+
* @param jump true if enabled, false otherwise
241+
*/
242+
public void setJump(Boolean jump) {
243+
this.jump = jump;
244+
}
245+
225246
/**
226247
* Gets the position of the annotation along the line.
227248
*
@@ -253,6 +274,7 @@ void copyLayoutInformationFrom(RelationshipView source) {
253274
setVertices(source.getVertices());
254275
setPosition(source.getPosition());
255276
setRouting(source.getRouting());
277+
setJump(source.getJump());
256278
}
257279
}
258280

structurizr-dsl/src/main/java/com/structurizr/dsl/RelationshipStyleParser.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,27 @@ void parseRouting(RelationshipStyleDslContext context, Tokens tokens) {
234234
}
235235
}
236236

237+
void parseJump(RelationshipStyleDslContext context, Tokens tokens) {
238+
// jump <true|false>
239+
RelationshipStyle style = context.getStyle();
240+
241+
if (tokens.hasMoreThan(FIRST_PROPERTY_INDEX)) {
242+
throw new RuntimeException("Too many tokens, expected: jump <true|false>");
243+
}
244+
245+
if (tokens.includes(FIRST_PROPERTY_INDEX)) {
246+
String jump = tokens.get(1);
247+
248+
if ("true".equalsIgnoreCase(jump)) {
249+
style.setJump(true);
250+
} else if ("false".equalsIgnoreCase(jump)) {
251+
style.setJump(false);
252+
} else {
253+
throw new RuntimeException("Jump must be true or false");
254+
}
255+
} else {
256+
throw new RuntimeException("Expected: jump <true|false>");
257+
}
258+
}
259+
237260
}

structurizr-dsl/src/main/java/com/structurizr/dsl/StructurizrDslParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,9 @@ void parse(List<String> lines, File dslFile, boolean fragment, boolean includeIn
901901
} else if (RELATIONSHIP_STYLE_ROUTING_TOKEN.equalsIgnoreCase(firstToken) && inContext(RelationshipStyleDslContext.class)) {
902902
new RelationshipStyleParser().parseRouting(getContext(RelationshipStyleDslContext.class), tokens);
903903

904+
} else if (RELATIONSHIP_STYLE_JUMP_TOKEN.equalsIgnoreCase(firstToken) && inContext(RelationshipStyleDslContext.class)) {
905+
new RelationshipStyleParser().parseJump(getContext(RelationshipStyleDslContext.class), tokens);
906+
904907
} else if (DEPLOYMENT_ENVIRONMENT_TOKEN.equalsIgnoreCase(firstToken) && inContext(ModelDslContext.class)) {
905908
String environment = new DeploymentEnvironmentParser().parse(tokens.withoutContextStartToken());
906909

structurizr-dsl/src/main/java/com/structurizr/dsl/StructurizrDslTokens.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class StructurizrDslTokens {
9090
static final String RELATIONSHIP_STYLE_DASHED_TOKEN = "dashed";
9191
static final String RELATIONSHIP_STYLE_OPACITY_TOKEN = "opacity";
9292
static final String RELATIONSHIP_STYLE_ROUTING_TOKEN = "routing";
93+
static final String RELATIONSHIP_STYLE_JUMP_TOKEN = "jump";
9394
static final String RELATIONSHIP_STYLE_LINE_STYLE_TOKEN = "style";
9495
static final String RELATIONSHIP_STYLE_FONT_SIZE_TOKEN = "fontSize";
9596
static final String RELATIONSHIP_STYLE_WIDTH_TOKEN = "width";

structurizr-dsl/src/test/java/com/structurizr/dsl/RelationshipStyleParserTests.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.structurizr.dsl;
22

3-
import com.structurizr.view.Border;
43
import com.structurizr.view.LineStyle;
54
import com.structurizr.view.RelationshipStyle;
65
import com.structurizr.view.Routing;
@@ -396,4 +395,44 @@ void test_parseRouting_SetsTheRouting() {
396395
assertEquals(Routing.Curved, relationshipStyle.getRouting());
397396
}
398397

398+
@Test
399+
void test_parseJump_ThrowsAnException_WhenThereAreTooManyTokens() {
400+
try {
401+
parser.parseJump(relationshipStyleDslContext(), tokens("jump", "boolean", "extra"));
402+
fail();
403+
} catch (Exception e) {
404+
assertEquals("Too many tokens, expected: jump <true|false>", e.getMessage());
405+
}
406+
}
407+
408+
@Test
409+
void test_parseJump_ThrowsAnException_WhenTheValueIsMissing() {
410+
try {
411+
parser.parseJump(relationshipStyleDslContext(), tokens("jump"));
412+
fail();
413+
} catch (Exception e) {
414+
assertEquals("Expected: jump <true|false>", e.getMessage());
415+
}
416+
}
417+
418+
@Test
419+
void test_parseJump_ThrowsAnException_WhenTheValueIsNotValid() {
420+
try {
421+
parser.parseJump(relationshipStyleDslContext(), tokens("jump", "abc"));
422+
fail();
423+
} catch (Exception e) {
424+
assertEquals("Jump must be true or false", e.getMessage());
425+
}
426+
}
427+
428+
@Test
429+
void test_parseJump_SetsTheJump() {
430+
RelationshipStyleDslContext context = relationshipStyleDslContext();
431+
parser.parseJump(context, tokens("jump", "false"));
432+
assertEquals(false, relationshipStyle.getJump());
433+
434+
parser.parseJump(context, tokens("jump", "true"));
435+
assertEquals(true, relationshipStyle.getJump());
436+
}
437+
399438
}

0 commit comments

Comments
 (0)