diff options
author | Tor Norbye <tnorbye@google.com> | 2011-04-28 15:51:38 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2011-05-17 13:25:31 -0700 |
commit | b557e173f82c4fcd9332ac75595348d988be5fc6 (patch) | |
tree | 0d4d0c919bf41447861e7335837caf7825a4284a /eclipse | |
parent | 9718ea331bfc609927b1ec2a2e7453579666fa4d (diff) | |
download | sdk-b557e173f82c4fcd9332ac75595348d988be5fc6.zip sdk-b557e173f82c4fcd9332ac75595348d988be5fc6.tar.gz sdk-b557e173f82c4fcd9332ac75595348d988be5fc6.tar.bz2 |
Make Go To Declaration work for <fragment> names.
Conflicts:
eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java
Change-Id: I5260aacb7d7a14141f43d9a65bb4bb87627d17c2
Diffstat (limited to 'eclipse')
8 files changed, 102 insertions, 5 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java index f88e7ab..319a2b4d 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/common/layout/LayoutConstants.java @@ -32,7 +32,10 @@ public class LayoutConstants { /** The element name in a <code><view class="..."></code> element. */ public static final String VIEW = "view"; //$NON-NLS-1$ - /** The attribute name in a <code><view class="..."></code> element. */ + /** The element name in a <code><fragment android:name="..."></code> element. */ + public static final String FRAGMENT = "fragment"; //$NON-NLS-1$ + + /** The attribute name in a {@code <view class="...">} element. */ public static final String ATTR_CLASS = "class"; //$NON-NLS-1$ public static final String ATTR_ON_CLICK = "onClick"; //$NON-NLS-1$ @@ -99,6 +102,7 @@ public class LayoutConstants { public static final String ATTR_LAYOUT_Y = "layout_y"; //$NON-NLS-1$ public static final String ATTR_LAYOUT_X = "layout_x"; //$NON-NLS-1$ + public static final String ATTR_NAME = "name"; //$NON-NLS-1$ public static final String VALUE_WRAP_CONTENT = "wrap_content"; //$NON-NLS-1$ public static final String VALUE_FILL_PARENT = "fill_parent"; //$NON-NLS-1$ diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/xml/Hyperlinks.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/xml/Hyperlinks.java index 83e9bc4..c30b78a 100644 --- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/xml/Hyperlinks.java +++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/editors/xml/Hyperlinks.java @@ -18,7 +18,9 @@ package com.android.ide.eclipse.adt.internal.editors.xml; import static com.android.ide.common.layout.LayoutConstants.ANDROID_URI; import static com.android.ide.common.layout.LayoutConstants.ATTR_CLASS; +import static com.android.ide.common.layout.LayoutConstants.ATTR_NAME; import static com.android.ide.common.layout.LayoutConstants.ATTR_ON_CLICK; +import static com.android.ide.common.layout.LayoutConstants.FRAGMENT; import static com.android.ide.common.layout.LayoutConstants.NEW_ID_PREFIX; import static com.android.ide.common.layout.LayoutConstants.VIEW; import static com.android.ide.common.resources.ResourceResolver.PREFIX_ANDROID_RESOURCE_REF; @@ -321,20 +323,25 @@ public class Hyperlinks { return false; } - /** Returns true if this represents a {@code <view class="foo.bar.Baz">} class attribute */ + /** Returns true if this represents a style attribute */ private static boolean isStyleAttribute(XmlContext context) { String tag = context.getElement().getTagName(); return STYLE_ELEMENT.equals(tag); } - /** Returns true if this represents a {@code <view class="foo.bar.Baz">} class attribute */ + /** + * Returns true if this represents a {@code <view class="foo.bar.Baz">} class + * attribute, or a {@code <fragment android:name="foo.bar.Baz">} class attribute + */ private static boolean isClassAttribute(XmlContext context) { Attr attribute = context.getAttribute(); if (attribute == null) { return false; } String tag = context.getElement().getTagName(); - return ATTR_CLASS.equals(attribute.getLocalName()) && VIEW.equals(tag); + String attributeName = attribute.getLocalName(); + return ATTR_CLASS.equals(attributeName) && (VIEW.equals(tag) || FRAGMENT.equals(tag)) + || ATTR_NAME.equals(attributeName) && FRAGMENT.equals(tag); } /** Returns true if this represents an onClick attribute specifying a method handler */ diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/AdtProjectTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/AdtProjectTest.java index 3b83bd7..0caeef3 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/AdtProjectTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/AdtProjectTest.java @@ -67,6 +67,8 @@ import java.util.Map; @SuppressWarnings("restriction") public class AdtProjectTest extends SdkTestCase { private static final int TARGET_API_LEVEL = 11; + public static final String TEST_PROJECT_PACKAGE = "com.android.eclipse.tests"; //$NON-NLS-1$ + /** Update golden files if different from the actual results */ private static final boolean UPDATE_DIFFERENT_FILES = false; /** Create golden files if missing */ @@ -689,7 +691,7 @@ public class AdtProjectTest extends SdkTestCase { } public String getPackageName() { - return "com.android.eclipse.tests"; + return TEST_PROJECT_PACKAGE; } public String getActivityName() { diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/TestFragment.java.txt b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/TestFragment.java.txt new file mode 100644 index 0000000..0942a19 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/TestFragment.java.txt @@ -0,0 +1,15 @@ +package com.android.eclipse.tests; + +import android.app.Fragment; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +public class TestFragment extends Fragment { + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + return null; + } +} diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/fragmentlayout-expected-navigate13.txt b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/fragmentlayout-expected-navigate13.txt new file mode 100644 index 0000000..ae30d58 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/fragmentlayout-expected-navigate13.txt @@ -0,0 +1,12 @@ +Go To Declaration in fragmentlayout.xml for android:name="com.android.ecl^ipse.tests.TestFragment": +Open XML Declaration : [com.android.eclipse.tests.TestFragment] + + +After open, the selected text is: +[^public class TestFragment extends Fragment { + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + return null; + } +}] diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/fragmentlayout-expected-navigate14.txt b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/fragmentlayout-expected-navigate14.txt new file mode 100644 index 0000000..0046483 --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/fragmentlayout-expected-navigate14.txt @@ -0,0 +1,12 @@ +Go To Declaration in fragmentlayout.xml for class="com.and^roid.eclipse.tests.TestFragment": +Open XML Declaration : [com.android.eclipse.tests.TestFragment] + + +After open, the selected text is: +[^public class TestFragment extends Fragment { + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + return null; + } +}] diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/fragmentlayout.xml b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/fragmentlayout.xml new file mode 100644 index 0000000..758599c --- /dev/null +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/layout/refactoring/testdata/fragmentlayout.xml @@ -0,0 +1,19 @@ +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/home_root" + android:orientation="horizontal" + android:layout_width="fill_parent" + android:layout_height="fill_parent"> + + <LinearLayout android:orientation="vertical" + android:layout_width="wrap_content" + android:layout_height="fill_parent"> + <fragment android:name="com.android.eclipse.tests.TestFragment" + android:id="@+id/test_fragment" + android:layout_marginLeft="20dp" + android:layout_weight="1" + android:layout_width="fill_parent" + android:layout_height="0dp" /> + <fragment class="com.android.eclipse.tests.TestFragment" + android:id="@+id/test_fragment2" /> + </LinearLayout> +</LinearLayout> diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/xml/HyperlinksTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/xml/HyperlinksTest.java index 57ca80f..afe6f3b 100644 --- a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/xml/HyperlinksTest.java +++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/adt/internal/editors/xml/HyperlinksTest.java @@ -15,6 +15,8 @@ */ package com.android.ide.eclipse.adt.internal.editors.xml; +import static com.android.sdklib.SdkConstants.FD_SOURCES; + import com.android.ide.common.resources.ResourceFile; import com.android.ide.eclipse.adt.internal.editors.AndroidXmlEditor; import com.android.ide.eclipse.adt.internal.editors.layout.refactoring.AdtProjectTest; @@ -22,6 +24,7 @@ import com.android.ide.eclipse.adt.internal.editors.xml.Hyperlinks.ResourceLink; import com.android.ide.eclipse.adt.internal.editors.xml.Hyperlinks.XmlResolver; import org.eclipse.core.resources.IFile; +import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.Region; @@ -157,6 +160,24 @@ public class HyperlinksTest extends AdtProjectTest { "<my.Cust^omView></my.CustomView>"); } + public void testNavigate13() throws Exception { + // Check jumping to classes pointed to by fragments + + getTestDataFile(getProject(), "TestFragment.java.txt", + FD_SOURCES + "/" + TEST_PROJECT_PACKAGE.replace('.', '/') + "/TestFragment.java"); + checkXmlNavigation("fragmentlayout.xml", "res/layout/fragmentlayout.xml", + "android:name=\"com.android.ecl^ipse.tests.TestFragment\""); + } + + public void testNavigate14() throws Exception { + // Check jumping to classes pointed to by fragments + + getTestDataFile(getProject(), "TestFragment.java.txt", + FD_SOURCES + "/" + TEST_PROJECT_PACKAGE.replace('.', '/') + "/TestFragment.java"); + checkXmlNavigation("fragmentlayout.xml", "res/layout/fragmentlayout.xml", + "class=\"com.and^roid.eclipse.tests.TestFragment\""); + } + // Left to test: // onClick handling // class attributes @@ -248,6 +269,11 @@ public class HyperlinksTest extends AdtProjectTest { sb.append(" "); sb.append(initialUrl); sb.append("\n"); + } else if (newEditor instanceof JavaEditor) { + JavaEditor javaEditor = (JavaEditor) newEditor; + document = javaEditor.getDocumentProvider().getDocument(javaEditor.getEditorInput()); + IRegion range = javaEditor.getHighlightRange(); + selection = new Point(range.getOffset(), range.getLength()); } else { fail("Unhandled editor type: " + newEditor.getClass().getName()); return; |