PT 162740382 - Support beans from types with multiple starting upper

case
This commit is contained in:
nsingh@pivotal.io
2018-12-28 04:01:08 -08:00
parent 9d6c5584cf
commit e82e122bd7
6 changed files with 42 additions and 17 deletions

View File

@@ -33,6 +33,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.boot.java.Annotations;
import org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchies;
import org.springframework.ide.vscode.boot.java.beans.BeanUtils;
import org.springframework.ide.vscode.boot.java.handlers.HoverProvider;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
import org.springframework.ide.vscode.boot.java.livehover.ComponentInjectionsHoverProvider;
@@ -298,7 +299,7 @@ public class AutowiredHoverProvider implements HoverProvider {
String beanTypeName = beanType.getName();
if (StringUtil.hasText(beanTypeName)) {
return LiveBean.builder()
.id(Character.toLowerCase(beanTypeName.charAt(0)) + beanTypeName.substring(1))
.id(getId(beanTypeName))
.type(beanTypeName).build();
}
}
@@ -306,6 +307,10 @@ public class AutowiredHoverProvider implements HoverProvider {
return null;
}
private String getId(String beanTypeName) {
return BeanUtils.getBeanName(beanTypeName);
}
@Override
public Hover provideHover(MethodDeclaration methodDeclaration, int offset, TextDocument doc, IJavaProject project, SpringBootApp[] runningApps) {
LiveBean definedBean = getDefinedBeanForImplicitAutowiredConstructor(methodDeclaration);

View File

@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2018 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.beans;
import org.springframework.ide.vscode.commons.util.StringUtil;
public class BeanUtils {
public static String getBeanName(String beanName) {
if (StringUtil.hasText(beanName) && beanName.length() > 0 && Character.isUpperCase(beanName.charAt(0))) {
// PT 162740382 - Special case: If more than one character is upper case, do not
// convert bean name to starting lower case. only convert if name has one character
// or the second character in the name is not upper case
if (beanName.length() == 1 || !Character.isUpperCase(beanName.charAt(1))) {
beanName = Character.toLowerCase(beanName.charAt(0)) + beanName.substring(1);
}
}
return beanName;
}
}

View File

@@ -95,10 +95,7 @@ public class ComponentSymbolProvider implements SymbolProvider {
TypeDeclaration type = (TypeDeclaration) parent;
String beanName = type.getName().toString();
if (beanName.length() > 0 && Character.isUpperCase(beanName.charAt(0))) {
beanName = Character.toLowerCase(beanName.charAt(0)) + beanName.substring(1);
}
return beanName;
return BeanUtils.getBeanName(beanName);
}
return null;
}

View File

@@ -19,6 +19,7 @@ import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.lsp4j.Location;
import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.SymbolKind;
import org.springframework.ide.vscode.boot.java.beans.BeanUtils;
import org.springframework.ide.vscode.boot.java.handlers.EnhancedSymbolInformation;
import org.springframework.ide.vscode.boot.java.handlers.SymbolProvider;
import org.springframework.ide.vscode.boot.java.utils.ASTUtils;
@@ -128,10 +129,7 @@ public class DataRepositorySymbolProvider implements SymbolProvider {
private static String getBeanName(TypeDeclaration typeDeclaration) {
String beanName = typeDeclaration.getName().toString();
if (beanName.length() > 0 && Character.isUpperCase(beanName.charAt(0))) {
beanName = Character.toLowerCase(beanName.charAt(0)) + beanName.substring(1);
}
return beanName;
return BeanUtils.getBeanName(beanName);
}
@Override

View File

@@ -29,6 +29,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.boot.java.Annotations;
import org.springframework.ide.vscode.boot.java.annotations.AnnotationHierarchies;
import org.springframework.ide.vscode.boot.java.beans.BeanUtils;
import org.springframework.ide.vscode.boot.java.links.SourceLinks;
import org.springframework.ide.vscode.boot.java.utils.ASTUtils;
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
@@ -82,10 +83,7 @@ public class ComponentInjectionsHoverProvider extends AbstractInjectedIntoHoverP
return getBeanType(beanType).toString();
}
if (StringUtil.hasText(typeName)) {
return Character.toLowerCase(typeName.charAt(0)) + typeName.substring(1);
}
return null;
return BeanUtils.getBeanName(typeName);
});
}

View File

@@ -18,6 +18,7 @@ import java.util.function.Supplier;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.springframework.ide.vscode.boot.java.beans.BeanUtils;
import org.springframework.ide.vscode.commons.util.text.DocumentRegion;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
@@ -84,10 +85,7 @@ public class FunctionUtils {
protected static String getBeanName(TypeDeclaration typeDeclaration) {
String beanName = typeDeclaration.getName().toString();
if (beanName.length() > 0 && Character.isUpperCase(beanName.charAt(0))) {
beanName = Character.toLowerCase(beanName.charAt(0)) + beanName.substring(1);
}
return beanName;
return BeanUtils.getBeanName(beanName);
}
protected static boolean isAbstractClass(TypeDeclaration typeDeclaration, ITypeBinding resolvedType) {