|
39 | 39 | import org.springframework.ide.vscode.boot.java.utils.ASTUtils; |
40 | 40 | import org.springframework.ide.vscode.boot.java.utils.CachedSymbol; |
41 | 41 | import org.springframework.ide.vscode.boot.java.utils.SpringIndexerJavaContext; |
| 42 | +import org.springframework.ide.vscode.commons.protocol.spring.Bean; |
| 43 | +import org.springframework.ide.vscode.commons.protocol.spring.SpringIndexElement; |
42 | 44 | import org.springframework.ide.vscode.commons.util.text.TextDocument; |
43 | 45 |
|
44 | 46 | /** |
@@ -77,20 +79,39 @@ protected void addSymbolsPass1(Annotation node, ITypeBinding annotationType, Col |
77 | 79 | context.getGeneratedSymbols().add(new CachedSymbol(context.getDocURI(), context.getLastModified(), symbol)); |
78 | 80 |
|
79 | 81 | // index element for request mapping |
80 | | - List<CachedBean> beans = context.getBeans(); |
81 | | - if (beans.size() > 0 ) { |
82 | | - CachedBean cachedBean = beans.get(beans.size() - 1); |
83 | | - if (cachedBean.getDocURI().equals(doc.getUri())) { |
84 | | - cachedBean.getBean().addChild(new RequestMappingIndexElement(p, methods, contentTypes, acceptTypes)); |
85 | | - } |
| 82 | + SpringIndexElement parent = getPotentialParentIndexNode(context); |
| 83 | + if (parent != null) { |
| 84 | + parent.addChild(new RequestMappingIndexElement(p, methods, contentTypes, acceptTypes, location.getRange(), symbol.getName())); |
| 85 | + } |
| 86 | + else { |
| 87 | + context.getBeans().add(new CachedBean(doc.getUri(), new RequestMappingIndexElement(p, methods, contentTypes, acceptTypes, location.getRange(), symbol.getName()))); |
86 | 88 | } |
87 | 89 | }); |
| 90 | + |
88 | 91 | } catch (Exception e) { |
89 | 92 | log.error("problem occured while scanning for request mapping symbols from " + doc.getUri(), e); |
90 | 93 | } |
91 | 94 | } |
92 | 95 | } |
93 | 96 |
|
| 97 | + private SpringIndexElement getPotentialParentIndexNode(SpringIndexerJavaContext context) { |
| 98 | + List<CachedBean> beans = context.getBeans(); |
| 99 | + |
| 100 | + for (int i = beans.size() - 1; i >= 0; i--) { |
| 101 | + CachedBean cachedBean = beans.get(i); |
| 102 | + |
| 103 | + if (!cachedBean.getDocURI().equals(context.getDocURI())) { |
| 104 | + return null; |
| 105 | + } |
| 106 | + |
| 107 | + if (cachedBean.getBean() instanceof Bean bean) { |
| 108 | + return bean; |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + return null; |
| 113 | + } |
| 114 | + |
94 | 115 | private String combinePath(String parent, String path) { |
95 | 116 | String separator = !parent.endsWith("/") && !path.startsWith("/") && !path.isEmpty() ? "/" : ""; |
96 | 117 | String resultPath = parent + separator + path; |
|
0 commit comments