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;
}
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;
}
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);
}
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());
}
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);
}
}
}
Aggregations