aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse/plugins
diff options
context:
space:
mode:
authorRaphael <raphael@google.com>2012-03-01 17:30:25 -0800
committerRaphael <raphael@google.com>2012-03-01 18:42:32 -0800
commitf0b625c2679ecd65345e4b33842d1773bf50cd8f (patch)
tree2abc9b632c99d167b885e842eaa19ef314456b2c /eclipse/plugins
parent540b8a8fac9d9f07c0439a08d3f9f8f0486fd71f (diff)
downloadsdk-f0b625c2679ecd65345e4b33842d1773bf50cd8f.zip
sdk-f0b625c2679ecd65345e4b33842d1773bf50cd8f.tar.gz
sdk-f0b625c2679ecd65345e4b33842d1773bf50cd8f.tar.bz2
ADT: fix assert when opening manifest.
In very rare instances, it seems like the xpath used to find the manifest root element isn't working properly and triggers the assert after it. It's unclear what can trigger this issue. This removes the XPath code and manually finds the root element. Change-Id: Idf983e12306aed3058916fe4a5e847830ecf8fe1
Diffstat (limited to 'eclipse/plugins')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java35
1 files changed, 18 insertions, 17 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java
index a8ebe75..8f34b48 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/manifest/ManifestEditor.java
@@ -35,7 +35,6 @@ import com.android.ide.eclipse.adt.internal.editors.uimodel.UiElementNode;
import com.android.ide.eclipse.adt.internal.resources.manager.GlobalProjectMonitor;
import com.android.ide.eclipse.adt.internal.resources.manager.GlobalProjectMonitor.IFileListener;
import com.android.ide.eclipse.adt.internal.sdk.AndroidTargetData;
-import com.android.sdklib.xml.AndroidXPathFactory;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
@@ -57,10 +56,6 @@ import org.w3c.dom.Node;
import java.util.Collection;
import java.util.List;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathExpressionException;
-
/**
* Multi-page form editor for AndroidManifest.xml.
*/
@@ -189,18 +184,24 @@ public final class ManifestEditor extends AndroidXmlEditor {
private Node getManifestXmlNode(Document xmlDoc) {
if (xmlDoc != null) {
- ElementDescriptor manifest_desc = mUiManifestNode.getDescriptor();
- try {
- XPath xpath = AndroidXPathFactory.newXPath();
- Node node = (Node) xpath.evaluate("/" + manifest_desc.getXmlName(), //$NON-NLS-1$
- xmlDoc,
- XPathConstants.NODE);
- assert node != null && node.getNodeName().equals(manifest_desc.getXmlName());
-
- return node;
- } catch (XPathExpressionException e) {
- AdtPlugin.log(e, "XPath error when trying to find '%s' element in XML.", //$NON-NLS-1$
- manifest_desc.getXmlName());
+ 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;
+ }
+ }
}
}