Skip to content

Commit d533a96

Browse files
authored
Merge pull request #3975 from bclothier/techdebt
Reflection API & COM management/cleanup
2 parents c5c11eb + f211f42 commit d533a96

File tree

112 files changed

+4460
-495
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+4460
-495
lines changed

Rubberduck.API/API/VBA/Accessibility.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.

Rubberduck.API/API/VBA/DeclarationType.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.

Rubberduck.API/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
using System.Reflection;
22
using System.Runtime.CompilerServices;
33
using System.Runtime.InteropServices;
4+
using Rubberduck.Resources.Registration;
45

56
// General Information about an assembly is controlled through the following
67
// set of attributes. Change these attribute values to modify the information
78
// associated with an assembly.
89
[assembly: AssemblyTitle("Rubberduck.API")]
9-
[assembly: AssemblyDescription("API for programmatic access to Rubberduck's Code Analysis features.")]
10+
[assembly: AssemblyDescription("Rubberduck Reflection API")]
1011
[assembly: AssemblyConfiguration("")]
1112
[assembly: AssemblyCompany("Rubberduck-VBA")]
1213
[assembly: AssemblyProduct("Rubberduck.API")]
@@ -21,7 +22,7 @@
2122
[assembly: ComVisible(false)]
2223

2324
// The following GUID is for the ID of the typelib if this project is exposed to COM
24-
[assembly: Guid("ac1b4a57-364a-4f90-a0cd-6ee818349ce5")]
25+
[assembly: Guid(RubberduckGuid.RubberduckApiTypeLibGuid)]
2526

2627
// Version information for an assembly consists of the following four values:
2728
//

Rubberduck.API/Rubberduck.API.csproj

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>Rubberduck.API</RootNamespace>
1111
<AssemblyName>Rubberduck.API</AssemblyName>
12-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
1414
<TargetFrameworkProfile />
1515
</PropertyGroup>
@@ -36,32 +36,47 @@
3636
<Reference Include="Microsoft.CSharp" />
3737
</ItemGroup>
3838
<ItemGroup>
39-
<Compile Include="API\VBA\Accessibility.cs" />
40-
<Compile Include="API\VBA\Declaration.cs" />
41-
<Compile Include="API\VBA\DeclarationType.cs" />
42-
<Compile Include="API\VBA\IdentifierReference.cs" />
43-
<Compile Include="API\VBA\ParserState.cs" />
39+
<Compile Include="VBA\ApiProvider.cs" />
40+
<Compile Include="VBA\Accessibility.cs" />
41+
<Compile Include="VBA\Declaration.cs" />
42+
<Compile Include="VBA\Declarations.cs" />
43+
<Compile Include="VBA\DeclarationType.cs" />
44+
<Compile Include="VBA\IdentifierReference.cs" />
45+
<Compile Include="VBA\IdentifierReferences.cs" />
46+
<Compile Include="VBA\Parser.cs" />
47+
<Compile Include="VBA\ParserState.cs" />
4448
<Compile Include="Properties\AssemblyInfo.cs" />
4549
</ItemGroup>
4650
<ItemGroup>
4751
<ProjectReference Include="..\Rubberduck.Core\Rubberduck.Core.csproj">
4852
<Project>{a1587eac-7b54-407e-853f-4c7493d0323e}</Project>
4953
<Name>Rubberduck.Core</Name>
5054
</ProjectReference>
55+
<ProjectReference Include="..\Rubberduck.Main\Rubberduck.Main.csproj">
56+
<Project>{E8AB5D93-2D0F-423D-BC15-5EE118673E48}</Project>
57+
<Name>Rubberduck.Main</Name>
58+
</ProjectReference>
5159
<ProjectReference Include="..\Rubberduck.Parsing\Rubberduck.Parsing.csproj">
5260
<Project>{a4a618e1-cbca-435f-9c6c-5181e030adfc}</Project>
5361
<Name>Rubberduck.Parsing</Name>
5462
</ProjectReference>
63+
<ProjectReference Include="..\Rubberduck.Resources\Rubberduck.Resources.csproj">
64+
<Project>{1b84b387-f7c4-4876-9bdf-c644c365359a}</Project>
65+
<Name>Rubberduck.Resources</Name>
66+
</ProjectReference>
5567
<ProjectReference Include="..\Rubberduck.VBEEditor\Rubberduck.VBEditor.csproj">
5668
<Project>{8ce35eb3-8852-4ba1-84dd-df3f5d2967b0}</Project>
5769
<Name>Rubberduck.VBEditor</Name>
5870
</ProjectReference>
5971
</ItemGroup>
6072
<ItemGroup>
61-
<Folder Include="API\Plugin\" />
73+
<Folder Include="Plugin\" />
6274
</ItemGroup>
6375
<ItemGroup>
6476
<None Include="app.config" />
6577
</ItemGroup>
78+
<ItemGroup>
79+
<Analyzer Include="..\RubberduckCodeAnalysis\bin\Release\RubberduckCodeAnalysis.dll" />
80+
</ItemGroup>
6681
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
6782
</Project>

Rubberduck.API/VBA/APIProvider.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.ComponentModel;
2+
using Rubberduck.API.VBA;
3+
using System.Runtime.InteropServices;
4+
using Rubberduck.Resources.Registration;
5+
6+
namespace Rubberduck.API
7+
{
8+
[
9+
ComVisible(true),
10+
Guid(RubberduckGuid.IApiProviderGuid),
11+
InterfaceType(ComInterfaceType.InterfaceIsDual)
12+
]
13+
public interface IApiProvider
14+
{
15+
Parser GetParser(object vbe);
16+
}
17+
18+
[
19+
ComVisible(true),
20+
Guid(RubberduckGuid.ApiProviderClassGuid),
21+
ProgId(RubberduckProgId.ApiProviderProgId),
22+
ClassInterface(ClassInterfaceType.None),
23+
ComDefaultInterface(typeof(IApiProvider)),
24+
EditorBrowsable(EditorBrowsableState.Always)
25+
]
26+
public class ApiProvider : IApiProvider
27+
{
28+
// vbe is the com coclass interface from the interop assembly.
29+
// There is no shared interface between VBA and VB6 types, hence object.
30+
public Parser GetParser(object vbe)
31+
{
32+
return new Parser(vbe);
33+
}
34+
}
35+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Runtime.InteropServices;
2+
using Rubberduck.Resources.Registration;
3+
using Source = Rubberduck.Parsing.Symbols;
4+
5+
namespace Rubberduck.API.VBA
6+
{
7+
[
8+
ComVisible(true),
9+
Guid(RubberduckGuid.AccessibilityGuid)
10+
]
11+
public enum Accessibility
12+
{
13+
Private = Source.Accessibility.Private,
14+
Friend = Source.Accessibility.Friend,
15+
Global = Source.Accessibility.Global,
16+
Implicit = Source.Accessibility.Implicit,
17+
Public = Source.Accessibility.Public,
18+
Static = Source.Accessibility.Static
19+
}
20+
}

Rubberduck.API/API/VBA/Declaration.cs renamed to Rubberduck.API/VBA/Declaration.cs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,42 @@
22
using System.ComponentModel;
33
using System.Linq;
44
using System.Runtime.InteropServices;
5+
using Rubberduck.Resources.Registration;
56
using RubberduckDeclaration = Rubberduck.Parsing.Symbols.Declaration;
67

78
namespace Rubberduck.API.VBA
89
{
9-
[ComVisible(true)]
10-
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
10+
[
11+
ComVisible(true),
12+
Guid(RubberduckGuid.IDeclarationGuid),
13+
InterfaceType(ComInterfaceType.InterfaceIsDual)
14+
]
1115
public interface IDeclaration
1216
{
13-
[ComVisible(true)]
17+
[DispId(1)]
1418
string Name { get; }
15-
[ComVisible(true)]
19+
[DispId(2)]
1620
Accessibility Accessibility { get; }
17-
[ComVisible(true)]
21+
[DispId(3)]
1822
DeclarationType DeclarationType { get; }
23+
[DispId(4)]
1924
string TypeName { get; }
20-
[ComVisible(true)]
25+
[DispId(5)]
2126
bool IsArray { get; }
22-
[ComVisible(true)]
27+
[DispId(6)]
2328
Declaration ParentDeclaration { get; }
24-
[ComVisible(true)]
25-
IdentifierReference[] References { get; }
29+
[DispId(7)]
30+
IdentifierReferences References { get; }
2631
}
2732

28-
[ComVisible(true)]
29-
[Guid(RubberduckGuid.DeclarationClassGuid)]
30-
[ProgId(RubberduckProgId.DeclarationProgId)]
31-
[ComDefaultInterface(typeof(IDeclaration))]
32-
[EditorBrowsable(EditorBrowsableState.Always)]
33+
[
34+
ComVisible(true),
35+
Guid(RubberduckGuid.DeclarationClassGuid),
36+
ProgId(RubberduckProgId.DeclarationProgId),
37+
ClassInterface(ClassInterfaceType.None),
38+
ComDefaultInterface(typeof(IDeclaration)),
39+
EditorBrowsable(EditorBrowsableState.Always)
40+
]
3341
public class Declaration : IDeclaration
3442
{
3543
internal Declaration(RubberduckDeclaration declaration)
@@ -49,7 +57,7 @@ internal Declaration(RubberduckDeclaration declaration)
4957
new Dictionary<Parsing.Symbols.DeclarationType, DeclarationType>
5058
{
5159
{ Parsing.Symbols.DeclarationType.Project, DeclarationType.Project },
52-
{ Parsing.Symbols.DeclarationType.ProceduralModule, DeclarationType.StandardModule },
60+
{ Parsing.Symbols.DeclarationType.ProceduralModule, DeclarationType.ProceduralModule },
5361
{ Parsing.Symbols.DeclarationType.ClassModule, DeclarationType.ClassModule },
5462
{ Parsing.Symbols.DeclarationType.Control, DeclarationType.Control },
5563
{ Parsing.Symbols.DeclarationType.UserForm, DeclarationType.UserForm },
@@ -75,12 +83,12 @@ internal Declaration(RubberduckDeclaration declaration)
7583
private Declaration _parentDeclaration;
7684
public Declaration ParentDeclaration => _parentDeclaration ?? (_parentDeclaration = new Declaration(Instance.ParentDeclaration));
7785

78-
private IdentifierReference[] _references;
79-
public IdentifierReference[] References
86+
private IdentifierReferences _references;
87+
public IdentifierReferences References
8088
{
8189
get
8290
{
83-
return _references ?? (_references = Instance.References.Select(item => new IdentifierReference(item)).ToArray());
91+
return _references ?? (_references = new IdentifierReferences(Instance.References.Select(item => new IdentifierReference(item))));
8492
}
8593
}
8694
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.Runtime.InteropServices;
2+
using Rubberduck.Resources.Registration;
3+
using Source = Rubberduck.Parsing.Symbols;
4+
5+
namespace Rubberduck.API.VBA
6+
{
7+
[
8+
ComVisible(true),
9+
Guid(RubberduckGuid.DeclarationTypeGuid)
10+
]
11+
public enum DeclarationType
12+
{
13+
//TODO: figure out a cleaner way to handle long/int
14+
BracketedExpression = (int)Source.DeclarationType.BracketedExpression,
15+
ClassModule = (int)Source.DeclarationType.ClassModule,
16+
ComAlias = (int)Source.DeclarationType.ComAlias,
17+
Constant = (int)Source.DeclarationType.Constant,
18+
Control = (int)Source.DeclarationType.Control,
19+
Document = (int)Source.DeclarationType.Document,
20+
Enumeration = (int)Source.DeclarationType.Enumeration,
21+
EnumerationMember = (int)Source.DeclarationType.EnumerationMember,
22+
Event = (int)Source.DeclarationType.Event,
23+
Function = (int)Source.DeclarationType.Function,
24+
LibraryFunction = (int)Source.DeclarationType.LibraryFunction,
25+
LibraryProcedure = (int)Source.DeclarationType.LibraryProcedure,
26+
LineLabel = (int)Source.DeclarationType.LineLabel,
27+
Member = (int)Source.DeclarationType.Member,
28+
Module = (int)Source.DeclarationType.Module,
29+
Parameter = (int)Source.DeclarationType.Parameter,
30+
ProceduralModule = (int)Source.DeclarationType.ProceduralModule,
31+
Procedure = (int)Source.DeclarationType.Procedure,
32+
Project = (int)Source.DeclarationType.Project,
33+
Property = (int)Source.DeclarationType.Property,
34+
PropertyGet = (int)Source.DeclarationType.PropertyGet,
35+
PropertyLet = (int)Source.DeclarationType.PropertyLet,
36+
PropertySet = (int)Source.DeclarationType.PropertySet,
37+
UnresolvedMember = (int)Source.DeclarationType.UnresolvedMember,
38+
UserDefinedType = (int)Source.DeclarationType.UserDefinedType,
39+
UserDefinedTypeMember = (int)Source.DeclarationType.UserDefinedTypeMember,
40+
UserForm = (int)Source.DeclarationType.UserForm,
41+
Variable = (int)Source.DeclarationType.Variable
42+
}
43+
}

Rubberduck.API/VBA/Declarations.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Runtime.InteropServices;
5+
using Rubberduck.Resources.Registration;
6+
7+
namespace Rubberduck.API.VBA
8+
{
9+
[
10+
ComVisible(true),
11+
Guid(RubberduckGuid.IDeclarationsGuid),
12+
InterfaceType(ComInterfaceType.InterfaceIsDual)
13+
]
14+
public interface IDeclarations : IEnumerable
15+
{
16+
[DispId(WellKnownDispIds.Value)]
17+
Declaration Item(int Index);
18+
19+
[DispId(1)]
20+
int Count { get; }
21+
22+
[DispId(WellKnownDispIds.NewEnum)]
23+
IEnumerator _GetEnumerator();
24+
}
25+
26+
[
27+
ComVisible(true),
28+
Guid(RubberduckGuid.DeclarationsClassGuid),
29+
ProgId(RubberduckProgId.DeclarationsProgId),
30+
ClassInterface(ClassInterfaceType.None),
31+
ComDefaultInterface(typeof(IDeclarations))
32+
]
33+
public class Declarations : IDeclarations, IEnumerable<Declaration>
34+
{
35+
private readonly IEnumerable<Declaration> _declarations;
36+
37+
public int Count => _declarations.Count();
38+
39+
internal Declarations(IEnumerable<Declaration> declarations)
40+
{
41+
_declarations = declarations;
42+
}
43+
44+
public Declaration Item(int Index)
45+
{
46+
return _declarations.ElementAt(Index);
47+
}
48+
49+
public IEnumerator<Declaration> GetEnumerator()
50+
{
51+
return _declarations.GetEnumerator();
52+
}
53+
54+
public IEnumerator _GetEnumerator()
55+
{
56+
return _declarations.GetEnumerator();
57+
}
58+
59+
IEnumerator IEnumerable.GetEnumerator()
60+
{
61+
return _declarations.GetEnumerator();
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)