Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflector#genGetterName(String prefix, String name)不符合常用标准规范! #528

Closed
liuliuliu12138 opened this issue Mar 21, 2023 · 2 comments

Comments

@liuliuliu12138
Copy link

liuliuliu12138 commented Mar 21, 2023

反射时用到的getter setter方法的构建方法实在太简单粗暴,不符合常规规范

    public static StringBuilder capitalize(StringBuilder sb, String s) {
        if (s == null) {
            return sb;
        } else {
            sb.append(s.substring(0, 1).toUpperCase());
            sb.append(s.substring(1));
            return sb;
        }
    }

不论是是intelij idea默认的getter setter生成策略代码:
https://github.com/JetBrains/intellij-community/blob/db4ae038643d134dfcf7199459ee8f5e0c2ac097/platform/util/src/com/intellij/openapi/util/text/StringUtil.java#L949

  public static @NotNull String capitalizeWithJavaBeanConvention(@NotNull String s) {
    if (s.length() > 1 && Character.isUpperCase(s.charAt(1))) {
      return s;
    }
    return capitalize(s);
  }

亦或是java.beans.Introspector#decapitalize,都是会对前两个char进行判断

public class Introspector {
    public static String decapitalize(String name) {
        if (name == null || name.length() == 0) {
            return name;
        }
        if (name.length() > 1 && Character.isUpperCase(name.charAt(1)) &&
                        Character.isUpperCase(name.charAt(0))){
            return name;
        }
        char chars[] = name.toCharArray();
        chars[0] = Character.toLowerCase(chars[0]);
        return new String(chars);
    }
}

而从4.x升到5.x直接将getter setter方法的构建变为首字母大写这么简单粗暴,将直接导致类似于aBC这种命名的property反射失败,希望考虑与标准规范兼容!

@liuliuliu12138 liuliuliu12138 changed the title Reflector#genGetterName(String prefix, String name)不符合常用规范! Reflector#genGetterName(String prefix, String name)不符合常用标准规范! Mar 21, 2023
@killme2008
Copy link
Owner

Good catch! Sorry,我对这个规范研究不深。 我修复下。

@killme2008
Copy link
Owner

jiudc pushed a commit to jiudc/aviatorscript that referenced this issue Feb 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants