public static int calculatePackagePriority(@NotNull String importPath, @Nullable String currentPath) { int priority = PACKAGE_PRIORITY; if (StringUtil.isNotEmpty(currentPath)) { String[] givenSplit = importPath.split("/"); String[] contextSplit = currentPath.split("/"); for (int i = 0; i < contextSplit.length && i < givenSplit.length; i++) { if (contextSplit[i].equals(givenSplit[i])) { priority++; } else { break; } } } return priority - StringUtil.countChars(importPath, '/') - StringUtil.countChars(importPath, '.'); }
beginIndex = 1; } else { int slashes = StringUtil.countChars(glob, '/'); if (slashes == 0 || (slashes == 1 && StringUtil.endsWithChar(glob, '/'))) { sb.append("(?:[^/]*?/)*");
@NotNull private static Collection<PsiComment> getCommentsToConsider(@NotNull GoFile file) { Collection<PsiComment> commentsToConsider = ContainerUtil.newArrayList(); PsiElement child = file.getFirstChild(); int lastEmptyLineOffset = 0; while (child != null) { if (child instanceof PsiComment) { commentsToConsider.add((PsiComment)child); } else if (child instanceof PsiWhiteSpace) { if (StringUtil.countChars(child.getText(), '\n') > 1) { lastEmptyLineOffset = child.getTextRange().getStartOffset(); } } else { break; } child = child.getNextSibling(); } int finalLastEmptyLineOffset = lastEmptyLineOffset; return ContainerUtil.filter(commentsToConsider, comment -> comment.getTextRange().getStartOffset() < finalLastEmptyLineOffset); } }
@Contract(pure = true) public static int countChars(@NotNull CharSequence text, char c, int offset, boolean stopAtOtherChar) { return countChars(text, c, offset, text.length(), stopAtOtherChar); }
@Contract(pure = true) public static int countNewLines(@NotNull CharSequence text) { return countChars(text, '\n'); }
@Contract(pure = true) public static int countChars(@NotNull CharSequence text, char c) { return countChars(text, c, 0, false); }