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; }
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); } }
private boolean prefixMatchersInternal( final LookupElement element, final boolean itemCaseInsensitive) { for (final String name : element.getAllLookupStrings()) { if (itemCaseInsensitive && StringUtil.startsWithIgnoreCase(name, myPrefix) || prefixMatches(name)) { return true; } if (itemCaseInsensitive && CodeInsightSettings.ALL != CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE) { if (myCaseInsensitiveMatcher.matches(name)) { return true; } } } return false; }
@Override protected void validateView() throws BadDataException { super.validateView(); final Project project = myClassUnderRefactoring.getProject(); if (!myNamesValidator.isIdentifier(myView.getSuperClassName(), project)) { throw new BadDataException( PyBundle.message( "refactoring.extract.super.name.0.must.be.ident", myView.getSuperClassName())); } boolean rootFound = false; final File moduleFile = new File(myView.getModuleFile()); try { final String targetDir = FileUtil.toSystemIndependentName(moduleFile.getCanonicalPath()); for (final VirtualFile file : ProjectRootManager.getInstance(project).getContentRoots()) { if (StringUtil.startsWithIgnoreCase(targetDir, file.getPath())) { rootFound = true; break; } } } catch (final IOException ignore) { } if (!rootFound) { throw new BadDataException( PyBundle.message("refactoring.extract.super.target.path.outside.roots")); } // TODO: Cover with test. It can't be done for now, because testFixture reports root path // incorrectly // PY-12173 myView.getModuleFile(); final VirtualFile moduleVirtualFile = LocalFileSystem.getInstance().findFileByIoFile(moduleFile); if (moduleVirtualFile != null) { final PsiFile psiFile = PsiManager.getInstance(project).findFile(moduleVirtualFile); if (psiFile instanceof PyFile) { if (((PyFile) psiFile).findTopLevelClass(myView.getSuperClassName()) != null) { throw new BadDataException( PyBundle.message( "refactoring.extract.super.target.class.already.exists", myView.getSuperClassName())); } } } }