PT #159866210: Remove injected beans from bean parameter hover
This commit is contained in:
@@ -83,7 +83,7 @@ public abstract class AbstractInjectedIntoHoverProvider implements HoverProvider
|
||||
|
||||
LiveBean definedBean = getDefinedBean(annotation);
|
||||
if (definedBean != null) {
|
||||
Hover hover = assembleHover(project, runningApps, definedBean, annotation);
|
||||
Hover hover = assembleHover(project, runningApps, definedBean, annotation, true, true);
|
||||
if (hover != null) {
|
||||
Optional<Range> nameRange = ASTUtils.nameRange(doc, annotation);
|
||||
if (nameRange.isPresent()) {
|
||||
@@ -134,7 +134,7 @@ public abstract class AbstractInjectedIntoHoverProvider implements HoverProvider
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
protected Hover assembleHover(IJavaProject project, SpringBootApp[] runningApps, LiveBean definedBean, ASTNode astNode) {
|
||||
protected Hover assembleHover(IJavaProject project, SpringBootApp[] runningApps, LiveBean definedBean, ASTNode astNode, boolean injected, boolean wired) {
|
||||
StringBuilder hover = new StringBuilder();
|
||||
|
||||
for (SpringBootApp app : runningApps) {
|
||||
@@ -142,30 +142,34 @@ public abstract class AbstractInjectedIntoHoverProvider implements HoverProvider
|
||||
List<LiveBean> relevantBeans = LiveHoverUtils.findRelevantBeans(app, definedBean);
|
||||
|
||||
if (!relevantBeans.isEmpty()) {
|
||||
List<LiveBean> injectedBeans = getRelevantInjectedIntoBeans(project, app, definedBean, relevantBeans);
|
||||
|
||||
if (hover.length() > 0) {
|
||||
hover.append(" \n \n");
|
||||
}
|
||||
|
||||
if (!injectedBeans.isEmpty()) {
|
||||
hover.append("**");
|
||||
hover.append(LiveHoverUtils.createBeansTitleMarkdown(sourceLinks, project, injectedBeans, BEANS_PREFIX_MARKDOWN, MAX_INLINE_BEANS_STRING_LENGTH, INLINE_BEANS_STRING_SEPARATOR));
|
||||
hover.append("**\n");
|
||||
hover.append(injectedBeans.stream()
|
||||
.map(b -> "- " + LiveHoverUtils.showBeanWithResource(sourceLinks, b, " ", project))
|
||||
.collect(Collectors.joining("\n")));
|
||||
hover.append("\n \n");
|
||||
}
|
||||
List<LiveBean> wiredBeans = findWiredBeans(project, app, relevantBeans, astNode);
|
||||
if (!wiredBeans.isEmpty()) {
|
||||
AutowiredHoverProvider.createHoverContentForBeans(sourceLinks, project, hover, wiredBeans);
|
||||
if (injected) {
|
||||
List<LiveBean> injectedBeans = getRelevantInjectedIntoBeans(project, app, definedBean, relevantBeans);
|
||||
if (!injectedBeans.isEmpty()) {
|
||||
hover.append("**");
|
||||
hover.append(LiveHoverUtils.createBeansTitleMarkdown(sourceLinks, project, injectedBeans, BEANS_PREFIX_MARKDOWN, MAX_INLINE_BEANS_STRING_LENGTH, INLINE_BEANS_STRING_SEPARATOR));
|
||||
hover.append("**\n");
|
||||
hover.append(injectedBeans.stream()
|
||||
.map(b -> "- " + LiveHoverUtils.showBeanWithResource(sourceLinks, b, " ", project))
|
||||
.collect(Collectors.joining("\n")));
|
||||
hover.append("\n \n");
|
||||
}
|
||||
}
|
||||
|
||||
hover.append("Bean id: `");
|
||||
hover.append(definedBean.getId());
|
||||
hover.append("` \n");
|
||||
hover.append(LiveHoverUtils.niceAppName(app));
|
||||
if (wired) {
|
||||
List<LiveBean> wiredBeans = findWiredBeans(project, app, relevantBeans, astNode);
|
||||
if (!wiredBeans.isEmpty()) {
|
||||
AutowiredHoverProvider.createHoverContentForBeans(sourceLinks, project, hover, wiredBeans);
|
||||
}
|
||||
|
||||
hover.append("Bean id: `");
|
||||
hover.append(definedBean.getId());
|
||||
hover.append("` \n");
|
||||
hover.append(LiveHoverUtils.niceAppName(app));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public class BeanInjectedIntoHoverProvider extends AbstractInjectedIntoHoverProv
|
||||
if (beanAnnotation != null) {
|
||||
LiveBean definedBean = getDefinedBean(beanAnnotation);
|
||||
if (definedBean != null) {
|
||||
Hover hover = assembleHover(project, runningApps, definedBean, parameter);
|
||||
Hover hover = assembleHover(project, runningApps, definedBean, parameter, false, true);
|
||||
if (hover != null) {
|
||||
hover.setRange(range);
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ public class ComponentInjectionsHoverProvider extends AbstractInjectedIntoHoverP
|
||||
|
||||
LiveBean definedBean = getDefinedBeanForType(typeDeclaration, null);
|
||||
if (definedBean != null) {
|
||||
Hover hover = assembleHover(project, runningApps, definedBean, typeDeclaration);
|
||||
Hover hover = assembleHover(project, runningApps, definedBean, typeDeclaration, true, true);
|
||||
if (hover != null) {
|
||||
SimpleName name = typeDeclaration.getName();
|
||||
try {
|
||||
|
||||
@@ -238,6 +238,80 @@ public class BeanInjectedIntoHoverProviderTest {
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanWithOneInjectionAndWiring() throws Exception {
|
||||
LiveBeansModel beans = LiveBeansModel.builder()
|
||||
.add(LiveBean.builder()
|
||||
.id("fooImplementation")
|
||||
.type("hello.FooImplementation")
|
||||
.dependencies("message")
|
||||
.build()
|
||||
)
|
||||
.add(LiveBean.builder()
|
||||
.id("myController")
|
||||
.type("hello.MyController")
|
||||
.dependencies("fooImplementation")
|
||||
.build()
|
||||
)
|
||||
.add(LiveBean.builder()
|
||||
.id("message")
|
||||
.type("java.lang.String")
|
||||
.build()
|
||||
)
|
||||
.add(LiveBean.builder()
|
||||
.id("irrelevantBean")
|
||||
.type("com.example.IrrelevantBean")
|
||||
.dependencies("myController")
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
mockAppProvider.builder()
|
||||
.isSpringBootApp(true)
|
||||
.processId("111")
|
||||
.processName("the-app")
|
||||
.beans(beans)
|
||||
.build();
|
||||
|
||||
Editor editor = harness.newEditor(LanguageId.JAVA,
|
||||
"package hello;\n" +
|
||||
"\n" +
|
||||
"import org.springframework.context.annotation.Bean;\n" +
|
||||
"import org.springframework.context.annotation.Configuration;\n" +
|
||||
"import org.springframework.context.annotation.Profile;\n" +
|
||||
"\n" +
|
||||
"@Configuration\n" +
|
||||
"public class LocalConfig {\n" +
|
||||
" \n" +
|
||||
" @Bean(\"fooImplementation\")\n" +
|
||||
" Foo someFoo(String msg) {\n" +
|
||||
" return new FooImplementation();\n" +
|
||||
" }\n" +
|
||||
"}"
|
||||
);
|
||||
// !!! 2 highlights over @Bean. 1 for injected beans CodeLens, 1 for wired beans CodeLens
|
||||
editor.assertHighlights("@Bean", "@Bean", "msg");
|
||||
editor.assertTrimmedHover("@Bean",
|
||||
"**→ `MyController`**\n" +
|
||||
"- Bean: `myController` \n" +
|
||||
" Type: `hello.MyController`\n" +
|
||||
" \n" +
|
||||
"**← `String`**\n" +
|
||||
"- Bean: `message` \n" +
|
||||
" Type: `java.lang.String`\n" +
|
||||
" \n" +
|
||||
"Bean id: `fooImplementation` \n" +
|
||||
"Process [PID=111, name=`the-app`]"
|
||||
);
|
||||
editor.assertTrimmedHover("msg",
|
||||
"**← `String`**\n" +
|
||||
"- Bean: `message` \n" +
|
||||
" Type: `java.lang.String`\n" +
|
||||
" \n" +
|
||||
"Bean id: `fooImplementation` \n" +
|
||||
"Process [PID=111, name=`the-app`]"
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanFromInnerClassWithOneInjection() throws Exception {
|
||||
LiveBeansModel beans = LiveBeansModel.builder()
|
||||
|
||||
Reference in New Issue
Block a user