Ejemplo 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;
  }
Ejemplo n.º 2
0
 public static boolean isAllUppercaseName(String name) {
   int uppercaseChars = 0;
   for (int i = 0; i < name.length(); i++) {
     if (Character.isLowerCase(name.charAt(i))) {
       return false;
     }
     if (Character.isUpperCase(name.charAt(i))) {
       uppercaseChars++;
     }
   }
   return uppercaseChars >= 3;
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 5
0
  @Override
  protected int drawUnselectedText(java.awt.Graphics g, int x, int y, int p0, int p1)
      throws BadLocationException {
    Document doc = getDocument();
    Segment segment = new Segment();
    Segment token = getLineBuffer();

    doc.getText(p0, p1 - p0, segment);

    int count = p1 - p0;
    int left = 0;

    int state = TEXT;

    int elementIndex = doc.getDefaultRootElement().getElementIndex(p0);

    AttributeSet lineAttributes =
        doc.getDefaultRootElement().getElement(elementIndex).getAttributes();

    if (lineAttributes.isDefined("inComment")) {
      state = MULTILINECOMMENT;
    }

    for (int i = 0; i < count; i++) {
      // Starting in default text state.
      if (state == TEXT) {
        if (Character.isLetter(segment.array[i + segment.offset])
            && Character.isLowerCase(segment.array[i + segment.offset])) {
          // flush now
          g.setColor(textColor);
          doc.getText(p0 + left, i - left, token);
          x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);
          left = i;
          state = KEYWORD;
        } // Do nothing
        else {
          if (segment.array[i + segment.offset] == '/') {
            // flush now
            g.setColor(textColor);
            doc.getText(p0 + left, i - left, token);
            x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);
            left = i;
            state = COMMENT;
          } else if (segment.array[i + segment.offset] == '"') {
            // flush now
            g.setColor(textColor);
            doc.getText(p0 + left, i - left, token);
            x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);
            left = i;
            state = STRING;
          }
        }
      } else if (state == KEYWORD) {
        // Still
        if (Character.isLetter(
            segment
                .array[
                i
                    + segment
                        .offset])) { // && Character.isLowerCase(segment.array[i+segment.offset]))
        } else {
          // flush now
          doc.getText(p0 + left, i - left, token);
          if (Keywords.isKeyword(token)) {
            g.setColor(keywordColor);
          } else {
            g.setColor(textColor);
          }
          x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);
          left = i;
          state = TEXT;
          if (segment.array[i + segment.offset] == '/') {
            state = COMMENT;
          } else if (segment.array[i + segment.offset] == '"') {
            state = STRING;
          }
        }
      } else if (state == COMMENT) {
        if (segment.array[i + segment.offset] == '/') {
          break;
        } else if (segment.array[i + segment.offset] == '*') {
          state = MULTILINECOMMENT;
        } else {
          state = TEXT;
        }
      } else if (state == MULTILINECOMMENT) {
        if (i > 0
            && segment.array[i + segment.offset] == '/'
            && segment.array[i + segment.offset - 1] == '*') {
          // flush now
          doc.getText(p0 + left, i + 1 - left, token);
          g.setColor(commentColor);
          x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);
          left = i + 1;
          state = TEXT;
        }
      } else if (state == STRING) {
        if (segment.array[i + segment.offset] == '"') {
          // flush now
          doc.getText(p0 + left, i + 1 - left, token);
          g.setColor(stringColor);
          x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);
          left = i + 1;
          state = TEXT;
        }
      }
      // Starting not in token
    } // end loop
    // Flush last
    doc.getText(p0 + left, p1 - p0 - left, token);
    if (state == KEYWORD) {
      if (Keywords.isKeyword(token)) {
        g.setColor(keywordColor);
      } else {
        g.setColor(textColor);
      }
    } else if (state == STRING) {
      g.setColor(stringColor);
    } else if (state == COMMENT && ((p1 - p0 - left) > 1)) {
      g.setColor(commentColor);
    } else if (state == MULTILINECOMMENT) {
      g.setColor(commentColor);
    } else {
      g.setColor(textColor);
    }
    x = Utilities.drawTabbedText(token, x, y, g, this, p0 + left);

    return x;
  }
Ejemplo n.º 6
0
  @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;
  }