Skip to content

Commit f375048

Browse files
atsushienojonpryor
authored andcommitted
Project refactoring: now TypeNameMappings on desktop is gone. (#184)
`JavaNativeTypeManager` is gone directly into `Mono.Android.csproj` and `Java.Interop.Tools.JavaCallableWrappers.csproj`. Most of the shared `NamingCustomAttributes` references are gone, because `Java.Interop.Tools.JavaCallableWrappers` references it and it is referenced almost everywhere. Other than that, `NamingCustomAttributes.shproj` is only in `Mono.Android.csproj` and `Xamarin.Android.Tools.JavadocImporter` (could not be removed due to visibility issue, so there are still duplicates). In addition, there is no need to have `#if GENERATOR` etc. so removed them except for `HAVE_CECIL`. And removed extra partial code blocks that use `HAVE_CECIL` for future source split.
1 parent 6c1053c commit f375048

File tree

5 files changed

+32
-33
lines changed

5 files changed

+32
-33
lines changed

Java.Interop.sln

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Java.Interop.Tools.Cecil",
8787
EndProject
8888
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}"
8989
EndProject
90-
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}"
91-
EndProject
9290
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "jcw-gen", "tools\jcw-gen\jcw-gen.csproj", "{52C7D9B6-E8C8-47D0-9471-652D278D7D77}"
9391
EndProject
9492
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}"
@@ -378,7 +376,6 @@ Global
378376
{D18FCF91-8876-48A0-A693-2DC1E7D3D80A} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
379377
{D48EE8D0-0A0A-4493-AEF5-DAF5F8CF86AD} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
380378
{64CC4E44-CE3A-4319-BF3F-6CF8BD513870} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
381-
{E706B6F2-5562-4765-8F07-8CF84A797B30} = {0998E45F-8BCE-4791-A944-962CD54E2D80}
382379
{52C7D9B6-E8C8-47D0-9471-652D278D7D77} = {C8F58966-94BF-407F-914A-8654F8B8AE3B}
383380
{58B564A1-570D-4DA2-B02D-25BDDB1A9F4F} = {271C9F30-F679-4793-942B-0D9527CB3E2F}
384381
{15945D4B-FF56-4BCC-B598-2718D199DD08} = {C8F58966-94BF-407F-914A-8654F8B8AE3B}

src/Java.Interop.Tools.JavaCallableWrappers/Java.Interop.Tools.JavaCallableWrappers.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838
<Compile Include="Java.Interop.Tools.JavaCallableWrappers\JavaCallableWrapperGenerator.cs" />
3939
<Compile Include="Java.Interop.Tools.JavaCallableWrappers\JavaTypeScanner.cs" />
4040
<Compile Include="Java.Interop.Tools.JavaCallableWrappers\TypeNameMapGenerator.cs" />
41+
<Compile Include="..\Java.Interop.Tools.TypeNameMappings\Java.Interop.Tools.TypeNameMappings\JavaNativeTypeManager.cs">
42+
<Link>JavaNativeTypeManager.cs</Link>
43+
</Compile>
4144
</ItemGroup>
42-
<Import Project="..\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems" Label="Shared" Condition="Exists('..\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems')" />
43-
<Import Project="..\Java.Interop.Tools.TypeNameMappings\Java.Interop.Tools.TypeNameMappings.projitems" Label="Shared" Condition="Exists('..\Java.Interop.Tools.TypeNameMappings\Java.Interop.Tools.TypeNameMappings.projitems')" />
4445
<ItemGroup>
4546
<ProjectReference Include="..\Java.Interop.Tools.Diagnostics\Java.Interop.Tools.Diagnostics.csproj">
4647
<Project>{64CC4E44-CE3A-4319-BF3F-6CF8BD513870}</Project>
@@ -63,5 +64,6 @@
6364
<LogicalName>MonoRuntimeProvider.Shared.java</LogicalName>
6465
</EmbeddedResource>
6566
</ItemGroup>
67+
<Import Project="..\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems" Label="Shared" Condition="Exists('..\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems')" />
6668
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
6769
</Project>

src/Java.Interop.Tools.JavaCallableWrappers/Test/Java.Interop.Tools.JavaCallableWrappers-Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464
<ItemGroup>
6565
<Folder Include="Java.Interop.Tools.JavaCallableWrappers\" />
6666
</ItemGroup>
67-
<Import Project="..\..\Java.Interop.Tools.TypeNameMappings\Java.Interop.Tools.TypeNameMappings.projitems" Label="Shared" Condition="Exists('..\..\Java.Interop.Tools.TypeNameMappings\Java.Interop.Tools.TypeNameMappings.projitems')" />
6867
<Import Project="..\..\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems" Label="Shared" Condition="Exists('..\..\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems')" />
6968
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
7069
</Project>

src/Java.Interop.Tools.TypeNameMappings/Java.Interop.Tools.TypeNameMappings/JavaNativeTypeManager.cs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,33 @@
1010
using Mono.Cecil;
1111
using Java.Interop.Tools.Cecil;
1212
using Android.Runtime;
13-
#if !GENERATOR
1413
using Java.Interop.Tools.JavaCallableWrappers;
15-
#endif // !GENERATOR
1614
#endif // HAVE_CECIL
1715

18-
namespace Java.Interop.Tools.TypeNameMappings {
16+
namespace Java.Interop.Tools.TypeNameMappings
17+
{
1918

19+
#if HAVE_CECIL
20+
public
21+
#endif
2022
enum PackageNamingPolicy {
2123
LowercaseHash,
2224
Lowercase,
2325
LowercaseWithAssemblyName,
2426
}
2527

26-
public class JniTypeName
28+
#if HAVE_CECIL
29+
public
30+
#endif
31+
class JniTypeName
2732
{
2833
public string Type { get; internal set; }
2934
public bool IsKeyword { get; internal set; }
3035
}
3136

37+
#if HAVE_CECIL
38+
public
39+
#endif
3240
static class JavaNativeTypeManager {
3341

3442
public static PackageNamingPolicy PackageNamingPolicy { get; set; }
@@ -143,7 +151,7 @@ public static string ToJniName (Type type)
143151
"java/lang/Object";
144152
}
145153

146-
public static string ToJniName (Type type, ExportParameterKind exportKind)
154+
static string ToJniName (Type type, ExportParameterKind exportKind)
147155
{
148156
if (type == null)
149157
throw new ArgumentNullException ("type");
@@ -159,12 +167,8 @@ public static string ToJniName (Type type, ExportParameterKind exportKind)
159167
return GetSpecialExportJniType (type.FullName, exportKind);
160168

161169
return ToJniName (type, t => t.DeclaringType, t => t.Name, GetPackageName, t => {
162-
#if !GEN_JAVA_STUBS && !GENERATOR && !JAVADOC_TO_MDOC
163170
return ToJniNameFromAttributes (t);
164-
#else
165-
return null;
166-
#endif
167-
});
171+
}, _ => false);
168172
}
169173

170174
public static string ToJniName (string jniType, int rank)
@@ -255,7 +259,6 @@ static string GetSpecialExportJniType (string typeName, ExportParameterKind expo
255259
return null;
256260
}
257261

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

350-
public static ExportParameterKind GetExportKind (System.Reflection.ICustomAttributeProvider p)
353+
static ExportParameterKind GetExportKind (System.Reflection.ICustomAttributeProvider p)
351354
{
352355
foreach (ExportParameterAttribute a in p.GetCustomAttributes (typeof (ExportParameterAttribute), false))
353356
return a.Kind;
@@ -370,7 +373,7 @@ public static string GetJniTypeName (Type typeRef)
370373
return GetJniTypeName (typeRef, ExportParameterKind.Unspecified);
371374
}
372375

373-
public static string GetJniTypeName (Type typeRef, ExportParameterKind exportKind)
376+
internal static string GetJniTypeName (Type typeRef, ExportParameterKind exportKind)
374377
{
375378
return GetJniTypeName<Type,Type> (typeRef, exportKind, t => t, t => {
376379
Type etype;
@@ -385,7 +388,6 @@ static string ToJniNameWhichShouldReplaceExistingToJniName (Type type, ExportPar
385388
var ret = ToJniNameFromAttributes (type);
386389
return ret ?? ToJniName (type, exportKind);
387390
}
388-
#endif
389391

390392
#if HAVE_CECIL
391393

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

404-
internal static bool IsApplication (TypeDefinition type)
406+
public static bool IsApplication (TypeDefinition type)
405407
{
406408
return type.GetBaseTypes ().Any (b => b.FullName == "Android.App.Application");
407409
}
408410

409-
internal static bool IsInstrumentation (TypeDefinition type)
411+
public static bool IsInstrumentation (TypeDefinition type)
410412
{
411413
return type.GetBaseTypes ().Any (b => b.FullName == "Android.App.Instrumentation");
412414
}
@@ -430,7 +432,7 @@ public static string GetJniTypeName (TypeReference typeRef)
430432
return GetJniTypeName (typeRef, ExportParameterKind.Unspecified);
431433
}
432434

433-
public static string GetJniTypeName (TypeReference typeRef, ExportParameterKind exportKind)
435+
internal static string GetJniTypeName (TypeReference typeRef, ExportParameterKind exportKind)
434436
{
435437
return GetJniTypeName<TypeReference, TypeDefinition> (typeRef, exportKind, t => t.Resolve (), t => {
436438
TypeReference etype;
@@ -441,7 +443,7 @@ public static string GetJniTypeName (TypeReference typeRef, ExportParameterKind
441443

442444
public static string ToCompatJniName (Mono.Cecil.TypeDefinition type)
443445
{
444-
return ToJniName (type, t => t.DeclaringType, t => t.Name, ToCompatPackageName, ToJniNameFromAttributes);
446+
return ToJniName (type, t => t.DeclaringType, t => t.Name, ToCompatPackageName, ToJniNameFromAttributes, t => IsNonStaticInnerClass (t as TypeDefinition));
445447
}
446448

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

459-
public static string ToJniName (TypeDefinition type, ExportParameterKind exportKind)
461+
static string ToJniName (TypeDefinition type, ExportParameterKind exportKind)
460462
{
461463
if (type == null)
462464
throw new ArgumentNullException ("type");
@@ -471,7 +473,7 @@ public static string ToJniName (TypeDefinition type, ExportParameterKind exportK
471473
return GetSpecialExportJniType (type.FullName, exportKind);
472474
}
473475

474-
return ToJniName (type, t => t.DeclaringType, t => t.Name, GetPackageName, ToJniNameFromAttributes);
476+
return ToJniName (type, t => t.DeclaringType, t => t.Name, GetPackageName, ToJniNameFromAttributes, t => IsNonStaticInnerClass (t as TypeDefinition));
475477
}
476478

477479
static string ToJniNameFromAttributes (TypeDefinition type)
@@ -562,7 +564,7 @@ public static string GetPackageName (TypeDefinition type)
562564
}
563565
#endif
564566

565-
static string ToJniName<T> (T type, Func<T, T> decl, Func<T, string> name, Func<T, string> ns, Func<T, string> overrideName)
567+
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)
566568
where T : class
567569
{
568570
var nameParts = new List<string> ();
@@ -576,12 +578,9 @@ static string ToJniName<T> (T type, Func<T, T> decl, Func<T, string> name, Func<
576578
break;
577579
}
578580
var n = name (declType).Replace ('`', '_');
579-
#if HAVE_CECIL
580-
var td = declType as TypeDefinition;
581-
if (IsNonStaticInnerClass (td)) {
581+
if (shouldUpdateName (declType)) {
582582
n = "$" + name (decl (declType)) + "_" + n;
583583
}
584-
#endif
585584
nameParts.Add (n);
586585
}
587586

tools/generator/generator.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@
112112
<ItemGroup>
113113
<Folder Include="MonoDroid.Generation\" />
114114
</ItemGroup>
115-
<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')" />
116-
<Import Project="..\..\src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems" Label="Shared" Condition="Exists('..\..\src\Java.Interop.NamingCustomAttributes\Java.Interop.NamingCustomAttributes.projitems')" />
117115
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
118116
<ItemGroup>
119117
<ProjectReference Include="..\..\src\Xamarin.Android.Tools.AnnotationSupport\Xamarin.Android.Tools.AnnotationSupport.csproj">
@@ -136,6 +134,10 @@
136134
<Project>{15945D4B-FF56-4BCC-B598-2718D199DD08}</Project>
137135
<Name>Xamarin.Android.Cecil</Name>
138136
</ProjectReference>
137+
<ProjectReference Include="..\..\src\Java.Interop.Tools.JavaCallableWrappers\Java.Interop.Tools.JavaCallableWrappers.csproj">
138+
<Project>{D18FCF91-8876-48A0-A693-2DC1E7D3D80A}</Project>
139+
<Name>Java.Interop.Tools.JavaCallableWrappers</Name>
140+
</ProjectReference>
139141
</ItemGroup>
140142
<ItemGroup>
141143
<None Include="packages.config" />

0 commit comments

Comments
 (0)