Exemplo n.º 1
0
 private static String truncDigits(String name) {
   int count = name.length() - 1;
   while (count >= 0) {
     char c = name.charAt(count);
     if (!Character.isDigit(c)) break;
     count--;
   }
   return name.substring(0, count + 1);
 }
 private static String suggestNewName(Project project, PsiVariable variable) {
   // new name should not conflict with another variable at the variable declaration level and
   // usage level
   String name = variable.getName();
   // trim last digit to suggest variable names like i1,i2, i3...
   if (name.length() > 1 && Character.isDigit(name.charAt(name.length() - 1))) {
     name = name.substring(0, name.length() - 1);
   }
   name = "final" + StringUtil.capitalize(StringUtil.trimStart(name, "final"));
   return JavaCodeStyleManager.getInstance(project)
       .suggestUniqueVariableName(name, variable, true);
 }
Exemplo n.º 3
0
 private static String getDigitPrefix(final String indexName) {
   final StringBuilder builder = StringBuilderSpinAllocator.alloc();
   try {
     for (int i = 0; i < indexName.length(); i++) {
       final char c = indexName.charAt(i);
       if (Character.isDigit(c)) {
         builder.append(c);
       } else {
         break;
       }
     }
     return builder.toString();
   } finally {
     StringBuilderSpinAllocator.dispose(builder);
   }
 }