コード例 #1
0
ファイル: ManifestEditor.java プロジェクト: qqedfr/kitkat-2
  /**
   * Creates the initial UI Root Node, including the known mandatory elements.
   *
   * @param force if true, a new UiManifestNode is recreated even if it already exists.
   */
  @Override
  protected void initUiRootNode(boolean force) {
    // The manifest UI node is always created, even if there's no corresponding XML node.
    if (mUiManifestNode != null && force == false) {
      return;
    }

    AndroidManifestDescriptors manifestDescriptor = getManifestDescriptors();

    if (manifestDescriptor != null) {
      ElementDescriptor manifestElement = manifestDescriptor.getManifestElement();
      mUiManifestNode = manifestElement.createUiNode();
      mUiManifestNode.setEditor(this);

      // Similarly, always create the /manifest/uses-sdk followed by /manifest/application
      // (order of the elements now matters)
      ElementDescriptor element = manifestDescriptor.getUsesSdkElement();
      boolean present = false;
      for (UiElementNode ui_node : mUiManifestNode.getUiChildren()) {
        if (ui_node.getDescriptor() == element) {
          present = true;
          break;
        }
      }
      if (!present) {
        mUiManifestNode.appendNewUiChild(element);
      }

      element = manifestDescriptor.getApplicationElement();
      present = false;
      for (UiElementNode ui_node : mUiManifestNode.getUiChildren()) {
        if (ui_node.getDescriptor() == element) {
          present = true;
          break;
        }
      }
      if (!present) {
        mUiManifestNode.appendNewUiChild(element);
      }

      onDescriptorsChanged();
    } else {
      // create a dummy descriptor/uinode until we have real descriptors
      ElementDescriptor desc =
          new ElementDescriptor(
              "manifest", //$NON-NLS-1$
              "temporary descriptors due to missing decriptors", //$NON-NLS-1$
              null /*tooltip*/,
              null /*sdk_url*/,
              null /*attributes*/,
              null /*children*/,
              false /*mandatory*/);
      mUiManifestNode = desc.createUiNode();
      mUiManifestNode.setEditor(this);
    }
  }
コード例 #2
0
  /**
   * 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);
      }
    }
  }
コード例 #3
0
ファイル: ManifestEditor.java プロジェクト: qqedfr/kitkat-2
  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;
  }
コード例 #4
0
ファイル: ManifestEditor.java プロジェクト: qqedfr/kitkat-2
  /**
   * 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.
    }
  }