boolean (PsiFile file, Editor editor) { final Map<String, String> map = new HashMap<>(); final StringBuilder sb = new StringBuilder(); final StringBuilder quote = new StringBuilder(); final ArrayList<String> split = new ArrayList<>(100); file.acceptChildren(new PsiRecursiveElementWalkingVisitor() { @Override public void visitElement(@NotNull PsiElement element) { if (element instanceof LeafPsiElement) { String type = ((LeafPsiElement)element).getElementType().toString(); String text = element.getText(); if (text.isEmpty()) return; for (int i = 0, len = text.length(); i < len / 2; i++) { char c = text.charAt(i); if (c == text.charAt(len - i - 1) && !Character.isLetter(c)) { quote.append(c); } else { break; } } boolean isQuoted = quote.length() > 0; boolean isNumber = false; if (isQuoted || type.equals("ID") || type.equals("word") || type.contains("IDENT") && !"ts".equals(text) || //NON-NLS (isNumber = text.matches("[0-9]+"))) { String replacement = map.get(text); if (replacement == null) { split.addAll(Arrays.asList( (isQuoted ? text.substring(quote.length(), text.length() - quote.length()).replace("''", "") : text).split(""))); if (!isNumber) { for (ListIterator<String> it = split.listIterator(); it.hasNext(); ) { String s = it.next(); if (s.isEmpty()) { it.remove(); continue; } int c = s.charAt(0); int cap = c & 32; c &= ~cap; c = (char)((c >= 'A') && (c <= 'Z') ? ((c - 'A' + 7) % 26 + 'A') : c) | cap; it.set(String.valueOf((char)c)); } } Collections.shuffle(split); if (isNumber && "0".equals(split.get(0))) { split.set(0, "1"); } replacement = StringUtil.join(split, ""); if (isQuoted) { replacement = quote + replacement + quote.reverse(); } map.put(text, replacement); } text = replacement; } sb.append(text); quote.setLength(0); split.clear(); } super.visitElement(element); } }); editor.getDocument().setText(sb.toString()); return true; }