forked from dotnet/java-interop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavaApiDllLoaderExtensions.cs
165 lines (150 loc) · 4.74 KB
/
JavaApiDllLoaderExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#if GENERATOR
using System;
using System.Linq;
using MonoDroid.Generation;
namespace Xamarin.Android.Tools.ApiXmlAdjuster
{
public static class JavaApiDllLoaderExtensions
{
public static void LoadReferences (this JavaApi api, GenBase [] gens)
{
JavaPackage pkg = null;
foreach (var gen in gens.Where (_ => _.IsAcw)) {
pkg = api.Packages.FirstOrDefault (_ => _.Name == gen.PackageName);
if (pkg == null) {
pkg = new JavaPackage (api) { Name = gen.PackageName };
api.Packages.Add (pkg);
}
if (gen is InterfaceGen) {
var iface = new JavaInterface (pkg);
pkg.Types.Add (iface);
iface.Load (gen);
} else if (gen is ClassGen) {
var kls = new JavaClass (pkg);
pkg.Types.Add (kls);
kls.Load (gen);
}
else
throw new InvalidOperationException ();
}
}
static void Load (this JavaType type, GenBase gen)
{
type.IsReferenceOnly = true;
type.Name = gen.JavaSimpleName;
type.ExtendedJniSignature = gen.JniName;
type.Deprecated = gen.DeprecatedComment;
type.Visibility = gen.RawVisibility;
type.Implements = gen.Interfaces.Select (_ => new JavaImplements () {
Name = _.JavaName,
ExtendedJniType = _.JniName,
}).ToArray ();
if (gen.TypeParameters != null && gen.TypeParameters.Any ()) {
type.TypeParameters = new JavaTypeParameters (type);
type.TypeParameters.Load (gen.TypeParameters);
}
foreach (var f in gen.Fields.Where (_ => _.IsAcw)) {
var fld = new JavaField (type);
fld.Load (f);
type.Members.Add (fld);
}
foreach (var p in gen.Properties) {
if (p.Getter != null && p.Getter.IsAcw) {
var getter = new JavaMethod (type);
getter.Load (p.Getter);
type.Members.Add (getter);
}
if (p.Setter != null && p.Setter.IsAcw) {
var setter = new JavaMethod (type);
setter.Load (p.Setter);
type.Members.Add (setter);
}
}
foreach (var m in gen.Methods.Where (_ => _.IsAcw)) {
var method = new JavaMethod (type);
method.Load (m);
type.Members.Add (method);
}
}
static void Load (this JavaInterface iface, InterfaceGen gen)
{
((JavaType) iface).Load (gen);
}
static string ExpandTypeParameters (GenericParameterDefinitionList tps)
{
if (tps == null)
return null;
return '<' + string.Join (", ", tps.Select (_ => _.Name)) + '>';
}
static void Load (this JavaClass kls, ClassGen gen)
{
((JavaType) kls).Load (gen);
kls.Abstract = gen.IsAbstract;
kls.Final = gen.IsFinal;
if (gen.BaseGen != null) {
kls.Extends = gen.BaseGen.JavaSimpleName;
kls.ExtendsGeneric = gen.BaseGen.JavaSimpleName + ExpandTypeParameters (gen.BaseGen.TypeParameters);
kls.ExtendedJniExtends = gen.BaseGen.JniName;
}
foreach (var c in gen.Ctors) {
var ctor = new JavaConstructor (kls);
ctor.Load (c);
kls.Members.Add (ctor);
}
}
static void Load (this JavaField field, Field gf)
{
field.Deprecated = gf.DeprecatedComment;
field.Final = gf.IsFinal;
field.Name = gf.JavaName;
field.Static = gf.IsStatic;
field.Visibility = gf.Visibility;
field.Type = gf.TypeName; // FIXME: this is managed name. Should there be Java typename?
field.TypeGeneric = gf.TypeName; // FIXME: this is NOT generic.
field.Value = gf.Value;
}
static void Load (this JavaMethodBase method, MethodBase gm)
{
method.Deprecated = gm.Deprecated;
method.Visibility = gm.Visibility;
method.Parameters = gm.Parameters.Select (_ => new JavaParameter () {
Name = _.JavaName,
Type = _.RawNativeType,
}).ToArray ();
}
static void Load (this JavaMethod method, Method gm)
{
((JavaMethodBase) method).Load (gm);
if (gm.RetVal.RawJavaType == "System.Boolean") throw new Exception (method.Parent.FullName + "." + gm.JavaName);
method.Final = gm.IsFinal;
method.Name = gm.JavaName;
method.Static = gm.IsStatic;
//method.ExtendedJniSignature = gm.JniSignature;
if (gm.GenericArguments != null && gm.GenericArguments.Any ()) {
method.TypeParameters = new JavaTypeParameters (method);
method.TypeParameters.Load (gm.GenericArguments);
}
method.Abstract = gm.IsAbstract;
method.Return = gm.RetVal.RawJavaType;
// FIXME: get ExtendedJniReturn?
}
static void Load (this JavaConstructor ctor, Ctor gc)
{
((JavaMethodBase) ctor).Load (gc);
}
static void Load (this JavaTypeParameters tps, GenericParameterDefinitionList gtps)
{
foreach (var stp in gtps) {
var tp = new JavaTypeParameter (tps) {
Name = stp.Name,
};
if (stp.Constraints != null)
tp.GenericConstraints = new JavaGenericConstraints () {
BoundsType = stp.Name,
GenericConstraints = stp.Constraints.Select (_ => new JavaGenericConstraint () { Type = _.JavaName }).ToArray ()};
tps.TypeParameters.Add (tp);
}
}
}
}
#endif