Skip to content

Commit 6632444

Browse files
committed
Merge pull request #1360 from rubberduck-vba/next
v2.0a-pre
2 parents 6c84bfd + bcf1b3d commit 6632444

File tree

933 files changed

+107329
-35710
lines changed

Some content is hidden

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

933 files changed

+107329
-35710
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ ClientBin/
126126
*.pfx
127127
*.publishsettings
128128

129+
# Monodevelop detritus
130+
*.userprefs
131+
129132
# RIA/Silverlight projects
130133
Generated_Code/
131134

RetailCoder.VBE/API/Accessibility.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Runtime.InteropServices;
2+
3+
namespace Rubberduck.API
4+
{
5+
[ComVisible(true)]
6+
public enum Accessibility
7+
{
8+
Implicit,
9+
Private,
10+
Public,
11+
Global,
12+
Friend,
13+
Static,
14+
}
15+
}

RetailCoder.VBE/API/Declaration.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using System.ComponentModel;
2+
using System.Linq;
3+
using System.Runtime.InteropServices;
4+
using RubberduckDeclaration = Rubberduck.Parsing.Symbols.Declaration;
5+
6+
namespace Rubberduck.API
7+
{
8+
[ComVisible(true)]
9+
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
10+
public interface IDeclaration
11+
{
12+
string Name { get; }
13+
Accessibility Accessibility { get; }
14+
DeclarationType DeclarationType { get; }
15+
string TypeName { get; }
16+
bool IsArray { get; }
17+
18+
Declaration ParentDeclaration { get; }
19+
20+
IdentifierReference[] References { get; }
21+
}
22+
23+
[ComVisible(true)]
24+
[Guid(ClassId)]
25+
[ProgId(ProgId)]
26+
[ComDefaultInterface(typeof(IDeclaration))]
27+
[EditorBrowsable(EditorBrowsableState.Always)]
28+
public class Declaration : IDeclaration
29+
{
30+
private const string ClassId = "67940D0B-081A-45BE-B0B9-CAEAFE034BC0";
31+
private const string ProgId = "Rubberduck.Declaration";
32+
33+
private readonly RubberduckDeclaration _declaration;
34+
35+
internal Declaration(RubberduckDeclaration declaration)
36+
{
37+
_declaration = declaration;
38+
}
39+
40+
protected RubberduckDeclaration Instance { get { return _declaration; } }
41+
42+
public string Name { get { return _declaration.IdentifierName; } }
43+
public Accessibility Accessibility { get { return (Accessibility)_declaration.Accessibility; } }
44+
public DeclarationType DeclarationType {get { return (DeclarationType)_declaration.DeclarationType; }}
45+
public string TypeName { get { return _declaration.AsTypeName; } }
46+
public bool IsArray { get { return _declaration.IsArray(); } }
47+
48+
private Declaration _parentDeclaration;
49+
public Declaration ParentDeclaration
50+
{
51+
get
52+
{
53+
return _parentDeclaration ?? (_parentDeclaration = new Declaration(Instance));
54+
}
55+
}
56+
57+
private IdentifierReference[] _references;
58+
public IdentifierReference[] References
59+
{
60+
get
61+
{
62+
return _references ?? (_references = _declaration.References.Select(item => new IdentifierReference(item)).ToArray());
63+
}
64+
}
65+
}
66+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace Rubberduck.API
5+
{
6+
[ComVisible(true)]
7+
[Flags]
8+
public enum DeclarationType
9+
{
10+
Project = 1 << 0,
11+
Module = 1 << 1,
12+
Class = 1 << 2,
13+
Control = 1 << 3,
14+
UserForm = 1 << 4,
15+
Document = 1 << 5,
16+
ModuleOption = 1 << 6,
17+
Member = 1 << 7,
18+
Procedure = 1 << 8 | Member,
19+
Function = 1 << 9 | Member,
20+
Property = 1 << 10 | Member,
21+
PropertyGet = 1 << 11 | Property | Function,
22+
PropertyLet = 1 << 12 | Property | Procedure,
23+
PropertySet = 1 << 13 | Property | Procedure,
24+
Parameter = 1 << 14,
25+
Variable = 1 << 15,
26+
Constant = 1 << 16,
27+
Enumeration = 1 << 17,
28+
EnumerationMember = 1 << 18 | Constant,
29+
Event = 1 << 19,
30+
UserDefinedType = 1 << 20,
31+
UserDefinedTypeMember = 1 << 21 | Variable,
32+
LibraryFunction = 1 << 22 | Function,
33+
LibraryProcedure = 1 << 23 | Procedure,
34+
LineLabel = 1 << 24
35+
}
36+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+

2+
using System.ComponentModel;
3+
using System.Runtime.InteropServices;
4+
5+
namespace Rubberduck.API
6+
{
7+
[ComVisible(true)]
8+
public interface IIdentifierReference
9+
{
10+
Declaration Declaration { get; }
11+
Declaration ParentScope { get; }
12+
Declaration ParentNonScoping { get; }
13+
int StartLine { get; }
14+
int StartColumn { get; }
15+
int EndLine { get; }
16+
int EndColumn { get; }
17+
}
18+
19+
[ComVisible(true)]
20+
[Guid(ClassId)]
21+
[ProgId(ProgId)]
22+
[ComDefaultInterface(typeof(IIdentifierReference))]
23+
[EditorBrowsable(EditorBrowsableState.Always)]
24+
public class IdentifierReference : IIdentifierReference
25+
{
26+
private const string ClassId = "57F78E64-8ADF-4D81-A467-A0139B877D14";
27+
private const string ProgId = "Rubberduck.IdentifierReference";
28+
29+
private readonly Parsing.Symbols.IdentifierReference _reference;
30+
31+
public IdentifierReference(Parsing.Symbols.IdentifierReference reference)
32+
{
33+
_reference = reference;
34+
}
35+
36+
private Declaration _declaration;
37+
public Declaration Declaration
38+
{
39+
get { return _declaration ?? (_declaration = new Declaration(_reference.Declaration)); }
40+
}
41+
42+
private Declaration _parentScoping;
43+
public Declaration ParentScope
44+
{
45+
get { return _parentScoping ?? (_parentScoping = new Declaration(_reference.ParentScoping)); }
46+
}
47+
48+
private Declaration _parentNonScoping;
49+
public Declaration ParentNonScoping
50+
{
51+
get { return _parentNonScoping ?? (_parentNonScoping = new Declaration(_reference.ParentNonScoping)); }
52+
}
53+
54+
public int StartLine { get { return _reference.Selection.StartLine; } }
55+
public int EndLine { get { return _reference.Selection.EndLine; } }
56+
public int StartColumn { get { return _reference.Selection.StartColumn; } }
57+
public int EndColumn { get { return _reference.Selection.EndColumn; } }
58+
}
59+
}

RetailCoder.VBE/API/ParserState.cs

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.Linq;
4+
using System.Runtime.InteropServices;
5+
using Microsoft.Vbe.Interop;
6+
using Rubberduck.Common;
7+
using Rubberduck.Parsing.VBA;
8+
9+
namespace Rubberduck.API
10+
{
11+
[ComVisible(true)]
12+
public interface IParserState
13+
{
14+
void Initialize(VBE vbe);
15+
16+
void Parse();
17+
void BeginParse();
18+
19+
Declaration[] AllDeclarations { get; }
20+
Declaration[] UserDeclarations { get; }
21+
}
22+
23+
[ComVisible(true)]
24+
[Guid("3D8EAA28-8983-44D5-83AF-2EEC4C363079")]
25+
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
26+
public interface IParserStateEvents
27+
{
28+
void OnParsed();
29+
void OnReady();
30+
void OnError();
31+
}
32+
33+
[ComVisible(true)]
34+
[Guid(ClassId)]
35+
[ProgId(ProgId)]
36+
[ClassInterface(ClassInterfaceType.AutoDual)]
37+
[ComDefaultInterface(typeof(IParserState))]
38+
[ComSourceInterfaces(typeof(IParserStateEvents))]
39+
[EditorBrowsable(EditorBrowsableState.Always)]
40+
public class ParserState : IParserState
41+
{
42+
private const string ClassId = "28754D11-10CC-45FD-9F6A-525A65412B7A";
43+
private const string ProgId = "Rubberduck.ParserState";
44+
45+
private readonly RubberduckParserState _state;
46+
private readonly AttributeParser _attributeParser;
47+
48+
private RubberduckParser _parser;
49+
50+
public ParserState()
51+
{
52+
_state = new RubberduckParserState();
53+
_attributeParser = new AttributeParser(new ModuleExporter());
54+
55+
_state.StateChanged += _state_StateChanged;
56+
}
57+
58+
public void Initialize(VBE vbe)
59+
{
60+
if (_parser != null)
61+
{
62+
throw new InvalidOperationException("ParserState is already initialized.");
63+
}
64+
65+
_parser = new RubberduckParser(vbe, _state, _attributeParser);
66+
}
67+
68+
/// <summary>
69+
/// Blocking call, for easier unit-test code
70+
/// </summary>
71+
public void Parse()
72+
{
73+
// blocking call
74+
_parser.Parse();
75+
}
76+
77+
/// <summary>
78+
/// Begins asynchronous parsing
79+
/// </summary>
80+
public void BeginParse()
81+
{
82+
// non-blocking call
83+
_state.OnParseRequested(this);
84+
}
85+
86+
public event Action OnParsed;
87+
public event Action OnReady;
88+
public event Action OnError;
89+
90+
private void _state_StateChanged(object sender, System.EventArgs e)
91+
{
92+
_allDeclarations = _state.AllDeclarations
93+
.Select(item => new Declaration(item))
94+
.ToArray();
95+
96+
_userDeclarations = _state.AllUserDeclarations
97+
.Select(item => new Declaration(item))
98+
.ToArray();
99+
100+
var errorHandler = OnError;
101+
if (_state.Status == Parsing.VBA.ParserState.Error && errorHandler != null)
102+
{
103+
errorHandler.Invoke();
104+
}
105+
106+
var parsedHandler = OnParsed;
107+
if (_state.Status == Parsing.VBA.ParserState.Parsed && parsedHandler != null)
108+
{
109+
parsedHandler.Invoke();
110+
}
111+
112+
var readyHandler = OnReady;
113+
if (_state.Status == Parsing.VBA.ParserState.Ready && readyHandler != null)
114+
{
115+
readyHandler.Invoke();
116+
}
117+
}
118+
119+
private Declaration[] _allDeclarations;
120+
121+
public Declaration[] AllDeclarations
122+
{
123+
[return: MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)]
124+
get { return _allDeclarations; }
125+
}
126+
127+
private Declaration[] _userDeclarations;
128+
public Declaration[] UserDeclarations
129+
{
130+
[return: MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)]
131+
get { return _userDeclarations; }
132+
}
133+
}
134+
}

0 commit comments

Comments
 (0)