Fix PT-153072942

Ignore `$$EnhancerBySpringCGLIB$$` in determining whether a
live bean corresponds to a bean defined in source-code.
This commit is contained in:
Kris De Volder
2017-11-21 14:20:05 -08:00
parent cfa0f5f13c
commit 6f1e80944c
4 changed files with 50 additions and 6 deletions

View File

@@ -71,7 +71,7 @@ public class LiveHoverUtils {
Stream<LiveBean> relevantBeans = beansModel.getBeansOfName(definedBean.getId()).stream();
String type = definedBean.getType();
if (type != null) {
relevantBeans = relevantBeans.filter(bean -> type.equals(bean.getType()));
relevantBeans = relevantBeans.filter(bean -> type.equals(bean.getType(true)));
}
return relevantBeans;
}

View File

@@ -585,4 +585,42 @@ public class ComponentInjectionsHoverProviderTest {
);
}
@Test public void bug_153072942_SpringBootApplication__withCGLib_is_a_Component() throws Exception {
LiveBeansModel beans = LiveBeansModel.builder()
.add(LiveBean.builder()
.id("demoApplication")
.type("com.example.DemoApplication$$EnhancerBySpringCGLIB$$f378241f")
.build()
)
.build();
mockAppProvider.builder()
.isSpringBootApp(true)
.processId("111")
.processName("the-app")
.beans(beans)
.build();
Editor editor = harness.newEditor(LanguageId.JAVA,
"package com.example;\n" +
"\n" +
"import org.springframework.boot.SpringApplication;\n" +
"import org.springframework.boot.autoconfigure.SpringBootApplication;\n" +
"import org.springframework.context.annotation.Bean;\n" +
"import org.springframework.web.client.RestTemplate;\n" +
"\n" +
"@SpringBootApplication\n" +
"public class DemoApplication {\n" +
" \n" +
"\n" +
" public static void main(String[] args) {\n" +
" SpringApplication.run(DemoApplication.class, args);\n" +
" }\n" +
"}\n"
);
editor.assertHighlights("@SpringBootApplication");
editor.assertHoverContains("@SpringBootApplication",
"**Injection report for Bean [id: demoApplication, type: `com.example.DemoApplication`]**"
);
}
}

View File

@@ -93,6 +93,17 @@ public class LiveBean {
return type;
}
public String getType(boolean stripCGLib) {
String type = this.type;
if (stripCGLib) {
int chop = type.indexOf("$$EnhancerBySpringCGLIB$$");
if (chop>=0) {
type = type.substring(0, chop);
}
}
return type;
}
public String getResource() {
return resource;
}

View File

@@ -11,9 +11,7 @@
package org.springframework.ide.vscode.commons.boot.app.cli.livebean;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;
import org.json.JSONArray;
import org.json.JSONObject;
@@ -21,9 +19,6 @@ import org.springframework.ide.vscode.commons.util.Log;
import org.springframework.ide.vscode.commons.util.StringUtil;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.MultimapBuilder;
/**
* @author Martin Lippert