forked from codecadwallader/codemaid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeItemMethod.cs
More file actions
150 lines (118 loc) · 4.95 KB
/
CodeItemMethod.cs
File metadata and controls
150 lines (118 loc) · 4.95 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using EnvDTE;
using EnvDTE80;
using SteveCadwallader.CodeMaid.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
namespace SteveCadwallader.CodeMaid.Model.CodeItems
{
/// <summary>
/// The representation of a code method.
/// </summary>
public class CodeItemMethod : BaseCodeItemElement, ICodeItemComplexity, ICodeItemParameters, IInterfaceItem
{
#region Fields
private readonly Lazy<int> _complexity;
private readonly Lazy<bool> _isConstructor;
private readonly Lazy<bool> _isDestructor;
private readonly Lazy<bool> _isExplicitInterfaceImplementation;
private readonly Lazy<vsCMOverrideKind> _overrideKind;
private readonly Lazy<IEnumerable<CodeParameter>> _parameters;
#endregion Fields
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="CodeItemMethod" /> class.
/// </summary>
public CodeItemMethod()
{
// Make exceptions for static constructors and explicit interface implementations -
// which report private access but really do not have a meaningful access level.
_Access = LazyTryDefault(
() => CodeFunction != null && !(IsStatic && IsConstructor) && !IsExplicitInterfaceImplementation ? CodeFunction.Access : vsCMAccess.vsCMAccessPublic);
_Attributes = LazyTryDefault(
() => CodeFunction?.Attributes);
_complexity = LazyTryDefault(
() => CodeElementHelper.CalculateComplexity(CodeElement));
_DocComment = LazyTryDefault(
() => CodeFunction?.DocComment);
_isConstructor = LazyTryDefault(
() => CodeFunction != null && CodeFunction.FunctionKind == vsCMFunction.vsCMFunctionConstructor);
_isDestructor = LazyTryDefault(
() => CodeFunction != null && CodeFunction.FunctionKind == vsCMFunction.vsCMFunctionDestructor);
_isExplicitInterfaceImplementation = LazyTryDefault(
() => CodeFunction != null && ExplicitInterfaceImplementationHelper.IsExplicitInterfaceImplementation(CodeFunction));
_IsStatic = LazyTryDefault(
() => CodeFunction != null && CodeFunction.IsShared);
_overrideKind = LazyTryDefault(
() => CodeFunction?.OverrideKind ?? vsCMOverrideKind.vsCMOverrideKindNone);
_parameters = LazyTryDefault(
() => CodeFunction?.Parameters?.Cast<CodeParameter>().ToList() ?? Enumerable.Empty<CodeParameter>());
_TypeString = LazyTryDefault(
() => CodeFunction?.Type?.AsString);
}
#endregion Constructors
#region BaseCodeItem Overrides
/// <summary>
/// Gets the kind.
/// </summary>
public override KindCodeItem Kind
{
get
{
if (IsConstructor)
{
return KindCodeItem.Constructor;
}
if (IsDestructor)
{
return KindCodeItem.Destructor;
}
return KindCodeItem.Method;
}
}
/// <summary>
/// Loads all lazy initialized values immediately.
/// </summary>
public override void LoadLazyInitializedValues()
{
base.LoadLazyInitializedValues();
var c = Complexity;
var ic = IsConstructor;
var id = IsDestructor;
var ieii = IsExplicitInterfaceImplementation;
var ok = OverrideKind;
var p = Parameters;
}
#endregion BaseCodeItem Overrides
#region Properties
/// <summary>
/// Gets or sets the underlying VSX CodeFunction.
/// </summary>
public CodeFunction2 CodeFunction { get; set; }
/// <summary>
/// Gets the complexity.
/// </summary>
public int Complexity => _complexity.Value;
/// <summary>
/// Gets a flag indicating if this method is a constructor.
/// </summary>
public bool IsConstructor => _isConstructor.Value;
/// <summary>
/// Gets a flag indicating if this method is a destructor.
/// </summary>
public bool IsDestructor => _isDestructor.Value;
/// <summary>
/// Gets a flag indicating if this method is an explicit interface implementation.
/// </summary>
public bool IsExplicitInterfaceImplementation => _isExplicitInterfaceImplementation.Value;
/// <summary>
/// Gets the override kind (abstract, virtual, override, new), defaulting to none.
/// </summary>
public vsCMOverrideKind OverrideKind => _overrideKind.Value;
/// <summary>
/// Gets the parameters.
/// </summary>
public IEnumerable<CodeParameter> Parameters => _parameters.Value;
#endregion Properties
}
}