Skip to content

Commit a6be7ec

Browse files
odrotbohmmartinlippert
authored andcommitted
Adapt to API changes in ad-hoc stereotype registration
The registration now requires a source object to be handed into the definition creation to keep track of the definition's origin. JsonNodeHandler is now made aware of a StereotypeCatalog to be able to obtain the definition of a stereotype. That makes the source available in handleStereotype(…) which now needs actual handling of it.
1 parent 7f6e230 commit a6be7ec

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public Node createTree(IJavaProject project, IndexBasedStereotypeFactory factory
5555
};
5656

5757
// create json nodes to display the structure in a nice way
58-
var jsonHandler = new JsonNodeHandler<StereotypePackageElement, Object>(labelProvider, consumer, springIndex);
58+
var jsonHandler = new JsonNodeHandler<StereotypePackageElement, Object>(labelProvider, consumer, springIndex, catalog);
5959

6060
// create the project tree and apply all the groupers from the project
6161
// TODO: in the future, we need to trim this grouper arrays down to what is selected on the UI

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.eclipse.lsp4j.DocumentSymbol;
2929
import org.eclipse.lsp4j.Location;
3030
import org.jmolecules.stereotype.api.Stereotype;
31+
import org.jmolecules.stereotype.catalog.StereotypeCatalog;
3132
import org.jmolecules.stereotype.tooling.LabelProvider;
3233
import org.jmolecules.stereotype.tooling.MethodNodeContext;
3334
import org.jmolecules.stereotype.tooling.NodeContext;
@@ -58,19 +59,25 @@ public class JsonNodeHandler<A, C> implements NodeHandler<A, StereotypePackageEl
5859
private final CachedSpringMetamodelIndex springIndex;
5960

6061
private Node current;
62+
private StereotypeCatalog catalog;
6163

6264
public JsonNodeHandler(LabelProvider<A, StereotypePackageElement, StereotypeClassElement, StereotypeMethodElement, C> labels, BiConsumer<Node, C> customHandler,
63-
CachedSpringMetamodelIndex springIndex) {
65+
CachedSpringMetamodelIndex springIndex, StereotypeCatalog catalog) {
6466
this.labels = labels;
6567
this.springIndex = springIndex;
6668
this.customHandler = customHandler;
6769

6870
this.root = new Node(null);
6971
this.current = root;
72+
this.catalog = catalog;
7073
}
7174

7275
@Override
7376
public void handleStereotype(Stereotype stereotype, NodeContext context) {
77+
78+
// var definition = catalog.getDefinition(stereotype);
79+
// var sources = definition.getSources();
80+
7481
addChild(node -> node
7582
.withAttribute(TEXT, labels.getStereotypeLabel(stereotype))
7683
.withAttribute(ICON, StereotypeIcons.getIcon(stereotype))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public Node createTree(IJavaProject project, IndexBasedStereotypeFactory factory
5656
};
5757

5858
// create json nodes to display the structure in a nice way
59-
var jsonHandler = new JsonNodeHandler<ApplicationModules, NamedInterfaceNode>(labelProvider, consumer, springIndex);
59+
var jsonHandler = new JsonNodeHandler<ApplicationModules, NamedInterfaceNode>(labelProvider, consumer, springIndex, catalog);
6060

6161
// create the project tree and apply all the groupers from the project
6262
// TODO: in the future, we need to trim this grouper arrays down to what is selected on the UI

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.jmolecules.stereotype.api.StereotypeFactory;
1919
import org.jmolecules.stereotype.api.Stereotypes;
2020
import org.jmolecules.stereotype.catalog.StereotypeDefinition.Assignment;
21-
import org.jmolecules.stereotype.catalog.StereotypeDefinition.Assignment.Type;
2221
import org.jmolecules.stereotype.catalog.support.AbstractStereotypeCatalog;
2322
import org.jmolecules.stereotype.catalog.support.StereotypeDetector.AnalysisLevel;
2423
import org.jmolecules.stereotype.catalog.support.StereotypeMatcher;
@@ -133,13 +132,12 @@ private StereotypePackageElement findPackageFor(StereotypeClassElement type) {
133132
}
134133

135134
private void registerStereotype(StereotypeDefinitionElement element) {
135+
136136
var stereotype = element.createStereotype();
137+
var type = element.getType();
138+
var assignment = element.getAssignment();
137139

138-
String type = element.getType();
139-
Type assignment = element.getAssignment();
140-
141-
catalog.getOrRegister(stereotype, () -> Assignment.of(type, assignment))
142-
.getStereotype();
140+
catalog.getOrRegister(stereotype, Assignment.of(type, assignment), type).getStereotype();
143141
}
144142

145143
}

0 commit comments

Comments
 (0)