take XML bean definitions without explicit bean ID into account when creating symbols
This commit is contained in:
@@ -19,9 +19,11 @@ import org.eclipse.lsp4j.SymbolInformation;
|
||||
import org.eclipse.lsp4j.SymbolKind;
|
||||
import org.eclipse.lsp4xml.dom.DOMAttr;
|
||||
import org.eclipse.lsp4xml.dom.DOMNode;
|
||||
import org.springframework.ide.vscode.boot.java.beans.BeanUtils;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
/**
|
||||
* @author Martin Lippert
|
||||
@@ -38,8 +40,8 @@ public class SpringIndexerXMLNamespaceHandlerBeans implements SpringIndexerXMLNa
|
||||
|
||||
private void createBeanSymbol(DOMNode node, IJavaProject project, String docURI, TextDocument document, SymbolHandler symbolHandler) throws Exception {
|
||||
String beanID = null;
|
||||
int beanIDStart = 0;
|
||||
int beanIDEnd = 0;
|
||||
int symbolStart = 0;
|
||||
int symbolEnd = 0;
|
||||
|
||||
String beanClass = null;
|
||||
|
||||
@@ -49,21 +51,27 @@ public class SpringIndexerXMLNamespaceHandlerBeans implements SpringIndexerXMLNa
|
||||
String name = attribute.getName();
|
||||
if (name != null && name.equals("id")) {
|
||||
beanID = attribute.getValue();
|
||||
beanIDStart = attribute.getStart();
|
||||
beanIDEnd = attribute.getEnd();
|
||||
|
||||
symbolStart = attribute.getStart();
|
||||
symbolEnd = attribute.getEnd();
|
||||
}
|
||||
else if (name != null && name.equals("class")) {
|
||||
String value = attribute.getValue();
|
||||
beanClass = value.substring(value.lastIndexOf(".") + 1);
|
||||
|
||||
if (symbolStart == 0 && symbolEnd == 0) {
|
||||
symbolStart = attribute.getStart();
|
||||
symbolEnd = attribute.getEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (beanID != null && beanClass != null) {
|
||||
int lineStart = document.getLineOfOffset(beanIDStart);
|
||||
int lineEnd = document.getLineOfOffset(beanIDEnd);
|
||||
if (beanClass != null) {
|
||||
int lineStart = document.getLineOfOffset(symbolStart);
|
||||
int lineEnd = document.getLineOfOffset(symbolEnd);
|
||||
|
||||
int startInLine = beanIDStart - document.getLineOffset(lineStart);
|
||||
int endInLine = beanIDEnd - document.getLineOffset(lineEnd);
|
||||
int startInLine = symbolStart - document.getLineOffset(lineStart);
|
||||
int endInLine = symbolEnd - document.getLineOffset(lineEnd);
|
||||
|
||||
Range range = new Range();
|
||||
range.setStart(new Position(lineStart + 1, startInLine));
|
||||
@@ -73,6 +81,10 @@ public class SpringIndexerXMLNamespaceHandlerBeans implements SpringIndexerXMLNa
|
||||
location.setUri(docURI);
|
||||
location.setRange(range);
|
||||
|
||||
if (beanID == null) {
|
||||
beanID = deriveBeanIDFromClass(beanClass);
|
||||
}
|
||||
|
||||
SymbolInformation symbol = new SymbolInformation("@+ '" + beanID + "' " + beanClass, SymbolKind.Interface, new Location(docURI, range));
|
||||
|
||||
EnhancedSymbolInformation fullSymbol = new EnhancedSymbolInformation(symbol, null);
|
||||
@@ -80,4 +92,8 @@ public class SpringIndexerXMLNamespaceHandlerBeans implements SpringIndexerXMLNa
|
||||
}
|
||||
}
|
||||
|
||||
private String deriveBeanIDFromClass(@NonNull String beanClass) {
|
||||
return BeanUtils.getBeanNameFromType(beanClass);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -70,12 +70,13 @@ public class SpringIndexerXMLProjectTest {
|
||||
public void testScanningSimpleSpringXMLConfig() throws Exception {
|
||||
List<? extends SymbolInformation> allSymbols = indexer.getAllSymbols("");
|
||||
|
||||
assertEquals(3, allSymbols.size());
|
||||
assertEquals(4, allSymbols.size());
|
||||
|
||||
String docUri = directory.toPath().resolve("config/simple-spring-config.xml").toUri().toString();
|
||||
assertTrue(containsSymbol(allSymbols, "@+ 'transactionManager' DataSourceTransactionManager", docUri, 7, 14, 7, 37));
|
||||
assertTrue(containsSymbol(allSymbols, "@+ 'jdbcTemplate' JdbcTemplate", docUri, 9, 14, 9, 31));
|
||||
assertTrue(containsSymbol(allSymbols, "@+ 'namedParameterJdbcTemplate' NamedParameterJdbcTemplate", docUri, 13, 14, 13, 45));
|
||||
assertTrue(containsSymbol(allSymbols, "@+ 'persistenceExceptionTranslationPostProcessor' PersistenceExceptionTranslationPostProcessor", docUri, 19, 10, 19, 97));
|
||||
}
|
||||
|
||||
private boolean containsSymbol(List<? extends SymbolInformation> symbols, String name, String uri, int startLine, int startCHaracter, int endLine, int endCharacter) {
|
||||
|
||||
@@ -16,4 +16,6 @@
|
||||
</bean>
|
||||
</beans>
|
||||
|
||||
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
|
||||
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user