|
10 | 10 | *******************************************************************************/ |
11 | 11 | package org.springframework.ide.vscode.boot.java.commands; |
12 | 12 |
|
| 13 | +import java.util.ArrayList; |
13 | 14 | import java.util.List; |
14 | 15 | import java.util.Objects; |
15 | 16 | import java.util.Optional; |
16 | 17 | import java.util.function.BiConsumer; |
17 | 18 | import java.util.stream.Collectors; |
18 | 19 |
|
| 20 | +import org.jmolecules.stereotype.catalog.StereotypeGroup; |
| 21 | +import org.jmolecules.stereotype.catalog.StereotypeGroups; |
| 22 | +import org.jmolecules.stereotype.catalog.support.AbstractStereotypeCatalog; |
19 | 23 | import org.jmolecules.stereotype.tooling.HierarchicalNodeHandler; |
20 | 24 | import org.jmolecules.stereotype.tooling.LabelUtils; |
21 | 25 | import org.jmolecules.stereotype.tooling.ProjectTree; |
|
36 | 40 | import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder; |
37 | 41 | import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer; |
38 | 42 |
|
| 43 | +import com.google.common.collect.Streams; |
39 | 44 | import com.google.gson.JsonPrimitive; |
40 | 45 |
|
41 | 46 | public class SpringIndexCommands { |
@@ -90,19 +95,62 @@ private Node nodeFrom(StereotypeCatalogRegistry stereotypeCatalogRegistry, Sprin |
90 | 95 | node.withAttribute(HierarchicalNodeHandler.TEXT, labelProvider.getCustomLabel(c)) |
91 | 96 | .withAttribute(ToolsJsonNodeHandler.ICON, "fa-named-interface"); |
92 | 97 | }; |
93 | | - |
94 | | - var jsonHandler = new ToolsJsonNodeHandler(labelProvider, consumer); |
95 | 98 |
|
| 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 |
96 | 104 | 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 | + } |
100 | 111 |
|
101 | 112 | jsonTree.process(mainApplicationPackage); |
102 | 113 |
|
103 | 114 | return jsonHandler.getRoot(); |
104 | 115 | } |
105 | 116 |
|
| 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 | + |
106 | 154 | private String getPackageLabel(StereotypePackageElement p) { |
107 | 155 | String packageName = p.getPackageName(); |
108 | 156 | if (p.isMainPackage() && (packageName == null || packageName.isEmpty())) { |
|
0 commit comments