aboutsummaryrefslogtreecommitdiffstats
path: root/eclipse/plugins/com.android.ide.eclipse.tests
diff options
context:
space:
mode:
authorTor Norbye <tnorbye@google.com>2011-08-03 16:43:19 -0700
committerTor Norbye <tnorbye@google.com>2011-08-03 16:58:57 -0700
commitc0cc7c38c016afb66987c2b2340c045f50136f90 (patch)
tree23f9b70ca3803286efefaa8f57e5031a1d042a8c /eclipse/plugins/com.android.ide.eclipse.tests
parent83d04640bf245bb9ce108cef01e188761bc905f8 (diff)
downloadsdk-c0cc7c38c016afb66987c2b2340c045f50136f90.zip
sdk-c0cc7c38c016afb66987c2b2340c045f50136f90.tar.gz
sdk-c0cc7c38c016afb66987c2b2340c045f50136f90.tar.bz2
Add tag-handling for Go To Matching in XML documents
Eclipse has a Go to Matching feature, bound to Ctrl-Shift-P. However, for XML documents it only works on the character level, so if the caret is inside a tag it does nothing, and if you place it on an angle bracket, it just jumps to the opposite angle bracket for the same tag. This changeset adds a new character pair matcher which works at the tag level, so if you for example place the caret anywhere in an end tag, it will highlight the first character of the opening tag, and if you jump it will jump to that opening tag. Similarly, if you place the caret next to the < or tag name of an opening tag, it will jump to the closing tag. Change-Id: Id25487b24616abf79c71de5eec21f8c0f07e68cc
Diffstat (limited to 'eclipse/plugins/com.android.ide.eclipse.tests')
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlCharacterMatcherTest.java144
1 files changed, 144 insertions, 0 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlCharacterMatcherTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlCharacterMatcherTest.java
new file mode 100644
index 0000000..acb2b04
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/AndroidXmlCharacterMatcherTest.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Eclipse Public License, Version 1.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.eclipse.org/org/documents/epl-v10.php
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.ide.eclipse.adt.internal.editors;
+
+import com.android.ide.eclipse.adt.internal.editors.layout.refactoring.AdtProjectTest;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
+
+@SuppressWarnings("restriction")
+public class AndroidXmlCharacterMatcherTest extends AdtProjectTest {
+ public void testGotoMatchingFwd1() throws Exception {
+ checkGotoMatching(
+ "<app^lication android:icon",
+ "^</application>");
+ }
+
+ public void testGotoMatchingFwd2() throws Exception {
+ checkGotoMatching(
+ "^<application android:icon",
+ "^</application>");
+ }
+
+ public void testGotoMatchingFwd3() throws Exception {
+ checkGotoMatching(
+ "<application^ android:icon",
+ "^</application>");
+ }
+
+ public void testGotoMatchingBwd1() throws Exception {
+ checkGotoMatching(
+ "^</application>",
+ "^<application android:icon");
+ }
+
+ public void testGotoMatchingBwd2() throws Exception {
+ checkGotoMatching(
+ "<^/application>",
+ "^<application android:icon");
+ }
+
+ public void testGotoMatchingBwd3() throws Exception {
+ checkGotoMatching(
+ "</^application>",
+ "^<application android:icon");
+ }
+
+ public void testGotoMatchingBwd4() throws Exception {
+ checkGotoMatching(
+ "</app^lication>",
+ "^<application android:icon");
+ }
+
+ public void testGotoMatchingBwd5() throws Exception {
+ checkGotoMatching(
+ "</^application>",
+ "^<application android:icon");
+ }
+
+ public void testGotoMatchingBwd6() throws Exception {
+ checkGotoMatching(
+ "</^application>",
+ "^<application android:icon");
+ }
+
+ public void testGotoMatchingFwd4() throws Exception {
+ checkGotoMatching(
+ "<intent-filter^>",
+ "^</intent-filter>");
+ }
+
+ public void testGotoMatchingFwd5() throws Exception {
+ checkGotoMatching(
+ "<intent-filter>^",
+ "^</intent-filter>");
+ }
+
+ public void testGotoMatchingFallback() throws Exception {
+ // Character matching is done by the superclass; ensure that fallback to the
+ // other XML matchers is working
+ checkGotoMatching(
+ "android:icon=^\"@drawable/icon\"",
+ "android:icon=\"@drawable/icon^\"");
+ }
+
+ private void checkGotoMatching(IFile file, String caretBefore,
+ String caretAfter) throws Exception {
+ IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
+ assertNotNull(page);
+ IEditorPart editor = IDE.openEditor(page, file);
+ assertTrue(editor instanceof AndroidXmlEditor);
+ AndroidXmlEditor layoutEditor = (AndroidXmlEditor) editor;
+ ISourceViewer viewer = layoutEditor.getStructuredSourceViewer();
+
+ int caretPosBefore = updateCaret(viewer, caretBefore);
+
+ AndroidXmlCharacterMatcher matcher = new AndroidXmlCharacterMatcher();
+ IStructuredDocument document = layoutEditor.getStructuredDocument();
+
+ IRegion match = matcher.match(document, caretPosBefore);
+ assertNotNull(match);
+
+ String text = document.get();
+ final String after = stripCaret(caretAfter);
+ int index = text.indexOf(after);
+ int caretPosAfter = match.getOffset() - index;
+ String textWithCaret = after.substring(0, caretPosAfter)
+ + "^" + after.substring(caretPosAfter);
+
+ assertEquals(caretAfter, textWithCaret);
+ }
+
+ private static String stripCaret(String s) {
+ int index = s.indexOf('^');
+ assertTrue(index != -1);
+ return s.substring(0, index) + s.substring(index + 1);
+ }
+
+ private void checkGotoMatching(String caretBefore,
+ String caretAfter) throws Exception {
+ checkGotoMatching(
+ getTestDataFile(getProject(), "manifest.xml", "AndroidManifest.xml", true),
+ caretBefore, caretAfter);
+ }
+}