Bug 12553 - ACW generator needs correct name resolution for ActivityAttribute
Summary: ACW generator needs correct name resolution for ActivityAttribute
Status: RESOLVED NOT_ON_ROADMAP
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 4.7.x
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2013-06-05 02:47 UTC by Atsushi Eno
Modified: 2013-06-05 16:21 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NOT_ON_ROADMAP

Description Atsushi Eno 2013-06-05 02:47:28 UTC
In Java Android it is possible to have simple dot-started Activity name e.g. ".SampleActivity" to avoid extraneous full naming of activities. XA doesn't seem to fully handle this yet.

Repro:
In the ActionBarSherlock sample:
https://github.com/xamarin/monodroid-samples/blob/master/ActionBarSherlock/ActionBarSherlockTest/

add the following files, first as TabNavigation.cs, and second as TabNavigationCollapsed.cs:

--------
using System;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Widget;
using Xamarin.ActionbarSherlockBinding.App;
using SherlockActionBar = Xamarin.ActionbarSherlockBinding.App.ActionBar;
using FragmentTransaction = Android.Support.V4.App.FragmentTransaction;

namespace Mono.ActionbarsherlockTest
{
	[Activity (Name = ".TabNavigation", Label = "@string/tab_navigation")]
	[IntentFilter (new string [] { Intent.ActionMain },
		Categories = new string [] { Constants.DemoCategory })]
	public class TabNavigation : SherlockActivity, SherlockActionBar.ITabListener
	{
		private TextView mSelected;

		protected override void OnCreate (Bundle savedInstanceState)
		{
			SetTheme (SampleList.THEME); //Used for theme switching in samples
			base.OnCreate (savedInstanceState);

			SetContentView (Resource.Layout.tab_navigation);
			mSelected = FindViewById<TextView> (Resource.Id.text);

			SupportActionBar.NavigationMode = SherlockActionBar.NavigationModeTabs;
			for (int i = 1; i <= 3; i++) {
				var tab = SupportActionBar.NewTab ();
				tab.SetText ("Tab " + i);
				tab.SetTabListener (this);
				SupportActionBar.AddTab (tab);
			}
		}

		public void OnTabReselected (SherlockActionBar.Tab tab, FragmentTransaction transaction)
		{
		}

		public void OnTabSelected (SherlockActionBar.Tab tab, FragmentTransaction transaction)
		{
			mSelected.Text = "Selected: " + tab.Text;
		}

		public void OnTabUnselected (SherlockActionBar.Tab tab, FragmentTransaction transaction)
		{
		}
	}
}

--------

using System;
using Android.App;
using Android.Content;
using Android.OS;

namespace Mono.ActionbarsherlockTest
{
	[Activity (Name = "mono.actionbarsherlocktest.TabNavigationCollapsed", Label = "@string/tab_navigation_collapsed")]
	[IntentFilter (new string [] { Intent.ActionMain },
		Categories = new string [] { Constants.DemoCategory })]
	public class TabNavigationCollapsed : TabNavigation
	{
		protected override void OnCreate (Bundle savedInstanceState)
		{
			base.OnCreate (savedInstanceState);

			//The following two options trigger the collapsing of the main action bar view.
			//See the parent activity for the rest of the implementation
			SupportActionBar.SetDisplayShowHomeEnabled (false);
			SupportActionBar.SetDisplayShowTitleEnabled (false);
		}
	}
}

--------

The resulting code is generated as follows (note "extends .TabNavigation"):

package mono.actionbarsherlocktest;


public class TabNavigationCollapsed
	extends .TabNavigation
	implements
		mono.android.IGCUserPeer
{
    ...
Comment 1 Jonathan Pryor 2013-06-05 16:14:47 UTC
> In Java Android it is possible to have simple dot-started Activity name e.g.
> ".SampleActivity" to avoid extraneous full naming of activities. XA doesn't
> seem to fully handle this yet.

Why do we need to support this? What's the use case?

Furthermore, we've already documented that the Name property needs to be fully qualified:

http://androidapi.xamarin.com/?link=P%3aAndroid.App.ActivityAttribute.Name
> it must be a fully-qualified type name.

In general, people SHOULD NOT be using the Name property. It slows down type lookup in JNIEnv.FindClass(Type), traversing an exception + custom attribute lookup via Reflection when it's used. It's an unavoidable perf hit; it should be avoided if at all possible.
Comment 2 Jonathan Pryor 2013-06-05 16:15:30 UTC
    [Activity (Name = ".TabNavigation")]

This now generates an XA4203 error in monodroid/0de35ae9.
Comment 3 Jonathan Pryor 2013-06-05 16:21:22 UTC
A funny thing happened while investigating this: I discovered that Java _really_ doesn't like the global package. The global package truly should be avoided if at all possible.

Consider:

    // G.java
    public class G {
    }

This compiles just fine:

    $ javac -d bin G.java
    $ ls bin
    G.glass

It exists:

    $ javap -classpath bin G
    Compiled from "G.java"
    public class G extends java.lang.Object{
        public G();
    }

Now let's try to use it:

    // A.java
    package a;

    public class A extends G {
    }

This doesn't compile:

    $ javac -d bin G.java 
    jon@melchior:java$ javac -d bin A.java 
    A.java:3: cannot find symbol
    symbol: class G
    public class A extends G {
                           ^
    1 error

Okay...what about classpath?

    $ javac -classpath bin -d bin A.java 
    ...
    1 error

Nope. CLASSPATH?

    $ CLASSPATH=bin javac -d bin A.java
    ...
    1 error

I'm out of ideas, but I think this shows the point: Java _really_ doesn't like attempts to inherit from a class in the Global package. I had not expected this at all.