~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to contrib/ICSharpCode.NRefactory.CSharp/TypeSystem/TypeOrNamespaceReference.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team
2
 
// 
3
 
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4
 
// software and associated documentation files (the "Software"), to deal in the Software
5
 
// without restriction, including without limitation the rights to use, copy, modify, merge,
6
 
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7
 
// to whom the Software is furnished to do so, subject to the following conditions:
8
 
// 
9
 
// The above copyright notice and this permission notice shall be included in all copies or
10
 
// substantial portions of the Software.
11
 
// 
12
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13
 
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14
 
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15
 
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
 
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17
 
// DEALINGS IN THE SOFTWARE.
18
 
 
19
 
using System;
20
 
using ICSharpCode.NRefactory.CSharp.Resolver;
21
 
using ICSharpCode.NRefactory.Semantics;
22
 
using ICSharpCode.NRefactory.TypeSystem;
23
 
 
24
 
namespace ICSharpCode.NRefactory.CSharp.TypeSystem
25
 
{
26
 
        /// <summary>
27
 
        /// Represents a reference which could point to a type or namespace.
28
 
        /// </summary>
29
 
        [Serializable]
30
 
        public abstract class TypeOrNamespaceReference : ITypeReference
31
 
        {
32
 
                /// <summary>
33
 
                /// Resolves the reference and returns the ResolveResult.
34
 
                /// </summary>
35
 
                public abstract ResolveResult Resolve(CSharpResolver resolver);
36
 
                
37
 
                /// <summary>
38
 
                /// Returns the namespace that is referenced; or null if no such namespace is found.
39
 
                /// </summary>
40
 
                public INamespace ResolveNamespace(CSharpResolver resolver)
41
 
                {
42
 
                        NamespaceResolveResult nrr = Resolve(resolver) as NamespaceResolveResult;
43
 
                        return nrr != null ? nrr.Namespace : null;
44
 
                }
45
 
                
46
 
                /// <summary>
47
 
                /// Returns the type that is referenced; or <see cref="SpecialType.UnknownType"/> if the type isn't found.
48
 
                /// </summary>
49
 
                public IType ResolveType(CSharpResolver resolver)
50
 
                {
51
 
                        TypeResolveResult trr = Resolve(resolver) as TypeResolveResult;
52
 
                        return trr != null ? trr.Type : SpecialType.UnknownType;
53
 
                }
54
 
                
55
 
                IType ITypeReference.Resolve(ITypeResolveContext context)
56
 
                {
57
 
                        // Strictly speaking, we might have to resolve the type in a nested compilation, similar
58
 
                        // to what we're doing with ConstantExpression.
59
 
                        // However, in almost all cases this will work correctly - if the resulting type is only available in the
60
 
                        // nested compilation and not in this, we wouldn't be able to map it anyways.
61
 
                        var ctx = context as CSharpTypeResolveContext;
62
 
                        if (ctx == null) {
63
 
                                ctx = new CSharpTypeResolveContext(context.CurrentAssembly ?? context.Compilation.MainAssembly, null, context.CurrentTypeDefinition, context.CurrentMember);
64
 
                        }
65
 
                        return ResolveType(new CSharpResolver(ctx));
66
 
                        
67
 
                        // A potential issue might be this scenario:
68
 
                        
69
 
                        // Assembly 1:
70
 
                        //  class A { public class Nested {} }
71
 
                        
72
 
                        // Assembly 2: (references asm 1)
73
 
                        //  class B : A {}
74
 
                        
75
 
                        // Assembly 3: (references asm 1 and 2)
76
 
                        //  class C { public B.Nested Field; }
77
 
                        
78
 
                        // Assembly 4: (references asm 1 and 3, but not 2):
79
 
                        //  uses C.Field;
80
 
                        
81
 
                        // Here we would not be able to resolve 'B.Nested' in the compilation of assembly 4, as type B is missing there.
82
 
                }
83
 
        }
84
 
}