Java 类com.intellij.psi.codeStyle.MinusculeMatcher 实例源码

项目:intellij-ce-playground    文件:DefaultSymbolNavigationContributor.java   
private static Condition<PsiMember> getQualifiedNameMatcher(String completePattern) {
  final Condition<PsiMember> qualifiedMatcher;
  if (completePattern.contains(".")) {
    final MinusculeMatcher matcher = new MinusculeMatcher("*" + StringUtil.replace(completePattern, ".", ".*"), NameUtil.MatchingCaseSensitivity.NONE);
    qualifiedMatcher = new Condition<PsiMember>() {
      @Override
      public boolean value(PsiMember member) {
        String qualifiedName = PsiUtil.getMemberQualifiedName(member);
        return qualifiedName != null && matcher.matches(qualifiedName);
      }
    };
  } else {
    //noinspection unchecked
    qualifiedMatcher = Condition.TRUE;
  }
  return qualifiedMatcher;
}
项目:intellij-ce-playground    文件:SpeedSearchUtil.java   
public static void appendColoredFragmentForMatcher(@NotNull String text,
                                                   SimpleColoredComponent component,
                                                   @NotNull final SimpleTextAttributes attributes,
                                                   Matcher matcher,
                                                   Color selectedBg,
                                                   boolean selected) {
  if (!(matcher instanceof MinusculeMatcher) || (Registry.is("ide.highlight.match.in.selected.only") && !selected)) {
    component.append(text, attributes);
    return;
  }

  final Iterable<TextRange> iterable = ((MinusculeMatcher)matcher).matchingFragments(text);
  if (iterable != null) {
    final Color fg = attributes.getFgColor();
    final int style = attributes.getStyle();
    final SimpleTextAttributes plain = new SimpleTextAttributes(style, fg);
    final SimpleTextAttributes highlighted = new SimpleTextAttributes(selectedBg, fg, null, style | SimpleTextAttributes.STYLE_SEARCH_MATCH);
    appendColoredFragments(component, text, iterable, plain, highlighted);
  }
  else {
    component.append(text, attributes);
  }
}
项目:intellij-ce-playground    文件:FileTextFieldImpl.java   
private void addMacroPaths(final CompletionResult result, final String typedText) {
  result.myMacros = new ArrayList<LookupFile>();

  MinusculeMatcher matcher = createMatcher(typedText);

  for (String eachMacro : myMacroMap.keySet()) {
    if (matcher.matches(eachMacro)) {
      final String eachPath = myMacroMap.get(eachMacro);
      if (eachPath != null) {
        final LookupFile macroFile = myFinder.find(eachPath);
        if (macroFile != null && macroFile.exists()) {
          result.myMacros.add(macroFile);
          result.myToComplete.add(macroFile);
          macroFile.setMacro(eachMacro);
        }
      }
    }
  }
}
项目:intellij-ce-playground    文件:OptionsTopHitProvider.java   
@Override
public final void consumeTopHits(@NonNls String pattern, Consumer<Object> collector, Project project) {
  if (!pattern.startsWith("#")) return;
  pattern = pattern.substring(1);
  final List<String> parts = StringUtil.split(pattern, " ");

  if (parts.size() == 0) {
    return;
  }

  String id = parts.get(0);
  if (getId().startsWith(id) || pattern.startsWith(" ")) {
    if (pattern.startsWith(" ")) {
      pattern = pattern.trim();
    } else {
      pattern = pattern.substring(id.length()).trim().toLowerCase();
    }
    final MinusculeMatcher matcher = NameUtil.buildMatcher("*" + pattern, NameUtil.MatchingCaseSensitivity.NONE);
    for (BooleanOptionDescription option : getOptions(project)) {
      if (matcher.matches(option.getOption())) {
        collector.consume(option);
      }
    }
  }
}
项目:intellij-ce-playground    文件:CamelHumpMatcher.java   
private MinusculeMatcher createMatcher(final boolean caseSensitive) {
  String prefix = applyMiddleMatching(myPrefix);

  if (!caseSensitive) {
    return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.NONE);
  }

  switch (CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE) {
    case CodeInsightSettings.NONE:
      return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.NONE);
    case CodeInsightSettings.FIRST_LETTER:
      return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.FIRST_LETTER);
    default:
      return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.ALL);
  }
}
项目:intellij-ce-playground    文件:SearchEverywhereAction.java   
private synchronized void buildStructure(final String pattern) {
  if (!Registry.is("search.everywhere.structure") || myStructureModel == null) return;
  final List<StructureViewTreeElement> elements = new ArrayList<StructureViewTreeElement>();
  final MinusculeMatcher matcher = new MinusculeMatcher("*" + pattern, NameUtil.MatchingCaseSensitivity.NONE);
  fillStructure(myStructureModel.getRoot(), elements, matcher);
  if (elements.size() > 0) {
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        if (isCanceled()) return;
        myListModel.titleIndex.structure = myListModel.size();
        for (Object element : elements) {
          myListModel.addElement(element);
        }
        myListModel.moreIndex.files = -1;
      }
    });
  }
}
项目:intellij-ce-playground    文件:DefaultChooseByNameItemProvider.java   
private static void processNamesByPattern(@NotNull final ChooseByNameBase base,
                                          @NotNull final String[] names,
                                          @NotNull final String pattern,
                                          final ProgressIndicator indicator,
                                          @NotNull final Consumer<MatchResult> consumer) {
  final MinusculeMatcher matcher = buildPatternMatcher(pattern, NameUtil.MatchingCaseSensitivity.NONE);
  Processor<String> processor = new Processor<String>() {
    @Override
    public boolean process(String name) {
      ProgressManager.checkCanceled();
      MatchResult result = matches(base, pattern, matcher, name);
      if (result != null) {
        consumer.consume(result);
      }
      return true;
    }
  };
  if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Arrays.asList(names), indicator, false, true, processor)) {
    throw new ProcessCanceledException();
  }
}
项目:intellij-ce-playground    文件:DefaultChooseByNameItemProvider.java   
@Nullable
private static MatchResult matches(@NotNull ChooseByNameBase base,
                                   @NotNull String pattern,
                                   @NotNull MinusculeMatcher matcher,
                                   @Nullable String name) {
  if (name == null) {
    return null;
  }
  if (base.getModel() instanceof CustomMatcherModel) {
    try {
      return ((CustomMatcherModel)base.getModel()).matches(name, pattern) ? new MatchResult(name, 0, true) : null;
    }
    catch (Exception e) {
      LOG.info(e);
      return null; // no matches appears valid result for "bad" pattern
    }
  }
  FList<TextRange> fragments = matcher.matchingFragments(name);
  return fragments != null ? new MatchResult(name, matcher.matchingDegree(name, false, fragments), MinusculeMatcher.isStartMatch(fragments)) : null;
}
项目:MvnRunner    文件:PomNavigationContributor.java   
@Override
public void processElementsWithName(@NotNull String name,
                                    @NotNull final Processor<NavigationItem> processor,
                                    @NotNull FindSymbolParameters parameters) {
    final MinusculeMatcher matcher = NameUtil.buildMatcher(parameters.getCompletePattern(), NameUtil.MatchingCaseSensitivity.FIRST_LETTER);

    if (!matcher.isStartMatch(name.substring(0, name.lastIndexOf(':')))) return;

    String[] names = name.split(":");
    MavenId mavenId = new MavenId(names[0], names[1], names[2]);
    projectsManager = MavenProjectsManager.getInstance(project);
    MavenProject p = projectsManager.findProject(mavenId);
    PsiFileSystemItem pomFile = null;
    if (p != null) {
        pomFile = PsiManager.getInstance(project).findFile(p.getFile());
    } else if (parameters.isSearchInLibraries()) {
        Map<MavenId, PsiFile> notImportPoms = getNotImportPoms(projectsManager.getRootProjects().get(0));
        pomFile = notImportPoms.get(mavenId);
    }
    if (pomFile != null) {
        PomWrapper pomWrapper = new PomWrapper(pomFile, mavenId, project.getBasePath(), showPomLocation);
        processor.process(pomWrapper);
    }
}
项目:tools-idea    文件:SpeedSearchUtil.java   
public static void appendColoredFragmentForMatcher(@NotNull final String text,
                                                   final SimpleColoredComponent component,
                                                   @NotNull final SimpleTextAttributes attributes,
                                                   final Matcher matcher,
                                                   final Color selectedBg,
                                                   final boolean selected) {
  if (!(matcher instanceof MinusculeMatcher) || (Registry.is("ide.highlight.match.in.selected.only") && !selected)) {
    component.append(text, attributes);
    return;
  }

  final Iterable<TextRange> iterable = ((MinusculeMatcher)matcher).matchingFragments(text);
  if (iterable != null) {
    final Color fg = attributes.getFgColor();
    final int style = attributes.getStyle();
    final SimpleTextAttributes plain = new SimpleTextAttributes(style, fg);
    final SimpleTextAttributes highlighted = new SimpleTextAttributes(selectedBg, fg, null, style | SimpleTextAttributes.STYLE_SEARCH_MATCH);
    appendColoredFragments(component, text, iterable, plain, highlighted);
  }
  else {
    component.append(text, attributes);
  }
}
项目:tools-idea    文件:FileTextFieldImpl.java   
private void addMacroPaths(final CompletionResult result, final String typedText) {
  result.myMacros = new ArrayList<LookupFile>();

  MinusculeMatcher matcher = createMatcher(typedText);

  for (String eachMacro : myMacroMap.keySet()) {
    if (matcher.matches(eachMacro)) {
      final String eachPath = myMacroMap.get(eachMacro);
      if (eachPath != null) {
        final LookupFile macroFile = myFinder.find(eachPath);
        if (macroFile != null && macroFile.exists()) {
          result.myMacros.add(macroFile);
          result.myToComplete.add(macroFile);
          macroFile.setMacro(eachMacro);
        }
      }
    }
  }
}
项目:tools-idea    文件:CamelHumpMatcher.java   
private MinusculeMatcher createMatcher(final boolean caseSensitive) {
  String prefix = applyMiddleMatching(myPrefix);

  if (!caseSensitive) {
    return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.NONE);
  }

  switch (CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE) {
    case CodeInsightSettings.NONE:
      return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.NONE);
    case CodeInsightSettings.FIRST_LETTER:
      return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.FIRST_LETTER);
    default:
      return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.ALL);
  }
}
项目:tools-idea    文件:DefaultChooseByNameItemProvider.java   
private static void processNamesByPattern(@NotNull final ChooseByNameBase base,
                                          @NotNull final String[] names,
                                          @NotNull final String pattern,
                                          final ProgressIndicator indicator,
                                          @NotNull final Consumer<MatchResult> consumer) {
  final MinusculeMatcher matcher = buildPatternMatcher(pattern, NameUtil.MatchingCaseSensitivity.NONE);
  Processor<String> processor = new Processor<String>() {
    @Override
    public boolean process(String name) {
      ProgressManager.checkCanceled();
      MatchResult result = matches(base, pattern, matcher, name);
      if (result != null) {
        consumer.consume(result);
      }
      return true;
    }
  };
  JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Arrays.asList(names), indicator, false, false, processor);
}
项目:tools-idea    文件:DefaultChooseByNameItemProvider.java   
@Nullable
private static MatchResult matches(@NotNull ChooseByNameBase base,
                                   @NotNull String pattern,
                                   @NotNull MinusculeMatcher matcher,
                                   @Nullable String name) {
  if (name == null) {
    return null;
  }
  if (base.getModel() instanceof CustomMatcherModel) {
    try {
      return ((CustomMatcherModel)base.getModel()).matches(name, pattern) ? new MatchResult(name, 0, true) : null;
    }
    catch (Exception e) {
      LOG.info(e);
      return null; // no matches appears valid result for "bad" pattern
    }
  }
  return matcher.matches(name) ? new MatchResult(name, matcher.matchingDegree(name), matcher.isStartMatch(name)) : null;
}
项目:consulo    文件:SpeedSearchUtil.java   
public static void appendColoredFragmentForMatcher(@Nonnull String text,
                                                   SimpleColoredComponent component,
                                                   @Nonnull final SimpleTextAttributes attributes,
                                                   Matcher matcher,
                                                   Color selectedBg,
                                                   boolean selected) {
  if (!(matcher instanceof MinusculeMatcher) || (Registry.is("ide.highlight.match.in.selected.only") && !selected)) {
    component.append(text, attributes);
    return;
  }

  final Iterable<TextRange> iterable = ((MinusculeMatcher)matcher).matchingFragments(text);
  if (iterable != null) {
    final Color fg = attributes.getFgColor();
    final int style = attributes.getStyle();
    final SimpleTextAttributes plain = new SimpleTextAttributes(style, fg);
    final SimpleTextAttributes highlighted = new SimpleTextAttributes(selectedBg, fg, null, style | SimpleTextAttributes.STYLE_SEARCH_MATCH);
    appendColoredFragments(component, text, iterable, plain, highlighted);
  }
  else {
    component.append(text, attributes);
  }
}
项目:consulo    文件:FileTextFieldImpl.java   
private void addMacroPaths(final CompletionResult result, final String typedText) {
  result.myMacros = new ArrayList<LookupFile>();

  MinusculeMatcher matcher = createMatcher(typedText);

  for (String eachMacro : myMacroMap.keySet()) {
    if (matcher.matches(eachMacro)) {
      final String eachPath = myMacroMap.get(eachMacro);
      if (eachPath != null) {
        final LookupFile macroFile = myFinder.find(eachPath);
        if (macroFile != null && macroFile.exists()) {
          result.myMacros.add(macroFile);
          result.myToComplete.add(macroFile);
          macroFile.setMacro(eachMacro);
        }
      }
    }
  }
}
项目:consulo    文件:OptionsTopHitProvider.java   
@Override
public final void consumeTopHits(@NonNls String pattern, Consumer<Object> collector, Project project) {
  if (!pattern.startsWith("#")) return;
  pattern = pattern.substring(1);
  final List<String> parts = StringUtil.split(pattern, " ");

  if (parts.size() == 0) return;

  String id = parts.get(0);
  if (getId().startsWith(id)) {
    pattern = pattern.substring(id.length()).trim().toLowerCase();
    final MinusculeMatcher matcher = NameUtil.buildMatcher("*" + pattern, NameUtil.MatchingCaseSensitivity.NONE);
    for (BooleanOptionDescription option : getOptions(project)) {
      if (matcher.matches(option.getOption())) {
        collector.consume(option);
      }
    }
  }
}
项目:consulo    文件:CamelHumpMatcher.java   
private MinusculeMatcher createMatcher(final boolean caseSensitive) {
  String prefix = applyMiddleMatching(myPrefix);

  if (!caseSensitive) {
    return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.NONE);
  }

  switch (CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE) {
    case CodeInsightSettings.NONE:
      return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.NONE);
    case CodeInsightSettings.FIRST_LETTER:
      return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.FIRST_LETTER);
    default:
      return NameUtil.buildMatcher(prefix, NameUtil.MatchingCaseSensitivity.ALL);
  }
}
项目:consulo    文件:SearchEverywhereAction.java   
private synchronized void buildStructure(final String pattern) {
  if (!Registry.is("search.everywhere.structure") || myStructureModel == null) return;
  final List<StructureViewTreeElement> elements = new ArrayList<>();
  final MinusculeMatcher matcher = new MinusculeMatcher("*" + pattern, NameUtil.MatchingCaseSensitivity.NONE);
  fillStructure(myStructureModel.getRoot(), elements, matcher);
  if (elements.size() > 0) {
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        if (isCanceled()) return;
        myListModel.titleIndex.structure = myListModel.size();
        for (Object element : elements) {
          myListModel.addElement(element);
        }
        myListModel.moreIndex.files = -1;
      }
    });
  }
}
项目:consulo    文件:SearchEverywhereAction.java   
private SearchResult getConfigurations(String pattern, int max) {
  SearchResult configurations = new SearchResult();
  if (!Registry.is("search.everywhere.configurations")) {
    return configurations;
  }
  MinusculeMatcher matcher = new MinusculeMatcher(pattern, NameUtil.MatchingCaseSensitivity.NONE);
  final ChooseRunConfigurationPopup.ItemWrapper[] wrappers = ChooseRunConfigurationPopup.createSettingsList(project, new ExecutorProvider() {
    @Override
    public Executor getExecutor() {
      return ExecutorRegistry.getInstance().getExecutorById(ToolWindowId.DEBUG);
    }
  }, false);
  check();
  for (ChooseRunConfigurationPopup.ItemWrapper wrapper : wrappers) {
    if (matcher.matches(wrapper.getText()) && !myListModel.contains(wrapper)) {
      if (configurations.size() == max) {
        configurations.needMore = true;
        break;
      }
      configurations.add(wrapper);
    }
    check();
  }

  return configurations;
}
项目:consulo    文件:DefaultChooseByNameItemProvider.java   
private static void processNamesByPattern(@Nonnull final ChooseByNameBase base,
                                          @Nonnull final String[] names,
                                          @Nonnull final String pattern,
                                          final ProgressIndicator indicator,
                                          @Nonnull final Consumer<MatchResult> consumer) {
  final MinusculeMatcher matcher = buildPatternMatcher(pattern, NameUtil.MatchingCaseSensitivity.NONE);
  Processor<String> processor = new Processor<String>() {
    @Override
    public boolean process(String name) {
      ProgressManager.checkCanceled();
      MatchResult result = matches(base, pattern, matcher, name);
      if (result != null) {
        consumer.consume(result);
      }
      return true;
    }
  };
  if (!JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Arrays.asList(names), indicator, false, true, processor)) {
    throw new ProcessCanceledException();
  }
}
项目:consulo    文件:DefaultChooseByNameItemProvider.java   
@Nullable
private static MatchResult matches(@Nonnull ChooseByNameBase base,
                                   @Nonnull String pattern,
                                   @Nonnull MinusculeMatcher matcher,
                                   @Nullable String name) {
  if (name == null) {
    return null;
  }
  if (base.getModel() instanceof CustomMatcherModel) {
    try {
      return ((CustomMatcherModel)base.getModel()).matches(name, pattern) ? new MatchResult(name, 0, true) : null;
    }
    catch (Exception e) {
      LOG.info(e);
      return null; // no matches appears valid result for "bad" pattern
    }
  }
  return matcher.matches(name) ? new MatchResult(name, matcher.matchingDegree(name), matcher.isStartMatch(name)) : null;
}
项目:SearchResourcePlugin    文件:StringEllipsisPolicy.java   
String ellipsizeText(@NotNull String text, Matcher matcher) {
    final int textLength = text.length();

    if (textLength > MAX_LENGTH) {
        if (matcher instanceof MinusculeMatcher) {
            FList iterable = ((MinusculeMatcher) matcher).matchingFragments(text);
            if (iterable != null) {
                TextRange textRange = (TextRange) iterable.getHead();
                int startOffset = textRange.getStartOffset();

                int startIndex = 0;
                int endIndex = textLength;

                if (startOffset > ELLIPSIS_EXTRA_LENGTH) {
                    startIndex = startOffset - ELLIPSIS_EXTRA_LENGTH;
                }
                if (textLength > startIndex + MAX_LENGTH) {
                    endIndex = startIndex + MAX_LENGTH;
                }

                String ellipsizedText = text.substring(startIndex, endIndex);

                if (startIndex > 0) {
                    ellipsizedText = DOTS + ellipsizedText;
                }
                if (endIndex < textLength) {
                    ellipsizedText = ellipsizedText + DOTS;
                }

                return ellipsizedText;
            }
        }
    }

    return text;
}
项目:android-strings-search-plugin    文件:StringEllipsisPolicy.java   
String ellipsizeText(@NotNull String text, Matcher matcher) {
    final int textLength = text.length();

    if (textLength > MAX_LENGTH) {
        if (matcher instanceof MinusculeMatcher) {
            FList iterable = ((MinusculeMatcher) matcher).matchingFragments(text);
            if (iterable != null) {
                TextRange textRange = (TextRange) iterable.getHead();
                int startOffset = textRange.getStartOffset();

                int startIndex = 0;
                int endIndex = textLength;

                if (startOffset > ELLIPSIS_EXTRA_LENGTH) {
                    startIndex = startOffset - ELLIPSIS_EXTRA_LENGTH;
                }
                if (textLength > startIndex + MAX_LENGTH) {
                    endIndex = startIndex + MAX_LENGTH;
                }

                String ellipsizedText = text.substring(startIndex, endIndex);

                if (startIndex > 0) {
                    ellipsizedText = DOTS + ellipsizedText;
                }
                if (endIndex < textLength) {
                    ellipsizedText = ellipsizedText + DOTS;
                }

                return ellipsizedText;
            }
        }
    }

    return text;
}
项目:intellij-ce-playground    文件:DefaultClassNavigationContributor.java   
@Override
public void processElementsWithName(@NotNull String name,
                                    @NotNull final Processor<NavigationItem> processor,
                                    @NotNull final FindSymbolParameters parameters) {
  String namePattern = StringUtil.getShortName(parameters.getCompletePattern());
  boolean hasDollar = namePattern.contains("$");
  if (hasDollar) {
    Matcher matcher = ChooseByNamePopup.patternToDetectAnonymousClasses.matcher(namePattern);
    if (matcher.matches()) {
      namePattern = matcher.group(1);
      hasDollar = namePattern.contains("$");
    }
  }
  final MinusculeMatcher innerMatcher = hasDollar ? new MinusculeMatcher("*" + namePattern, NameUtil.MatchingCaseSensitivity.NONE) : null;
  PsiShortNamesCache.getInstance(parameters.getProject()).processClassesWithName(name, new Processor<PsiClass>() {
    final boolean isAnnotation = parameters.getLocalPatternName().startsWith("@");

    @Override
    public boolean process(PsiClass aClass) {
      if (aClass.getContainingFile().getVirtualFile() == null || !aClass.isPhysical()) return true;
      if (isAnnotation && !aClass.isAnnotationType()) return true;
      if (innerMatcher != null) {
        if (aClass.getContainingClass() == null) return true;
        String jvmQName = ClassUtil.getJVMClassName(aClass);
        if (jvmQName == null || !innerMatcher.matches(StringUtil.getShortName(jvmQName))) return true;
      }
      return processor.process(aClass);
    }
  }, parameters.getSearchScope(), parameters.getIdFilter());
}
项目:intellij-ce-playground    文件:SpeedSearchComparator.java   
private MinusculeMatcher obtainMatcher(@NotNull String pattern) {
  if (myRecentSearchText == null || !myRecentSearchText.equals(pattern)) {
    myRecentSearchText = pattern;
    if (myShouldMatchCamelCase) {
      pattern = StringUtil.join(NameUtil.nameToWords(pattern), "*");
    }
    if (!myShouldMatchFromTheBeginning && !pattern.startsWith("*")) {
      pattern = "*" + pattern;
    }
    myMinusculeMatcher = createMatcher(pattern);
  }
  return myMinusculeMatcher;
}
项目:intellij-ce-playground    文件:BetterPrefixMatcher.java   
@Override
public boolean prefixMatches(@NotNull String name) {
  if (myHumpMatcher != null) {
    FList<TextRange> fragments = myHumpMatcher.matchingFragments(name);
    if (fragments == null || !MinusculeMatcher.isStartMatch(fragments)) {
      return false;
    }
    return myHumpMatcher.matchingDegree(name, fragments) >= myMinMatchingDegree;
  }

  if (!myOriginal.prefixMatches(name) || !myOriginal.isStartMatch(name)) {
    return false;
  }
  return myOriginal.matchingDegree(name) >= myMinMatchingDegree;
}
项目:intellij-ce-playground    文件:SearchEverywhereAction.java   
private SearchResult getActionsOrSettings(final String pattern, final int max, final boolean actions) {
  final SearchResult result = new SearchResult();
  if ((actions && !Registry.is("search.everywhere.actions")) || (!actions && !Registry.is("search.everywhere.settings"))) {
    return result;
  }
  final MinusculeMatcher matcher = new MinusculeMatcher("*" +pattern, NameUtil.MatchingCaseSensitivity.NONE);
  if (myActionProvider == null) {
    myActionProvider = createActionProvider();
  }

  myActionProvider.filterElements(pattern, true, new Processor<GotoActionModel.MatchedValue>() {
    @Override
    public boolean process(GotoActionModel.MatchedValue matched) {
      check();
      Object object = matched.value;
      if (myListModel.contains(object)) return true;

      if (!actions && isSetting(object)) {
        if (matcher.matches(getSettingText((OptionDescription)object))) {
          result.add(object);
        }
      }
      else if (actions && !isToolWindowAction(object) && isActionValue(object)) {
        AnAction action = object instanceof AnAction ? ((AnAction)object) : ((GotoActionModel.ActionWrapper)object).getAction();
        Object lock = myCalcThread;
        if (lock != null) {
          synchronized (lock) {
            if (isEnabled(action)) {
              result.add(object);
            }
          }
        }
      }
      return result.size() <= max;
    }
  });

  return result;
}
项目:intellij-ce-playground    文件:SearchEverywhereAction.java   
private SearchResult getConfigurations(String pattern, int max) {
  SearchResult configurations = new SearchResult();
  if (!Registry.is("search.everywhere.configurations")) {
    return configurations;
  }
  MinusculeMatcher matcher = new MinusculeMatcher(pattern, NameUtil.MatchingCaseSensitivity.NONE);
  final ChooseRunConfigurationPopup.ItemWrapper[] wrappers =
    ChooseRunConfigurationPopup.createSettingsList(project, new ExecutorProvider() {
      @Override
      public Executor getExecutor() {
        return ExecutorRegistry.getInstance().getExecutorById(ToolWindowId.DEBUG);
      }
    }, false);
  check();
  for (ChooseRunConfigurationPopup.ItemWrapper wrapper : wrappers) {
    if (matcher.matches(wrapper.getText()) && !myListModel.contains(wrapper)) {
      if (configurations.size() == max) {
        configurations.needMore = true;
        break;
      }
      configurations.add(wrapper);
    }
    check();
  }

  return configurations;
}
项目:intellij-ce-playground    文件:GotoClassAction.java   
@Nullable
private static Navigatable findMember(String pattern, PsiElement psiElement, VirtualFile file) {
  final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(psiElement.getLanguage());
  final StructureViewBuilder builder = factory == null ? null : factory.getStructureViewBuilder(psiElement.getContainingFile());
  final FileEditor[] editors = FileEditorManager.getInstance(psiElement.getProject()).getEditors(file);
  if (builder == null || editors.length == 0) {
    return null;
  }

  final StructureView view = builder.createStructureView(editors[0], psiElement.getProject());
  try {
    final StructureViewTreeElement element = findElement(view.getTreeModel().getRoot(), psiElement, 4);
    if (element == null) {
      return null;
    }

    final MinusculeMatcher matcher = new MinusculeMatcher(pattern, NameUtil.MatchingCaseSensitivity.NONE);
    int max = Integer.MIN_VALUE;
    Object target = null;
    for (TreeElement treeElement : element.getChildren()) {
      if (treeElement instanceof StructureViewTreeElement) {
        String presentableText = treeElement.getPresentation().getPresentableText();
        if (presentableText != null) {
          final int degree = matcher.matchingDegree(presentableText);
          if (degree > max) {
            max = degree;
            target = ((StructureViewTreeElement)treeElement).getValue();
          }
        }
      }
    }
    return target instanceof Navigatable ? (Navigatable)target : null;
  }
  finally {
    Disposer.dispose(view);
  }
}
项目:intellij-ce-playground    文件:FileStructureDialog.java   
private static SpeedSearchComparator createSpeedSearchComparator() {
  return new SpeedSearchComparator(false) {
    @NotNull
    @Override
    protected MinusculeMatcher createMatcher(@NotNull String pattern) {
      return createFileStructureMatcher(pattern);
    }
  };
}
项目:intellij-ce-playground    文件:DefaultChooseByNameItemProvider.java   
@NotNull
private static List<Pair<String, MinusculeMatcher>> getPatternsAndMatchers(@NotNull String qualifierPattern, @NotNull final ChooseByNameBase base) {
  return ContainerUtil.map2List(split(qualifierPattern, base), new Function<String, Pair<String, MinusculeMatcher>>() {
    @NotNull
    @Override
    public Pair<String, MinusculeMatcher> fun(String s) {
      String namePattern = addSearchAnywherePatternDecorationIfNeeded(base, getNamePattern(base, s));
      return Pair.create(namePattern, buildPatternMatcher(namePattern, NameUtil.MatchingCaseSensitivity.NONE));
    }
  });
}
项目:intellij-ce-playground    文件:ChooseByNameBase.java   
private int detectBestStatisticalPosition() {
  if (myModel instanceof Comparator) {
    return 0;
  }

  int best = 0;
  int bestPosition = 0;
  int bestMatch = Integer.MIN_VALUE;
  final int count = myListModel.getSize();

  Matcher matcher = buildPatternMatcher(transformPattern(getTrimmedText()));

  final String statContext = statisticsContext();
  for (int i = 0; i < count; i++) {
    final Object modelElement = myListModel.getElementAt(i);
    String text = EXTRA_ELEM.equals(modelElement) || NON_PREFIX_SEPARATOR.equals(modelElement) ? null : myModel.getFullName(modelElement);
    if (text != null) {
      String shortName = myModel.getElementName(modelElement);
      int match = shortName != null && matcher instanceof MinusculeMatcher
                  ? ((MinusculeMatcher)matcher).matchingDegree(shortName) : Integer.MIN_VALUE;
      int stats = StatisticsManager.getInstance().getUseCount(new StatisticsInfo(statContext, text));
      if (match > bestMatch || match == bestMatch && stats > best) {
        best = stats;
        bestPosition = i;
        bestMatch = match;
      }
    }
  }

  if (bestPosition < count - 1 && myListModel.getElementAt(bestPosition) == NON_PREFIX_SEPARATOR) {
    bestPosition++;
  }

  return bestPosition;
}
项目:tools-idea    文件:SpeedSearchComparator.java   
private MinusculeMatcher obtainMatcher(String pattern) {
  if (myRecentSearchText == null || !myRecentSearchText.equals(pattern)) {
    myRecentSearchText = pattern;
    if (myShouldMatchCamelCase) {
      pattern = StringUtil.join(NameUtil.nameToWords(pattern), "*");
    }
    if (!myShouldMatchFromTheBeginning && !pattern.startsWith("*")) {
      pattern = "*" + pattern;
    }
    myMinusculeMatcher = new MinusculeMatcher(pattern, NameUtil.MatchingCaseSensitivity.NONE);
  }
  return myMinusculeMatcher;
}
项目:tools-idea    文件:GotoClassAction.java   
@Nullable private static Navigatable findMember(String pattern, PsiElement psiElement, VirtualFile file) {
  final PsiStructureViewFactory factory = LanguageStructureViewBuilder.INSTANCE.forLanguage(psiElement.getLanguage());
  final StructureViewBuilder builder = factory == null ? null : factory.getStructureViewBuilder(psiElement.getContainingFile());
  final FileEditor[] editors = FileEditorManager.getInstance(psiElement.getProject()).getEditors(file);
  if (builder == null || editors.length == 0) {
    return null;
  }

  final StructureView view = builder.createStructureView(editors[0], psiElement.getProject());
  try {
    final StructureViewTreeElement element = findElement(view.getTreeModel().getRoot(), psiElement, 4);
    if (element == null) {
      return null;
    }

    final MinusculeMatcher matcher = new MinusculeMatcher(pattern, NameUtil.MatchingCaseSensitivity.NONE);
    int max = Integer.MIN_VALUE;
    Object target = null;
    for (TreeElement treeElement : element.getChildren()) {
      if (treeElement instanceof StructureViewTreeElement) {
        final ItemPresentation presentation = treeElement.getPresentation();
        String presentableText = presentation == null ? null : presentation.getPresentableText();
        if (presentableText != null) {
          final int degree = matcher.matchingDegree(presentableText);
          if (degree > max) {
            max = degree;
            target = ((StructureViewTreeElement)treeElement).getValue();
          }
        }
      }
    }
    return target instanceof Navigatable ? (Navigatable)target : null;
  }
  finally {
    Disposer.dispose(view);
  }
}
项目:tools-idea    文件:DefaultChooseByNameItemProvider.java   
@NotNull
private static List<Pair<String, MinusculeMatcher>> getPatternsAndMatchers(@NotNull String qualifierPattern, @NotNull final ChooseByNameBase base) {
  return ContainerUtil.map2List(split(qualifierPattern, base), new Function<String, Pair<String, MinusculeMatcher>>() {
    @NotNull
    @Override
    public Pair<String, MinusculeMatcher> fun(String s) {
      String namePattern = addSearchAnywherePatternDecorationIfNeeded(base, getNamePattern(base, s));
      return Pair.create(namePattern, buildPatternMatcher(namePattern, NameUtil.MatchingCaseSensitivity.NONE));
    }
  });
}
项目:tools-idea    文件:ChooseByNameBase.java   
private int detectBestStatisticalPosition() {
  if (myModel instanceof Comparator) {
    return 0;
  }

  int best = 0;
  int bestPosition = 0;
  int bestMatch = Integer.MIN_VALUE;
  final int count = myListModel.getSize();

  Matcher matcher = buildPatternMatcher(transformPattern(myTextField.getText()));

  final String statContext = statisticsContext();
  for (int i = 0; i < count; i++) {
    final Object modelElement = myListModel.getElementAt(i);
    String text = EXTRA_ELEM.equals(modelElement) || NON_PREFIX_SEPARATOR.equals(modelElement) ? null : myModel.getFullName(modelElement);
    if (text != null) {
      String shortName = myModel.getElementName(modelElement);
      int match = shortName != null && matcher instanceof MinusculeMatcher
                  ? ((MinusculeMatcher)matcher).matchingDegree(shortName) : Integer.MIN_VALUE;
      int stats = StatisticsManager.getInstance().getUseCount(new StatisticsInfo(statContext, text));
      if (match > bestMatch || match == bestMatch && stats > best) {
        best = stats;
        bestPosition = i;
        bestMatch = match;
      }
    }
  }

  if (bestPosition < count - 1 && myListModel.getElementAt(bestPosition) == NON_PREFIX_SEPARATOR) {
    bestPosition++;
  }

  return bestPosition;
}
项目:consulo    文件:SpeedSearch.java   
@Nullable
@Override
public Iterable<TextRange> matchingFragments(@Nonnull String text) {
  if (myMatcher instanceof MinusculeMatcher) {
    return ((MinusculeMatcher)myMatcher).matchingFragments(text);
  }
  return null;
}
项目:consulo    文件:SpeedSearchComparator.java   
private MinusculeMatcher obtainMatcher(@Nonnull String pattern) {
  if (myRecentSearchText == null || !myRecentSearchText.equals(pattern)) {
    myRecentSearchText = pattern;
    if (myShouldMatchCamelCase) {
      pattern = StringUtil.join(NameUtil.nameToWords(pattern), "*");
    }
    if (!myShouldMatchFromTheBeginning && !pattern.startsWith("*")) {
      pattern = "*" + pattern;
    }
    myMinusculeMatcher = createMatcher(pattern);
  }
  return myMinusculeMatcher;
}
项目:consulo    文件:SearchEverywhereAction.java   
private SearchResult getActionsOrSettings(final String pattern, final int max, final boolean actions) {
  final SearchResult result = new SearchResult();
  if ((actions && !Registry.is("search.everywhere.actions")) || (!actions && !Registry.is("search.everywhere.settings"))) {
    return result;
  }
  final MinusculeMatcher matcher = new MinusculeMatcher("*" + pattern, NameUtil.MatchingCaseSensitivity.NONE);
  if (myActionProvider == null) {
    myActionProvider = createActionProvider();
  }

  myActionProvider.filterElements(pattern, true, new Processor<GotoActionModel.MatchedValue>() {
    @Override
    public boolean process(GotoActionModel.MatchedValue matched) {
      check();
      Object object = matched.value;
      if (myListModel.contains(object)) return true;

      if (!actions && isSetting(object)) {
        if (matcher.matches(getSettingText((OptionDescription)object))) {
          result.add(object);
        }
      }
      else if (actions && !isToolWindowAction(object) && isActionValue(object)) {
        result.add(object);
      }
      return result.size() <= max;
    }
  });

  return result;
}