Search in sources :

Example 1 with LiveBeansModel

use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel in project sts4 by spring-projects.

the class AbstractInjectedIntoHoverProvider method provideHover.

@Override
public Hover provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset, TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) {
    if (runningApps.length > 0) {
        LiveBean definedBean = getDefinedBean(annotation);
        if (definedBean != null) {
            StringBuilder hover = new StringBuilder();
            hover.append("**Injection report for " + LiveHoverUtils.showBean(definedBean) + "**\n\n");
            boolean hasInterestingApp = 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) {
                        addInjectedInto(definedBean, hover, beans, bean, project);
                        addAutomaticallyWiredContructor(hover, annotation, beans, bean, project);
                    }
                }
            }
            if (hasInterestingApp) {
                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 2 with LiveBeansModel

use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel in project sts4 by spring-projects.

the class ComponentInjectionsHoverProvider method provideHover.

@Override
public Hover provideHover(ASTNode node, TypeDeclaration typeDeclaration, ITypeBinding type, int offset, TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) {
    if (runningApps.length > 0 && !isComponentAnnotatedType(typeDeclaration)) {
        LiveBean definedBean = getDefinedBeanForType(typeDeclaration, null);
        if (definedBean != null) {
            StringBuilder hover = new StringBuilder();
            hover.append("**Injection report for " + LiveHoverUtils.showBean(definedBean) + "**\n\n");
            boolean hasInterestingApp = 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) {
                        addInjectedInto(definedBean, hover, beans, bean, project);
                    }
                }
            }
            if (hasInterestingApp) {
                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 3 with LiveBeansModel

use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel in project sts4 by spring-projects.

the class LiveBeansModelTest method testSimpleModel.

@Test
public void testSimpleModel() throws Exception {
    String json = IOUtils.toString(getResourceAsStream("/live-beans-models/simple-live-beans-model.json"));
    LiveBeansModel model = LiveBeansModel.parse(json);
    LiveBean[] bean = model.getBeansOfType("org.test.DependencyA").toArray(new LiveBean[0]);
    assertEquals(1, bean.length);
    assertEquals("dependencyA", bean[0].getId());
    assertEquals("singleton", bean[0].getScope());
    assertEquals("org.test.DependencyA", bean[0].getType());
    assertEquals("file [/test-projects/classes/org/test/DependencyA.class]", bean[0].getResource());
    assertEquals(0, bean[0].getAliases().length);
    assertEquals(0, bean[0].getDependencies().length);
    bean = model.getBeansOfName("dependencyB").toArray(new LiveBean[0]);
    assertEquals(1, bean.length);
    assertEquals("dependencyB", bean[0].getId());
    assertEquals("singleton", bean[0].getScope());
    assertEquals("org.test.DependencyB", bean[0].getType());
    assertEquals("file [/test-projects/classes/org/test/DependencyB.class]", bean[0].getResource());
    assertEquals(0, bean[0].getAliases().length);
    assertEquals(0, bean[0].getDependencies().length);
}
Also used : LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) LiveBean(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean) Test(org.junit.Test)

Example 4 with LiveBeansModel

use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel in project sts4 by spring-projects.

the class LiveBeansModelTest method testTotallyEmptyModel.

@Test
public void testTotallyEmptyModel() throws Exception {
    String json = IOUtils.toString(getResourceAsStream("/live-beans-models/totally-empty-live-beans-model.json"));
    LiveBeansModel model = LiveBeansModel.parse(json);
    List<LiveBean> bean = model.getBeansOfType("org.test.DependencyA");
    assertEquals(0, bean.size());
}
Also used : LiveBeansModel(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel) LiveBean(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean) Test(org.junit.Test)

Example 5 with LiveBeansModel

use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel in project sts4 by spring-projects.

the class SpringBootAppTest method getBeans.

@Test
public void getBeans() throws Exception {
    for (SpringBootApp testApp : getTestApps()) {
        try {
            ACondition.waitFor(TIMEOUT, () -> {
                LiveBeansModel beansModel = testApp.getBeans();
                assertFalse(beansModel.isEmpty());
            // System.out.println("beans = "+beans);
            });
        } catch (Throwable e) {
            // Make it easier to identify the culprit of failing test
            throw new RuntimeException("Failed for: " + testApp.getProcessName(), e);
        }
    }
}
Also used : 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