GH-1425: groundwork to allow nested beans in internal index structure
This commit is contained in:
@@ -10,19 +10,39 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.protocol.spring;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractSpringIndexElement implements SpringIndexElement {
|
||||
|
||||
public static final SpringIndexElement[] NO_CHILDREN = new SpringIndexElement[0];
|
||||
|
||||
private final SpringIndexElement[] children;
|
||||
public static final List<SpringIndexElement> NO_CHILDREN = List.of();
|
||||
private List<SpringIndexElement> children;
|
||||
|
||||
public AbstractSpringIndexElement(SpringIndexElement[] children) {
|
||||
this.children = children != null ? children : NO_CHILDREN;
|
||||
public AbstractSpringIndexElement() {
|
||||
this.children = NO_CHILDREN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpringIndexElement[] getChildren() {
|
||||
public List<SpringIndexElement> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void addChild(SpringIndexElement child) {
|
||||
if (children == NO_CHILDREN) {
|
||||
children = new ArrayList<>();
|
||||
}
|
||||
|
||||
this.children.add(child);
|
||||
}
|
||||
|
||||
public void removeChild(SpringIndexElement doc) {
|
||||
boolean removed = this.children.remove(doc);
|
||||
|
||||
if (removed && this.children.size() == 0) {
|
||||
this.children = NO_CHILDREN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -33,11 +33,8 @@ public class Bean extends AbstractSpringIndexElement {
|
||||
InjectionPoint[] injectionPoints,
|
||||
Set<String> supertypes,
|
||||
AnnotationMetadata[] annotations,
|
||||
boolean isConfiguration,
|
||||
SpringIndexElement[] children) {
|
||||
boolean isConfiguration) {
|
||||
|
||||
super(children);
|
||||
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.location = location;
|
||||
@@ -68,18 +65,6 @@ public class Bean extends AbstractSpringIndexElement {
|
||||
}
|
||||
}
|
||||
|
||||
public Bean(
|
||||
String name,
|
||||
String type,
|
||||
Location location,
|
||||
InjectionPoint[] injectionPoints,
|
||||
Set<String> supertypes,
|
||||
AnnotationMetadata[] annotations,
|
||||
boolean isConfiguration) {
|
||||
this(name, type, location, injectionPoints, supertypes, annotations, isConfiguration, AbstractSpringIndexElement.NO_CHILDREN);
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2024 Broadcom
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Broadcom - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.protocol.spring;
|
||||
|
||||
public class DocumentElement extends AbstractSpringIndexElement {
|
||||
|
||||
private final String docURI;
|
||||
|
||||
public DocumentElement(String docURI) {
|
||||
this.docURI = docURI;
|
||||
}
|
||||
|
||||
public String getDocURI() {
|
||||
return docURI;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2025 Broadcom
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Broadcom - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.protocol.spring;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class ProjectElement extends AbstractSpringIndexElement {
|
||||
|
||||
private String projectName;
|
||||
|
||||
public ProjectElement(String projectName) {
|
||||
this.projectName = projectName;
|
||||
}
|
||||
|
||||
public String getProjectName() {
|
||||
return projectName;
|
||||
}
|
||||
|
||||
public void removeDocument(String docURI) {
|
||||
List<SpringIndexElement> children = this.getChildren();
|
||||
|
||||
for (Iterator<SpringIndexElement> iterator = children.iterator(); iterator.hasNext();) {
|
||||
SpringIndexElement springIndexElement = (SpringIndexElement) iterator.next();
|
||||
if (springIndexElement instanceof DocumentElement doc && doc.getDocURI().equals(docURI)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,8 +10,10 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.commons.protocol.spring;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface SpringIndexElement {
|
||||
|
||||
SpringIndexElement[] getChildren();
|
||||
List<SpringIndexElement> getChildren();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user