From 9ad73114789823965d0e043c4dfb8c4436973a08 Mon Sep 17 00:00:00 2001 From: aboyko Date: Fri, 31 Mar 2023 17:24:38 -0400 Subject: [PATCH] Account for Boot 3 bean type CGLib suffix --- .../boot/java/livehover/v2/LiveBean.java | 27 +++++---- .../RequestMappingHoverProvider.java | 10 +--- .../ComponentInjectionsHoverProviderTest.java | 57 ++++++++++++++++++- 3 files changed, 76 insertions(+), 18 deletions(-) diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/LiveBean.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/LiveBean.java index c2f46f266..3371bdea5 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/LiveBean.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/LiveBean.java @@ -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; + } } diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/RequestMappingHoverProvider.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/RequestMappingHoverProvider.java index 10bc46e2c..6158985c2 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/RequestMappingHoverProvider.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/RequestMappingHoverProvider.java @@ -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) { 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 deb366392..c72a9fc2b 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 @@ -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", + "**→ `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 {