1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
4
// created on 22.08.2003 at 19:02
7
using System.Collections.Generic;
10
using ICSharpCode.NRefactory;
11
using ICSharpCode.NRefactory.Ast;
12
using ICSharpCode.NRefactory.Visitors;
14
namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
16
// TODO: Rename this class, the visitor functionality was moved to ResolveVisitor
17
public static class TypeVisitor
20
public enum ReturnTypeOptions
27
public static IReturnType CreateReturnType(TypeReference reference, NRefactoryResolver resolver)
29
return CreateReturnType(reference,
30
resolver.CallingClass, resolver.CallingMember,
31
resolver.CaretLine, resolver.CaretColumn,
32
resolver.ProjectContent, ReturnTypeOptions.None);
35
public static IReturnType CreateReturnType(TypeReference reference, IClass callingClass,
36
IMember callingMember, int caretLine, int caretColumn,
37
IProjectContent projectContent,
38
ReturnTypeOptions options)
40
if (reference == null) return null;
41
if (reference.IsNull) return null;
42
if (reference is InnerClassTypeReference) {
43
reference = ((InnerClassTypeReference)reference).CombineToNormalTypeReference();
46
bool useLazyReturnType = (options & ReturnTypeOptions.Lazy) == ReturnTypeOptions.Lazy;
47
bool isBaseTypeReference = (options & ReturnTypeOptions.BaseTypeReference) == ReturnTypeOptions.BaseTypeReference;
49
LanguageProperties languageProperties = projectContent.Language;
51
if (callingClass != null && !reference.IsGlobal) {
52
foreach (ITypeParameter tp in callingClass.TypeParameters) {
53
if (languageProperties.NameComparer.Equals(tp.Name, reference.Type)) {
54
t = new GenericReturnType(tp);
58
IMethod callingMethod = callingMember as IMethod;
59
if (t == null && callingMethod != null) {
60
foreach (ITypeParameter tp in callingMethod.TypeParameters) {
61
if (languageProperties.NameComparer.Equals(tp.Name, reference.Type)) {
62
t = new GenericReturnType(tp);
68
if (t == null && reference.Type == "dynamic") {
69
t = new DynamicReturnType(projectContent);
72
int typeParameterCount = reference.GenericTypes.Count;
73
if (reference.IsKeyword) {
74
// keyword-type like void, int, string etc.
75
IClass c = projectContent.GetClass(reference.Type, typeParameterCount);
77
t = c.DefaultReturnType;
79
t = new GetClassReturnType(projectContent, reference.Type, typeParameterCount);
81
if (useLazyReturnType || isBaseTypeReference) {
82
if (reference.IsGlobal) {
83
t = new GetClassReturnType(projectContent, reference.Type, typeParameterCount);
84
} else if (callingClass != null) {
85
SearchClassReturnType scrt = new SearchClassReturnType(projectContent, callingClass, caretLine, caretColumn, reference.Type, typeParameterCount);
86
if (isBaseTypeReference)
87
scrt.LookForInnerClassesInDeclaringClass = false;
92
if (reference.IsGlobal) {
93
c = projectContent.GetClass(reference.Type, typeParameterCount);
94
t = (c != null) ? c.DefaultReturnType : null;
95
} else if (callingClass != null) {
96
t = projectContent.SearchType(new SearchTypeRequest(reference.Type, typeParameterCount, callingClass, caretLine, caretColumn)).Result;
104
if (reference.GenericTypes.Count > 0) {
105
IReturnType[] para = new IReturnType[reference.GenericTypes.Count];
106
for (int i = 0; i < reference.GenericTypes.Count; ++i) {
107
para[i] = CreateReturnType(reference.GenericTypes[i], callingClass, callingMember, caretLine, caretColumn, projectContent, options);
109
t = new ConstructedReturnType(t, para);
111
for (int i = 0; i < reference.PointerNestingLevel; i++) {
112
t = new PointerReturnType(t);
114
return WrapArray(projectContent, t, reference);
117
static IReturnType WrapArray(IProjectContent pc, IReturnType t, TypeReference reference)
119
if (reference.IsArrayType) {
120
for (int i = reference.RankSpecifier.Length - 1; i >= 0; --i) {
121
int dimensions = reference.RankSpecifier[i] + 1;
122
if (dimensions > 0) {
123
t = new ArrayReturnType(pc, t, dimensions);