Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Java.Interop.sln
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Java.Interop.Tools.Cecil",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Java.Interop.Tools.Diagnostics", "src\Java.Interop.Tools.Diagnostics\Java.Interop.Tools.Diagnostics.csproj", "{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Java.Interop.Tools.TypeNameMappings", "src\Java.Interop.Tools.TypeNameMappings\Java.Interop.Tools.TypeNameMappings.shproj", "{E706B6F2-5562-4765-8F07-8CF84A797B30}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "jcw-gen", "tools\jcw-gen\jcw-gen.csproj", "{52C7D9B6-E8C8-47D0-9471-652D278D7D77}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Java.Interop.Tools.JavaCallableWrappers-Tests", "src\Java.Interop.Tools.JavaCallableWrappers\Test\Java.Interop.Tools.JavaCallableWrappers-Tests.csproj", "{58B564A1-570D-4DA2-B02D-25BDDB1A9F4F}"
Expand Down Expand Up @@ -378,7 +376,6 @@ Global
{D18FCF91-8876-48A0-A693-2DC1E7D3D80A} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
{64CC4E44-CE3A-4319-BF3F-6CF8BD513870} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
{E706B6F2-5562-4765-8F07-8CF84A797B30} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
{52C7D9B6-E8C8-47D0-9471-652D278D7D77} = {C8F58966-94BF-407F-914A-8654F8B8AE3B}
{58B564A1-570D-4DA2-B02D-25BDDB1A9F4F} = {271C9F30-F679-4793-942B-0D9527CB3E2F}
{15945D4B-FF56-4BCC-B598-2718D199DD08} = {C8F58966-94BF-407F-914A-8654F8B8AE3B}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@
<Compile Include="Java.Interop.Tools.JavaCallableWrappers\JavaCallableWrapperGenerator.cs" />
<Compile Include="Java.Interop.Tools.JavaCallableWrappers\JavaTypeScanner.cs" />
<Compile Include="Java.Interop.Tools.JavaCallableWrappers\TypeNameMapGenerator.cs" />
<Compile Include="..\Java.Interop.Tools.TypeNameMappings\Java.Interop.Tools.TypeNameMappings\JavaNativeTypeManager.cs">
<Link>JavaNativeTypeManager.cs</Link>
</Compile>
</ItemGroup>
<Import Project="..\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems" Label="Shared" Condition="Exists('..\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems')" />
<Import Project="..\Java.Interop.Tools.TypeNameMappings\Java.Interop.Tools.TypeNameMappings.projitems" Label="Shared" Condition="Exists('..\Java.Interop.Tools.TypeNameMappings\Java.Interop.Tools.TypeNameMappings.projitems')" />
<ItemGroup>
<ProjectReference Include="..\Java.Interop.Tools.Diagnostics\Java.Interop.Tools.Diagnostics.csproj">
<Project>{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}</Project>
Expand All @@ -63,5 +64,6 @@
<LogicalName>MonoRuntimeProvider.Shared.java</LogicalName>
</EmbeddedResource>
</ItemGroup>
<Import Project="..\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems" Label="Shared" Condition="Exists('..\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems')" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
<ItemGroup>
<Folder Include="Java.Interop.Tools.JavaCallableWrappers\" />
</ItemGroup>
<Import Project="..\..\Java.Interop.Tools.TypeNameMappings\Java.Interop.Tools.TypeNameMappings.projitems" Label="Shared" Condition="Exists('..\..\Java.Interop.Tools.TypeNameMappings\Java.Interop.Tools.TypeNameMappings.projitems')" />
<Import Project="..\..\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems" Label="Shared" Condition="Exists('..\..\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems')" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,33 @@
using Mono.Cecil;
using Java.Interop.Tools.Cecil;
using Android.Runtime;
#if !GENERATOR
using Java.Interop.Tools.JavaCallableWrappers;
#endif // !GENERATOR
#endif // HAVE_CECIL

namespace Java.Interop.Tools.TypeNameMappings {
namespace Java.Interop.Tools.TypeNameMappings
{

#if HAVE_CECIL
public
#endif
enum PackageNamingPolicy {
LowercaseHash,
Lowercase,
LowercaseWithAssemblyName,
}

public class JniTypeName
#if HAVE_CECIL
public
#endif
class JniTypeName
{
public string Type { get; internal set; }
public bool IsKeyword { get; internal set; }
}

#if HAVE_CECIL
public
#endif
static class JavaNativeTypeManager {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to not make this public until we've turned it into an "instance" class instead of a static class. Could that be done first/as part of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally speaking "no", because the type is in Java.Interop.JavaCallableWrappers.dll and if that is public then the consumers (Xamarin.Android.Build.Tasks.dll, Xamarin.Android.JavadocImporter.dll, etc.) has no access to the this class.

It is NOT public in the mobile profile which is reasonable enough.


public static PackageNamingPolicy PackageNamingPolicy { get; set; }
Expand Down Expand Up @@ -143,7 +151,7 @@ public static string ToJniName (Type type)
"java/lang/Object";
}

public static string ToJniName (Type type, ExportParameterKind exportKind)
static string ToJniName (Type type, ExportParameterKind exportKind)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mono.Android.dll requires this method in JNIEnv.GetJniName(Type). It can't be made private, at least not yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what JNIEnv.GetJniName() does:
https://github.com/xamarin/xamarin-android/blob/0d16153f0239602fa96dd5876b1e400c2dd2cdea/src/Mono.Android/Android.Runtime/JNIEnv.cs#L885

It only references GetJniName(Type), not GetJniName(Type,ExportParameterKind).

{
if (type == null)
throw new ArgumentNullException ("type");
Expand All @@ -159,12 +167,8 @@ public static string ToJniName (Type type, ExportParameterKind exportKind)
return GetSpecialExportJniType (type.FullName, exportKind);

return ToJniName (type, t => t.DeclaringType, t => t.Name, GetPackageName, t => {
#if !GEN_JAVA_STUBS && !GENERATOR && !JAVADOC_TO_MDOC
return ToJniNameFromAttributes (t);
#else
return null;
#endif
});
}, _ => false);
}

public static string ToJniName (string jniType, int rank)
Expand Down Expand Up @@ -255,7 +259,6 @@ static string GetSpecialExportJniType (string typeName, ExportParameterKind expo
return null;
}

#if !GEN_JAVA_STUBS && !JAVADOC_TO_MDOC
// Keep in sync with ToJniNameFromAttributes(TypeDefinition)
public static string ToJniNameFromAttributes (Type type)
{
Expand Down Expand Up @@ -347,7 +350,7 @@ static string GetJniTypeName<TR,TD> (TR typeRef, ExportParameterKind exportKind,
return rank == 0 && pJniName.Length > 1 ? "L" + pJniName + ";" : ToJniName (pJniName, rank);
}

public static ExportParameterKind GetExportKind (System.Reflection.ICustomAttributeProvider p)
static ExportParameterKind GetExportKind (System.Reflection.ICustomAttributeProvider p)
{
foreach (ExportParameterAttribute a in p.GetCustomAttributes (typeof (ExportParameterAttribute), false))
return a.Kind;
Expand All @@ -370,7 +373,7 @@ public static string GetJniTypeName (Type typeRef)
return GetJniTypeName (typeRef, ExportParameterKind.Unspecified);
}

public static string GetJniTypeName (Type typeRef, ExportParameterKind exportKind)
internal static string GetJniTypeName (Type typeRef, ExportParameterKind exportKind)
{
return GetJniTypeName<Type,Type> (typeRef, exportKind, t => t, t => {
Type etype;
Expand All @@ -385,7 +388,6 @@ static string ToJniNameWhichShouldReplaceExistingToJniName (Type type, ExportPar
var ret = ToJniNameFromAttributes (type);
return ret ?? ToJniName (type, exportKind);
}
#endif

#if HAVE_CECIL

Expand All @@ -401,12 +403,12 @@ internal static ExportParameterAttribute ToExportParameterAttribute (CustomAttri
return new ExportParameterAttribute ((ExportParameterKind)attr.ConstructorArguments [0].Value);
}

internal static bool IsApplication (TypeDefinition type)
public static bool IsApplication (TypeDefinition type)
{
return type.GetBaseTypes ().Any (b => b.FullName == "Android.App.Application");
}

internal static bool IsInstrumentation (TypeDefinition type)
public static bool IsInstrumentation (TypeDefinition type)
{
return type.GetBaseTypes ().Any (b => b.FullName == "Android.App.Instrumentation");
}
Expand All @@ -430,7 +432,7 @@ public static string GetJniTypeName (TypeReference typeRef)
return GetJniTypeName (typeRef, ExportParameterKind.Unspecified);
}

public static string GetJniTypeName (TypeReference typeRef, ExportParameterKind exportKind)
internal static string GetJniTypeName (TypeReference typeRef, ExportParameterKind exportKind)
{
return GetJniTypeName<TypeReference, TypeDefinition> (typeRef, exportKind, t => t.Resolve (), t => {
TypeReference etype;
Expand All @@ -441,7 +443,7 @@ public static string GetJniTypeName (TypeReference typeRef, ExportParameterKind

public static string ToCompatJniName (Mono.Cecil.TypeDefinition type)
{
return ToJniName (type, t => t.DeclaringType, t => t.Name, ToCompatPackageName, ToJniNameFromAttributes);
return ToJniName (type, t => t.DeclaringType, t => t.Name, ToCompatPackageName, ToJniNameFromAttributes, t => IsNonStaticInnerClass (t as TypeDefinition));
}

static string ToCompatPackageName (Mono.Cecil.TypeDefinition type)
Expand All @@ -456,7 +458,7 @@ public static string ToJniName (Mono.Cecil.TypeDefinition type)
"java/lang/Object";
}

public static string ToJniName (TypeDefinition type, ExportParameterKind exportKind)
static string ToJniName (TypeDefinition type, ExportParameterKind exportKind)
{
if (type == null)
throw new ArgumentNullException ("type");
Expand All @@ -471,7 +473,7 @@ public static string ToJniName (TypeDefinition type, ExportParameterKind exportK
return GetSpecialExportJniType (type.FullName, exportKind);
}

return ToJniName (type, t => t.DeclaringType, t => t.Name, GetPackageName, ToJniNameFromAttributes);
return ToJniName (type, t => t.DeclaringType, t => t.Name, GetPackageName, ToJniNameFromAttributes, t => IsNonStaticInnerClass (t as TypeDefinition));
}

static string ToJniNameFromAttributes (TypeDefinition type)
Expand Down Expand Up @@ -562,7 +564,7 @@ public static string GetPackageName (TypeDefinition type)
}
#endif

static string ToJniName<T> (T type, Func<T, T> decl, Func<T, string> name, Func<T, string> ns, Func<T, string> overrideName)
static string ToJniName<T> (T type, Func<T, T> decl, Func<T, string> name, Func<T, string> ns, Func<T, string> overrideName, Func<T,bool> shouldUpdateName)
where T : class
{
var nameParts = new List<string> ();
Expand All @@ -576,12 +578,9 @@ static string ToJniName<T> (T type, Func<T, T> decl, Func<T, string> name, Func<
break;
}
var n = name (declType).Replace ('`', '_');
#if HAVE_CECIL
var td = declType as TypeDefinition;
if (IsNonStaticInnerClass (td)) {
if (shouldUpdateName (declType)) {
n = "$" + name (decl (declType)) + "_" + n;
}
#endif
nameParts.Add (n);
}

Expand Down
6 changes: 4 additions & 2 deletions tools/generator/generator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@
<ItemGroup>
<Folder Include="MonoDroid.Generation\" />
</ItemGroup>
<Import Project="..\..\src\Java.Interop.Tools.TypeNameMappings\Java.Interop.Tools.TypeNameMappings.projitems" Label="Shared" Condition="Exists('..\..\src\Java.Interop.Tools.TypeNameMappings\Java.Interop.Tools.TypeNameMappings.projitems')" />
<Import Project="..\..\src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems" Label="Shared" Condition="Exists('..\..\src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems')" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="..\..\src\Xamarin.Android.Tools.AnnotationSupport\Xamarin.Android.Tools.AnnotationSupport.csproj">
Expand All @@ -136,6 +134,10 @@
<Project>{15945D4B-FF56-4BCC-B598-2718D199DD08}</Project>
<Name>Xamarin.Android.Cecil</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Java.Interop.Tools.JavaCallableWrappers\Java.Interop.Tools.JavaCallableWrappers.csproj">
<Project>{D18FCF91-8876-48A0-A693-2DC1E7D3D80A}</Project>
<Name>Java.Interop.Tools.JavaCallableWrappers</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down