fix: 修复转大驼峰命名失败
This commit is contained in:
parent
16a8170e86
commit
8f3ea1e87f
|
@ -3,8 +3,6 @@ package cn.bunny.core;
|
|||
import com.google.common.base.CaseFormat;
|
||||
import org.assertj.core.util.introspection.CaseFormatUtils;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/* 类型转换,数据库转Java类型等 */
|
||||
public class TypeConvertCore {
|
||||
|
||||
|
@ -49,27 +47,15 @@ public class TypeConvertCore {
|
|||
public static String convertToCamelCase(String name, boolean firstLetterCapital) {
|
||||
if (name == null || name.isEmpty()) return name;
|
||||
|
||||
// 转成小驼峰
|
||||
String lowerCamelCase = CaseFormatUtils.toCamelCase(name);
|
||||
|
||||
// 首字母不大写
|
||||
if (!firstLetterCapital) return CaseFormatUtils.toCamelCase(name);
|
||||
|
||||
// 检查是否全大写带下划线 (UPPER_UNDERSCORE)
|
||||
if (Pattern.matches("^[A-Z]+(_[A-Z]+)*$", name)) {
|
||||
return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name);
|
||||
if (!firstLetterCapital) {
|
||||
return lowerCamelCase;
|
||||
}
|
||||
|
||||
// 检查是否小写带下划线 (LOWER_UNDERSCORE)
|
||||
if (Pattern.matches("^[a-z]+(_[a-z]+)*$", name)) {
|
||||
return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, name);
|
||||
}
|
||||
|
||||
// 检查是否大驼峰 (UpperCamelCase)
|
||||
if (Character.isUpperCase(name.charAt(0)) &&
|
||||
!name.contains("_") &&
|
||||
name.chars().anyMatch(Character::isLowerCase)) {
|
||||
return CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_CAMEL, name);
|
||||
}
|
||||
|
||||
// 默认认为是小驼峰 (lowerCamelCase)
|
||||
return CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, name);
|
||||
// 将小驼峰转成大驼峰
|
||||
return CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, lowerCamelCase);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,8 @@ public class VmsUtil {
|
|||
String CamelCase = TypeConvertCore.convertToCamelCase(className, true);
|
||||
// 小驼峰名称
|
||||
String camelCase = TypeConvertCore.convertToCamelCase(className);
|
||||
|
||||
System.out.println("CamelCase:" + CamelCase);
|
||||
System.out.println("camelCase:" + camelCase);
|
||||
// 当前文件名
|
||||
String filename = splitPaths[splitPathsSize];
|
||||
filename = filename.replace(".vm" , "" );
|
||||
|
|
|
@ -32,5 +32,12 @@ public class StringFormatTest {
|
|||
System.out.println(TypeConvertCore.convertToCamelCase("User_Login_A" ));
|
||||
System.out.println(TypeConvertCore.convertToCamelCase("userLoginA" ));
|
||||
System.out.println(TypeConvertCore.convertToCamelCase("UserLoginA" ));
|
||||
|
||||
System.out.println("--------------------------------" );
|
||||
|
||||
System.out.println(TypeConvertCore.convertToCamelCase("i18n_type_A" , true));
|
||||
System.out.println(TypeConvertCore.convertToCamelCase("User_Login_A" , true));
|
||||
System.out.println(TypeConvertCore.convertToCamelCase("userLoginA" , true));
|
||||
System.out.println(TypeConvertCore.convertToCamelCase("UserLoginA" , true));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"hash": "727e0168",
|
||||
"configHash": "10198a12",
|
||||
"lockfileHash": "530f8857",
|
||||
"browserHash": "41b39cb9",
|
||||
"optimized": {},
|
||||
"chunks": {}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"type": "module"
|
||||
}
|
Loading…
Reference in New Issue