public static PsiElement getChild( final PsiElement parent, int position, boolean ignoreWhiteSpaces, boolean ignoreComments, boolean ignoreErrors) { PsiElement curChild = parent.getFirstChild(); int i = 0; while (i <= position && curChild != null) { if (WHITE_SPACES.contains(curChild.getNode().getElementType())) { if (!ignoreWhiteSpaces) i++; curChild = curChild.getNextSibling(); } else if (COMMENTS.contains(curChild.getNode().getElementType())) { if (!ignoreComments) i++; curChild = curChild.getNextSibling(); } else if (curChild instanceof PsiErrorElement) { if (!ignoreErrors) { return null; } i++; curChild = curChild.getNextSibling(); } else { if (i == position) return curChild; i++; curChild = curChild.getNextSibling(); } } return null; }
public static ASTNode createSimpleNodeWithText(String text, Project project) { assert !text.contains(" ") : "name cannot contain white spaces"; PsiFileFactory psiFileFactory = PsiFileFactory.getInstance(project); PbFile dummyFile = (PbFile) psiFileFactory.createFileFromText( "DUMMY_SET_NAME", PbFileType.PROTOBUF_FILE_TYPE, "message " + text + " {}"); PbMessageDef dummyMessage = (PbMessageDef) PbPsiUtil.getChild(dummyFile, 0, true, true, false); PsiElement newNameElement = dummyMessage.getNameElement(); return newNameElement.getNode(); }
public static boolean sameType(PsiElement element, IElementType type) { return type.equals(element.getNode().getElementType()); }