From 457423e005beae7ade72e3b95c1abf7b1cbb58bc Mon Sep 17 00:00:00 2001 From: BoykoAlex Date: Tue, 15 Feb 2022 20:15:40 -0500 Subject: [PATCH] Fixed data symbols provider tests --- .../data/DataRepositorySymbolProvider.java | 63 ++++++++++--------- .../DataRepositorySymbolProviderTest.java | 2 +- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/data/DataRepositorySymbolProvider.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/data/DataRepositorySymbolProvider.java index c6ea4013b..3feaade1c 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/data/DataRepositorySymbolProvider.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/data/DataRepositorySymbolProvider.java @@ -95,39 +95,46 @@ public class DataRepositorySymbolProvider extends AbstractSymbolProvider { private static Tuple4 getRepositoryBean(ClassDeclaration typeDeclaration, TextDocument doc, FullyQualified resolvedType) { - for (FullyQualified resolvedInterface : resolvedType.getInterfaces()) { - if (Constants.REPOSITORY_TYPE.equals(resolvedInterface.getFullyQualifiedName())) { - String beanName = getBeanName(typeDeclaration); - String beanType = ORAstUtils.getSimpleNameWithParamTypes(resolvedInterface); - - String domainType = null; - if (resolvedInterface instanceof Parameterized) { - List typeParams = ((Parameterized)resolvedInterface).getTypeParameters(); - if (typeParams != null && !typeParams.isEmpty()) { - FullyQualified typeParam = TypeUtils.asFullyQualified(typeParams.get(0)); - domainType = typeParam == null ? null : ORAstUtils.getSimpleNameWithParamTypes(typeParam); - } - } - - DocumentRegion region = ORAstUtils.nodeRegion(doc, typeDeclaration.getName()); - - return Tuples.of(beanName, beanType.toString(), domainType, region); - } else { - Tuple4 result = getRepositoryBean(typeDeclaration, doc, resolvedInterface); - if (result != null) { - return result; + if (TypeUtils.isAssignableTo(Constants.REPOSITORY_TYPE, resolvedType)) { + List typeParams = calculateTypeParams(resolvedType); + + String domainType = null; + String beanName = getBeanName(typeDeclaration); + StringBuilder beanType = new StringBuilder(Constants.REPOSITORY_TYPE.substring(Constants.REPOSITORY_TYPE.lastIndexOf('.') + 1)); + if (typeParams != null) { + beanType.append(typeParams.stream().map(ORAstUtils::getSimpleNameWithParamTypes).collect(Collectors.joining(",", "<", ">"))); + if (!typeParams.isEmpty()) { + FullyQualified typeParam = TypeUtils.asFullyQualified(typeParams.get(0)); + domainType = typeParam == null ? null : ORAstUtils.getSimpleNameWithParamTypes(typeParam); } } + + DocumentRegion region = ORAstUtils.nodeRegion(doc, typeDeclaration.getName()); + + return Tuples.of(beanName, beanType.toString(), domainType, region); } - FullyQualified superclass = resolvedType.getSupertype(); - if (superclass != null) { - return getRepositoryBean(typeDeclaration, doc, superclass); - } else { - return null; + return null; + } + + private static List calculateTypeParams(JavaType type) { + if (type instanceof FullyQualified) { + if (type instanceof Parameterized) { + return ((Parameterized) type).getTypeParameters(); + } + FullyQualified fqType = (FullyQualified) type; + for (FullyQualified i : fqType.getInterfaces()) { + List res = calculateTypeParams(i); + if (res != null) { + return res; + } + } + FullyQualified superType = fqType.getSupertype(); + if (superType != null) { + return calculateTypeParams(superType); + } } - - + return null; } private static String getBeanName(ClassDeclaration typeDeclaration) { diff --git a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/data/test/DataRepositorySymbolProviderTest.java b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/data/test/DataRepositorySymbolProviderTest.java index 23a4316e5..63e4b7913 100644 --- a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/data/test/DataRepositorySymbolProviderTest.java +++ b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/boot/java/data/test/DataRepositorySymbolProviderTest.java @@ -61,7 +61,7 @@ public class DataRepositorySymbolProviderTest { projectFinder.find(new TextDocumentIdentifier(projectDir)).get(); CompletableFuture initProject = indexer.waitOperation(); - initProject.get(25000000L, TimeUnit.SECONDS); + initProject.get(20, TimeUnit.SECONDS); } @Test