/** The element name in a {@code <view class="...">} element. */
public static final String VIEW = "view"; //$NON-NLS-1$
+ /** 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$
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$
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;
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 */
@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 */
}
public String getPackageName() {
- return "com.android.eclipse.tests";
+ return TEST_PROJECT_PACKAGE;
}
public String getActivityName() {
--- /dev/null
+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;
+ }
+}
--- /dev/null
+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;
+ }
+}]
--- /dev/null
+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;
+ }
+}]
--- /dev/null
+<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>
*/
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;
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;
"<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
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;