private static void renamePackagesInDirectory(@NotNull Project project, @NotNull PsiDirectory dir, @NotNull String newName) { WriteCommandAction.runWriteCommandAction(project, () -> { Module module = ModuleUtilCore.findModuleForPsiElement(dir); for (PsiFile file : dir.getFiles()) { if (file instanceof GoFile && GoPsiImplUtil.allowed(file, null, module)) { GoPackageClause packageClause = ((GoFile)file).getPackage(); String oldName = ((GoFile)file).getPackageName(); if (packageClause != null && oldName != null) { String fullName = GoTestFinder.isTestFile(file) && StringUtil.endsWith(oldName, GoConstants.TEST_SUFFIX) ? newName + GoConstants.TEST_SUFFIX : newName; packageClause.replace(GoElementFactory.createPackageClause(project, fullName)); } } } }); }
protected void doTest(@NotNull String codeBefore, @NotNull String expectedCodeAfter, @NotNull String surrounderDescription, boolean apply) { PsiFile file = myFixture.configureByText("a.go", normalizeCode(codeBefore)); List<AnAction> applicable = SurroundWithHandler.buildSurroundActions(myFixture.getProject(), myFixture.getEditor(), file, null); if (applicable == null) { assertFalse(apply); return; } String suffix = ". " + surrounderDescription; for (AnAction action : applicable) { String actionPresentation = action.getTemplatePresentation().getText(); if (actionPresentation != null && StringUtil.endsWith(actionPresentation, suffix)) { assertTrue(apply); myFixture.testAction(action); return; } } if (apply) { myFixture.checkResult(normalizeCode(expectedCodeAfter), true); } } }
@Override public void documentChanged(DocumentEvent e) { String text = field.getText(); if (StringUtil.isEmpty(text) || StringUtil.endsWith(text, "\\")) { return; } addUpdateRequest(250, () -> consumer.consume(field.getText())); } });
public static boolean trimEnd(@NotNull StringBuilder buffer, @NotNull CharSequence end) { if (endsWith(buffer, end)) { buffer.delete(buffer.length() - end.length(), buffer.length()); return true; } return false; }
@TestOnly @NotNull public static String toIdentifier(@NotNull String text, @Nullable NameFormat format, @NotNull Case cas) { if (text.isEmpty()) return ""; String fixed = text.replaceAll("[^:\\p{javaJavaIdentifierPart}]", "_"); boolean allCaps = Case.UPPER.apply(fixed).equals(fixed); StringBuilder sb = new StringBuilder(); if (!Character.isJavaIdentifierStart(fixed.charAt(0)) && sb.length() == 0) sb.append("_"); String[] strings = NameUtil.nameToWords(fixed); for (int i = 0, len = strings.length; i < len; i++) { String s = strings[i]; if (cas == Case.CAMEL && s.startsWith("_") && !(i == 0 || i == len - 1)) continue; if (cas == Case.UPPER && !s.startsWith("_") && !(i == 0 || StringUtil.endsWith(sb, "_"))) sb.append("_"); if (cas == Case.CAMEL && !allCaps && Case.UPPER.apply(s).equals(s)) sb.append(s); else sb.append(cas.apply(s)); } return format == null ? sb.toString() : format.apply(sb.toString()); }
protected boolean isCloseMarker() { PerlHeredocQueueElement currentHeredoc = heredocQueue.peekFirst(); CharSequence tokenText = yytext(); CharSequence markerText = currentHeredoc.getMarker(); if (currentHeredoc.isIndentable()) { if (!StringUtil.endsWith(tokenText, markerText)) { return false; } for (int i = 0; i < tokenText.length() - markerText.length(); i++) { if (!Character.isWhitespace(tokenText.charAt(i))) { return false; } } return true; } else { return StringUtil.equals(tokenText, markerText); } }
@Override public PerlHeredocElementImpl handleContentChange(@NotNull PerlHeredocElementImpl element, @NotNull TextRange range, String newContent) throws IncorrectOperationException { StringBuilder sb = new StringBuilder(newContent); if (element.getTextLength() == range.getEndOffset() && !StringUtil.endsWith(newContent, "\n")) { sb.append("\n"); } Project project = element.getProject(); if (range.getStartOffset() > 0) { sb.insert(0, getIndenter(project, range.getStartOffset())); range = TextRange.from(0, range.getEndOffset()); } normalizeIndentation(project, sb, element.getRealIndentSize()); String newElementText = range.replace(element.getText(), sb.toString()); PerlHeredocElementImpl replacement = PerlElementFactory.createHeredocBodyReplacement(element, newElementText); return (PerlHeredocElementImpl)element.replace(replacement); }
if (runType == NUMBER_SIMPLE || runType == NUMBER && StringUtil.endsWith(run.getText(), ".")) { return Spacing.createSpacing(1, 1, 0, true, 1);