Skip to content

Commit e6fac93

Browse files
authored
Merge branch 'next' into TestCategorization
2 parents 15812c2 + b4ec056 commit e6fac93

16 files changed

+208
-50
lines changed

RetailCoder.VBE/API/Declaration.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ namespace Rubberduck.API
1010
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
1111
public interface IDeclaration
1212
{
13+
[ComVisible(true)]
1314
string Name { get; }
15+
[ComVisible(true)]
1416
Accessibility Accessibility { get; }
17+
[ComVisible(true)]
1518
DeclarationType DeclarationType { get; }
1619
string TypeName { get; }
20+
[ComVisible(true)]
1721
bool IsArray { get; }
18-
22+
[ComVisible(true)]
1923
Declaration ParentDeclaration { get; }
20-
24+
[ComVisible(true)]
2125
IdentifierReference[] References { get; }
2226
}
2327

RetailCoder.VBE/API/ParserState.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
using System.Linq;
55
using System.Runtime.InteropServices;
66
using Rubberduck.Common;
7+
using Rubberduck.Parsing.Symbols.DeclarationLoaders;
78
using Rubberduck.Parsing.VBA;
89
using Rubberduck.UI.Command.MenuItems;
910
using Rubberduck.Parsing.Preprocessing;
1011
using System.Globalization;
11-
using Rubberduck.Parsing.Symbols;
12-
using Rubberduck.VBEditor.SafeComWrappers;
1312
using Rubberduck.VBEditor.SafeComWrappers.VBA;
1413

1514
namespace Rubberduck.API
@@ -72,7 +71,14 @@ public void Initialize(Microsoft.Vbe.Interop.VBE vbe)
7271
Func<IVBAPreprocessor> preprocessorFactory = () => new VBAPreprocessor(double.Parse(_vbe.Version, CultureInfo.InvariantCulture));
7372
_attributeParser = new AttributeParser(new ModuleExporter(), preprocessorFactory);
7473
_parser = new ParseCoordinator(_vbe, _state, _attributeParser, preprocessorFactory,
75-
new List<ICustomDeclarationLoader> { new DebugDeclarations(_state), new SpecialFormDeclarations(_state), new FormEventDeclarations(_state), new AliasDeclarations(_state) });
74+
new List<ICustomDeclarationLoader>
75+
{
76+
new DebugDeclarations(_state),
77+
new SpecialFormDeclarations(_state),
78+
new FormEventDeclarations(_state),
79+
new AliasDeclarations(_state),
80+
//new RubberduckApiDeclarations(_state)
81+
});
7682
}
7783

7884
/// <summary>
@@ -97,7 +103,7 @@ public void BeginParse()
97103
public event Action OnReady;
98104
public event Action OnError;
99105

100-
private void _state_StateChanged(object sender, System.EventArgs e)
106+
private void _state_StateChanged(object sender, EventArgs e)
101107
{
102108
_allDeclarations = _state.AllDeclarations
103109
.Select(item => new Declaration(item))

RetailCoder.VBE/Root/RubberduckModule.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Ninject.Modules;
88
using Rubberduck.Common;
99
using Rubberduck.Parsing;
10+
using Rubberduck.Parsing.Symbols.DeclarationLoaders;
1011
using Rubberduck.Parsing.VBA;
1112
using Rubberduck.Settings;
1213
using Rubberduck.SettingsProvider;

RetailCoder.VBE/UnitTesting/TestMethod.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Globalization;
44
using System.Linq;
5+
using Rubberduck.Parsing;
56
using Rubberduck.Parsing.Symbols;
67
using Rubberduck.UI;
78
using Rubberduck.UI.Controls;
@@ -88,16 +89,7 @@ private AssertCompletedEventArgs EvaluateResults()
8889

8990
public NavigateCodeEventArgs GetNavigationArgs()
9091
{
91-
var moduleName = Declaration.QualifiedName.QualifiedModuleName;
92-
var methodName = Declaration.IdentifierName;
93-
var module = moduleName.Component.CodeModule;
94-
95-
var startLine = module.GetProcBodyStartLine(methodName, ProcKind.Procedure);
96-
var endLine = startLine + module.GetProcCountLines(methodName, ProcKind.Procedure);
97-
var endLineColumns = module.GetLines(endLine, 1).Length;
98-
99-
var selection = new Selection(startLine, 1, endLine, endLineColumns == 0 ? 1 : endLineColumns);
100-
return new NavigateCodeEventArgs(new QualifiedSelection(moduleName, selection));
92+
return new NavigateCodeEventArgs(new QualifiedSelection(Declaration.QualifiedName.QualifiedModuleName, Declaration.Context.GetSelection()));
10193
}
10294

10395
public object[] ToArray()

Rubberduck.Parsing/Rubberduck.Parsing.csproj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@
143143
<Compile Include="ComReflection\ComMember.cs" />
144144
<Compile Include="ComReflection\ComModule.cs" />
145145
<Compile Include="ComReflection\ComProject.cs" />
146-
<Compile Include="Symbols\SpecialFormDeclarations.cs" />
146+
<Compile Include="Symbols\DeclarationLoaders\SpecialFormDeclarations.cs" />
147147
<Compile Include="Symbols\CommentNode.cs" />
148148
<Compile Include="ComReflection\ComParameter.cs" />
149-
<Compile Include="Symbols\DebugDeclarations.cs" />
150-
<Compile Include="Symbols\AliasDeclarations.cs" />
151-
<Compile Include="Symbols\FormEventDeclarations.cs" />
152-
<Compile Include="Symbols\ICustomDeclarationLoader.cs" />
149+
<Compile Include="Symbols\DeclarationLoaders\DebugDeclarations.cs" />
150+
<Compile Include="Symbols\DeclarationLoaders\AliasDeclarations.cs" />
151+
<Compile Include="Symbols\DeclarationLoaders\FormEventDeclarations.cs" />
152+
<Compile Include="Symbols\DeclarationLoaders\ICustomDeclarationLoader.cs" />
153153
<Compile Include="Symbols\Identifier.cs" />
154154
<Compile Include="Binding\IBindingContext.cs" />
155155
<Compile Include="Binding\IBoundExpression.cs" />
@@ -257,6 +257,7 @@
257257
<Compile Include="Symbols\PropertySetDeclaration.cs" />
258258
<Compile Include="Symbols\PropertyGetDeclaration.cs" />
259259
<Compile Include="Symbols\FunctionDeclaration.cs" />
260+
<Compile Include="Symbols\DeclarationLoaders\RubberduckApiDeclarations.cs" />
260261
<Compile Include="Symbols\SerializableDeclaration.cs" />
261262
<Compile Include="Symbols\SquareBracketedNameComparer.cs" />
262263
<Compile Include="Symbols\SubroutineDeclaration.cs" />

Rubberduck.Parsing/Symbols/AliasDeclarations.cs renamed to Rubberduck.Parsing/Symbols/DeclarationLoaders/AliasDeclarations.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using System.Collections.Generic;
2-
using Rubberduck.Parsing.VBA;
3-
using Rubberduck.VBEditor;
42
using System.Linq;
53
using Rubberduck.Parsing.Annotations;
4+
using Rubberduck.Parsing.VBA;
5+
using Rubberduck.VBEditor;
66

7-
namespace Rubberduck.Parsing.Symbols
7+
namespace Rubberduck.Parsing.Symbols.DeclarationLoaders
88
{
99
public class AliasDeclarations : ICustomDeclarationLoader
1010
{

Rubberduck.Parsing/Symbols/DebugDeclarations.cs renamed to Rubberduck.Parsing/Symbols/DeclarationLoaders/DebugDeclarations.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using Rubberduck.Parsing.Annotations;
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Rubberduck.Parsing.Annotations;
24
using Rubberduck.Parsing.VBA;
35
using Rubberduck.VBEditor;
4-
using System.Collections.Generic;
5-
using System.Linq;
6-
using Rubberduck.Parsing.Grammar;
76

8-
namespace Rubberduck.Parsing.Symbols
7+
namespace Rubberduck.Parsing.Symbols.DeclarationLoaders
98
{
109
public class DebugDeclarations : ICustomDeclarationLoader
1110
{

Rubberduck.Parsing/Symbols/FormEventDeclarations.cs renamed to Rubberduck.Parsing/Symbols/DeclarationLoaders/FormEventDeclarations.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using System.Collections.Generic;
2+
using Rubberduck.Parsing.Annotations;
23
using Rubberduck.Parsing.VBA;
34
using Rubberduck.VBEditor;
4-
using Rubberduck.Parsing.Annotations;
55

6-
namespace Rubberduck.Parsing.Symbols
6+
namespace Rubberduck.Parsing.Symbols.DeclarationLoaders
77
{
88
public class FormEventDeclarations : ICustomDeclarationLoader
99
{

Rubberduck.Parsing/Symbols/ICustomDeclarationLoader.cs renamed to Rubberduck.Parsing/Symbols/DeclarationLoaders/ICustomDeclarationLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Collections.Generic;
22

3-
namespace Rubberduck.Parsing.Symbols
3+
namespace Rubberduck.Parsing.Symbols.DeclarationLoaders
44
{
55
public interface ICustomDeclarationLoader
66
{
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
//using System;
2+
//using System.Collections.Generic;
3+
//using System.Diagnostics;
4+
//using System.IO;
5+
//using System.Linq;
6+
//using System.Reflection;
7+
//using System.Runtime.InteropServices;
8+
//using Rubberduck.Parsing.Annotations;
9+
//using Rubberduck.Parsing.ComReflection;
10+
//using Rubberduck.Parsing.VBA;
11+
//using Rubberduck.VBEditor;
12+
13+
//namespace Rubberduck.Parsing.Symbols.DeclarationLoaders
14+
//{
15+
// public class RubberduckApiDeclarations : ICustomDeclarationLoader
16+
// {
17+
// private readonly RubberduckParserState _state;
18+
// private readonly List<Declaration> _declarations = new List<Declaration>();
19+
20+
// public RubberduckApiDeclarations(RubberduckParserState state)
21+
// {
22+
// _state = state;
23+
// }
24+
25+
// public IReadOnlyList<Declaration> Load()
26+
// {
27+
// var assembly = AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault(a => a.GetName().Name.Equals("Rubberduck"));
28+
// if (assembly == null)
29+
// {
30+
// return _declarations;
31+
// }
32+
33+
// var name = assembly.GetName();
34+
// var path = Path.ChangeExtension(assembly.Location, "tlb");
35+
36+
// var projectName = new QualifiedModuleName("Rubberduck", path, "Rubberduck");
37+
// var project = new ProjectDeclaration(projectName.QualifyMemberName("Rubberduck"), "Rubberduck", true, null)
38+
// {
39+
// MajorVersion = name.Version.Major,
40+
// MinorVersion = name.Version.Minor
41+
// };
42+
// _declarations.Add(project);
43+
44+
// var types = assembly.DefinedTypes.WhereIsComVisible();
45+
46+
// foreach (var type in types)
47+
// {
48+
// var module = type.ToModuleDeclaration(project, projectName, type.IsEnum);
49+
// _declarations.Add(module);
50+
51+
// var properties = type.GetProperties().WhereIsComVisible().ToList();
52+
53+
// foreach (var property in properties)
54+
// {
55+
// if (property.CanWrite && property.GetSetMethod().IsPublic)
56+
// {
57+
// var declaration = property.ToMemberDeclaration(module, false);
58+
// _declarations.Add(declaration);
59+
// }
60+
// if (property.CanRead && property.GetGetMethod().IsPublic)
61+
// {
62+
// var declaration = property.ToMemberDeclaration(module, true);
63+
// _declarations.Add(declaration);
64+
// }
65+
// }
66+
67+
// var members = type.GetMembers().WhereIsComVisible();
68+
69+
// foreach (var member in members)
70+
// {
71+
// if (member.MemberType == MemberTypes.Property)
72+
// {
73+
74+
// }
75+
// //var declaration = member.ToMemberDeclaration(project);
76+
// }
77+
// };
78+
// return _declarations;
79+
// }
80+
// }
81+
82+
// internal static class RubberduckApiDeclarationStatics
83+
// {
84+
// public static IEnumerable<T> WhereIsComVisible<T>(this IEnumerable<T> source) where T : MemberInfo
85+
// {
86+
// return source.Where(member =>
87+
// {
88+
// var attr = member.GetCustomAttributes(typeof(ComVisibleAttribute), true).FirstOrDefault();
89+
// return attr != null && ((ComVisibleAttribute)attr).Value;
90+
// });
91+
// }
92+
93+
// public static Declaration ToModuleDeclaration(this TypeInfo type, Declaration project, QualifiedModuleName projectName, bool isEnum = false)
94+
// {
95+
// return isEnum ? new ProceduralModuleDeclaration(projectName.QualifyMemberName(type.Name), project, type.Name, true, null, null) as Declaration :
96+
// new ClassModuleDeclaration(projectName.QualifyMemberName(type.Name), project, type.Name, true, null, null);
97+
// }
98+
99+
// public static Declaration ToMemberDeclaration(this PropertyInfo member, Declaration parent, bool getter)
100+
// {
101+
// if (getter)
102+
// {
103+
// return new PropertyGetDeclaration(parent.QualifiedName.QualifiedModuleName.QualifyMemberName(member.Name),
104+
// parent,
105+
// parent,
106+
// member.PropertyType.ToVbaTypeName(),
107+
// null,
108+
// string.Empty,
109+
// parent.Accessibility,
110+
// null,
111+
// Selection.Home,
112+
// member.PropertyType.IsArray,
113+
// true,
114+
// null,
115+
// new Attributes());
116+
// }
117+
// if (member.PropertyType.IsClass)
118+
// {
119+
// return new PropertySetDeclaration(parent.QualifiedName.QualifiedModuleName.QualifyMemberName(member.Name),
120+
// parent,
121+
// parent,
122+
// member.PropertyType.ToVbaTypeName(),
123+
// parent.Accessibility,
124+
// null,
125+
// Selection.Home,
126+
// true,
127+
// null,
128+
// new Attributes());
129+
// }
130+
// return new PropertyLetDeclaration(parent.QualifiedName.QualifiedModuleName.QualifyMemberName(member.Name),
131+
// parent,
132+
// parent,
133+
// member.PropertyType.ToVbaTypeName(),
134+
// parent.Accessibility,
135+
// null,
136+
// Selection.Home,
137+
// true,
138+
// null,
139+
// new Attributes());
140+
// }
141+
142+
// public static string ToVbaTypeName(this Type type)
143+
// {
144+
// var name = string.Empty;
145+
// if (type.IsClass || type.IsEnum)
146+
// {
147+
// name = type.Name;
148+
// }
149+
// switch (type.Name)
150+
// {
151+
// case "bool":
152+
// name = "Boolean";
153+
// break;
154+
// case "short":
155+
// name = "Integer";
156+
// break;
157+
// case "int":
158+
// name = "Long";
159+
// break;
160+
// }
161+
// return name + (type.IsArray ? "()" : string.Empty);
162+
// }
163+
// }
164+
//}

0 commit comments

Comments
 (0)