/**
   * Helper method to recursively insert all XML names for the given {@link ElementDescriptor} into
   * the roots array list. Keeps track of visited nodes to avoid infinite recursion. Also avoids
   * inserting the top {@link DocumentDescriptor} which is generally synthetic and not a valid root
   * element.
   */
  private void initRootElementDescriptor(
      ArrayList<String> roots, ElementDescriptor desc, HashSet<ElementDescriptor> visited) {
    if (!(desc instanceof DocumentDescriptor)) {
      String xmlName = desc.getXmlName();
      if (xmlName != null && xmlName.length() > 0) {
        roots.add(xmlName);
      }
    }

    visited.add(desc);

    for (ElementDescriptor child : desc.getChildren()) {
      if (!visited.contains(child)) {
        initRootElementDescriptor(roots, child, visited);
      }
    }
  }
Exemple #2
0
  private Node getManifestXmlNode(Document xmlDoc) {
    if (xmlDoc != null) {
      ElementDescriptor manifestDesc = mUiManifestNode.getDescriptor();
      String manifestXmlName = manifestDesc == null ? null : manifestDesc.getXmlName();
      assert manifestXmlName != null;

      if (manifestXmlName != null) {
        Node node = xmlDoc.getDocumentElement();
        if (node != null && manifestXmlName.equals(node.getNodeName())) {
          return node;
        }

        for (node = xmlDoc.getFirstChild(); node != null; node = node.getNextSibling()) {
          if (node.getNodeType() == Node.ELEMENT_NODE
              && manifestXmlName.equals(node.getNodeName())) {
            return node;
          }
        }
      }
    }

    return null;
  }
Exemple #3
0
  /**
   * Processes the markers of the specified {@link IFile} and updates the error status of {@link
   * UiElementNode}s and {@link UiAttributeNode}s.
   *
   * @param inputFile the file being edited.
   */
  private void updateFromExistingMarkers(IFile inputFile) {
    try {
      // get the markers for the file
      IMarker[] markers =
          inputFile.findMarkers(AdtConstants.MARKER_ANDROID, true, IResource.DEPTH_ZERO);

      AndroidManifestDescriptors desc = getManifestDescriptors();
      if (desc != null) {
        ElementDescriptor appElement = desc.getApplicationElement();

        if (appElement != null && mUiManifestNode != null) {
          UiElementNode appUiNode = mUiManifestNode.findUiChildNode(appElement.getXmlName());
          List<UiElementNode> children = appUiNode.getUiChildren();

          for (IMarker marker : markers) {
            processMarker(marker, children, IResourceDelta.ADDED);
          }
        }
      }

    } catch (CoreException e) {
      // findMarkers can throw an exception, in which case, we'll do nothing.
    }
  }