diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/autowired/AutowiredHoverProvider.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/autowired/AutowiredHoverProvider.java index b19aa07dc..add03f263 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/autowired/AutowiredHoverProvider.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/autowired/AutowiredHoverProvider.java @@ -55,7 +55,7 @@ public class AutowiredHoverProvider implements HoverProvider { final static Logger log = LoggerFactory.getLogger(AutowiredHoverProvider.class); - private static final int MAX_INLINE_BEANS_STRING_LENGTH = 50; + private static final int MAX_INLINE_BEANS_STRING_LENGTH = 60; private static final String INLINE_BEANS_STRING_SEPARATOR = " "; private BootJavaLanguageServerComponents server; @@ -66,14 +66,16 @@ public class AutowiredHoverProvider implements HoverProvider { @Override public Collection getLiveHoverHints(IJavaProject project, Annotation annotation, TextDocument doc, SpringBootApp[] runningApps) { - LiveBean definedBean = getDefinedBeanForTypeDeclaration(ASTUtils.findDeclaringType(annotation)); - // Annotation is MarkerNode, parent is some field, method, variable declaration node. - ASTNode declarationNode = annotation.getParent(); - try { - Range hoverRange = doc.toRange(annotation.getStartPosition(), annotation.getLength()); - return getLiveHoverHints(project, declarationNode, hoverRange, runningApps, definedBean); - } catch (BadLocationException e) { - log.error("", e); + if (runningApps.length > 0) { + LiveBean definedBean = getDefinedBeanForTypeDeclaration(ASTUtils.findDeclaringType(annotation)); + // Annotation is MarkerNode, parent is some field, method, variable declaration node. + ASTNode declarationNode = annotation.getParent(); + try { + Range hoverRange = doc.toRange(annotation.getStartPosition(), annotation.getLength()); + return getLiveHoverHints(project, declarationNode, hoverRange, runningApps, definedBean); + } catch (BadLocationException e) { + log.error("", e); + } } return null; } @@ -94,15 +96,18 @@ public class AutowiredHoverProvider implements HoverProvider { @Override public Hover provideHover(ASTNode node, Annotation annotation, ITypeBinding type, int offset, TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) { - LiveBean definedBean = getDefinedBeanForTypeDeclaration(ASTUtils.findDeclaringType(annotation)); - // Annotation is MarkerNode, parent is some field, method, variable declaration node. - ASTNode declarationNode = annotation.getParent(); - return provideHover(definedBean, declarationNode, offset, doc, project, runningApps); + if (runningApps.length > 0) { + LiveBean definedBean = getDefinedBeanForTypeDeclaration(ASTUtils.findDeclaringType(annotation)); + // Annotation is MarkerNode, parent is some field, method, variable declaration node. + ASTNode declarationNode = annotation.getParent(); + return provideHover(definedBean, declarationNode, offset, doc, project, runningApps); + } + return null; } private Hover provideHover(LiveBean definedBean, ASTNode declarationNode, int offset, TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) { - if (definedBean != null && runningApps.length > 0) { + if (definedBean != null) { StringBuilder hover = new StringBuilder(); @@ -118,15 +123,21 @@ public class AutowiredHoverProvider implements HoverProvider { } else { hover.append(" \n \n"); } - hover.append("**Autowired → "); - if (LiveHoverUtils.doBeansFitInline(autowiredBeans, MAX_INLINE_BEANS_STRING_LENGTH, + hover.append("**Autowired `"); + hover.append(definedBean.getId()); + hover.append("` → "); + if (LiveHoverUtils.doBeansFitInline(autowiredBeans, MAX_INLINE_BEANS_STRING_LENGTH - definedBean.getId().length(), INLINE_BEANS_STRING_SEPARATOR)) { hover.append(autowiredBeans.stream().map(b -> LiveHoverUtils.showBeanInline(server, project, b)) .collect(Collectors.joining(INLINE_BEANS_STRING_SEPARATOR))); hover.append("**\n"); } else { hover.append(autowiredBeans.size()); - hover.append(" beans**\n"); + hover.append(" bean"); + if (autowiredBeans.size() > 1) { + hover.append('s'); + } + hover.append("**\n"); } // if (autowiredBeans.size() == 1) { // hover.append(LiveHoverUtils.showBeanIdAndTypeInline(server, project, autowiredBeans.get(0))); @@ -151,8 +162,7 @@ public class AutowiredHoverProvider implements HoverProvider { private List getRelevantAutowiredBeans(IJavaProject project, ASTNode declarationNode, SpringBootApp app, LiveBean definedBean) { LiveBeansModel beans = app.getBeans(); - List relevantBeans = LiveHoverUtils.findRelevantBeans(app, definedBean) - .collect(Collectors.toList()); + List relevantBeans = LiveHoverUtils.findRelevantBeans(app, definedBean); if (!relevantBeans.isEmpty()) { List allDependencyBeans = relevantBeans.stream() diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/AbstractInjectedIntoHoverProvider.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/AbstractInjectedIntoHoverProvider.java index 13c861fc5..8e166424e 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/AbstractInjectedIntoHoverProvider.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/AbstractInjectedIntoHoverProvider.java @@ -11,6 +11,7 @@ package org.springframework.ide.vscode.boot.java.livehover; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -22,6 +23,8 @@ import org.eclipse.jdt.core.dom.ITypeBinding; import org.eclipse.lsp4j.Hover; import org.eclipse.lsp4j.Range; import org.eclipse.lsp4j.jsonrpc.messages.Either; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents; import org.springframework.ide.vscode.boot.java.handlers.HoverProvider; import org.springframework.ide.vscode.boot.java.utils.ASTUtils; @@ -29,13 +32,17 @@ import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp; import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean; import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel; import org.springframework.ide.vscode.commons.java.IJavaProject; -import org.springframework.ide.vscode.commons.util.Log; import org.springframework.ide.vscode.commons.util.text.TextDocument; import com.google.common.collect.ImmutableList; public abstract class AbstractInjectedIntoHoverProvider implements HoverProvider { + private static Logger LOG = LoggerFactory.getLogger(AbstractInjectedIntoHoverProvider.class); + + private static final int MAX_INLINE_BEANS_STRING_LENGTH = 60; + private static final String INLINE_BEANS_STRING_SEPARATOR = " "; + protected BootJavaLanguageServerComponents server; public AbstractInjectedIntoHoverProvider(BootJavaLanguageServerComponents server) { @@ -58,7 +65,7 @@ public abstract class AbstractInjectedIntoHoverProvider implements HoverProvider } } } catch (Exception e) { - Log.log(e); + LOG.error("", e); } return ImmutableList.of(); } @@ -70,52 +77,80 @@ public abstract class AbstractInjectedIntoHoverProvider implements HoverProvider 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 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 assembleHover(project, runningApps, definedBean); } } return null; } + protected Hover assembleHover(IJavaProject project, SpringBootApp[] runningApps, LiveBean definedBean) { + StringBuilder hover = new StringBuilder(); + + boolean hasContent = false; + + for (SpringBootApp app : runningApps) { + + List relevantBeans = LiveHoverUtils.findRelevantBeans(app, definedBean); + + if (!relevantBeans.isEmpty()) { + List injectedBeans = getRelevantInjectedIntoBeans(project, app, definedBean, relevantBeans); + + if (!hasContent) { + hasContent = true; + } else { + hover.append(" \n \n"); + } + + if (injectedBeans.isEmpty()) { + hover.append("**Injected `"); + hover.append(definedBean.getId()); + hover.append("` → _not injected anywhere_** \n"); + } else { + hover.append("**Injected `"); + hover.append(definedBean.getId()); + hover.append("` → "); + if (LiveHoverUtils.doBeansFitInline(injectedBeans, MAX_INLINE_BEANS_STRING_LENGTH - definedBean.getId().length(), + INLINE_BEANS_STRING_SEPARATOR)) { + hover.append(injectedBeans.stream().map(b -> LiveHoverUtils.showBeanInline(server, project, b)) + .collect(Collectors.joining(INLINE_BEANS_STRING_SEPARATOR))); + hover.append("**\n"); + } else { + hover.append(injectedBeans.size()); + hover.append(" bean"); + if (injectedBeans.size() > 1) { + hover.append('s'); + } + hover.append("**\n"); + } + hover.append(injectedBeans.stream() + .map(b -> "- " + LiveHoverUtils.showBeanWithResource(server, b, " ", project)) + .collect(Collectors.joining("\n"))); + hover.append("\n \n"); + } + hover.append(LiveHoverUtils.niceAppName(app)); + } + + } + if (hasContent) { + return new Hover(ImmutableList.of(Either.forLeft(hover.toString()))); + } else { + return null; + } + + } + + protected List getRelevantInjectedIntoBeans(IJavaProject project, SpringBootApp app, LiveBean definedBean, List relevantBeans) { + LiveBeansModel beans = app.getBeans(); + if (relevantBeans != null) { + return relevantBeans.stream() + .flatMap(b -> beans.getBeansDependingOn(b.getId()).stream()) + .distinct() + .collect(Collectors.toList()); + + } + return Collections.emptyList(); + } + protected abstract LiveBean getDefinedBean(Annotation annotation); - protected void addInjectedInto(LiveBean definedBean, StringBuilder hover, LiveBeansModel beans, LiveBean bean, IJavaProject project) { - hover.append("\n\n"); - List 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; - } - } - } } diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/ComponentInjectionsHoverProvider.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/ComponentInjectionsHoverProvider.java index dfcbb832d..aa6d9da57 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/ComponentInjectionsHoverProvider.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/ComponentInjectionsHoverProvider.java @@ -14,7 +14,6 @@ import java.util.Collection; import java.util.List; import java.util.Optional; import java.util.Set; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.jdt.core.dom.ASTNode; @@ -23,16 +22,15 @@ import org.eclipse.jdt.core.dom.ITypeBinding; import org.eclipse.jdt.core.dom.TypeDeclaration; import org.eclipse.lsp4j.Hover; import org.eclipse.lsp4j.Range; -import org.eclipse.lsp4j.jsonrpc.messages.Either; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.ide.vscode.boot.java.Annotations; import org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents; import org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchies; import org.springframework.ide.vscode.boot.java.utils.ASTUtils; import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp; import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean; -import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel; import org.springframework.ide.vscode.commons.java.IJavaProject; -import org.springframework.ide.vscode.commons.util.Log; import org.springframework.ide.vscode.commons.util.StringUtil; import org.springframework.ide.vscode.commons.util.text.TextDocument; @@ -40,6 +38,8 @@ import com.google.common.collect.ImmutableList; public class ComponentInjectionsHoverProvider extends AbstractInjectedIntoHoverProvider { + private static Logger LOG = LoggerFactory.getLogger(ComponentInjectionsHoverProvider.class); + public ComponentInjectionsHoverProvider(BootJavaLanguageServerComponents server) { super(server); } @@ -101,7 +101,7 @@ public class ComponentInjectionsHoverProvider extends AbstractInjectedIntoHoverP } } } catch (Exception e) { - Log.log(e); + LOG.error("", e); } } return ImmutableList.of(); @@ -115,30 +115,7 @@ public class ComponentInjectionsHoverProvider extends AbstractInjectedIntoHoverP 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 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 assembleHover(project, runningApps, definedBean); } } return null; diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/LiveHoverUtils.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/LiveHoverUtils.java index 4851bb21c..f8365c374 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/LiveHoverUtils.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/LiveHoverUtils.java @@ -11,8 +11,10 @@ package org.springframework.ide.vscode.boot.java.livehover; import java.util.Collection; +import java.util.Collections; +import java.util.List; import java.util.Optional; -import java.util.stream.Stream; +import java.util.stream.Collectors; import org.springframework.ide.vscode.boot.java.BootJavaLanguageServerComponents; import org.springframework.ide.vscode.boot.java.links.SourceLinkFactory; @@ -131,20 +133,20 @@ public class LiveHoverUtils { } public static boolean hasRelevantBeans(SpringBootApp app, LiveBean definedBean) { - return findRelevantBeans(app, definedBean).findAny().isPresent(); + return findRelevantBeans(app, definedBean).stream().findAny().isPresent(); } - public static Stream findRelevantBeans(SpringBootApp app, LiveBean definedBean) { + public static List findRelevantBeans(SpringBootApp app, LiveBean definedBean) { LiveBeansModel beansModel = app.getBeans(); if (beansModel != null) { - Stream relevantBeans = beansModel.getBeansOfName(definedBean.getId()).stream(); + List relevantBeans = beansModel.getBeansOfName(definedBean.getId()); String type = definedBean.getType(); if (type != null) { - relevantBeans = relevantBeans.filter(bean -> type.equals(bean.getType(true))); + relevantBeans = relevantBeans.stream().filter(bean -> type.equals(bean.getType(true))).collect(Collectors.toList()); } return relevantBeans; } - return Stream.empty(); + return Collections.emptyList(); } public static String niceAppName(SpringBootApp app) { diff --git a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/autowired/test/AutowiredHoverProviderTest.java b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/autowired/test/AutowiredHoverProviderTest.java index c43871115..098a99075 100644 --- a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/autowired/test/AutowiredHoverProviderTest.java +++ b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/autowired/test/AutowiredHoverProviderTest.java @@ -146,7 +146,7 @@ public class AutowiredHoverProviderTest { editor.assertHighlights("@Component", "@Inject"); editor.assertTrimmedHover("@Inject", - "**Autowired → `dependencyA`**\n" + + "**Autowired `autowiredClass` → `dependencyA`**\n" + "- Bean: `dependencyA` \n" + " Type: `com.example.DependencyA` \n" + " Resource: `" + Paths.get("com/example/DependencyA.class") + "`\n" + @@ -201,7 +201,7 @@ public class AutowiredHoverProviderTest { editor.assertHighlights("@Component", "@Autowired"); editor.assertTrimmedHover("@Autowired", - "**Autowired → `dependencyA` `dependencyB`**\n" + + "**Autowired `autowiredClass` → `dependencyA` `dependencyB`**\n" + "- Bean: `dependencyA` \n" + " Type: `com.example.DependencyA` \n" + " Resource: `" + Paths.get("com/example/DependencyA.class") + "`\n" + @@ -352,11 +352,11 @@ public class AutowiredHoverProviderTest { Editor editor = harness.newEditor(LanguageId.JAVA, FOO_IMPL_CONTENTS); editor.assertHighlights("@Component", "@Autowired", "@Autowired"); editor.assertHoverContains("@Autowired", 1, - "**Autowired → `superBean`**\n" + + "**Autowired `defaultFoo` → `superBean`**\n" + "- Bean: `superBean` \n" + " Type: `com.example.FooImplementation`"); editor.assertHoverContains("@Autowired", 2, - "**Autowired → `scheduler`**\n" + + "**Autowired `defaultFoo` → `scheduler`**\n" + "- Bean: `scheduler` \n" + " Type: `org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler`"); } @@ -406,12 +406,13 @@ public class AutowiredHoverProviderTest { ); editor.assertHighlights("@Controller", "@Autowired"); editor.assertHoverContains("@Autowired", - "**Autowired → `restTemplate`**\n" + + "**Autowired `myController` → `restTemplate`**\n" + "- Bean: `restTemplate` \n" + " Type: `org.springframework.web.client.RestTemplate`" ); editor.assertHoverContains("@Controller", - "**Injection report for Bean [id: myController, type: `com.example.MyController`]**" + "**Injected `myController` → _not injected anywhere_** \n" + + "Process [PID=111, name=`the-app`]" ); } @@ -463,7 +464,7 @@ public class AutowiredHoverProviderTest { editor.assertHighlights("@Component", "SomeComponent"); editor.assertTrimmedHover("SomeComponent", 2, - "**Autowired → `dependencyA` `dependencyB`**\n" + + "**Autowired `someComponent` → `dependencyA` `dependencyB`**\n" + "- Bean: `dependencyA` \n" + " Type: `com.example.DependencyA`\n" + "- Bean: `dependencyB` \n" + diff --git a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/livehover/test/BeanInjectedIntoHoverProviderTest.java b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/livehover/test/BeanInjectedIntoHoverProviderTest.java index a995fe702..e126497e9 100644 --- a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/livehover/test/BeanInjectedIntoHoverProviderTest.java +++ b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/livehover/test/BeanInjectedIntoHoverProviderTest.java @@ -95,11 +95,8 @@ public class BeanInjectedIntoHoverProviderTest { ); editor.assertHighlights("@Bean"); editor.assertTrimmedHover("@Bean", - "**Injection report for Bean [id: myFoo]**\n" + - "\n" + - "Process [PID=111, name=`the-app`]:\n" + - "\n" + - "Bean [id: myFoo, type: `hello.FooImplementation`] exists but is **Not injected anywhere**\n" + "**Injected `myFoo` → _not injected anywhere_** \n" + + "Process [PID=111, name=`the-app`]" ); } @@ -154,11 +151,8 @@ public class BeanInjectedIntoHoverProviderTest { ); 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" + "**Injected `beanId` → _not injected anywhere_** \n" + + "Process [PID=111, name=`the-app`]" ); } } @@ -209,14 +203,11 @@ public class BeanInjectedIntoHoverProviderTest { ); 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" + + "**Injected `fooImplementation` → `myController`**\n" + "- Bean: `myController` \n" + - " Type: `hello.MyController`\n" + " Type: `hello.MyController`\n" + + " \n" + + "Process [PID=111, name=`the-app`]" ); } @@ -269,14 +260,11 @@ public class BeanInjectedIntoHoverProviderTest { ); 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" + + "**Injected `fooImplementation` → `myController`**\n" + "- Bean: `myController` \n" + - " Type: `hello.MyController`\n" + " Type: `hello.MyController`\n" + + " \n" + + "Process [PID=111, name=`the-app`]" ); } @@ -323,15 +311,12 @@ public class BeanInjectedIntoHoverProviderTest { ); 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" + + "**Injected `fooImplementation` → `myController`**\n" + "- Bean: `myController` \n" + " Type: `hello.MyController` \n" + - " Resource: `" + Paths.get("hello/MyController.class") + "`" + " Resource: `" + Paths.get("hello/MyController.class") + "`\n" + + " \n" + + "Process [PID=111, name=`the-app`]" ); } @@ -377,15 +362,12 @@ public class BeanInjectedIntoHoverProviderTest { ); 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" + + "**Injected `fooImplementation` → `myController`**\n" + "- Bean: `myController` \n" + " Type: `hello.MyController` \n" + - " Resource: `hello/MyController.class`" + " Resource: `hello/MyController.class`\n" + + " \n" + + "Process [PID=111, name=`the-app`]" ); } @@ -435,16 +417,13 @@ public class BeanInjectedIntoHoverProviderTest { ); 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" + + "**Injected `fooImplementation` → `myController` `otherBean`**\n" + "- Bean: `myController` \n" + " Type: `hello.MyController`\n" + "- Bean: `otherBean` \n" + - " Type: `hello.OtherBean`\n" + " Type: `hello.OtherBean`\n" + + " \n" + + "Process [PID=111, name=`the-app`]" ); } diff --git a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/livehover/test/BeansByTypeHoverProviderTest.java b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/livehover/test/BeansByTypeHoverProviderTest.java index cea6fc61f..e80574434 100644 --- a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/livehover/test/BeansByTypeHoverProviderTest.java +++ b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/livehover/test/BeansByTypeHoverProviderTest.java @@ -134,14 +134,11 @@ public class BeansByTypeHoverProviderTest { ); 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" + + "**Injected `scannedRandomClass` → `randomOtherBean`**\n" + "- Bean: `randomOtherBean` \n" + - " Type: `randomOtherBeanType`" + " Type: `randomOtherBeanType`\n" + + " \n" + + "Process [PID=111, name=`the-app`]" ); } @@ -190,14 +187,12 @@ public class BeansByTypeHoverProviderTest { ); editor.assertHighlights("ScannedFunctionClass"); editor.assertTrimmedHover("ScannedFunctionClass", - "**Injection report for Bean [id: scannedFunctionClass, type: `com.example.ScannedFunctionClass`]**\n" + - "\n" + - "Process [PID=111, name=`the-app`]:\n" + - "\n" + - "Bean [id: scannedFunctionClass, type: `com.example.ScannedFunctionClass`] injected into:\n" + - "\n" + + "**Injected `scannedFunctionClass` → 1 bean**\n" + "- Bean: `org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration` \n" + - " Type: `org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration`" + " Type: `org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration`\n" + + " \n" + + "Process [PID=111, name=`the-app`]" + ); } @@ -233,11 +228,8 @@ public class BeansByTypeHoverProviderTest { ); editor.assertHighlights("@Component"); editor.assertTrimmedHover("@Component", - "**Injection report for Bean [id: fooImplementation, type: `com.example.FooImplementation`]**\n" + - "\n" + - "Process [PID=111, name=`the-app`]:\n" + - "\n" + - "Bean [id: fooImplementation, type: `com.example.FooImplementation`] exists but is **Not injected anywhere**\n" + "**Injected `fooImplementation` → _not injected anywhere_** \n" + + "Process [PID=111, name=`the-app`]" ); } diff --git a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/livehover/test/ComponentInjectionsHoverProviderTest.java b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/livehover/test/ComponentInjectionsHoverProviderTest.java index 1301aa66b..3d7f6d1dc 100644 --- a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/livehover/test/ComponentInjectionsHoverProviderTest.java +++ b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/livehover/test/ComponentInjectionsHoverProviderTest.java @@ -12,7 +12,6 @@ package org.springframework.ide.vscode.boot.java.livehover.test; import static org.junit.Assert.assertTrue; -import java.nio.file.Paths; import java.time.Duration; import org.junit.Before; @@ -107,11 +106,8 @@ public class ComponentInjectionsHoverProviderTest { ); editor.assertHighlights("@Component"); editor.assertTrimmedHover("@Component", - "**Injection report for Bean [id: fooImplementation, type: `com.example.FooImplementation`]**\n" + - "\n" + - "Process [PID=111, name=`the-app`]:\n" + - "\n" + - "Bean [id: fooImplementation, type: `com.example.FooImplementation`] exists but is **Not injected anywhere**\n" + "**Injected `fooImplementation` → _not injected anywhere_** \n" + + "Process [PID=111, name=`the-app`]" ); } @@ -159,14 +155,11 @@ public class ComponentInjectionsHoverProviderTest { ); editor.assertHighlights("@Component"); editor.assertTrimmedHover("@Component", - "**Injection report for Bean [id: fooImplementation, type: `com.example.FooImplementation`]**\n" + - "\n" + - "Process [PID=111, name=`the-app`]:\n" + - "\n" + - "Bean [id: fooImplementation, type: `com.example.FooImplementation`] injected into:\n" + - "\n" + + "**Injected `fooImplementation` → `myController`**\n" + "- Bean: `myController` \n" + - " Type: `com.example.MyController`" + " Type: `com.example.MyController`\n" + + " \n" + + "Process [PID=111, name=`the-app`]\n" ); } @@ -214,16 +207,13 @@ public class ComponentInjectionsHoverProviderTest { ); editor.assertHighlights("@Component"); editor.assertTrimmedHover("@Component", - "**Injection report for Bean [id: fooImplementation, type: `com.example.FooImplementation`]**\n" + - "\n" + - "Process [PID=111, name=`the-app`]:\n" + - "\n" + - "Bean [id: fooImplementation, type: `com.example.FooImplementation`] injected into:\n" + - "\n" + + "**Injected `fooImplementation` → `myController` `otherBean`**\n" + "- Bean: `myController` \n" + " Type: `com.example.MyController`\n" + "- Bean: `otherBean` \n" + - " Type: `com.example.OtherBean`" + " Type: `com.example.OtherBean`\n" + + " \n" + + "Process [PID=111, name=`the-app`]" ); } @@ -273,25 +263,21 @@ public class ComponentInjectionsHoverProviderTest { ); editor.assertHighlights("@Component"); editor.assertTrimmedHover("@Component", - "**Injection report for Bean [id: fooImplementation, type: `com.example.FooImplementation`]**\n" + - "\n" + - "Process [PID=1001, name=`app-instance-1`]:\n" + - "\n" + - "Bean [id: fooImplementation, type: `com.example.FooImplementation`] injected into:\n" + - "\n" + + "**Injected `fooImplementation` → `myController` `otherBean`**\n" + "- Bean: `myController` \n" + " Type: `com.example.MyController`\n" + "- Bean: `otherBean` \n" + " Type: `com.example.OtherBean`\n" + - "\n" + - "Process [PID=1002, name=`app-instance-2`]:\n" + - "\n" + - "Bean [id: fooImplementation, type: `com.example.FooImplementation`] injected into:\n" + - "\n" + + " \n" + + "Process [PID=1001, name=`app-instance-1`]" + + " \n \n" + + "**Injected `fooImplementation` → `myController` `otherBean`**\n" + "- Bean: `myController` \n" + " Type: `com.example.MyController`\n" + "- Bean: `otherBean` \n" + - " Type: `com.example.OtherBean`\n" + " Type: `com.example.OtherBean`\n" + + " \n" + + "Process [PID=1002, name=`app-instance-2`]" ); } @@ -344,14 +330,11 @@ public class ComponentInjectionsHoverProviderTest { ); editor.assertHighlights("@Component"); editor.assertHoverExactText("@Component", - "**Injection report for Bean [id: fooImplementation, type: `com.example.FooImplementation`]**\n" + - "\n" + - "Process [PID=111, name=`the-app`]:\n" + - "\n" + - "Bean [id: fooImplementation, type: `com.example.FooImplementation`] injected into:\n" + - "\n" + + "**Injected `fooImplementation` → `myController`**\n" + "- Bean: `myController` \n" + - " Type: `com.example.MyController`" + " Type: `com.example.MyController`\n" + + " \n" + + "Process [PID=111, name=`the-app`]" ); } @@ -404,14 +387,11 @@ public class ComponentInjectionsHoverProviderTest { ); editor.assertHighlights("@Component"); editor.assertTrimmedHover("@Component", - "**Injection report for Bean [id: alternateFooImplementation, type: `com.example.FooImplementation`]**\n" + - "\n" + - "Process [PID=111, name=`the-app`]:\n" + - "\n" + - "Bean [id: alternateFooImplementation, type: `com.example.FooImplementation`] injected into:\n" + - "\n" + + "**Injected `alternateFooImplementation` → `otherBean`**\n" + "- Bean: `otherBean` \n" + - " Type: `com.example.OtherBean`\n" + " Type: `com.example.OtherBean`\n" + + " \n" + + "Process [PID=111, name=`the-app`]" ); } @@ -451,7 +431,7 @@ public class ComponentInjectionsHoverProviderTest { " }\n" + "}\n" ); - editor.assertHighlights(/*MONE*/); + editor.assertHighlights(/*NONE*/); editor.assertNoHover("@Component"); } @@ -518,12 +498,8 @@ public class ComponentInjectionsHoverProviderTest { ); editor.assertHighlights("@Component", "AutowiredClass"); editor.assertTrimmedHover("@Component", - "**Injection report for Bean [id: autowiredClass, type: `com.example.AutowiredClass`]**\n" + - "\n" + - "Process [PID=111, name=`the-app`]:\n" + - "\n" + - "Bean [id: autowiredClass, type: `com.example.AutowiredClass`] exists but is **Not injected anywhere**\n" + - "\n\n" + "**Injected `autowiredClass` → _not injected anywhere_** \n" + + "Process [PID=111, name=`the-app`]\n" ); } @@ -570,11 +546,8 @@ public class ComponentInjectionsHoverProviderTest { ); editor.assertHighlights("@Component", "@Autowired"); editor.assertTrimmedHover("@Component", - "**Injection report for Bean [id: autowiredClass, type: `com.example.AutowiredClass`]**\n" + - "\n" + - "Process [PID=111, name=`the-app`]:\n" + - "\n" + - "Bean [id: autowiredClass, type: `com.example.AutowiredClass`] exists but is **Not injected anywhere**\n" + "**Injected `autowiredClass` → _not injected anywhere_** \n" + + "Process [PID=111, name=`the-app`]\n" ); } @@ -613,7 +586,8 @@ public class ComponentInjectionsHoverProviderTest { ); editor.assertHighlights("@SpringBootApplication"); editor.assertHoverContains("@SpringBootApplication", - "**Injection report for Bean [id: demoApplication, type: `com.example.DemoApplication`]**" + "**Injected `demoApplication` → _not injected anywhere_** \n" + + "Process [PID=111, name=`the-app`]" ); } @@ -654,7 +628,8 @@ public class ComponentInjectionsHoverProviderTest { ); editor.assertHighlights("@SpringBootApplication"); editor.assertHoverContains("@SpringBootApplication", - "**Injection report for Bean [id: demoApplication.InnerClass, type: `com.example.DemoApplication.InnerClass`]**" + "**Injected `demoApplication.InnerClass` → _not injected anywhere_** \n" + + "Process [PID=111, name=`the-app`]" ); } @@ -698,7 +673,8 @@ public class ComponentInjectionsHoverProviderTest { ); editor.assertHighlights("@SpringBootApplication"); editor.assertHoverContains("@SpringBootApplication", - "**Injection report for Bean [id: demoApplication.InnerClass.InnerInnerClass, type: `com.example.DemoApplication.InnerClass.InnerInnerClass`]**" + "**Injected `demoApplication.InnerClass.InnerInnerClass` → _not injected anywhere_** \n" + + "Process [PID=111, name=`the-app`]" ); } }