pocorall / scaloid

Scaloid makes your Android code easy to understand and maintain.
Other
2.09k stars 163 forks source link

android.view.ViewGroup.debug shadows org.scaloid.common.debug #112

Closed PkmX closed 8 years ago

PkmX commented 9 years ago

This causes inconveniences when calling debug to write strings to logcat in the DSL, as we will have to qualify the org.scaloid.common.debug.

pocorall commented 9 years ago

Thanks for reporting. I didn't know about this issue.

org.scaloid.common.Logger.debug gets => String as a parameter. Normally, passing Int value (e.g. debug(1)) should not be passed it to Scaloid debug function. However, that Int value is implicitly converted by ResourceConversion.r2String. Definitely, it is a problem. Excessively converting Int to other resource type would cause confusions like this situation. I am consider reimplementing ConversionImplicits.Int2resource with macros to distinguish the Int number is a resource ID or not (e.g. resource IDs has R. on its parameter names). I am not sure it is possible, because I am not Scala macro expert. Any other suggestions are welcome.

pocorall commented 9 years ago

I was misunderstood the problem. I thought ViewGroup.debug is shadowed by scaloid.common.debug.

But, the actual problem is the opposite case. This is relatively easy. Use r2String to explicitly convert a resource id to the corresponding String resource.

debug(R.string.mystr.r2String) \\ will call org.scaloid.common.debug
PkmX commented 9 years ago

Converting to String would not work as org.scaloid.common.debug is still shadowed by ViewGroup.debug, so it is not considered for overloading at all. It will just give an error saying that it is given a String while expecting an Int. The issue only arise when we define UI with anonymous classes (new SLinearLayout { ... }, etc), which brings ViewGroup.debug into scope in the body as it is protected.

pocorall commented 8 years ago

I added an overloading function on TraitViewGroup.

def debug(str: String)(implicit tag: LoggerTag)