Search in sources :

Example 1 with LiveBean

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

the class AbstractInjectedIntoHoverProvider method addInjectedInto.

protected void addInjectedInto(LiveBean definedBean, StringBuilder hover, LiveBeansModel beans, LiveBean bean, IJavaProject project) {
    hover.append("\n\n");
    List<LiveBean> dependers = beans.getBeansDependingOn(bean.getId());
    if (dependers.isEmpty()) {
        hover.append(LiveHoverUtils.showBean(bean) + " exists but is **Not injected anywhere**\n");
    } else {
        hover.append(LiveHoverUtils.showBean(bean) + " injected into:\n\n");
        boolean firstDependency = true;
        for (LiveBean dependingBean : dependers) {
            if (!firstDependency) {
                hover.append("\n");
            }
            hover.append("- " + LiveHoverUtils.showBeanWithResource(server, dependingBean, "  ", project));
            firstDependency = false;
        }
    }
}
Also used : LiveBean(org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean)

Example 2 with LiveBean

use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean 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 3 with LiveBean

use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean 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 4 with LiveBean

use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean 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 5 with LiveBean

use of org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean 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)

Aggregations

LiveBean (org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean)10 LiveBeansModel (org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel)7 SpringBootApp (org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp)4 Hover (org.eclipse.lsp4j.Hover)3 Test (org.junit.Test)3 Optional (java.util.Optional)1 Stream (java.util.stream.Stream)1 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)1 TypeDeclaration (org.eclipse.jdt.core.dom.TypeDeclaration)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