com.intellij.codeInsight.completion.impl.CamelHumpMatcher Java Examples

The following examples show how to use com.intellij.codeInsight.completion.impl.CamelHumpMatcher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PhpEntityClassCompletionProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) {

        if(!Symfony2ProjectComponent.isEnabled(parameters.getPosition())) {
            return;
        }

        PhpIndex phpIndex = PhpIndex.getInstance(parameters.getOriginalFile().getProject());
        Map<String, String> entityNamespaces = ServiceXmlParserFactory.getInstance(parameters.getOriginalFile().getProject(), EntityNamesServiceParser.class).getEntityNameMap();

        // copied from PhpCompletionUtil::addClassesInNamespace looks the official way to find classes in namespaces
        // its a really performance nightmare

        Collection<String> names = phpIndex.getAllClassNames(new CamelHumpMatcher(resultSet.getPrefixMatcher().getPrefix()));
        for (String name : names) {
            Collection<PhpClass> classes = phpIndex.getClassesByName(name);

            for(Map.Entry<String, String> entry: entityNamespaces.entrySet()) {
                String namespaceFqn = PhpLangUtil.toFQN(entry.getValue());
                Collection<PhpClass> filtered = PhpCompletionUtil.filterByNamespace(classes, namespaceFqn);
                for (PhpClass phpClass : filtered) {
                    resultSet.addElement(new PhpClassLookupElement(phpClass, true, PhpClassReferenceInsertHandler.getInstance()));
                }
            }
        }
    }
 
Example #2
Source File: CompletionResultSetFactory.java    From intellij-swagger with MIT License 5 votes vote down vote up
public static CompletionResultSet forValue(
    final @NotNull CompletionParameters parameters, final @NotNull CompletionResultSet result) {
  final boolean caseSensitive = false;

  return getPrefix(parameters.getOffset() - 1, parameters.getOriginalFile().getText())
      .map(prefix -> result.withPrefixMatcher(new CamelHumpMatcher(prefix, caseSensitive)))
      .orElse(result);
}
 
Example #3
Source File: GeneratedParserUtilBase.java    From intellij-latte with MIT License 5 votes vote down vote up
public boolean prefixMatches(@NotNull String prefix, @NotNull String variant) {
	boolean matches = new CamelHumpMatcher(prefix, false).prefixMatches(variant.replace(' ', '_'));
	if (matches && StringUtil.isWhiteSpace(prefix.charAt(prefix.length() - 1))) {
		return StringUtil.startsWithIgnoreCase(variant, prefix);
	}
	return matches;
}
 
Example #4
Source File: GeneratedParserUtilBase.java    From intellij-xquery with Apache License 2.0 5 votes vote down vote up
public boolean prefixMatches(@NotNull String prefix, @NotNull String variant) {
    boolean matches = new CamelHumpMatcher(prefix, false).prefixMatches(variant.replace(' ', '_'));
    if (matches && isWhiteSpace(prefix.charAt(prefix.length() - 1))) {
        return startsWithIgnoreCase(variant, prefix);
    }
    return matches;
}
 
Example #5
Source File: CommitCompletionContributor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Override
public void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) {
  PsiFile file = parameters.getOriginalFile();
  Document document = PsiDocumentManager.getInstance(file.getProject()).getDocument(file);
  if (document != null) {
    DataContext dataContext = document.getUserData(CommitMessage.DATA_CONTEXT_KEY);
    if (dataContext != null) {
      result.stopHere();
      if (parameters.getInvocationCount() > 0) {
        ChangeList[] lists = dataContext.getData(VcsDataKeys.CHANGE_LISTS);
        if (lists != null) {
          String prefix = TextFieldWithAutoCompletionListProvider.getCompletionPrefix(parameters);
          CompletionResultSet insensitive = result.caseInsensitive().withPrefixMatcher(new CamelHumpMatcher(prefix));
          for (ChangeList list : lists) {
            for (Change change : list.getChanges()) {
              VirtualFile virtualFile = change.getVirtualFile();
              if (virtualFile != null) {
                LookupElementBuilder element = LookupElementBuilder.create(virtualFile.getName()).
                  withIcon(VirtualFilePresentation.getAWTIcon(virtualFile));
                insensitive.addElement(element);
              }
            }
          }
        }
      }
    }
  }
}
 
Example #6
Source File: HippieWordCompletionHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredUIAccess
@Override
public void invoke(@Nonnull Project project, @Nonnull final Editor editor, @Nonnull PsiFile file) {
  if (!FileModificationService.getInstance().prepareFileForWrite(file)) return;

  LookupManager.getInstance(project).hideActiveLookup();

  final CharSequence charsSequence = editor.getDocument().getCharsSequence();

  final CompletionData data = computeData(editor, charsSequence);
  String currentPrefix = data.myPrefix;

  final CompletionState completionState = getCompletionState(editor);

  String oldPrefix = completionState.oldPrefix;
  CompletionVariant lastProposedVariant = completionState.lastProposedVariant;

  if (lastProposedVariant == null || oldPrefix == null || !new CamelHumpMatcher(oldPrefix).isStartMatch(currentPrefix) ||
      !currentPrefix.equals(lastProposedVariant.variant)) {
    //we are starting over
    oldPrefix = currentPrefix;
    completionState.oldPrefix = oldPrefix;
    lastProposedVariant = null;
  }

  CompletionVariant nextVariant = computeNextVariant(editor, oldPrefix, lastProposedVariant, data, file);
  if (nextVariant == null) return;

  int replacementEnd = data.startOffset + data.myWordUnderCursor.length();
  editor.getDocument().replaceString(data.startOffset, replacementEnd, nextVariant.variant);
  editor.getCaretModel().moveToOffset(data.startOffset + nextVariant.variant.length());
  completionState.lastProposedVariant = nextVariant;
  highlightWord(nextVariant, project, data);
}
 
Example #7
Source File: HippieWordCompletionHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void addWordsForEditor(final EditorEx editor,
                                      final CamelHumpMatcher matcher,
                                      final CharSequence chars,
                                      final List<CompletionVariant> words,
                                      final List<CompletionVariant> afterWords, final int caretOffset) {
  int startOffset = 0;
  TokenProcessor processor = new TokenProcessor() {
    @Override
    public boolean processToken(int start, int end) {
      if ((start > caretOffset || end < caretOffset) &&  //skip prefix itself
          end - start > matcher.getPrefix().length()) {
        final String word = chars.subSequence(start, end).toString();
        if (matcher.isStartMatch(word)) {
          CompletionVariant v = new CompletionVariant(editor, word, start);
          if (end > caretOffset) {
            afterWords.add(v);
          }
          else {
            words.add(v);
          }
        }
      }
      return true;
    }
  };
  processWords(editor, startOffset, processor);
}
 
Example #8
Source File: LookupImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public PrefixMatcher itemMatcher(@Nonnull LookupElement item) {
  if (item instanceof EmptyLookupItem) {
    return new CamelHumpMatcher("");
  }
  return myPresentableArranger.itemMatcher(item);
}
 
Example #9
Source File: GeneratedParserUtilBase.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean prefixMatches(@Nonnull String prefix, @Nonnull String variant) {
  boolean matches = new CamelHumpMatcher(prefix, false).prefixMatches(variant.replace(' ', '_'));
  if (matches && isWhiteSpace(prefix.charAt(prefix.length() - 1))) {
    return startsWithIgnoreCase(variant, prefix);
  }
  return matches;
}