Esempio n. 1
0
 @Nullable
 public static <T> T getParentOfType(
     final DomElement element, final Class<T> requiredClass, final boolean strict) {
   for (DomElement curElement = strict && element != null ? element.getParent() : element;
       curElement != null;
       curElement = curElement.getParent()) {
     if (requiredClass.isInstance(curElement)) {
       return (T) curElement;
     }
   }
   return null;
 }
Esempio n. 2
0
 @Nullable
 public static List<JavaMethod> getFixedPath(DomElement element) {
   assert element.isValid();
   final LinkedList<JavaMethod> methods = new LinkedList<>();
   while (true) {
     final DomElement parent = element.getParent();
     if (parent instanceof DomFileElement) {
       break;
     }
     final JavaMethod method = getGetterMethod(element, parent);
     if (method == null) {
       return null;
     }
     methods.addFirst(method);
     element = element.getParent();
   }
   return methods;
 }
Esempio n. 3
0
 /**
  * @param domElement DomElement to search root of
  * @return the topmost valid DomElement being a parent of the given one. May be and may be not
  *     DomFileElement. If root tag has changed, file may lose its domness, so there will be no
  *     DomFileElement, but the inner DomElement's will be still alive because the underlying XML
  *     tags are valid
  */
 @NotNull
 public static DomElement getRoot(@NotNull DomElement domElement) {
   while (true) {
     final DomElement parent = domElement.getParent();
     if (parent == null) {
       return domElement;
     }
     domElement = parent;
   }
 }
Esempio n. 4
0
  public static <T extends DomElement> DomFileElement<T> getFileElement(
      @NotNull DomElement element) {

    if (element instanceof DomFileElement) {
      return (DomFileElement) element;
    }
    DomFileElement fileElement = element.getUserData(FILE_ELEMENT_KEY);
    if (fileElement == null) {
      DomElement parent = element.getParent();
      if (parent != null) {
        fileElement = getFileElement(parent);
      }
      element.putUserData(FILE_ELEMENT_KEY, fileElement);
    }
    return fileElement;
  }
Esempio n. 5
0
 public static boolean isAncestor(
     @NotNull DomElement ancestor, @NotNull DomElement descendant, boolean strict) {
   if (!strict && ancestor.equals(descendant)) return true;
   final DomElement parent = descendant.getParent();
   return parent != null && isAncestor(ancestor, parent, false);
 }