Search in sources :

Example 6 with LiveBeansModel

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;
}
Also used : SpringBootApp(org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp) Hover(org.eclipse.lsp4j.Hover) LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) LiveBean(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean)

Example 7 with LiveBeansModel

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");
    }
}
Also used : Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) Test(org.junit.Test)

Example 8 with LiveBeansModel

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");
}
Also used : Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) Test(org.junit.Test)

Example 9 with LiveBeansModel

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`");
}
Also used : Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) Test(org.junit.Test)

Example 10 with LiveBeansModel

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`");
}
Also used : Editor(org.springframework.ide.vscode.languageserver.testharness.Editor) LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) Test(org.junit.Test)

Aggregations

LiveBeansModel (org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel)37 Test (org.junit.Test)33 Editor (org.springframework.ide.vscode.languageserver.testharness.Editor)29 LiveBean (org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean)7 SpringBootApp (org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp)4 Hover (org.eclipse.lsp4j.Hover)3 Path (java.nio.file.Path)1 Optional (java.util.Optional)1 Stream (java.util.stream.Stream)1 BootJavaLanguageServerComponents (org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents)1 SourceLinkFactory (org.springframework.ide.vscode.boot.java.links.SourceLinkFactory)1 SourceLinks (org.springframework.ide.vscode.boot.java.links.SourceLinks)1 SpringResource (org.springframework.ide.vscode.boot.java.utils.SpringResource)1 IJavaProject (org.springframework.ide.vscode.commons.java.IJavaProject)1 SimpleLanguageServer (org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer)1 Renderables (org.springframework.ide.vscode.commons.util.Renderables)1 StringUtil (org.springframework.ide.vscode.commons.util.StringUtil)1