-
Notifications
You must be signed in to change notification settings - Fork 537
/
Copy pathPreserveJavaExceptions.cs
67 lines (51 loc) · 1.4 KB
/
PreserveJavaExceptions.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
using System;
using System.Collections;
using System.Linq;
using Mono.Linker;
using Mono.Linker.Steps;
using Mono.Tuner;
using Mobile.Tuner;
using Mono.Cecil;
namespace MonoDroid.Tuner {
public class PreserveJavaExceptions : BaseMarkHandler
{
public override void Initialize (LinkContext context, MarkContext markContext)
{
base.Initialize (context, markContext);
markContext.RegisterMarkTypeAction (type => ProcessType (type));
}
public void ProcessType (TypeDefinition type)
{
if (type.IsJavaException (cache))
PreserveJavaException (type);
}
void PreserveJavaException (TypeDefinition type)
{
PreserveStringConstructor (type);
}
void PreserveStringConstructor (TypeDefinition type)
{
var constructor = GetStringConstructor (type);
if (constructor == null)
return;
PreserveMethod (type, constructor);
}
MethodDefinition GetStringConstructor (TypeDefinition type)
{
if (!type.HasMethods)
return null;
foreach (MethodDefinition constructor in type.Methods.Where (m => m.IsConstructor)) {
if (!constructor.HasParameters)
continue;
if (constructor.Parameters.Count != 1 || constructor.Parameters [0].ParameterType.FullName != "System.String")
continue;
return constructor;
}
return null;
}
void PreserveMethod (TypeDefinition type, MethodDefinition method)
{
Annotations.AddPreservedMethod (type, method);
}
}
}