-
Notifications
You must be signed in to change notification settings - Fork 57
[api-xml-adjuster] method overrides cannot expose non-public types. #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Xamarin.Android.Tools.ApiXmlAdjuster | ||
{ | ||
public static class JavaApiFixVisibilityExtensions | ||
{ | ||
public static string GetVisibleTypeName (this JavaParameter parameter) | ||
{ | ||
var r = GetVisibleNonSpecialType (parameter); | ||
return r != null ? r.ToString () : parameter.Type; | ||
} | ||
|
||
public static string GetVisibleReturnTypeName (this JavaMethod method) | ||
{ | ||
var r = GetVisibleNonSpecialReturnType (method); | ||
return r != null ? r.ToString () : method.Return; | ||
} | ||
|
||
public static JavaTypeReference GetVisibleNonSpecialType (this JavaParameter parameter) | ||
{ | ||
return GetVisibleNonSpecialType (parameter.Parent, parameter.ResolvedType); | ||
} | ||
|
||
public static JavaTypeReference GetVisibleNonSpecialReturnType (this JavaMethod method) | ||
{ | ||
return GetVisibleNonSpecialType (method, method.ResolvedReturnType); | ||
} | ||
|
||
static JavaTypeReference GetVisibleNonSpecialType (this JavaMethodBase method, JavaTypeReference r) | ||
{ | ||
if (r == null || r.SpecialName != null || r.ReferencedTypeParameter != null || r.ArrayPart != null) | ||
return null; | ||
var requiredVisibility = method.Visibility == "public" && method.Parent.Visibility == "public" ? "public" : method.Visibility; | ||
for (var t = r; t != null; t = (t.ReferencedType as JavaClass)?.ResolvedExtends) { | ||
if (t.ReferencedType == null) | ||
break; | ||
if (IsAcceptableVisibility (required: requiredVisibility, actual: t.ReferencedType.Visibility)) | ||
return t; | ||
} | ||
return null; | ||
} | ||
|
||
static bool IsAcceptableVisibility (string required, string actual) | ||
{ | ||
if (required == "public") | ||
return actual == "public"; | ||
else | ||
return true; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,24 @@ public void TestToString () | |
var kls = pkg.Types.First (t => t.FullName == "android.database.ContentObservable"); | ||
Assert.AreEqual ("[Class] android.database.ContentObservable", kls.ToString ()); | ||
} | ||
|
||
[Test] | ||
public void ParseName () | ||
{ | ||
var tn = JavaTypeName.Parse ("java.util.Function<java.util.Map.Entry<K, V>, ? extends U>"); | ||
Assert.AreEqual ("java.util.Function", tn.FullNameNonGeneric, "top failed to parse name"); | ||
Assert.AreEqual (2, tn.GenericArguments.Count, "top incorrect number of parsed generic arguments"); | ||
var ga1 = tn.GenericArguments [0]; | ||
Assert.AreEqual ("java.util.Map.Entry", ga1.FullNameNonGeneric, "genarg#0 name mismatch"); | ||
Assert.AreEqual (2, ga1.GenericArguments.Count, "genarg#0 incorrect number of parsed generic arguments"); | ||
Assert.AreEqual ("K", ga1.GenericArguments [0].FullNameNonGeneric, "genarg#0.1 name mismatch"); | ||
Assert.AreEqual ("V", ga1.GenericArguments [1].FullNameNonGeneric, "genarg#0.2 name mismatch"); | ||
var ga2 = tn.GenericArguments [1]; | ||
Assert.AreEqual ("?", ga2.FullNameNonGeneric, "genarg#1 name mismatch"); | ||
Assert.AreEqual (" extends ", ga2.BoundsType, "genarg#1 incorrect bounds type"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit "odd", in that it means that Should the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course I thought about that, but I didn't find very reason to perform extra string stripping and cause more memory consumption. |
||
Assert.AreEqual (1, ga2.GenericConstraints.Count, "genarg#1 incorrect number of parsed generic constraints"); | ||
Assert.AreEqual ("U", ga2.GenericConstraints [0].FullNameNonGeneric, "genarg#1.1 constraint name mismatch"); | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the removal of the constraints from
JavaTypeParameter
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically we have right to choose what to output in this ToString() overrides.
There are places that should output generic constraints and that should NOT. When writing generic type parameter definitions they should be there. When writing USE of generic type parameters they should NOT. And this generic constraints part were always written.
An exceptional case that it SHOULD be written for USE of generics is that the name is "?" which is handled specially.