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
|
//
// BaseTypeFolderNodeBuilder.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using MonoDevelop.Ide.Gui.Components;
using ICSharpCode.NRefactory.TypeSystem;
using System;
using Mono.Cecil;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using MonoDevelop.Core;
using MonoDevelop.Projects;
using MonoDevelop.Ide.TypeSystem;
namespace MonoDevelop.AssemblyBrowser
{
abstract class AssemblyBrowserTypeNodeBuilder : TypeNodeBuilder
{
internal AssemblyBrowserWidget Widget {
get;
private set;
}
protected MonoDevelop.Ide.TypeSystem.Ambience Ambience {
get {
return Widget.Ambience;
}
}
internal CecilLoader CecilLoader {
get {
return Widget.CecilLoader;
}
}
public override int CompareObjects (ITreeNavigator thisNode, ITreeNavigator otherNode)
{
try {
if (thisNode == null || otherNode == null)
return -1;
var e1 = thisNode.DataItem as IUnresolvedEntity;
var e2 = otherNode.DataItem as IUnresolvedEntity;
if (e1 == null && e2 == null)
return 0;
if (e1 == null)
return -1;
if (e2 == null)
return 1;
if (e1.SymbolKind != e2.SymbolKind)
return e2.SymbolKind.CompareTo (e1.SymbolKind);
return e1.Name.CompareTo (e2.Name);
} catch (Exception e) {
LoggingService.LogError ("Exception in assembly browser sort function.", e);
return -1;
}
}
public AssemblyBrowserTypeNodeBuilder (AssemblyBrowserWidget assemblyBrowserWidget)
{
this.Widget = assemblyBrowserWidget;
}
protected static bool IsFromAssembly (ITreeNavigator treeBuilder)
{
return treeBuilder.GetParentDataItem (typeof(AssemblyLoader), true) != null;
}
protected IUnresolvedAssembly GetMainAssembly (ITreeNavigator treeBuilder)
{
var loader = (AssemblyLoader)treeBuilder.GetParentDataItem (typeof(AssemblyLoader), true);
if (loader != null)
return loader.UnresolvedAssembly;
return null;
}
protected ITypeResolveContext GetContext (ITreeNavigator treeBuilder)
{
var mainAssembly = GetMainAssembly (treeBuilder);
if (mainAssembly != null) {
var simpleCompilation = new SimpleCompilation (mainAssembly);
return new SimpleTypeResolveContext (simpleCompilation.MainAssembly);
}
var project = (Project)treeBuilder.GetParentDataItem (typeof(Project), true);
var compilation = TypeSystemService.GetCompilation (project);
return new SimpleTypeResolveContext (compilation.MainAssembly);
}
protected IMember Resolve (ITreeNavigator treeBuilder, IUnresolvedMember member, ITypeDefinition currentType = null)
{
var ctx = GetContext (treeBuilder);
return member.CreateResolved (currentType != null ? ctx.WithCurrentTypeDefinition (currentType) : ctx);
}
protected IType Resolve (ITreeNavigator treeBuilder, IUnresolvedTypeDefinition type)
{
var mainAssembly = GetMainAssembly (treeBuilder);
if (mainAssembly != null) {
var simpleCompilation = new SimpleCompilation (mainAssembly);
return type.Resolve (new SimpleTypeResolveContext (simpleCompilation.MainAssembly));
}
var project = (Project)treeBuilder.GetParentDataItem (typeof(Project), true);
var ctx = TypeSystemService.GetCompilation (project);
return ctx.MainAssembly.GetTypeDefinition (type.Namespace, type.Name, type.TypeParameters.Count);
}
}
}
|