Exemplo n.º 1
0
  private String getCaseCorrectedLookupString(LookupElement item) {
    String lookupString = item.getLookupString();
    if (item.isCaseSensitive()) {
      return lookupString;
    }

    final String prefix = itemPattern(item);
    final int length = prefix.length();
    if (length == 0 || !itemMatcher(item).prefixMatches(prefix)) return lookupString;
    boolean isAllLower = true;
    boolean isAllUpper = true;
    boolean sameCase = true;
    for (int i = 0; i < length && (isAllLower || isAllUpper || sameCase); i++) {
      final char c = prefix.charAt(i);
      boolean isLower = Character.isLowerCase(c);
      boolean isUpper = Character.isUpperCase(c);
      // do not take this kind of symbols into account ('_', '@', etc.)
      if (!isLower && !isUpper) continue;
      isAllLower = isAllLower && isLower;
      isAllUpper = isAllUpper && isUpper;
      sameCase = sameCase && isLower == Character.isLowerCase(lookupString.charAt(i));
    }
    if (sameCase) return lookupString;
    if (isAllLower) return lookupString.toLowerCase();
    if (isAllUpper) return StringUtil.toUpperCase(lookupString);
    return lookupString;
  }
  public void testToLowerCase() {
    assertEquals('/', StringUtil.toLowerCase('/'));
    assertEquals(':', StringUtil.toLowerCase(':'));
    assertEquals('a', StringUtil.toLowerCase('a'));
    assertEquals('a', StringUtil.toLowerCase('A'));
    assertEquals('k', StringUtil.toLowerCase('k'));
    assertEquals('k', StringUtil.toLowerCase('K'));

    assertEquals('\u2567', StringUtil.toUpperCase(Character.toLowerCase('\u2567')));
  }
Exemplo n.º 3
0
 public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
   final boolean rgb = isRGBMode();
   char[] source = str.toCharArray();
   if (mySrc != null) {
     final int selected = mySrc.getSelectionEnd() - mySrc.getSelectionStart();
     int newLen = mySrc.getText().length() - selected + str.length();
     if (newLen > (myHex ? 6 : 3)) {
       Toolkit.getDefaultToolkit().beep();
       return;
     }
   }
   char[] result = new char[source.length];
   int j = 0;
   for (int i = 0; i < result.length; i++) {
     if (myHex
         ? "0123456789abcdefABCDEF".indexOf(source[i]) >= 0
         : Character.isDigit(source[i])) {
       result[j++] = source[i];
     } else {
       Toolkit.getDefaultToolkit().beep();
     }
   }
   final String toInsert = StringUtil.toUpperCase(new String(result, 0, j));
   final String res = new StringBuilder(mySrc.getText()).insert(offs, toInsert).toString();
   try {
     if (!myHex) {
       final int num = Integer.parseInt(res);
       if (rgb) {
         if (num > 255) {
           Toolkit.getDefaultToolkit().beep();
           return;
         }
       } else {
         if ((mySrc == myRed && num > 359)
             || ((mySrc == myGreen || mySrc == myBlue) && num > 100)) {
           Toolkit.getDefaultToolkit().beep();
           return;
         }
       }
     }
   } catch (NumberFormatException ignore) {
   }
   super.insertString(offs, toInsert, a);
 }
Exemplo n.º 4
0
  @Override
  public String propertyNameToVariableName(String propertyName, VariableKind variableKind) {
    if (variableKind == VariableKind.STATIC_FINAL_FIELD) {
      String[] words = NameUtil.nameToWords(propertyName);
      StringBuilder buffer = new StringBuilder();
      for (int i = 0; i < words.length; i++) {
        String word = words[i];
        if (i > 0) {
          buffer.append("_");
        }
        buffer.append(StringUtil.toUpperCase(word));
      }
      return buffer.toString();
    }

    String prefix = getPrefixByVariableKind(variableKind);
    String name = propertyName;
    if (!name.isEmpty() && !prefix.isEmpty() && !StringUtil.endsWithChar(prefix, '_')) {
      name = Character.toUpperCase(name.charAt(0)) + name.substring(1);
    }
    name = prefix + name + getSuffixByVariableKind(variableKind);
    name = changeIfNotIdentifier(name);
    return name;
  }
 public MinusculeMatcher(
     @NotNull String pattern, @NotNull NameUtil.MatchingCaseSensitivity options) {
   myOptions = options;
   myPattern = StringUtil.trimEnd(pattern, "* ").toCharArray();
   isLowerCase = new boolean[myPattern.length];
   isUpperCase = new boolean[myPattern.length];
   isWordSeparator = new boolean[myPattern.length];
   toUpperCase = new char[myPattern.length];
   toLowerCase = new char[myPattern.length];
   for (int k = 0; k < myPattern.length; k++) {
     char c = myPattern[k];
     isLowerCase[k] = Character.isLowerCase(c);
     isUpperCase[k] = Character.isUpperCase(c);
     isWordSeparator[k] = isWordSeparator(c);
     toUpperCase[k] = StringUtil.toUpperCase(c);
     toLowerCase[k] = StringUtil.toLowerCase(c);
   }
   int i = 0;
   while (isWildcard(i)) i++;
   myHasHumps = hasFlag(i + 1, isUpperCase) && hasFlag(i, isLowerCase);
   myHasSeparators = hasFlag(i, isWordSeparator);
   myHasDots = hasDots(i);
   myHasWildCards = hasWildCards();
 }