Exemplo n.º 1
0
 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();
 }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
 public static PsiElement getUpperScope(final PsiElement element) {
   if (element instanceof PsiPackage) {
     return ((PsiPackage) element).getParentPackage();
   }
   if (element instanceof PbFile) {
     JavaPsiFacade facade = JavaPsiFacade.getInstance(element.getManager().getProject());
     return facade.findPackage(((PbFile) element).getPackageName());
   }
   if (element instanceof PbPsiElement) {
     PbPsiElement scope = (PbPsiElement) element.getParent();
     while (scope != null && !(scope instanceof PbFile) && !(scope instanceof PbBlock)) {
       scope = (PbPsiElement) scope.getParent();
     }
     /* // TC: This seems to skip from message block scope to package scope, preventing finding other messages
     defined in the same file.  Commenting out for now, since I don't see a good reason for it.
     if (scope instanceof PbFile) {
         JavaPsiFacade facade = JavaPsiFacade.getInstance(scope.getManager().getProject());
         return facade.findPackage(((PbFile) scope).getPackageName());
     }*/
     return scope;
   }
   assert false;
   return null;
 }
Exemplo n.º 4
0
 public static boolean sameType(PsiElement element, IElementType type) {
   return type.equals(element.getNode().getElementType());
 }
Exemplo n.º 5
0
 public static PsiElement getRootScope(final PsiElement element) {
   return JavaPsiFacade.getInstance(element.getManager().getProject()).findPackage("");
 }