-
Notifications
You must be signed in to change notification settings - Fork 528
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate mappings used by
Xamarin.Android.Build.Tasks
.
- Loading branch information
Showing
43 changed files
with
1,421 additions
and
1,089 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
build-tools/manifest-attribute-codegen/SourceWriters/AttributeMappingField.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Xamarin.SourceWriter; | ||
|
||
namespace Xamarin.Android.Tools.ManifestAttributeCodeGenerator; | ||
|
||
class AttributeMappingField : FieldWriter | ||
{ | ||
public static AttributeMappingField Create (MetadataType type) | ||
{ | ||
var field = new AttributeMappingField { | ||
Name = "mapping", | ||
IsStatic = true, | ||
Type = new TypeReferenceWriter ($"Xamarin.Android.Manifest.ManifestDocumentElement<{type.ManagedName}>"), | ||
Value = $"new (\"{type.Name}\")", | ||
}; | ||
|
||
return field; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
build-tools/manifest-attribute-codegen/SourceWriters/AttributeMappingManualInitializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Xamarin.SourceWriter; | ||
|
||
namespace Xamarin.Android.Tools.ManifestAttributeCodeGenerator; | ||
|
||
class AttributeMappingManualInitializer : MethodWriter | ||
{ | ||
public static AttributeMappingManualInitializer Create () | ||
{ | ||
var method = new AttributeMappingManualInitializer { | ||
Name = "AddManualMapping", | ||
IsStatic = true, | ||
IsPartial = true, | ||
IsDeclaration = true, | ||
ReturnType = TypeReferenceWriter.Void, | ||
}; | ||
|
||
return method; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
build-tools/manifest-attribute-codegen/SourceWriters/AttributeMappingStaticConstructor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Xamarin.SourceWriter; | ||
|
||
namespace Xamarin.Android.Tools.ManifestAttributeCodeGenerator; | ||
|
||
class AttributeMappingStaticConstructor : ConstructorWriter | ||
{ | ||
public static AttributeMappingStaticConstructor Create (ElementDefinition attr, MetadataSource metadata, MetadataType type) | ||
{ | ||
var ctor = new AttributeMappingStaticConstructor { | ||
Name = type.ManagedName, | ||
IsStatic = true, | ||
}; | ||
|
||
// mapping.Add ( | ||
// member: "Name", | ||
// attributeName: "name", | ||
// getter: self => self.Name, | ||
// setter: (self, value) => self.Name = (string?) value | ||
// ); | ||
foreach (var a in attr.Attributes.OrderBy (a => a.Name)) { | ||
var attr_metadata = metadata.GetMetadata ($"{attr.ActualElementName}.{a.Name}"); | ||
|
||
if (!attr_metadata.Visible || attr_metadata.ManualMap) | ||
continue; | ||
|
||
var name = (attr_metadata.Name ?? a.Name).Capitalize (); | ||
var setter = $"(self, value) => self.{name} = ({attr_metadata.Type ?? a.GetAttributeType ()}) value"; | ||
|
||
if (attr_metadata.ReadOnly) | ||
setter = "null"; | ||
|
||
ctor.Body.Add ($"mapping.Add ("); | ||
ctor.Body.Add ($" member: \"{name}\","); | ||
ctor.Body.Add ($" attributeName: \"{a.Name}\","); | ||
ctor.Body.Add ($" getter: self => self.{name},"); | ||
ctor.Body.Add ($" setter: {setter}"); | ||
ctor.Body.Add ($");"); | ||
} | ||
|
||
ctor.Body.Add (string.Empty); | ||
ctor.Body.Add ($"AddManualMapping ();"); | ||
|
||
return ctor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.