2 // ResolveFromXApiStep.cs
5 // Jb Evain (jbevain@novell.com)
7 // (C) 2007 Novell, Inc.
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.Xml.XPath;
35 namespace Mono.Linker.Steps {
37 public class ResolveFromXApiStep : ResolveStep, IXApiVisitor {
39 static readonly string _name = "name";
40 static readonly string _ns = string.Empty;
42 XPathDocument _document;
44 public ResolveFromXApiStep (XPathDocument document)
49 protected override void Process ()
51 XApiReader reader = new XApiReader (_document, this);
52 reader.Process (Context);
55 public void OnAssembly (XPathNavigator nav, AssemblyDefinition assembly)
59 public void OnAttribute (XPathNavigator nav)
61 string name = GetName (nav);
63 TypeDefinition type = Context.GetType (name);
68 public void OnClass (XPathNavigator nav, TypeDefinition type)
73 public void OnInterface (XPathNavigator nav, TypeDefinition type)
78 public void OnField (XPathNavigator nav, FieldDefinition field)
83 public void OnMethod (XPathNavigator nav, MethodDefinition method)
88 public void OnConstructor (XPathNavigator nav, MethodDefinition method)
93 public void OnProperty (XPathNavigator nav, PropertyDefinition property)
97 public void OnEvent (XPathNavigator nav, EventDefinition evt)
99 if (evt.AddMethod != null)
100 MarkMethod (evt.AddMethod);
101 if (evt.InvokeMethod != null)
102 MarkMethod (evt.InvokeMethod);
103 if (evt.RemoveMethod != null)
104 MarkMethod (evt.RemoveMethod);
107 static string GetName (XPathNavigator nav)
109 return GetAttribute (nav, _name);
112 static string GetAttribute (XPathNavigator nav, string attribute)
114 return nav.GetAttribute (attribute, _ns);
117 void MarkType (TypeDefinition type)
122 void MarkField (FieldDefinition field)
124 InternalMark (field);
127 void InternalMark (IMetadataTokenProvider provider)
129 Annotations.Mark (provider);
130 Annotations.SetPublic (provider);
133 void MarkMethod (MethodDefinition method)
135 InternalMark (method);
136 Annotations.SetAction (method, MethodAction.Parse);