use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel in project sts4 by spring-projects.
the class AutowiredHoverProvider method provideHover.
@Override
public Hover provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset, TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) {
if (runningApps.length > 0) {
StringBuilder hover = new StringBuilder();
LiveBean definedBean = getDefinedBean(annotation);
if (definedBean != null) {
hover.append("**Injection report for " + LiveHoverUtils.showBean(definedBean) + "**\n\n");
boolean hasInterestingApp = false;
boolean hasAutowiring = false;
for (SpringBootApp app : runningApps) {
LiveBeansModel beans = app.getBeans();
List<LiveBean> relevantBeans = LiveHoverUtils.findRelevantBeans(app, definedBean).collect(Collectors.toList());
if (!relevantBeans.isEmpty()) {
if (!hasInterestingApp) {
hasInterestingApp = true;
} else {
hover.append("\n\n");
}
hover.append(LiveHoverUtils.niceAppName(app) + ":");
for (LiveBean bean : relevantBeans) {
hover.append("\n\n");
hasAutowiring |= addAutomaticallyWired(hover, annotation, beans, bean, project);
}
}
}
if (hasInterestingApp && hasAutowiring) {
return new Hover(ImmutableList.of(Either.forLeft(hover.toString())));
}
}
}
return null;
}
use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel in project sts4 by spring-projects.
the class BeanInjectedIntoHoverProviderTest method explicitIdCases.
@Test
public void explicitIdCases() throws Exception {
LiveBeansModel beans = LiveBeansModel.builder().add(LiveBean.builder().id("beanId").type("hello.FooImplementation").build()).add(LiveBean.builder().id(// wrong id
"irrelevantBean").type(// right type (but should be ignored!)
"hello.Foo").build()).build();
mockAppProvider.builder().isSpringBootApp(true).processId("111").processName("the-app").beans(beans).build();
String[] beanAnnotations = { "@Bean(value=\"beanId\")", "@Bean(value=\"beanId\", destroyMethod=\"cleanup\")", "@Bean(value= {\"beanId\", \"alias\"}, destroyMethod=\"cleanup\")", "@Bean(name=\"beanId\")", "@Bean(name=\"beanId\", destroyMethod=\"cleanup\")", "@Bean(name= {\"beanId\", \"alias\"}, destroyMethod=\"cleanup\")", "@Bean(\"beanId\")", "@Bean({\"beanId\", \"alias\"})" };
for (String beanAnnotation : beanAnnotations) {
Editor editor = harness.newEditor("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" + " " + beanAnnotation + "\n" + " Foo otherFoo() {\n" + " return new FooImplementation();\n" + " }\n" + "}");
editor.assertHighlights("@Bean");
editor.assertTrimmedHover("@Bean", "**Injection report for Bean [id: beanId]**\n" + "\n" + "Process [PID=111, name=`the-app`]:\n" + "\n" + "Bean [id: beanId, type: `hello.FooImplementation`] exists but is **Not injected anywhere**\n");
}
}
use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel in project sts4 by spring-projects.
the class BeanInjectedIntoHoverProviderTest method beanWithMultipleInjections.
@Test
public void beanWithMultipleInjections() throws Exception {
LiveBeansModel beans = LiveBeansModel.builder().add(LiveBean.builder().id("fooImplementation").type("hello.FooImplementation").build()).add(LiveBean.builder().id("myController").type("hello.MyController").dependencies("fooImplementation").build()).add(LiveBean.builder().id("otherBean").type("hello.OtherBean").dependencies("fooImplementation").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() {\n" + " return new FooImplementation();\n" + " }\n" + "}");
editor.assertHighlights("@Bean");
editor.assertTrimmedHover("@Bean", "**Injection report for Bean [id: fooImplementation]**\n" + "\n" + "Process [PID=111, name=`the-app`]:\n" + "\n" + "Bean [id: fooImplementation, type: `hello.FooImplementation`] injected into:\n" + "\n" + "- Bean: myController \n" + " Type: `hello.MyController`\n" + "- Bean: otherBean \n" + " Type: `hello.OtherBean`\n");
}
use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel in project sts4 by spring-projects.
the class BeanInjectedIntoHoverProviderTest method beanWithClasspathResource.
@Test
public void beanWithClasspathResource() throws Exception {
LiveBeansModel beans = LiveBeansModel.builder().add(LiveBean.builder().id("fooImplementation").type("hello.FooImplementation").fileResource("should/not/matter").build()).add(LiveBean.builder().id("myController").type("hello.MyController").classpathResource("hello/MyController.class").dependencies("fooImplementation").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() {\n" + " return new FooImplementation();\n" + " }\n" + "}");
editor.assertHighlights("@Bean");
editor.assertTrimmedHover("@Bean", "**Injection report for Bean [id: fooImplementation]**\n" + "\n" + "Process [PID=111, name=`the-app`]:\n" + "\n" + "Bean [id: fooImplementation, type: `hello.FooImplementation`] injected into:\n" + "\n" + "- Bean: myController \n" + " Type: `hello.MyController` \n" + " Resource: `hello/MyController.class`");
}
use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel in project sts4 by spring-projects.
the class BeansByTypeHoverProviderTest method typeWithGeneralBean.
@Test
public void typeWithGeneralBean() throws Exception {
LiveBeansModel beans = LiveBeansModel.builder().add(LiveBean.builder().id("scannedRandomClass").type("com.example.ScannedRandomClass").build()).add(LiveBean.builder().id("randomOtherBean").type("randomOtherBeanType").dependencies("scannedRandomClass").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 com.example;\n" + "\n" + "import java.io.Serializable;\n" + "\n" + "public class ScannedRandomClass implements Serializable {\n" + "\n" + " public String apply(String t) {\n" + " return t.toUpperCase();\n" + " }\n" + "\n" + "}\n" + "");
editor.assertHighlights("ScannedRandomClass");
editor.assertTrimmedHover("ScannedRandomClass", "**Injection report for Bean [id: scannedRandomClass, type: `com.example.ScannedRandomClass`]**\n" + "\n" + "Process [PID=111, name=`the-app`]:\n" + "\n" + "Bean [id: scannedRandomClass, type: `com.example.ScannedRandomClass`] injected into:\n" + "\n" + "- Bean: randomOtherBean \n" + " Type: `randomOtherBeanType`");
}
Aggregations