Skip to content

Commit 85afe5c

Browse files
committed
GH-1425: groundwork to allow nested beans in internal index structure
1 parent 1c64204 commit 85afe5c

File tree

15 files changed

+328
-149
lines changed

15 files changed

+328
-149
lines changed

headless-services/commons/commons-lsp-extensions/src/main/java/org/springframework/ide/vscode/commons/protocol/spring/AbstractSpringIndexElement.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,39 @@
1010
*******************************************************************************/
1111
package org.springframework.ide.vscode.commons.protocol.spring;
1212

13+
import java.util.ArrayList;
14+
import java.util.List;
15+
1316
public abstract class AbstractSpringIndexElement implements SpringIndexElement {
1417

15-
public static final SpringIndexElement[] NO_CHILDREN = new SpringIndexElement[0];
16-
17-
private final SpringIndexElement[] children;
18+
public static final List<SpringIndexElement> NO_CHILDREN = List.of();
19+
private List<SpringIndexElement> children;
1820

19-
public AbstractSpringIndexElement(SpringIndexElement[] children) {
20-
this.children = children != null ? children : NO_CHILDREN;
21+
public AbstractSpringIndexElement() {
22+
this.children = NO_CHILDREN;
2123
}
2224

2325
@Override
24-
public SpringIndexElement[] getChildren() {
26+
public List<SpringIndexElement> getChildren() {
2527
return children;
2628
}
29+
30+
public void addChild(SpringIndexElement child) {
31+
if (children == NO_CHILDREN) {
32+
children = new ArrayList<>();
33+
}
34+
35+
this.children.add(child);
36+
}
37+
38+
public void removeChild(SpringIndexElement doc) {
39+
boolean removed = this.children.remove(doc);
40+
41+
if (removed && this.children.size() == 0) {
42+
this.children = NO_CHILDREN;
43+
}
44+
}
45+
46+
2747

2848
}

headless-services/commons/commons-lsp-extensions/src/main/java/org/springframework/ide/vscode/commons/protocol/spring/Bean.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@ public Bean(
3333
InjectionPoint[] injectionPoints,
3434
Set<String> supertypes,
3535
AnnotationMetadata[] annotations,
36-
boolean isConfiguration,
37-
SpringIndexElement[] children) {
36+
boolean isConfiguration) {
3837

39-
super(children);
40-
4138
this.name = name;
4239
this.type = type;
4340
this.location = location;
@@ -68,18 +65,6 @@ else if (supertypes != null && supertypes.size() == 1 && supertypes.contains("ja
6865
}
6966
}
7067

71-
public Bean(
72-
String name,
73-
String type,
74-
Location location,
75-
InjectionPoint[] injectionPoints,
76-
Set<String> supertypes,
77-
AnnotationMetadata[] annotations,
78-
boolean isConfiguration) {
79-
this(name, type, location, injectionPoints, supertypes, annotations, isConfiguration, AbstractSpringIndexElement.NO_CHILDREN);
80-
}
81-
82-
8368
public String getName() {
8469
return name;
8570
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Broadcom
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Broadcom - initial API and implementation
10+
*******************************************************************************/
11+
package org.springframework.ide.vscode.commons.protocol.spring;
12+
13+
public class DocumentElement extends AbstractSpringIndexElement {
14+
15+
private final String docURI;
16+
17+
public DocumentElement(String docURI) {
18+
this.docURI = docURI;
19+
}
20+
21+
public String getDocURI() {
22+
return docURI;
23+
}
24+
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Broadcom
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Broadcom - initial API and implementation
10+
*******************************************************************************/
11+
package org.springframework.ide.vscode.commons.protocol.spring;
12+
13+
import java.util.Iterator;
14+
import java.util.List;
15+
16+
public class ProjectElement extends AbstractSpringIndexElement {
17+
18+
private String projectName;
19+
20+
public ProjectElement(String projectName) {
21+
this.projectName = projectName;
22+
}
23+
24+
public String getProjectName() {
25+
return projectName;
26+
}
27+
28+
public void removeDocument(String docURI) {
29+
List<SpringIndexElement> children = this.getChildren();
30+
31+
for (Iterator<SpringIndexElement> iterator = children.iterator(); iterator.hasNext();) {
32+
SpringIndexElement springIndexElement = (SpringIndexElement) iterator.next();
33+
if (springIndexElement instanceof DocumentElement doc && doc.getDocURI().equals(docURI)) {
34+
iterator.remove();
35+
}
36+
}
37+
}
38+
39+
}

headless-services/commons/commons-lsp-extensions/src/main/java/org/springframework/ide/vscode/commons/protocol/spring/SpringIndexElement.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
*******************************************************************************/
1111
package org.springframework.ide.vscode.commons.protocol.spring;
1212

13+
import java.util.List;
14+
1315
public interface SpringIndexElement {
1416

15-
SpringIndexElement[] getChildren();
17+
List<SpringIndexElement> getChildren();
1618

1719
}

0 commit comments

Comments
 (0)