added missing resource information for automatically wired constructor live hovers
This commit is contained in:
@@ -82,7 +82,7 @@ public abstract class AbstractInjectedIntoHoverProvider implements HoverProvider
|
||||
|
||||
for (LiveBean bean : relevantBeans) {
|
||||
addInjectedInto(definedBean, hover, beans, bean, project);
|
||||
addAutomaticallyWiredContructor(hover, annotation, beans, bean);
|
||||
addAutomaticallyWiredContructor(hover, annotation, beans, bean, project);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,7 @@ public abstract class AbstractInjectedIntoHoverProvider implements HoverProvider
|
||||
|
||||
protected abstract LiveBean getDefinedBean(Annotation annotation);
|
||||
|
||||
protected void addAutomaticallyWiredContructor(StringBuilder hover, Annotation annotation, LiveBeansModel beans, LiveBean bean) {
|
||||
protected void addAutomaticallyWiredContructor(StringBuilder hover, Annotation annotation, LiveBeansModel beans, LiveBean bean, IJavaProject project) {
|
||||
//This doesn't really belong here, but it accomodates Martin's additional logic to handle implicitly
|
||||
//@Autowired constructor.
|
||||
//This does nothing by default as its really only relevant to @Component annotation report.
|
||||
|
||||
@@ -21,12 +21,13 @@ import org.springframework.ide.vscode.boot.java.Annotations;
|
||||
import org.springframework.ide.vscode.boot.java.utils.ASTUtils;
|
||||
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.StringUtil;
|
||||
|
||||
public class ComponentInjectionsHoverProvider extends AbstractInjectedIntoHoverProvider {
|
||||
|
||||
@Override
|
||||
protected void addAutomaticallyWiredContructor(StringBuilder hover, Annotation annotation, LiveBeansModel beans, LiveBean bean) {
|
||||
protected void addAutomaticallyWiredContructor(StringBuilder hover, Annotation annotation, LiveBeansModel beans, LiveBean bean, IJavaProject project) {
|
||||
TypeDeclaration typeDecl = ASTUtils.findDeclaringType(annotation);
|
||||
if (typeDecl != null) {
|
||||
MethodDeclaration[] constructors = ASTUtils.findConstructors(typeDecl);
|
||||
@@ -44,7 +45,7 @@ public class ComponentInjectionsHoverProvider extends AbstractInjectedIntoHoverP
|
||||
}
|
||||
List<LiveBean> dependencyBeans = beans.getBeansOfName(injectedBean);
|
||||
for (LiveBean dependencyBean : dependencyBeans) {
|
||||
hover.append("- " + LiveHoverUtils.showBean(dependencyBean));
|
||||
hover.append("- " + LiveHoverUtils.showBeanWithResource(dependencyBean, " ", project));
|
||||
}
|
||||
firstDependency = false;
|
||||
}
|
||||
|
||||
@@ -89,11 +89,13 @@ public class AutowiredHoverProviderTest {
|
||||
.add(LiveBean.builder()
|
||||
.id("dependencyA")
|
||||
.type("com.example.DependencyA")
|
||||
.fileResource(harness.getOutputFolder() + "/com/example/DependencyA.class")
|
||||
.build()
|
||||
)
|
||||
.add(LiveBean.builder()
|
||||
.id("dependencyB")
|
||||
.type("com.example.DependencyB")
|
||||
.classpathResource("com/example/DependencyB.class")
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
@@ -128,9 +130,11 @@ public class AutowiredHoverProviderTest {
|
||||
"Bean [id: autowiredClass, type: `com.example.AutowiredClass`] got autowired with:\n" +
|
||||
"\n" +
|
||||
"- Bean: dependencyA \n" +
|
||||
" Type: `com.example.DependencyA`\n" +
|
||||
" Type: `com.example.DependencyA` \n" +
|
||||
" Resource: `com/example/DependencyA.class`\n" +
|
||||
"- Bean: dependencyB \n" +
|
||||
" Type: `com.example.DependencyB`\n"
|
||||
" Type: `com.example.DependencyB` \n" +
|
||||
" Resource: `com/example/DependencyB.class`\n"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,13 +14,11 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
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.maven.java.MavenJavaProject;
|
||||
import org.springframework.ide.vscode.commons.util.text.LanguageId;
|
||||
import org.springframework.ide.vscode.languageserver.testharness.Editor;
|
||||
@@ -223,7 +221,7 @@ public class BeanInjectedIntoHoverProviderTest {
|
||||
|
||||
@Test
|
||||
public void beanWithFileResource() throws Exception {
|
||||
Path of = getOutputFolder();
|
||||
Path of = harness.getOutputFolder();
|
||||
LiveBeansModel beans = LiveBeansModel.builder()
|
||||
.add(LiveBean.builder()
|
||||
.id("fooImplementation")
|
||||
@@ -278,7 +276,6 @@ public class BeanInjectedIntoHoverProviderTest {
|
||||
|
||||
@Test
|
||||
public void beanWithClasspathResource() throws Exception {
|
||||
Path of = getOutputFolder();
|
||||
LiveBeansModel beans = LiveBeansModel.builder()
|
||||
.add(LiveBean.builder()
|
||||
.id("fooImplementation")
|
||||
@@ -331,10 +328,6 @@ public class BeanInjectedIntoHoverProviderTest {
|
||||
);
|
||||
}
|
||||
|
||||
private Path getOutputFolder() {
|
||||
return harness.getProjectFinder().find(null).get().getClasspath().getOutputFolder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanWithMultipleInjections() throws Exception {
|
||||
LiveBeansModel beans = LiveBeansModel.builder()
|
||||
|
||||
@@ -486,11 +486,13 @@ public class ComponentInjectionsHoverProviderTest {
|
||||
.add(LiveBean.builder()
|
||||
.id("dependencyA")
|
||||
.type("com.example.DependencyA")
|
||||
.fileResource(harness.getOutputFolder() + "/com/example/DependencyA.class")
|
||||
.build()
|
||||
)
|
||||
.add(LiveBean.builder()
|
||||
.id("dependencyB")
|
||||
.type("com.example.DependencyB")
|
||||
.classpathResource("com/example/DependencyB.class")
|
||||
.build()
|
||||
)
|
||||
.build();
|
||||
@@ -522,8 +524,12 @@ public class ComponentInjectionsHoverProviderTest {
|
||||
"Bean [id: autowiredClass, type: `com.example.AutowiredClass`] exists but is **Not injected anywhere**\n" +
|
||||
"Bean [id: autowiredClass, type: `com.example.AutowiredClass`] got autowired with:\n" +
|
||||
"\n" +
|
||||
"- Bean [id: dependencyA, type: `com.example.DependencyA`]\n" +
|
||||
"- Bean [id: dependencyB, type: `com.example.DependencyB`]\n"
|
||||
"- Bean: dependencyA \n" +
|
||||
" Type: `com.example.DependencyA` \n" +
|
||||
" Resource: `com/example/DependencyA.class`\n" +
|
||||
"- Bean: dependencyB \n" +
|
||||
" Type: `com.example.DependencyB` \n" +
|
||||
" Resource: `com/example/DependencyB.class`"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.project.harness;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
|
||||
import org.junit.Assert;
|
||||
@@ -123,4 +124,10 @@ public class BootLanguageServerHarness extends LanguageServerHarness<BootJavaLan
|
||||
public void useProject(IJavaProject p) throws Exception {
|
||||
indexHarness.useProject(p);
|
||||
}
|
||||
|
||||
public Path getOutputFolder() {
|
||||
return getProjectFinder().find(null).get().getClasspath().getOutputFolder();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user