Skip to content

Commit 38bb45e

Browse files
committed
icon refinements for structural view, including startsWith logic
1 parent 3b70735 commit 38bb45e

File tree

3 files changed

+78
-71
lines changed

3 files changed

+78
-71
lines changed

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/commands/ApplicationModulesJsonNodeHandler.java

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.ide.vscode.boot.java.commands;
1818

19-
import java.util.Optional;
2019
import java.util.function.BiConsumer;
2120
import java.util.function.Consumer;
2221

@@ -56,34 +55,17 @@ public ApplicationModulesJsonNodeHandler(LabelProvider<ApplicationModules, Stere
5655

5756
@Override
5857
public void handleStereotype(Stereotype stereotype, NodeContext context) {
59-
60-
// icon for concrete stereotype
61-
String stereotypeID = stereotype.getIdentifier();
62-
63-
String icon = StereotypeIcons.ICONS.get(stereotypeID);
64-
65-
// group fallback
66-
if (icon == null) {
67-
Optional<String> groupIcon = stereotype.getGroups().stream()
68-
.filter(group -> StereotypeIcons.ICONS.containsKey(group))
69-
.map(group -> StereotypeIcons.ICONS.get(group))
70-
.findFirst();
71-
72-
icon = groupIcon.isPresent() ? icon = groupIcon.get() : StereotypeIcons.ICONS.get("Stereotype");
73-
}
74-
75-
String finalIcon = icon;
7658
addChild(node -> node
7759
.withAttribute(TEXT, labels.getSterotypeLabel(stereotype))
78-
.withAttribute(ICON, finalIcon)
60+
.withAttribute(ICON, StereotypeIcons.getIcon(stereotype))
7961
);
8062
}
8163

8264
@Override
8365
public void handleApplication(ApplicationModules application) {
8466
this.root
8567
.withAttribute(TEXT, labels.getApplicationLabel(application))
86-
.withAttribute(ICON, StereotypeIcons.ICONS.get("Application"))
68+
.withAttribute(ICON, StereotypeIcons.getIcon(StereotypeIcons.APPLICATION_KEY))
8769
;
8870
}
8971

@@ -92,7 +74,7 @@ public void handlePackage(StereotypePackageElement pkg, NodeContext context) {
9274

9375
addChild(node -> node
9476
.withAttribute(TEXT, labels.getPackageLabel(pkg))
95-
.withAttribute(ICON, StereotypeIcons.ICONS.get("Packages"))
77+
.withAttribute(ICON, StereotypeIcons.getIcon(StereotypeIcons.PACKAGES_KEY))
9678
);
9779
}
9880

@@ -101,7 +83,7 @@ public void handleType(StereotypeClassElement type, NodeContext context) {
10183
addChild(node -> node
10284
.withAttribute(TEXT, labels.getTypeLabel(type))
10385
.withAttribute(LOCATION, type.getLocation())
104-
.withAttribute(ICON, StereotypeIcons.ICONS.get("Type"))
86+
.withAttribute(ICON, StereotypeIcons.getIcon(StereotypeIcons.TYPE_KEY))
10587
);
10688
}
10789

@@ -110,7 +92,7 @@ public void handleMethod(StereotypeMethodElement method, MethodNodeContext<Stere
11092
addChildFoo(node -> node
11193
.withAttribute(TEXT, labels.getMethodLabel(method, context.getContextualType()))
11294
.withAttribute(LOCATION, method.getLocation())
113-
.withAttribute(ICON, StereotypeIcons.ICONS.get("Method"))
95+
.withAttribute(ICON, StereotypeIcons.getIcon(StereotypeIcons.METHOD_KEY))
11496
);
11597
}
11698

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/commands/StereotypeIcons.java

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,53 +11,53 @@
1111
package org.springframework.ide.vscode.boot.java.commands;
1212

1313
import java.util.Map;
14+
import java.util.Optional;
15+
import java.util.Set;
16+
17+
import org.jmolecules.stereotype.api.Stereotype;
1418

1519
public class StereotypeIcons {
1620

17-
public static final Map<String, String> ICONS = Map.ofEntries(
21+
public static final String APPLICATION_KEY = "Application";
22+
public static final String PACKAGES_KEY = "Packages";
23+
public static final String METHOD_KEY = "Method";
24+
public static final String TYPE_KEY = "Type";
25+
26+
private static final Map<String, String> ICONS = Map.ofEntries(
27+
1828
Map.entry("architecture.hexagonal", "debug-breakpoint-data-unverified"),
1929
Map.entry("architecture.hexagonal.Port", "symbol-interface"),
2030
Map.entry("architecture.hexagonal.Adapter", "debug-disconnect"),
2131
Map.entry("architecture.hexagonal.Application", "circuit-board"),
32+
2233
Map.entry("architecture.layered", "layers"),
34+
2335
Map.entry("architecture.onion", "target"),
2436
Map.entry("architecture.onion.Application", "circuit-board"),
2537
// Map.entry("architecture.onion.Domain", "?"), // TODO
2638
Map.entry("architecture.onion.Infrastructure", "debug-disconnect"),
39+
2740
Map.entry("ddd.AggregateRoot", "symbol-class"),
2841
Map.entry("ddd.Association", "link"),
2942
Map.entry("ddd.Entity", "symbol-field"),
3043
Map.entry("ddd.Identifier", "lightbulb"),
3144
Map.entry("ddd.Repository", "database"),
3245
// Map.entry("ddd.Service", "?"), // TODO
3346
Map.entry("ddd.ValueObject", "symbol-value"),
34-
Map.entry("event.DomainEvent", "bell"),
35-
Map.entry("event.DomainEventHandler", "callhierarchy-incoming"),
3647

37-
Map.entry("org.jmolecules.architecture.hexagonal", "debug-breakpoint-data-unverified"),
38-
Map.entry("org.jmolecules.architecture.hexagonal.Port", "symbol-interface"),
39-
Map.entry("org.jmolecules.architecture.hexagonal.Adapter", "debug-disconnect"),
40-
Map.entry("org.jmolecules.architecture.hexagonal.Application", "circuit-board"),
41-
Map.entry("org.jmolecules.architecture.layered", "layers"),
42-
Map.entry("org.jmolecules.architecture.onion", "target"),
43-
Map.entry("org.jmolecules.architecture.onion.Application", "circuit-board"),
44-
// Map.entry("org.jmolecules.architecture.onion.Domain", "?"), // TODO
45-
Map.entry("org.jmolecules.architecture.onion.Infrastructure", "debug-disconnect"),
46-
Map.entry("org.jmolecules.ddd.AggregateRoot", "symbol-class"),
47-
Map.entry("org.jmolecules.ddd.Association", "link"),
48-
Map.entry("org.jmolecules.ddd.Entity", "symbol-field"),
49-
Map.entry("org.jmolecules.ddd.Identifier", "lightbulb"),
50-
Map.entry("org.jmolecules.ddd.Repository", "database"),
51-
// Map.entry("org.jmolecules.ddd.Service", "?"), // TODO
52-
Map.entry("org.jmolecules.ddd.ValueObject", "symbol-value"),
53-
Map.entry("org.jmolecules.event.DomainEvent", "bell"),
54-
Map.entry("org.jmolecules.event.DomainEventHandler", "callhierarchy-incoming"),
48+
Map.entry("events.DomainEvent", "bell"),
49+
Map.entry("events.DomainEventHandler", "callhierarchy-incoming"),
5550

5651
Map.entry("jackson", "bracket"),
5752
Map.entry("java.Exception", "zap"),
53+
5854
Map.entry("jpa", "database"),
55+
5956
Map.entry("spring.Configuration", "gear"),
57+
Map.entry("spring.Validator", "verified"),
58+
Map.entry("spring.Formatter", "text-size"),
6059
Map.entry("spring.MessageListener", "callhierarchy-incoming"),
60+
Map.entry("spring.aot", "file-binary"),
6161
Map.entry("spring.boot", "coffee"),
6262
Map.entry("spring.boot.ConfigurationProperties", "symbol-property"),
6363
Map.entry("spring.data", "database"),
@@ -66,13 +66,56 @@ public class StereotypeIcons {
6666
Map.entry("spring.EventListener", "callhierarchy-incoming"),
6767
Map.entry("spring.web", "globe"),
6868
Map.entry("spring.web.rest.hypermedia", "link"),
69-
Map.entry("Application", "project"),
69+
70+
Map.entry(APPLICATION_KEY, "project"),
7071
Map.entry("Module", "library"),
71-
Map.entry("Packages", "package"),
72-
Map.entry("Method", "symbol-method"),
73-
Map.entry("Type", "symbol-class"),
72+
Map.entry(PACKAGES_KEY, "package"),
73+
Map.entry(METHOD_KEY, "symbol-method"),
74+
Map.entry(TYPE_KEY, "symbol-class"),
75+
7476
Map.entry("Stereotype", "record")
7577
);
78+
79+
private static final Map<String, String> ICONS_ENDS_WITH = Map.ofEntries(
80+
Map.entry("Port", "symbol-interface"),
81+
Map.entry("Repository", "database"),
82+
Map.entry("Adapter", "debug-disconnect")
83+
);
84+
85+
public static String getIcon(Stereotype stereotype) {
86+
String stereotypeID = stereotype.getIdentifier();
87+
88+
// exact icon
89+
String icon = StereotypeIcons.ICONS.get(stereotypeID);
90+
91+
// endsWith fallback
92+
if (icon == null) {
93+
Set<String> keySet = ICONS_ENDS_WITH.keySet();
94+
for (String key : keySet) {
95+
if (stereotypeID.endsWith(key)) {
96+
icon = ICONS_ENDS_WITH.get(key);
97+
}
98+
}
99+
}
100+
101+
// group fallback
102+
if (icon == null) {
103+
Optional<String> groupIcon = stereotype.getGroups().stream()
104+
.filter(group -> StereotypeIcons.ICONS.containsKey(group))
105+
.map(group -> StereotypeIcons.ICONS.get(group))
106+
.findFirst();
107+
108+
if (groupIcon.isPresent()) {
109+
icon = groupIcon.get();
110+
}
111+
}
112+
113+
return icon != null ? icon : StereotypeIcons.ICONS.get("Stereotype");
114+
}
115+
116+
public static String getIcon(String key) {
117+
return ICONS.get(key);
118+
}
76119

77120

78121
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/commands/ToolsJsonNodeHandler.java

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.springframework.ide.vscode.boot.java.commands;
1818

19-
import java.util.Optional;
2019
import java.util.function.BiConsumer;
2120
import java.util.function.Consumer;
2221

@@ -56,34 +55,17 @@ public ToolsJsonNodeHandler(LabelProvider<StereotypePackageElement, StereotypePa
5655

5756
@Override
5857
public void handleStereotype(Stereotype stereotype, NodeContext context) {
59-
60-
// icon for concrete stereotype
61-
String stereotypeID = stereotype.getIdentifier();
62-
63-
String icon = StereotypeIcons.ICONS.get(stereotypeID);
64-
65-
// group fallback
66-
if (icon == null) {
67-
Optional<String> groupIcon = stereotype.getGroups().stream()
68-
.filter(group -> StereotypeIcons.ICONS.containsKey(group))
69-
.map(group -> StereotypeIcons.ICONS.get(group))
70-
.findFirst();
71-
72-
icon = groupIcon.isPresent() ? icon = groupIcon.get() : StereotypeIcons.ICONS.get("Stereotype");
73-
}
74-
75-
String finalIcon = icon;
7658
addChild(node -> node
7759
.withAttribute(TEXT, labels.getSterotypeLabel(stereotype))
78-
.withAttribute(ICON, finalIcon)
60+
.withAttribute(ICON, StereotypeIcons.getIcon(stereotype))
7961
);
8062
}
8163

8264
@Override
8365
public void handleApplication(StereotypePackageElement application) {
8466
this.root
8567
.withAttribute(TEXT, labels.getApplicationLabel(application))
86-
.withAttribute(ICON, StereotypeIcons.ICONS.get("Application"))
68+
.withAttribute(ICON, StereotypeIcons.getIcon(StereotypeIcons.APPLICATION_KEY))
8769
;
8870
}
8971

@@ -92,7 +74,7 @@ public void handlePackage(StereotypePackageElement pkg, NodeContext context) {
9274

9375
addChild(node -> node
9476
.withAttribute(TEXT, labels.getPackageLabel(pkg))
95-
.withAttribute(ICON, StereotypeIcons.ICONS.get("Packages"))
77+
.withAttribute(ICON, StereotypeIcons.getIcon(StereotypeIcons.PACKAGES_KEY))
9678
);
9779
}
9880

@@ -101,7 +83,7 @@ public void handleType(StereotypeClassElement type, NodeContext context) {
10183
addChild(node -> node
10284
.withAttribute(TEXT, labels.getTypeLabel(type))
10385
.withAttribute(LOCATION, type.getLocation())
104-
.withAttribute(ICON, StereotypeIcons.ICONS.get("Type"))
86+
.withAttribute(ICON, StereotypeIcons.getIcon(StereotypeIcons.TYPE_KEY))
10587
);
10688
}
10789

@@ -110,7 +92,7 @@ public void handleMethod(StereotypeMethodElement method, MethodNodeContext<Stere
11092
addChildFoo(node -> node
11193
.withAttribute(TEXT, labels.getMethodLabel(method, context.getContextualType()))
11294
.withAttribute(LOCATION, method.getLocation())
113-
.withAttribute(ICON, StereotypeIcons.ICONS.get("Method"))
95+
.withAttribute(ICON, StereotypeIcons.getIcon(StereotypeIcons.METHOD_KEY))
11496
);
11597
}
11698

0 commit comments

Comments
 (0)