Skip to content

Commit 0baf453

Browse files
committed
GH-1628: show all groups by default, organized in the three categories
1 parent b6b9ae6 commit 0baf453

File tree

4 files changed

+57
-9
lines changed

4 files changed

+57
-9
lines changed

headless-services/spring-boot-language-server/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@
167167
<dependency>
168168
<groupId>org.jmolecules.integrations</groupId>
169169
<artifactId>jmolecules-stereotype</artifactId>
170-
<version>0.29.0-STEREOTYPE-SNAPSHOT</version>
170+
<version>0.30.0-STEREOTYPE-SNAPSHOT</version>
171171
</dependency>
172172

173173
<dependency>
174174
<groupId>org.jmolecules.integrations</groupId>
175175
<artifactId>jmolecules-spring</artifactId>
176-
<version>0.29.0-STEREOTYPE-SNAPSHOT</version>
176+
<version>0.30.0-STEREOTYPE-SNAPSHOT</version>
177177
</dependency>
178178

179179

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

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010
*******************************************************************************/
1111
package org.springframework.ide.vscode.boot.java.commands;
1212

13+
import java.util.ArrayList;
1314
import java.util.List;
1415
import java.util.Objects;
1516
import java.util.Optional;
1617
import java.util.function.BiConsumer;
1718
import java.util.stream.Collectors;
1819

20+
import org.jmolecules.stereotype.catalog.StereotypeGroup;
21+
import org.jmolecules.stereotype.catalog.StereotypeGroups;
22+
import org.jmolecules.stereotype.catalog.support.AbstractStereotypeCatalog;
1923
import org.jmolecules.stereotype.tooling.HierarchicalNodeHandler;
2024
import org.jmolecules.stereotype.tooling.LabelUtils;
2125
import org.jmolecules.stereotype.tooling.ProjectTree;
@@ -36,6 +40,7 @@
3640
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
3741
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
3842

43+
import com.google.common.collect.Streams;
3944
import com.google.gson.JsonPrimitive;
4045

4146
public class SpringIndexCommands {
@@ -90,19 +95,62 @@ private Node nodeFrom(StereotypeCatalogRegistry stereotypeCatalogRegistry, Sprin
9095
node.withAttribute(HierarchicalNodeHandler.TEXT, labelProvider.getCustomLabel(c))
9196
.withAttribute(ToolsJsonNodeHandler.ICON, "fa-named-interface");
9297
};
93-
94-
var jsonHandler = new ToolsJsonNodeHandler(labelProvider, consumer);
9598

99+
// create json nodes to display the structure in a nice way
100+
var jsonHandler = new ToolsJsonNodeHandler(labelProvider, consumer);
101+
102+
// create the project tree and apply all the groupers from the project
103+
// TODO: in the future, we need to trim this grouper arrays down to what is selected on the UI
96104
var jsonTree = new ProjectTree<>(factory, catalog, jsonHandler)
97-
.withStructureProvider(structureProvider)
98-
.withGrouper("org.jmolecules.architecture")
99-
.withGrouper("org.jmolecules.ddd", "org.jmolecules.event", "spring", "jpa", "java");
105+
.withStructureProvider(structureProvider);
106+
107+
List<String[]> groupers = identifyGroupers(catalog);
108+
for (String[] grouper : groupers) {
109+
jsonTree = jsonTree.withGrouper(grouper);
110+
}
100111

101112
jsonTree.process(mainApplicationPackage);
102113

103114
return jsonHandler.getRoot();
104115
}
105116

117+
private List<String[]> identifyGroupers(AbstractStereotypeCatalog catalog) {
118+
119+
// List<String[]> allGroupsWithSpecificOrder = Arrays.asList(
120+
// new String[] {"architecture"},
121+
// new String[] {"ddd", "event", "spring", "jpa", "java"}
122+
// );
123+
//
124+
// return allGroupsWithSpecificOrder;
125+
126+
127+
// var yourList = List.of("foo");
128+
129+
StereotypeGroups groups = catalog.getGroups();
130+
131+
var architectureIds = groups.streamByType(StereotypeGroup.Type.ARCHITECTURE)
132+
.map(StereotypeGroup::getIdentifier)
133+
// .filter(yourList::contains)
134+
.toList();
135+
136+
var designIds = groups.streamByType(StereotypeGroup.Type.DESIGN)
137+
.map(StereotypeGroup::getIdentifier);
138+
// .filter(yourList::contains)
139+
140+
var customIds = new ArrayList<String>().stream();
141+
142+
var technologyIds = groups.streamByType(StereotypeGroup.Type.TECHNOLOGY)
143+
.map(StereotypeGroup::getIdentifier);
144+
// .filter(yourList::contains)
145+
146+
ArrayList<String[]> result = new ArrayList<String[]>();
147+
result.add(architectureIds.toArray(String[]::new));
148+
result.add(Streams.concat(designIds, customIds, technologyIds)
149+
.toArray(String[]::new));
150+
151+
return result;
152+
}
153+
106154
private String getPackageLabel(StereotypePackageElement p) {
107155
String packageName = p.getPackageName();
108156
if (p.isMainPackage() && (packageName == null || packageName.isEmpty())) {

headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/stereotypes/StereotypesIndexerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ void testFromClassIndexBasedFactory() {
247247
List<Stereotype> myControllerStereotypes = factory.fromType(myControllerClassElement).stream().toList();
248248
assertEquals(2, myControllerStereotypes.size());
249249

250-
assertEquals("spring.Controller", myControllerStereotypes.get(0).getIdentifier());
250+
assertEquals("spring.web.Controller", myControllerStereotypes.get(0).getIdentifier());
251251
assertEquals("architecture.hexagonal.Port", myControllerStereotypes.get(1).getIdentifier());
252252

253253

headless-services/spring-boot-language-server/src/test/resources/test-projects/test-stereotypes-support/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<java.version>17</java.version>
2222

2323
<jmolecules.version>2.0.0-STEREOTYPE-SNAPSHOT</jmolecules.version>
24-
<jmolecules.integrations.version>0.29.0-STEREOTYPE-SNAPSHOT</jmolecules.integrations.version>
24+
<jmolecules.integrations.version>0.30.0-STEREOTYPE-SNAPSHOT</jmolecules.integrations.version>
2525

2626
</properties>
2727

0 commit comments

Comments
 (0)