private void replaceCollectionGetAccess( PsiElement element, String contentVariableName, PsiVariable listVariable, String indexName, PsiElement childToSkip, StringBuilder out) { if (isListGetLookup(element, indexName, listVariable)) { out.append(contentVariableName); } else { final PsiElement[] children = element.getChildren(); if (children.length == 0) { final String text = element.getText(); if (PsiKeyword.INSTANCEOF.equals(text) && out.charAt(out.length() - 1) != ' ') { out.append(' '); } out.append(text); } else { boolean skippingWhiteSpace = false; for (final PsiElement child : children) { if (child.equals(childToSkip)) { skippingWhiteSpace = true; } else if (child instanceof PsiWhiteSpace && skippingWhiteSpace) { // don't do anything } else { skippingWhiteSpace = false; replaceCollectionGetAccess( child, contentVariableName, listVariable, indexName, childToSkip, out); } } } } }
private void replaceIteratorNext( PsiElement element, String contentVariableName, String iteratorName, PsiElement childToSkip, StringBuilder out, PsiType contentType) { if (isIteratorNext(element, iteratorName, contentType)) { out.append(contentVariableName); } else { final PsiElement[] children = element.getChildren(); if (children.length == 0) { final String text = element.getText(); if (PsiKeyword.INSTANCEOF.equals(text) && out.charAt(out.length() - 1) != ' ') { out.append(' '); } out.append(text); } else { boolean skippingWhiteSpace = false; for (final PsiElement child : children) { if (child.equals(childToSkip)) { skippingWhiteSpace = true; } else if (child instanceof PsiWhiteSpace && skippingWhiteSpace) { // don't do anything } else { skippingWhiteSpace = false; replaceIteratorNext( child, contentVariableName, iteratorName, childToSkip, out, contentType); } } } } }
private static int getSeqNumber(@NotNull PsiClass aClass) { // sequence number of this class among its parent' child classes named the same PsiElement parent = aClass.getParent(); if (parent == null) return -1; int seqNo = 0; for (PsiElement child : parent.getChildren()) { if (child == aClass) return seqNo; if (child instanceof PsiClass && Comparing.strEqual(aClass.getName(), ((PsiClass) child).getName())) { seqNo++; } } return -1; }
private static List<PsiElement> getTopLevelRegExpChars(String regExpText, Project project) { @SuppressWarnings("deprecation") PsiFile file = PsiFileFactory.getInstance(project).createFileFromText("A.regexp", regExpText); List<PsiElement> result = null; final PsiElement[] children = file.getChildren(); for (PsiElement child : children) { PsiElement[] grandChildren = child.getChildren(); if (grandChildren.length != 1) return Collections .emptyList(); // a | b, more than one branch, can not predict in current way for (PsiElement grandGrandChild : grandChildren[0].getChildren()) { if (result == null) result = new ArrayList<>(); result.add(grandGrandChild); } } return result != null ? result : Collections.<PsiElement>emptyList(); }