Esempio n. 1
0
 private static void uppercaseFirstLetter(final StringBuffer buf) {
   if (buf.length() > 1) {
     char[] firstLetter = new char[1];
     buf.getChars(0, 1, firstLetter, 0);
     buf.setCharAt(0, Character.toUpperCase(firstLetter[0]));
   }
 }
  /**
   * Some String can be too long to be correctly displayed on the screen. Mainly when it is a path
   * to a file. This method truncate a String.
   *
   * @param longString The <code>String</code> to be truncated
   * @param maxLength The maximum length of the <code>String</code>
   * @return The truncated string
   */
  public static String getShortStringOf(String longString, int maxLength) {
    int len = longString.length();

    if (len <= maxLength) return longString;
    else if (longString.indexOf('\\') == -1 && longString.indexOf('/') == -1) {
      StringBuffer buff = new StringBuffer(longString.substring(longString.length() - maxLength));
      for (int i = 0; i < 3; i++) buff.setCharAt(i, '.');
      return buff.toString();
    } else {
      int first = len / 2;
      int second = first;

      for (int i = first - 1; i >= 0; i--) {
        if (longString.charAt(i) == '\\' || longString.charAt(i) == '/') {
          first = i;
          break;
        }
      }

      for (int i = second + 1; i < len; i++) {
        if (longString.charAt(i) == '\\' || longString.charAt(i) == '/') {
          second = i;
          break;
        }
      }

      loop:
      while ((len - (second - first)) > maxLength) {
        out:
        for (int i = first - 1; i >= 0; i--) {
          switch (longString.charAt(i)) {
            case '\\':
            case '/':
              first = i;
              break out;
          }
        }

        if ((len - (second - first)) < maxLength) break loop;

        out2:
        for (int i = second + 1; i < len; i++) {
          switch (longString.charAt(i)) {
            case '\\':
            case '/':
              second = i;
              break out2;
          }
        }
      }

      return longString.substring(0, first + 1) + "..." + longString.substring(second);

      // return longString.substring(0, maxLength / 2) + "..." +
      //       longString.substring(len - (maxLength / 2));
    }
  }
 /**
  * Getters/Setters are supposed to be kept with their associated property. Search the list of
  * entries to find the property and attach the setter.
  *
  * @param entries list of all items (methods, fields) in the class.
  */
 private void hookGetterToProperty(List<ClassContentsEntry> entries) {
   ListIterator<ClassContentsEntry> li = entries.listIterator();
   String property = MethodUtil.getPropertyName((PsiMethod) myEnd);
   while (li.hasNext()) {
     Object o = li.next();
     if (o instanceof FieldEntry) {
       FieldEntry fe = (FieldEntry) o;
       StringBuffer sb = new StringBuffer(fe.getName());
       sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
       if (fe.getGetterMethod() == null && property.equals(sb.toString())) {
         fe.setGetterMethod(this);
         myKeptWithProperty = true;
         break;
       }
     }
   }
 }