Account for Boot 3 bean type CGLib suffix

This commit is contained in:
aboyko
2023-03-31 17:24:38 -04:00
parent 4c7e821da8
commit 9ad7311478
3 changed files with 76 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2018 Pivotal, Inc.
* Copyright (c) 2017, 2023 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -98,15 +98,7 @@ public class LiveBean {
if (type != null) {
if (stripCGLib) {
int chop = type.indexOf("$$EnhancerBySpringCGLIB$$");
if (chop >= 0) {
type = type.substring(0, chop);
}
chop = type.indexOf("$$Lambda$");
if (chop >= 0) {
type = type.substring(0, chop);
}
type = getTypeWithoutCGLib(type);
}
}
@@ -130,4 +122,19 @@ public class LiveBean {
return new Builder();
}
public static String getTypeWithoutCGLib(String type) {
int chop = type.indexOf("$$EnhancerBySpringCGLIB$$");
if (chop < 0) {
chop = type.indexOf("$$SpringCGLIB$$");
}
if (chop >= 0) {
type = type.substring(0, chop);
}
chop = type.indexOf("$$Lambda$");
if (chop >= 0) {
type = type.substring(0, chop);
}
return type;
}
}

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2020 Pivotal, Inc.
* Copyright (c) 2017, 2023 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -32,6 +32,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.boot.java.handlers.HoverProvider;
import org.springframework.ide.vscode.boot.java.livehover.LiveHoverUtils;
import org.springframework.ide.vscode.boot.java.livehover.v2.LiveBean;
import org.springframework.ide.vscode.boot.java.livehover.v2.LiveRequestMapping;
import org.springframework.ide.vscode.boot.java.livehover.v2.RequestMappingMetrics;
import org.springframework.ide.vscode.boot.java.livehover.v2.SpringProcessLiveData;
@@ -213,12 +214,7 @@ public class RequestMappingHoverProvider implements HoverProvider {
String rqClassName = rm.getFullyQualifiedClassName();
if (rqClassName != null) {
int chop = rqClassName.indexOf("$$EnhancerBySpringCGLIB$$");
if (chop >= 0) {
rqClassName = rqClassName.substring(0, chop);
}
rqClassName = rqClassName.replace('$', '.');
rqClassName = LiveBean.getTypeWithoutCGLib(rqClassName).replace('$', '.');
ASTNode parent = annotation.getParent();
if (parent instanceof MethodDeclaration) {

View File

@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2019 Pivotal, Inc.
* Copyright (c) 2017, 2023 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -327,6 +327,61 @@ public class ComponentInjectionsHoverProviderTest {
"Process [PID=111, name=`the-app`]\n"
);
}
@Test
void componentWithOneBoot3CGILibInjection() throws Exception {
LiveBeansModel beans = LiveBeansModel.builder()
.add(LiveBean.builder()
.id("fooImplementation")
.type("com.example.FooImplementation$$SpringCGLIB$$Blah")
.build()
)
.add(LiveBean.builder()
.id("myController")
.type("com.example.MyController$$SpringCGLIB$$Blah")
.dependencies("fooImplementation")
.build()
)
.add(LiveBean.builder()
.id("irrelevantBean")
.type("com.example.IrrelevantBean$$SpringCGLIB$$Blah")
.dependencies("myController")
.build()
)
.build();
SpringProcessLiveData liveData = new SpringProcessLiveDataBuilder()
.processID("111")
.processName("the-app")
.beans(beans)
.build();
liveDataProvider.add("processkey", liveData);
Editor editor = harness.newEditor(LanguageId.JAVA,
"package com.example;\n" +
"\n" +
"import org.springframework.stereotype.Component;\n" +
"\n" +
"@Component\n" +
"public class FooImplementation implements Foo {\n" +
"\n" +
" @Override\n" +
" public void doSomeFoo() {\n" +
" System.out.println(\"Foo do do do!\");\n" +
" }\n" +
"}\n"
);
editor.assertHighlights("@Component");
editor.assertTrimmedHover("@Component",
"**&#8594; `MyController`**\n" +
"- Bean: `myController` \n" +
" Type: `com.example.MyController`\n" +
" \n" +
"Bean id: `fooImplementation` \n" +
"Process [PID=111, name=`the-app`]\n"
);
}
@Test
void componentWithMultipleInjections() throws Exception {