コード例 #1
0
 private static void addCompletionVariant(
     ErrorState state,
     CompletionState completionState,
     PsiBuilder builder_,
     Object o,
     int offset) {
   boolean add = false;
   int diff = completionState.offset - offset;
   String text = completionState.convertItem(o);
   int length = text == null ? 0 : text.length();
   if (length == 0) return;
   if (diff == 0) {
     add = true;
   } else if (diff > 0 && diff <= length) {
     CharSequence fragment =
         builder_.getOriginalText().subSequence(offset, completionState.offset);
     add = StringUtil.startsWithIgnoreCase(text, fragment.toString());
   } else if (diff < 0) {
     for (int i = -1; ; i--) {
       IElementType type = builder_.rawLookup(i);
       int tokenStart = builder_.rawTokenTypeStart(i);
       if (state.whitespaceTokens.contains(type) || state.commentTokens.contains(type)) {
         diff = completionState.offset - tokenStart;
       } else if (type != null && tokenStart < completionState.offset) {
         CharSequence fragment =
             builder_.getOriginalText().subSequence(tokenStart, completionState.offset);
         if (StringUtil.startsWithIgnoreCase(text, fragment.toString())) {
           diff = completionState.offset - tokenStart;
         }
         break;
       } else break;
     }
     add = diff >= 0 && diff < length;
   }
   add =
       add
           && length > 1
           && !(text.charAt(0) == '<' && text.charAt(length - 1) == '>')
           && !(text.charAt(0) == '\'' && text.charAt(length - 1) == '\'' && length < 5);
   if (add) {
     completionState.items.add(text);
   }
 }
コード例 #2
0
  private static void addCompletionVariant(
      @NotNull PsiBuilder builder, @NotNull CompletionState completionState, Object o) {
    int offset = builder.getCurrentOffset();
    if (!builder.eof() && offset == builder.rawTokenTypeStart(1))
      return; // suppress for zero-length tokens

    boolean add = false;
    int diff = completionState.offset - offset;
    String text = completionState.convertItem(o);
    int length = text == null ? 0 : text.length();
    if (length == 0) return;
    if (diff == 0) {
      add = true;
    } else if (diff > 0 && diff <= length) {
      CharSequence fragment = builder.getOriginalText().subSequence(offset, completionState.offset);
      add = completionState.prefixMatches(fragment.toString(), text);
    } else if (diff < 0) {
      for (int i = -1; ; i--) {
        IElementType type = builder.rawLookup(i);
        int tokenStart = builder.rawTokenTypeStart(i);
        if (isWhitespaceOrComment(builder, type)) {
          diff = completionState.offset - tokenStart;
        } else if (type != null && tokenStart < completionState.offset) {
          CharSequence fragment =
              builder.getOriginalText().subSequence(tokenStart, completionState.offset);
          if (completionState.prefixMatches(fragment.toString(), text)) {
            diff = completionState.offset - tokenStart;
          }
          break;
        } else break;
      }
      add = diff >= 0 && diff < length;
    }
    add =
        add
            && length > 1
            && !(text.charAt(0) == '<' && text.charAt(length - 1) == '>')
            && !(text.charAt(0) == '\'' && text.charAt(length - 1) == '\'' && length < 5);
    if (add) {
      completionState.addItem(builder, text);
    }
  }