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;
  }
 @Override
 public boolean value(PsiPackage aPackage) {
   return JavaPsiFacade.getInstance(aPackage.getProject())
           .getNameHelper()
           .isQualifiedName(aPackage.getQualifiedName())
       && Character.isLowerCase(aPackage.getName().charAt(0));
 }
  private static void registerAddImportFixes(
      GrReferenceElement refElement, @Nullable HighlightInfo info, final HighlightDisplayKey key) {
    final String referenceName = refElement.getReferenceName();
    //noinspection ConstantConditions
    if (StringUtil.isEmpty(referenceName)) return;
    if (!(refElement instanceof GrCodeReferenceElement)
        && Character.isLowerCase(referenceName.charAt(0))) return;
    if (refElement.getQualifier() != null) return;

    QuickFixAction.registerQuickFixAction(info, new GroovyAddImportAction(refElement), key);
  }
Exemple #4
0
 public static boolean startWithIgnoreCase(String line, String prefix) {
   /**
    * this implementation is faster than 'line.toLowerCase().startsWith(prefix)', that's important
    * if processing huge log files
    */
   int pLen = prefix.length();
   if (line.length() < pLen) return false;
   for (int i = 0; i < pLen; i++) {
     char lineChar = Character.toLowerCase(line.charAt(i));
     char prefixChar = prefix.charAt(i);
     if (Character.isLetter(prefixChar) && !Character.isLowerCase(prefixChar))
       throw new IllegalStateException("Not lower: " + prefix);
     if (lineChar != prefixChar) return false;
   }
   return true;
 }
Exemple #5
0
 public void keyTyped(char ch) {
   if (this.emuSys != null) {
     if (this.emuSys.getSwapKeyCharCase()) {
       if (Character.isUpperCase(ch)) {
         ch = Character.toLowerCase(ch);
       } else if (Character.isLowerCase(ch)) {
         ch = Character.toUpperCase(ch);
       }
     }
     if (this.emuSys.getConvertKeyCharToISO646DE()) {
       this.emuSys.keyTyped(TextUtil.toISO646DE(ch));
     } else {
       this.emuSys.keyTyped(ch);
     }
   }
 }
 public int getPriority() {
   return myName == null || Character.isLowerCase(myName.charAt(0)) ? HIGHER : NORMAL;
 }
  @NotNull
  private Pattern getPattern(String pattern) {
    if (!Comparing.strEqual(pattern, myPattern)) {
      myCompiledPattern = null;
      myPattern = pattern;
    }
    if (myCompiledPattern == null) {
      boolean allowToLower = true;
      final int eol = pattern.indexOf('\n');
      if (eol != -1) {
        pattern = pattern.substring(0, eol);
      }
      if (pattern.length() >= 80) {
        pattern = pattern.substring(0, 80);
      }

      final @NonNls StringBuffer buffer = new StringBuffer();

      if (containsOnlyUppercaseLetters(pattern)) {
        allowToLower = false;
      }

      if (allowToLower) {
        buffer.append(".*");
      }

      boolean firstIdentifierLetter = true;
      for (int i = 0; i < pattern.length(); i++) {
        final char c = pattern.charAt(i);
        if (Character.isLetterOrDigit(c)) {
          // This logic allows to use uppercase letters only to catch the name like PDM for
          // PsiDocumentManager
          if (Character.isUpperCase(c) || Character.isDigit(c)) {

            if (!firstIdentifierLetter) {
              buffer.append("[^A-Z]*");
            }

            buffer.append("[");
            buffer.append(c);
            if (allowToLower || i == 0) {
              buffer.append('|');
              buffer.append(Character.toLowerCase(c));
            }
            buffer.append("]");
          } else if (Character.isLowerCase(c)) {
            buffer.append('[');
            buffer.append(c);
            buffer.append('|');
            buffer.append(Character.toUpperCase(c));
            buffer.append(']');
          } else {
            buffer.append(c);
          }

          firstIdentifierLetter = false;
        } else if (c == '*') {
          buffer.append(".*");
          firstIdentifierLetter = true;
        } else if (c == '.') {
          buffer.append("\\.");
          firstIdentifierLetter = true;
        } else if (c == ' ') {
          buffer.append("[^A-Z]*\\ ");
          firstIdentifierLetter = true;
        } else {
          firstIdentifierLetter = true;
          // for standard RegExp engine
          // buffer.append("\\u");
          // buffer.append(Integer.toHexString(c + 0x20000).substring(1));

          // for OROMATCHER RegExp engine
          buffer.append("\\x");
          buffer.append(Integer.toHexString(c + 0x20000).substring(3));
        }
      }

      buffer.append(".*");

      try {
        myCompiledPattern = new Perl5Compiler().compile(buffer.toString());
      } catch (MalformedPatternException e) {
        // do nothing
      }
    }

    return myCompiledPattern;
  }