Skip to content

Commit 4f01d58

Browse files
committed
[structure view] display specific label when there is no main application package identified
1 parent f4bbb6c commit 4f01d58

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ private Node nodeFrom(StereotypeCatalogRegistry stereotypeCatalogRegistry, Sprin
5858
var labelProvider = new SimpleLabelProvider<>(StereotypePackageElement::getPackageName, StereotypePackageElement::getPackageName, StereotypeClassElement::getType,
5959
(StereotypeMethodElement m, StereotypeClassElement __) -> m.getMethodName(), Object::toString)
6060
.withTypeLabel(it -> abbreviate(mainApplicationPackage, it))
61-
.withMethodLabel((m, c) -> getMethodLabel(project, m, c));
61+
.withMethodLabel((m, c) -> getMethodLabel(project, m, c))
62+
.withPackageLabel((p) -> getPackageLabel(p))
63+
.withApplicationLabel((p) -> getPackageLabel(p));
6264

6365
var structureProvider = new ToolsStructureProvider(springIndex, project);
6466

@@ -80,6 +82,16 @@ private Node nodeFrom(StereotypeCatalogRegistry stereotypeCatalogRegistry, Sprin
8082
return jsonHandler.getRoot();
8183
}
8284

85+
private String getPackageLabel(StereotypePackageElement p) {
86+
String packageName = p.getPackageName();
87+
if (p.isMainPackage() && (packageName == null || packageName.isEmpty())) {
88+
return "(no main application package identified)";
89+
}
90+
else {
91+
return packageName;
92+
}
93+
}
94+
8395
private String abbreviate(StereotypePackageElement mainApplicationPackage, StereotypeClassElement it) {
8496
if (mainApplicationPackage == null || mainApplicationPackage.getPackageName() == null || mainApplicationPackage.getPackageName().isBlank()) {
8597
return it.getType();
@@ -115,10 +127,10 @@ public StereotypePackageElement identifyMainApplicationPackage(IJavaProject proj
115127
.findFirst();
116128

117129
if (packageElement.isPresent()) {
118-
return packageElement.get();
130+
return new StereotypePackageElement(packageElement.get().getPackageName(), packageElement.get().getAnnotationTypes(), true);
119131
}
120132
else {
121-
return new StereotypePackageElement("", null);
133+
return new StereotypePackageElement("", null, true);
122134
}
123135
}
124136

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,27 @@
1717
public class StereotypePackageElement extends AbstractSpringIndexElement implements StereotypeAnnotatedElement {
1818

1919
private final String packageName;
20+
private final boolean isMainPackage;
2021
private final List<String> annotationTypes;
2122

2223
public StereotypePackageElement(String packageName, List<String> annotationTypes) {
24+
this(packageName, annotationTypes, false);
25+
}
26+
27+
public StereotypePackageElement(String packageName, List<String> annotationTypes, boolean isMainPackage) {
2328
this.packageName = packageName;
29+
this.isMainPackage = isMainPackage;
2430
this.annotationTypes = annotationTypes;
2531
}
2632

2733
public String getPackageName() {
2834
return packageName;
2935
}
3036

37+
public boolean isMainPackage() {
38+
return isMainPackage;
39+
}
40+
3141
public List<String> getAnnotationTypes() {
3242
return annotationTypes;
3343
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public class SpringIndexerJava implements SpringIndexer {
9494

9595
// whenever the implementation of the indexer changes in a way that the stored data in the cache is no longer valid,
9696
// we need to change the generation - this will result in a re-indexing due to no up-to-date cache data being found
97-
private static final String GENERATION = "GEN-26";
97+
private static final String GENERATION = "GEN-27";
9898
private static final String INDEX_FILES_TASK_ID = "index-java-source-files-task-";
9999

100100
private static final String SYMBOL_KEY = "symbols";

0 commit comments

Comments
 (0)