Skip to content

Commit

Permalink
GH-1425: groundwork to allow nested beans in internal index structure
Browse files Browse the repository at this point in the history
  • Loading branch information
martinlippert committed Jan 24, 2025
1 parent 1c64204 commit 85afe5c
Show file tree
Hide file tree
Showing 15 changed files with 328 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ public Bean(
InjectionPoint[] injectionPoints,
Set<String> supertypes,
AnnotationMetadata[] annotations,
boolean isConfiguration,
SpringIndexElement[] children) {
boolean isConfiguration) {

super(children);

this.name = name;
this.type = type;
this.location = location;
Expand Down Expand Up @@ -68,18 +65,6 @@ else if (supertypes != null && supertypes.size() == 1 && supertypes.contains("ja
}
}

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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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();
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
*******************************************************************************/
package org.springframework.ide.vscode.commons.protocol.spring;

import java.util.List;

public interface SpringIndexElement {

SpringIndexElement[] getChildren();
List<SpringIndexElement> getChildren();

}
Loading

0 comments on commit 85afe5c

Please sign in to comment.