com.intellij.psi.codeStyle.NameUtil Java Examples
The following examples show how to use
com.intellij.psi.codeStyle.NameUtil.
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: CSharpCompletionSorting.java From consulo-csharp with Apache License 2.0 | 6 votes |
@Nullable @Override @RequiredReadAction public Comparable weigh(@Nonnull LookupElement element) { if(myExpectedNames.isEmpty()) { return null; } String targetName = getName(element); if(targetName != null) { int max = 0; final List<String> wordsNoDigits = NameUtil.nameToWordsLowerCase(truncDigits(targetName)); for(String expectedName : myExpectedNames) { final THashSet<String> set = new THashSet<>(NameUtil.nameToWordsLowerCase(truncDigits(expectedName))); set.retainAll(wordsNoDigits); max = Math.max(max, set.size()); } return -max; } return 0; }
Example #2
Source File: CSharpCompletionSorting.java From consulo-csharp with Apache License 2.0 | 6 votes |
private static int calcMatch(final String expectedName, final List<String> words, int max) { if(expectedName == null) { return max; } String[] expectedWords = NameUtil.nameToWords(expectedName); int limit = Math.min(words.size(), expectedWords.length); for(int i = 0; i < limit; i++) { String word = words.get(words.size() - i - 1); String expectedWord = expectedWords[expectedWords.length - i - 1]; if(word.equalsIgnoreCase(expectedWord)) { max = Math.max(max, i + 1); } else { break; } } return max; }
Example #3
Source File: ListChooseByNameModel.java From consulo with Apache License 2.0 | 6 votes |
@Nullable private Pattern getTaskPattern(String pattern) { if (!Comparing.strEqual(pattern, myPattern)) { myCompiledPattern = null; myPattern = pattern; } if (myCompiledPattern == null) { final String regex = "^.*" + NameUtil.buildRegexp(pattern, 0, true, true); final Perl5Compiler compiler = new Perl5Compiler(); try { myCompiledPattern = compiler.compile(regex); } catch (MalformedPatternException ignored) { } } return myCompiledPattern; }
Example #4
Source File: CapitalizeAndUnderscoreMacro.java From consulo with Apache License 2.0 | 6 votes |
@Override protected Result calculateResult(@Nonnull Expression[] params, ExpressionContext context, boolean quick) { String text = getTextResult(params, context, true); if (text != null && text.length() > 0) { final String[] words = NameUtil.nameToWords(text); boolean insertUnderscore = false; final StringBuffer buf = new StringBuffer(); for (String word : words) { if (insertUnderscore) { buf.append("_"); } else { insertUnderscore = true; } buf.append(StringUtil.toUpperCase(word)); } return new TextResult(buf.toString()); } return null; }
Example #5
Source File: OptionsTopHitProvider.java From consulo with Apache License 2.0 | 6 votes |
@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.accept(option); } } } }
Example #6
Source File: CamelHumpMatcher.java From consulo with Apache License 2.0 | 6 votes |
private MinusculeMatcher createMatcher(final boolean caseSensitive) { String prefix = applyMiddleMatching(myPrefix); NameUtil.MatcherBuilder builder = NameUtil.buildMatcher(prefix); if (caseSensitive) { int setting = CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE; if (setting == CodeInsightSettings.FIRST_LETTER) { builder = builder.withCaseSensitivity(NameUtil.MatchingCaseSensitivity.FIRST_LETTER); } else if (setting == CodeInsightSettings.ALL) { builder = builder.withCaseSensitivity(NameUtil.MatchingCaseSensitivity.ALL); } } if (myTypoTolerant) { builder = builder.typoTolerant(); } return builder.build(); }
Example #7
Source File: CSharpCompletionSorting.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Nonnull @Override @RequiredReadAction public Comparable weigh(@Nonnull LookupElement element) { final String name = getName(element); if(name != null && getNameEndMatchingDegree(name, myExpectedTypes) != 0) { return NameUtil.nameToWords(name).length - 1000; } return 0; }
Example #8
Source File: NameSuggester.java From consulo with Apache License 2.0 | 5 votes |
public String suggestName(final String propertyName) { if (myOldClassNameAsGiven.equals(propertyName)) return myNewClassNameAsGiven; final String[] propertyWords = NameUtil.splitNameIntoWords(propertyName); TIntIntHashMap matches = calculateMatches(propertyWords); if (matches.isEmpty()) return propertyName; TreeMap<Pair<Integer,Integer>, String> replacements = calculateReplacements(propertyWords, matches); if (replacements.isEmpty()) return propertyName; return calculateNewName(replacements, propertyWords, propertyName); }
Example #9
Source File: NameSuggester.java From consulo with Apache License 2.0 | 5 votes |
public NameSuggester(String oldClassName, String newClassName) { myOldClassNameAsGiven = oldClassName; myNewClassNameAsGiven = newClassName; myOldClassName = NameUtil.splitNameIntoWords(oldClassName); myNewClassName = NameUtil.splitNameIntoWords(newClassName); myChanges = new ArrayList<OriginalToNewChange>(); int oldIndex = myOldClassName.length - 1; int oldLastMatch = myOldClassName.length; int newLastMatch = myNewClassName.length; while(oldIndex >= 0) { final String patternWord = myOldClassName[oldIndex]; final int matchingWordIndex = findInNewBackwardsFromIndex(patternWord, newLastMatch - 1); if (matchingWordIndex < 0) { // no matching word oldIndex--; } else { // matching word found if (oldIndex + 1 <= oldLastMatch - 1 || matchingWordIndex + 1 <= newLastMatch - 1) { final OriginalToNewChange change = new OriginalToNewChange( oldIndex + 1, oldLastMatch - 1, matchingWordIndex + 1, newLastMatch - 1); myChanges.add(change); } oldLastMatch = oldIndex; newLastMatch = matchingWordIndex; oldIndex--; } } if (0 <= oldLastMatch - 1 || 0 <= newLastMatch - 1) { myChanges.add(new OriginalToNewChange(0, oldLastMatch - 1, 0, newLastMatch - 1)); } }
Example #10
Source File: DefaultChooseByNameItemProvider.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static MinusculeMatcher getFullMatcher(FindSymbolParameters parameters, ChooseByNameViewModel base) { String fullRawPattern = buildFullPattern(base, parameters.getCompletePattern()); String fullNamePattern = buildFullPattern(base, base.transformPattern(parameters.getCompletePattern())); return NameUtil.buildMatcherWithFallback(fullRawPattern, fullNamePattern, NameUtil.MatchingCaseSensitivity.NONE); }
Example #11
Source File: RecentFilesSEContributor.java From consulo with Apache License 2.0 | 5 votes |
@Override public void fetchWeightedElements(@Nonnull String pattern, @Nonnull ProgressIndicator progressIndicator, @Nonnull Processor<? super FoundItemDescriptor<Object>> consumer) { if (myProject == null) { return; //nothing to search } String searchString = filterControlSymbols(pattern); MinusculeMatcher matcher = NameUtil.buildMatcher("*" + searchString).build(); List<VirtualFile> opened = Arrays.asList(FileEditorManager.getInstance(myProject).getSelectedFiles()); List<VirtualFile> history = Lists.reverse(EditorHistoryManager.getInstance(myProject).getFileList()); List<FoundItemDescriptor<Object>> res = new ArrayList<>(); ProgressIndicatorUtils.yieldToPendingWriteActions(); ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(() -> { PsiManager psiManager = PsiManager.getInstance(myProject); Stream<VirtualFile> stream = history.stream(); if (!StringUtil.isEmptyOrSpaces(searchString)) { stream = stream.filter(file -> matcher.matches(file.getName())); } res.addAll(stream.filter(vf -> !opened.contains(vf) && vf.isValid()).distinct().map(vf -> { PsiFile f = psiManager.findFile(vf); return f == null ? null : new FoundItemDescriptor<Object>(f, matcher.matchingDegree(vf.getName())); }).filter(file -> file != null).collect(Collectors.toList())); ContainerUtil.process(res, consumer); }, progressIndicator); }
Example #12
Source File: RunConfigurationsSEContributor.java From consulo with Apache License 2.0 | 5 votes |
@Override public void fetchElements(@Nonnull String pattern, @Nonnull ProgressIndicator progressIndicator, @Nonnull Processor<? super ChooseRunConfigurationPopup.ItemWrapper> consumer) { if (StringUtil.isEmptyOrSpaces(pattern)) return; pattern = filterString(pattern); MinusculeMatcher matcher = NameUtil.buildMatcher(pattern).build(); for (ChooseRunConfigurationPopup.ItemWrapper wrapper : ChooseRunConfigurationPopup.createFlatSettingsList(myProject)) { if (matcher.matches(wrapper.getText()) && !consumer.process(wrapper)) { return; } } }
Example #13
Source File: TestFinderHelper.java From consulo with Apache License 2.0 | 5 votes |
public static List<Pair<String, Integer>> collectPossibleClassNamesWithWeights(String testName) { String[] words = NameUtil.splitNameIntoWords(testName); List<Pair<String, Integer>> result = new ArrayList<Pair<String, Integer>>(); for (int from = 0; from < words.length; from++) { for (int to = from; to < words.length; to++) { result.add(new Pair<String, Integer>(StringUtil.join(words, from, to + 1, ""), words.length - from + to)); } } return result; }
Example #14
Source File: SpeedSearchComparator.java From consulo with Apache License 2.0 | 5 votes |
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; }
Example #15
Source File: TypePresentationService.java From consulo with Apache License 2.0 | 5 votes |
public static String getDefaultTypeName(final Class aClass) { String simpleName = aClass.getSimpleName(); final int i = simpleName.indexOf('$'); if (i >= 0) { simpleName = simpleName.substring(i + 1); } return StringUtil.capitalizeWords(StringUtil.join(NameUtil.nameToWords(simpleName), " "), true); }
Example #16
Source File: CSharpCompletionSorting.java From consulo-csharp with Apache License 2.0 | 5 votes |
@RequiredReadAction private static int getNameEndMatchingDegree(final String name, List<ExpectedTypeInfo> expectedInfos) { int res = 0; if(name != null && expectedInfos != null) { final List<String> words = NameUtil.nameToWordsLowerCase(name); final List<String> wordsNoDigits = NameUtil.nameToWordsLowerCase(truncDigits(name)); int max1 = calcMatch(words, 0, expectedInfos); max1 = calcMatch(wordsNoDigits, max1, expectedInfos); res = max1; } return res; }
Example #17
Source File: HaxeNameSuggesterUtil.java From intellij-haxe with Apache License 2.0 | 5 votes |
@NotNull public static Collection<String> generateNames(@NotNull String name, boolean useUpperCase, boolean isArray) { name = prepareNameTextForSuggestions(name); Collection<String> candidates = new LinkedHashSet<String>(); if (null != name && !name.isEmpty()) { candidates.addAll(NameUtil.getSuggestionsByName(name, "", "", useUpperCase, false, isArray)); } return candidates; }
Example #18
Source File: SpeedSearch.java From consulo with Apache License 2.0 | 5 votes |
public void updatePattern(final String string) { String prevString = myString; myString = string; try { String pattern = "*" + string; NameUtil.MatchingCaseSensitivity caseSensitivity = NameUtil.MatchingCaseSensitivity.NONE; String separators = ""; myMatcher = myMatchAllOccurrences ? AllOccurrencesMatcher.create(pattern, caseSensitivity, separators) : new FixingLayoutMatcher(pattern, caseSensitivity, separators); } catch (Exception e) { myMatcher = null; } fireStateChanged(prevString); }
Example #19
Source File: GotoClassAction.java From consulo with Apache License 2.0 | 4 votes |
@Nullable public static Navigatable findMember(String memberPattern, String fullPattern, 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; } MinusculeMatcher matcher = NameUtil.buildMatcher(memberPattern).build(); int max = Integer.MIN_VALUE; Object target = null; for (TreeElement treeElement : element.getChildren()) { if (treeElement instanceof StructureViewTreeElement) { Object value = ((StructureViewTreeElement)treeElement).getValue(); if (value instanceof PsiElement && value instanceof Navigatable && fullPattern.equals(CopyReferenceAction.elementToFqn((PsiElement)value))) { return (Navigatable)value; } 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); } }
Example #20
Source File: FileTextFieldImpl.java From consulo with Apache License 2.0 | 4 votes |
private static MinusculeMatcher createMatcher(String prefix) { return NameUtil.buildMatcher("*" + prefix, NameUtil.MatchingCaseSensitivity.NONE); }
Example #21
Source File: ChooseByNameBase.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull private static Matcher buildPatternMatcher(@Nonnull String pattern) { return NameUtil.buildMatcher(pattern, NameUtil.MatchingCaseSensitivity.NONE); }
Example #22
Source File: NameUtilTest.java From consulo with Apache License 2.0 | 4 votes |
private static void assertSplitEquals(String[] expected, String name) { final String[] result = NameUtil.splitNameIntoWords(name); assertEquals(Arrays.asList(expected).toString(), Arrays.asList(result).toString()); }
Example #23
Source File: GotoActionItemProvider.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull static Matcher buildMatcher(String pattern) { return pattern.contains(" ") ? new WordPrefixMatcher(pattern) : NameUtil.buildMatcher("*" + pattern, NameUtil.MatchingCaseSensitivity.NONE); }
Example #24
Source File: DefaultChooseByNameItemProvider.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull private static MinusculeMatcher buildPatternMatcher(@Nonnull String pattern) { return NameUtil.buildMatcher(pattern, NameUtil.MatchingCaseSensitivity.NONE); }
Example #25
Source File: SpeedSearchComparator.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull protected MinusculeMatcher createMatcher(@Nonnull String pattern) { return NameUtil.buildMatcher(pattern).build(); }
Example #26
Source File: GotoFileItemProvider.java From consulo with Apache License 2.0 | 4 votes |
SuffixMatches(String pattern, int from, @Nonnull ProgressIndicator indicator) { patternSuffix = pattern.substring(from); matcher = NameUtil.buildMatcher((from > 0 ? " " : "*") + patternSuffix, NameUtil.MatchingCaseSensitivity.NONE); this.indicator = indicator; }
Example #27
Source File: GotoFileItemProvider.java From consulo with Apache License 2.0 | 4 votes |
@Nonnull public static MinusculeMatcher getQualifiedNameMatcher(@Nonnull String pattern) { pattern = "*" + StringUtil.replace(StringUtil.replace(pattern, "\\", "*\\*"), "/", "*/*"); return NameUtil.buildMatcher(pattern).withCaseSensitivity(NameUtil.MatchingCaseSensitivity.NONE).preferringStartMatches().build(); }
Example #28
Source File: SearchEverywhereUI.java From consulo with Apache License 2.0 | 4 votes |
private void rebuildList() { ApplicationManager.getApplication().assertIsDispatchThread(); stopSearching(); myResultsList.setEmptyText(IdeBundle.message("label.choosebyname.searching")); String rawPattern = getSearchPattern(); updateViewType(rawPattern.isEmpty() ? ViewType.SHORT : ViewType.FULL); String namePattern = mySelectedTab.getContributor().map(contributor -> contributor.filterControlSymbols(rawPattern)).orElse(rawPattern); MinusculeMatcher matcher = NameUtil.buildMatcherWithFallback("*" + rawPattern, "*" + namePattern, NameUtil.MatchingCaseSensitivity.NONE); MatcherHolder.associateMatcher(myResultsList, matcher); Map<SearchEverywhereContributor<?>, Integer> contributorsMap = new HashMap<>(); Optional<SearchEverywhereContributor<?>> selectedContributor = mySelectedTab.getContributor(); if (selectedContributor.isPresent()) { contributorsMap.put(selectedContributor.get(), SINGLE_CONTRIBUTOR_ELEMENTS_LIMIT); } else { contributorsMap.putAll(getAllTabContributors().stream().collect(Collectors.toMap(c -> c, c -> MULTIPLE_CONTRIBUTORS_ELEMENTS_LIMIT))); } List<SearchEverywhereContributor<?>> contributors = DumbService.getInstance(myProject).filterByDumbAwareness(contributorsMap.keySet()); if (contributors.isEmpty() && DumbService.isDumb(myProject)) { myResultsList.setEmptyText(IdeBundle.message("searcheverywhere.indexing.mode.not.supported", mySelectedTab.getText(), ApplicationNamesInfo.getInstance().getFullProductName())); myListModel.clear(); return; } if (contributors.size() != contributorsMap.size()) { myResultsList.setEmptyText(IdeBundle.message("searcheverywhere.indexing.incomplete.results", mySelectedTab.getText(), ApplicationNamesInfo.getInstance().getFullProductName())); } myListModel.expireResults(); contributors.forEach(contributor -> myListModel.setHasMore(contributor, false)); String commandPrefix = SearchTopHitProvider.getTopHitAccelerator(); if (rawPattern.startsWith(commandPrefix)) { String typedCommand = rawPattern.split(" ")[0].substring(commandPrefix.length()); List<SearchEverywhereCommandInfo> commands = getCommandsForCompletion(contributors, typedCommand); if (!commands.isEmpty()) { if (rawPattern.contains(" ")) { contributorsMap.keySet().retainAll(commands.stream().map(SearchEverywhereCommandInfo::getContributor).collect(Collectors.toSet())); } else { myListModel.clear(); List<SearchEverywhereFoundElementInfo> lst = ContainerUtil.map(commands, command -> new SearchEverywhereFoundElementInfo(command, 0, myStubCommandContributor)); myListModel.addElements(lst); ScrollingUtil.ensureSelectionExists(myResultsList); } } } mySearchProgressIndicator = mySearcher.search(contributorsMap, rawPattern); }
Example #29
Source File: ChangeCollectingVisitor.java From consulo with Apache License 2.0 | 4 votes |
public ChangeCollectingVisitor(String path, String projectId, @javax.annotation.Nullable String pattern) { myPath = path; myProjectId = projectId; myPattern = pattern == null ? null : Pattern.compile(NameUtil.buildRegexp(pattern, 0, true, true), Pattern.CASE_INSENSITIVE); }
Example #30
Source File: LookupCellRenderer.java From consulo with Apache License 2.0 | 4 votes |
public static FList<TextRange> getMatchingFragments(String prefix, String name) { return NameUtil.buildMatcher("*" + prefix).build().matchingFragments(name); }