Example #1
0
        private static Business.Component[] GetComponnets(vbext_ComponentType componentType, IEnumerable <Business.Component> components)
        {
            var component    = components.Where(x => x.Type == componentType);
            var vbComponents = component as Business.Component[] ?? component.ToArray();

            return(vbComponents);
        }
Example #2
0
        protected Mock<VBProject> SetupMockProject(string inputCode, string projectName = null, string moduleName = null, vbext_ComponentType? componentType = null)
        {
            if (componentType == null)
            {
                componentType = vbext_ComponentType.vbext_ct_StdModule;
            }

            if (moduleName == null)
            {
                moduleName = componentType == vbext_ComponentType.vbext_ct_StdModule 
                    ? "Module1" 
                    : componentType == vbext_ComponentType.vbext_ct_ClassModule
                        ? "Class1"
                        : componentType == vbext_ComponentType.vbext_ct_MSForm
                            ? "Form1"
                            : "Document1";
            }

            if (projectName == null)
            {
                projectName = "VBAProject";
            }

            var component = CreateMockComponent(inputCode, moduleName, componentType.Value);
            var components = new List<Mock<VBComponent>> {component};

            var project = CreateMockProject(projectName, vbext_ProjectProtection.vbext_pp_none, components);
            return project;
        }
Example #3
0
        public static BitmapImage ComponentIcon(vbext_ComponentType componentType)
        {
            Tuple <DeclarationType, Accessibility> key;

            switch (componentType)
            {
            case vbext_ComponentType.vbext_ct_StdModule:
                key = Tuple.Create(DeclarationType.ProceduralModule, Accessibility.Public);
                break;

            case vbext_ComponentType.vbext_ct_ClassModule:
                key = Tuple.Create(DeclarationType.ClassModule, Accessibility.Public);
                break;

            case vbext_ComponentType.vbext_ct_Document:
                key = Tuple.Create(DeclarationType.Document, Accessibility.Public);
                break;

            case vbext_ComponentType.vbext_ct_MSForm:
                key = Tuple.Create(DeclarationType.UserForm, Accessibility.Public);
                break;

            default:
                key = Tuple.Create(DeclarationType.Project, Accessibility.Public);
                break;
            }

            return(Images[key]);
        }
Example #4
0
        protected Mock<VBComponent> CreateMockComponent(string content, string name, vbext_ComponentType type)
        {
            var module = SetupMockCodeModule(content, name);
            var component = MockFactory.CreateComponentMock(name, module.Object, type, _ide);

            module.SetupGet(m => m.Parent).Returns(component.Object);
            return component;
        }        private Mock<VBComponents> SetupMockComponents(ICollection<Mock<VBComponent>> items, VBProject project)
Example #5
0
 public Mock<VBE> BuildFromSingleModule(string content, vbext_ComponentType type, out VBComponent component)
 {
     var builder = ProjectBuilder("TestProject1", vbext_ProjectProtection.vbext_pp_none);
     builder.AddComponent("TestModule1", type, content);
     var project = builder.Build();
     component = project.Object.VBComponents.Item(0);
     return AddProject(project).Build();
 }
        public DeclarationSymbolsListener(
            QualifiedModuleName qualifiedName,
            vbext_ComponentType type,
            IEnumerable <CommentNode> comments,
            IEnumerable <IAnnotation> annotations,
            IDictionary <Tuple <string, DeclarationType>, Attributes> attributes,
            HashSet <ReferencePriorityMap> projectReferences,
            Declaration projectDeclaration)
        {
            _qualifiedName = qualifiedName;
            _comments      = comments;
            _annotations   = annotations;
            _attributes    = attributes;

            var declarationType = type == vbext_ComponentType.vbext_ct_StdModule
                ? DeclarationType.ProceduralModule
                : DeclarationType.ClassModule;

            _projectReferences  = projectReferences;
            _projectDeclaration = projectDeclaration;

            var key = Tuple.Create(_qualifiedName.ComponentName, declarationType);
            var moduleAttributes = attributes.ContainsKey(key)
                ? attributes[key]
                : new Attributes();

            if (declarationType == DeclarationType.ProceduralModule)
            {
                _moduleDeclaration = new ProceduralModuleDeclaration(
                    _qualifiedName.QualifyMemberName(_qualifiedName.Component.Name),
                    _projectDeclaration,
                    _qualifiedName.Component.Name,
                    false,
                    FindAnnotations(),
                    moduleAttributes);
            }
            else
            {
                bool hasDefaultInstanceVariable = type != vbext_ComponentType.vbext_ct_ClassModule && type != vbext_ComponentType.vbext_ct_StdModule;
                _moduleDeclaration = new ClassModuleDeclaration(
                    _qualifiedName.QualifyMemberName(_qualifiedName.Component.Name),
                    _projectDeclaration,
                    _qualifiedName.Component.Name,
                    false,
                    FindAnnotations(),
                    moduleAttributes,
                    hasDefaultInstanceVariable: hasDefaultInstanceVariable);
            }
            SetCurrentScope();
            AddDeclaration(_moduleDeclaration);
            var component = _moduleDeclaration.QualifiedName.QualifiedModuleName.Component;

            if (component.Type == vbext_ComponentType.vbext_ct_MSForm || component.Designer != null)
            {
                DeclareControlsAsMembers(component);
            }
        }
Example #7
0
        public Mock <VBE> BuildFromSingleModule(string content, vbext_ComponentType type, out VBComponent component, Selection selection)
        {
            var builder = ProjectBuilder(TestProjectName, vbext_ProjectProtection.vbext_pp_none);

            builder.AddComponent(TestModuleName, type, content, selection);
            var project = builder.Build();

            component = project.Object.VBComponents.Item(0);
            return(AddProject(project).Build());
        }
Example #8
0
 private void ChangeCheckedStateOfNodes(vbext_ComponentType type, bool state)
 {
     foreach (TreeNode nd in Nodes)
     {
         Business.Component item = (Business.Component)nd.FirstNode.Tag;
         if (item.Type == type)
         {
             nd.Checked = state;
             CheckChildren(nd, state);
         }
     }
 }
Example #9
0
        public DeclarationSymbolsListener(
            QualifiedModuleName qualifiedName,
            Accessibility componentAccessibility,
            vbext_ComponentType type,
            IEnumerable <CommentNode> comments,
            IEnumerable <IAnnotation> annotations,
            IDictionary <Tuple <string, DeclarationType>, Attributes> attributes,
            HashSet <ReferencePriorityMap> projectReferences,
            Declaration projectDeclaration)
        {
            _qualifiedName = qualifiedName;
            _comments      = comments;
            _annotations   = annotations;
            _attributes    = attributes;

            var declarationType = type == vbext_ComponentType.vbext_ct_StdModule
                ? DeclarationType.ProceduralModule
                : DeclarationType.ClassModule;

            _projectReferences  = projectReferences;
            _projectDeclaration = projectDeclaration;

            var key = Tuple.Create(_qualifiedName.ComponentName, declarationType);
            var moduleAttributes = attributes.ContainsKey(key)
                ? attributes[key]
                : new Attributes();

            if (declarationType == DeclarationType.ProceduralModule)
            {
                _moduleDeclaration = new ProceduralModuleDeclaration(
                    _qualifiedName.QualifyMemberName(_qualifiedName.Component.Name),
                    _projectDeclaration,
                    _qualifiedName.Component.Name,
                    false,
                    FindAnnotations(),
                    moduleAttributes);
            }
            else
            {
                _moduleDeclaration = new ClassModuleDeclaration(
                    _qualifiedName.QualifyMemberName(_qualifiedName.Component.Name),
                    _projectDeclaration,
                    _qualifiedName.Component.Name,
                    false,
                    FindAnnotations(),
                    moduleAttributes);
            }

            SetCurrentScope();
        }
Example #10
0
        public XlVBComponent Add(vbext_ComponentType componentType)
        {
            object[] parameter = new object[1];
            parameter[0] = componentType;
            object returnValue = InstanceType.InvokeMember("Add", BindingFlags.InvokeMethod, null, ComReference, parameter, XlLateBindingApiSettings.XlThreadCulture);

            if (null == returnValue)
            {
                return(null);
            }
            XlVBComponent newClass = new XlVBComponent(this, returnValue);

            ListChildReferences.Add(newClass);
            return(newClass);
        }
Example #11
0
        private RubberduckParserState Resolve(string code, vbext_ComponentType moduleType = vbext_ComponentType.vbext_ct_StdModule)
        {
            var builder = new MockVbeBuilder();
            VBComponent component;
            var vbe = builder.BuildFromSingleModule(code, moduleType, out component);
            var parser = MockParser.Create(vbe.Object, new RubberduckParserState());

            parser.Parse();
            if (parser.State.Status != ParserState.Ready)
            {
                Assert.Inconclusive("Parser state should be 'Ready', but returns '{0}'.", parser.State.Status);
            }

            return parser.State;
        }
Example #12
0
        private Mock <VBComponent> CreateComponentMock(string name, vbext_ComponentType type, string content, Selection selection)
        {
            var result = new Mock <VBComponent>();

            result.SetupGet(m => m.VBE).Returns(_getVbe);
            result.SetupGet(m => m.Collection).Returns(() => _vbComponents.Object);
            result.SetupGet(m => m.Type).Returns(() => type);
            result.SetupProperty(m => m.Name, name);

            var module = CreateCodeModuleMock(name, content, selection);

            module.SetupGet(m => m.Parent).Returns(() => result.Object);
            result.SetupGet(m => m.CodeModule).Returns(() => module.Object);

            result.Setup(m => m.Activate());

            return(result);
        }
        public static string FileExtension(this vbext_ComponentType componentType)
        {
            switch (componentType)
            {
            case vbext_ComponentType.vbext_ct_ClassModule:
                return(".cls");

            case vbext_ComponentType.vbext_ct_MSForm:
                return(".frm");

            case vbext_ComponentType.vbext_ct_StdModule:
                return(".bas");

            case vbext_ComponentType.vbext_ct_Document:
            case vbext_ComponentType.vbext_ct_ActiveXDesigner:
            default:
                return(string.Empty);
            }
        }
        public DeclarationSymbolsListener(
            QualifiedModuleName qualifiedName,
            Accessibility componentAccessibility,
            vbext_ComponentType type,
            IEnumerable<CommentNode> comments,
            IEnumerable<IAnnotation> annotations,
            IDictionary<Tuple<string, DeclarationType>, Attributes> attributes,
            HashSet<ReferencePriorityMap> projectReferences)
        {
            _qualifiedName = qualifiedName;
            _comments = comments;
            _annotations = annotations;
            _attributes = attributes;

            var declarationType = type == vbext_ComponentType.vbext_ct_StdModule
                ? DeclarationType.Module
                : DeclarationType.Class;

            var project = _qualifiedName.Component.Collection.Parent;
            var projectQualifiedName = new QualifiedModuleName(project);
            _projectReferences = projectReferences;

            _projectDeclaration = CreateProjectDeclaration(projectQualifiedName, project);

            var key = Tuple.Create(_qualifiedName.ComponentName, declarationType);
            var moduleAttributes = attributes.ContainsKey(key)
                ? attributes[key]
                : new Attributes();

            _moduleDeclaration = new Declaration(
                _qualifiedName.QualifyMemberName(_qualifiedName.Component.Name),
                _projectDeclaration,
                _projectDeclaration,
                _qualifiedName.Component.Name,
                false,
                false,
                componentAccessibility,
                declarationType,
                null, Selection.Home, false,
                FindAnnotations(), moduleAttributes);

            SetCurrentScope();
        }
        public DeclarationSymbolsListener(QualifiedModuleName qualifiedName, Accessibility componentAccessibility, vbext_ComponentType type)
        {
            _qualifiedName = qualifiedName;

            var declarationType = type == vbext_ComponentType.vbext_ct_StdModule
                ? DeclarationType.Module
                //: result.Component.Type == vbext_ComponentType.vbext_ct_MSForm 
                //    ? DeclarationType.UserForm
                //    : result.Component.Type == vbext_ComponentType.vbext_ct_Document
                //        ? DeclarationType.Document
                : DeclarationType.Class;

            SetCurrentScope();
            _declarations.Add(new Declaration(_qualifiedName.QualifyMemberName(_qualifiedName.Component.Name), _qualifiedName.Project.Name, _qualifiedName.Component.Name, false, false, componentAccessibility, declarationType, null, Selection.Home));

            if (type == vbext_ComponentType.vbext_ct_MSForm)
            {
                DeclareControlsAsMembers(qualifiedName.Component);
            }
        }
Example #16
0
        /// <summary>
        /// Gets the correct Import class based on given type
        /// </summary>
        /// <param name="componentType">type of the component</param>
        /// <returns>Instance of the appropriate class for import</returns>
        /// <exception cref="ArgumentException">if the type is not recognized or supported. Supported types are: ClassModule, STDModule, MSForms, Document</exception>
        public static IImportType GetTypeClass(vbext_ComponentType componentType)
        {
            switch (componentType)
            {
            case vbext_ComponentType.vbext_ct_ClassModule:
                return(new ImportClassorDocument());

            case vbext_ComponentType.vbext_ct_Document:
                return(new ImportClassorDocument());

            case vbext_ComponentType.vbext_ct_MSForm:
                return(new ImportForm());

            case vbext_ComponentType.vbext_ct_StdModule:
                return(new ImportModule());

            default:
                throw new ArgumentException(string.Format(strings.ComponentNotValid, componentType));
            }
        }
Example #17
0
        /// <summary>
        /// Returns component type name
        /// </summary>
        /// <param name="componentType"></param>
        /// <returns>The string represents component type name</returns>
        public static string GetName(this vbext_ComponentType componentType)
        {
            switch (componentType)
            {
            case vbext_ComponentType.vbext_ct_ClassModule:
                return(ClassModule);

            case vbext_ComponentType.vbext_ct_MSForm:
                return(Form);

            case vbext_ComponentType.vbext_ct_StdModule:
                return(Module);

            case vbext_ComponentType.vbext_ct_Document:
                return(Module);

            case vbext_ComponentType.vbext_ct_ActiveXDesigner:
            default:
                return(string.Empty);
            }
        }
Example #18
0
        /// <summary>
        /// Returns the proper file extension for the Component Type.
        /// </summary>
        /// <param name="componentType"></param>
        /// <returns>File extension that includes a preceeding "dot" (.) </returns>
        public static string GetFileExtension(this vbext_ComponentType componentType)
        {
            switch (componentType)
            {
            case vbext_ComponentType.vbext_ct_ClassModule:
                return(ClassExtesnion);

            case vbext_ComponentType.vbext_ct_MSForm:
                return(FormExtension);

            case vbext_ComponentType.vbext_ct_StdModule:
                return(StandardExtension);

            case vbext_ComponentType.vbext_ct_Document:
                return(DocClassExtension);

            case vbext_ComponentType.vbext_ct_ActiveXDesigner:
            default:
                return(string.Empty);
            }
        }
Example #19
0
        /// <summary>
        /// Returns the proper file extension for the Component Type.
        /// </summary>
        /// <remarks>Document classes should properly have a ".cls" file extension.
        /// However, because they cannot be removed and imported like other component types, we need to make a distinction.</remarks>
        /// <param name="componentType"></param>
        /// <returns>File extension that includes a preceeding "dot" (.) </returns>
        public static string FileExtension(this vbext_ComponentType componentType)
        {
            switch (componentType)
            {
            case vbext_ComponentType.vbext_ct_ClassModule:
                return(ClassExtesnion);

            case vbext_ComponentType.vbext_ct_MSForm:
                return(FormExtension);

            case vbext_ComponentType.vbext_ct_StdModule:
                return(StandardExtension);

            case vbext_ComponentType.vbext_ct_Document:
                // documents should technically be a ".cls", but we need to be able to tell them apart.
                return(DocClassExtension);

            case vbext_ComponentType.vbext_ct_ActiveXDesigner:
            default:
                return(string.Empty);
            }
        }
Example #20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static string GetExtension(vbext_ComponentType type)
        {
            switch (type)
            {
            case vbext_ComponentType.vbext_ct_StdModule:
                return(".bas");

            case vbext_ComponentType.vbext_ct_ClassModule:
                return(".cls");

            case vbext_ComponentType.vbext_ct_MSForm:
                return(".frm");

            case vbext_ComponentType.vbext_ct_ActiveXDesigner:
                throw new ArgumentOutOfRangeException("type");

            case vbext_ComponentType.vbext_ct_Document:
                return(".cls");

            default:
                throw new ArgumentOutOfRangeException("type");
            }
        }
        public static BitmapImage ComponentIcon(vbext_ComponentType componentType)
        {
            Tuple<DeclarationType, Accessibility> key;
            switch (componentType)
            {
                case vbext_ComponentType.vbext_ct_StdModule:
                    key = Tuple.Create(DeclarationType.Module, Accessibility.Public);
                    break;
                case vbext_ComponentType.vbext_ct_ClassModule:
                    key = Tuple.Create(DeclarationType.Class, Accessibility.Public);
                    break;
                case vbext_ComponentType.vbext_ct_Document:
                    key = Tuple.Create(DeclarationType.Document, Accessibility.Public);
                    break;
                case vbext_ComponentType.vbext_ct_MSForm:
                    key = Tuple.Create(DeclarationType.UserForm, Accessibility.Public);
                    break;
                default:
                    key = Tuple.Create(DeclarationType.Project, Accessibility.Public);
                    break;
            }

            return Images[key];
        }
        private Mock<VBComponent> CreateComponentMock(string name, vbext_ComponentType type, string content, Selection selection)
        {
            var result = new Mock<VBComponent>();

            result.SetupGet(m => m.VBE).Returns(_getVbe);
            result.SetupGet(m => m.Collection).Returns(() => _vbComponents.Object);
            result.SetupGet(m => m.Type).Returns(() => type);
            result.SetupProperty(m => m.Name, name);

            var module = CreateCodeModuleMock(name, content, selection);
            module.SetupGet(m => m.Parent).Returns(() => result.Object);
            result.SetupGet(m => m.CodeModule).Returns(() => module.Object);

            result.Setup(m => m.Activate());

            return result;
        }
 public AddComponentEventArgs(vbext_ComponentType type)
 {
     _type = type;
 }
Example #24
0
        /// <summary>
        /// Creates a new <see cref="Mock{VBComponent}"/>.
        /// </summary>
        /// <param name="name">The name to return from the <see cref="VBComponent.Name"/> property.</param>
        /// <param name="codeModule">The <see cref="CodeModule"/> to return from the CodeModule property.</param>
        /// <param name="componentType">
        /// The type of component to be simulated.
        /// Use vbext_ct_StdModule for standard modules.
        /// Use vbext_ct_ClassModule for classes.
        /// vbext_ct_ActiveXDesigner is invalid for the VBE.
        /// </param>
        /// <returns></returns>
        internal static Mock <VBComponent> CreateComponentMock(string name, CodeModule codeModule, vbext_ComponentType componentType)
        {
            var component = new Mock <VBComponent>();

            component.SetupProperty(c => c.Name, name);
            component.SetupGet(c => c.CodeModule).Returns(codeModule);
            component.SetupGet(c => c.Type).Returns(componentType);
            return(component);
        }
Example #25
0
        /// <summary>
        /// Adds a new component to the project.
        /// </summary>
        /// <param name="name">The name of the new component.</param>
        /// <param name="type">The type of component to create.</param>
        /// <param name="content">The VBA code associated to the component.</param>
        /// <returns>Returns the <see cref="MockProjectBuilder"/> instance.</returns>
        public MockProjectBuilder AddComponent(string name, vbext_ComponentType type, string content)
        {
            var component = CreateComponentMock(name, type, content);

            return(AddComponent(component));
        }
Example #26
0
        /// <summary>
        /// Creates a new <see cref="Mock{VBComponent}"/>.
        /// </summary>
        /// <param name="name">The name to return from the <see cref="VBComponent.Name"/> property.</param>
        /// <param name="codeModule">The <see cref="CodeModule"/> to return from the CodeModule property.</param>
        /// <param name="componentType">
        /// The type of component to be simulated.
        /// Use vbext_ct_StdModule for standard modules.
        /// Use vbext_ct_ClassModule for classes.
        /// vbext_ct_ActiveXDesigner is invalid for the VBE.
        /// </param>
        /// <returns></returns>
        internal static Mock <VBComponent> CreateComponentMock(string name, CodeModule codeModule, vbext_ComponentType componentType, Mock <VBE> vbe)
        {
            var component = new Mock <VBComponent>();

            component.SetupProperty(m => m.Name, name);
            component.SetupGet(m => m.CodeModule).Returns(codeModule);
            component.SetupGet(m => m.Type).Returns(componentType);
            component.SetupGet(m => m.VBE).Returns(vbe.Object);
            return(component);
        }
Example #27
0
        /// <summary>
        /// Adds a new component to the project.
        /// </summary>
        /// <param name="name">The name of the new component.</param>
        /// <param name="type">The type of component to create.</param>
        /// <param name="content">The VBA code associated to the component.</param>
        /// <param name="selection"></param>
        /// <returns>Returns the <see cref="MockProjectBuilder"/> instance.</returns>
        public MockProjectBuilder AddComponent(string name, vbext_ComponentType type, string content, Selection selection = new Selection())
        {
            var component = CreateComponentMock(name, type, content, selection);

            return(AddComponent(component));
        }
Example #28
0
        public DeclarationSymbolsListener(QualifiedModuleName qualifiedName, Accessibility componentAccessibility, vbext_ComponentType type)
        {
            _qualifiedName = qualifiedName;

            var declarationType = type == vbext_ComponentType.vbext_ct_StdModule
                ? DeclarationType.Module
                                  //: result.Component.Type == vbext_ComponentType.vbext_ct_MSForm
                                  //    ? DeclarationType.UserForm
                                  //    : result.Component.Type == vbext_ComponentType.vbext_ct_Document
                                  //        ? DeclarationType.Document
                : DeclarationType.Class;

            SetCurrentScope();
            _declarations.Add(new Declaration(_qualifiedName.QualifyMemberName(_qualifiedName.Component.Name), _qualifiedName.Project.Name, _qualifiedName.Component.Name, false, false, componentAccessibility, declarationType, null, Selection.Home));

            if (type == vbext_ComponentType.vbext_ct_MSForm)
            {
                DeclareControlsAsMembers(qualifiedName.Component);
            }
        }
 /// <summary>
 /// Adds a new component to the project.
 /// </summary>
 /// <param name="name">The name of the new component.</param>
 /// <param name="type">The type of component to create.</param>
 /// <param name="content">The VBA code associated to the component.</param>
 /// <returns>Returns the <see cref="MockProjectBuilder"/> instance.</returns>
 public MockProjectBuilder AddComponent(string name, vbext_ComponentType type, string content)
 {
     var component = CreateComponentMock(name, type, content);
     return AddComponent(component);
 }
        public DeclarationSymbolsListener(
            RubberduckParserState state,
            QualifiedModuleName qualifiedName,
            vbext_ComponentType type,
            IEnumerable <IAnnotation> annotations,
            IDictionary <Tuple <string, DeclarationType>, Attributes> attributes,
            Declaration projectDeclaration)
        {
            _qualifiedName = qualifiedName;
            _annotations   = annotations;
            _attributes    = attributes;

            var declarationType = type == vbext_ComponentType.vbext_ct_StdModule
                ? DeclarationType.ProceduralModule
                : DeclarationType.ClassModule;

            var key = Tuple.Create(_qualifiedName.ComponentName, declarationType);
            var moduleAttributes = attributes.ContainsKey(key)
                ? attributes[key]
                : new Attributes();

            if (declarationType == DeclarationType.ProceduralModule)
            {
                _moduleDeclaration = new ProceduralModuleDeclaration(
                    _qualifiedName.QualifyMemberName(_qualifiedName.Component.Name),
                    projectDeclaration,
                    _qualifiedName.Component.Name,
                    false,
                    FindAnnotations(),
                    moduleAttributes);
            }
            else
            {
                bool hasDefaultInstanceVariable = type != vbext_ComponentType.vbext_ct_ClassModule && type != vbext_ComponentType.vbext_ct_StdModule;

                Declaration superType = null;
                if (type == vbext_ComponentType.vbext_ct_Document)
                {
                    foreach (var coclass in state.CoClasses)
                    {
                        try
                        {
                            if (coclass.Key.Count != _qualifiedName.Component.Properties.Count)
                            {
                                continue;
                            }

                            var allNamesMatch = true;
                            for (var i = 0; i < coclass.Key.Count; i++)
                            {
                                if (coclass.Key[i] != _qualifiedName.Component.Properties.Item(i + 1).Name)
                                {
                                    allNamesMatch = false;
                                    break;
                                }
                            }

                            if (allNamesMatch)
                            {
                                superType = coclass.Value;
                                break;
                            }
                        }
                        catch (COMException)
                        {
                        }
                    }
                }

                _moduleDeclaration = new ClassModuleDeclaration(
                    _qualifiedName.QualifyMemberName(_qualifiedName.Component.Name),
                    projectDeclaration,
                    _qualifiedName.Component.Name,
                    false,
                    FindAnnotations(),
                    moduleAttributes,
                    hasDefaultInstanceVariable: hasDefaultInstanceVariable);

                if (superType != null)
                {
                    ((ClassModuleDeclaration)_moduleDeclaration).AddSupertype(superType);
                }
            }
            SetCurrentScope();
            AddDeclaration(_moduleDeclaration);
            var component = _moduleDeclaration.QualifiedName.QualifiedModuleName.Component;

            if (component.Type == vbext_ComponentType.vbext_ct_MSForm || component.Designer != null)
            {
                DeclareControlsAsMembers(component);
            }
        }
Example #31
0
        protected Mock <VBComponent> CreateMockComponent(string content, string name, vbext_ComponentType type)
        {
            var module    = SetupMockCodeModule(content, name);
            var component = MockFactory.CreateComponentMock(name, module.Object, type, _ide);

            module.SetupGet(m => m.Parent).Returns(component.Object);
            return(component);
        }
Example #32
0
 /// <summary>
 /// Select components by type
 /// </summary>
 /// <param name="project"></param>
 /// <param name="type">type to select</param>
 /// <returns></returns>
 public static IEnumerable <VBComponent> SelectComponents(this VBProject project, vbext_ComponentType type)
 {
     return(project.VBComponents.Select(type));
 }
Example #33
0
 /// <summary>
 /// Creates a new <see cref="Mock{VBComponent}"/>.
 /// </summary>
 /// <param name="name">The name to return from the <see cref="VBComponent.Name"/> property.</param>
 /// <param name="codeModule">The <see cref="CodeModule"/> to return from the CodeModule property.</param>
 /// <param name="componentType">
 /// The type of component to be simulated.
 /// Use vbext_ct_StdModule for standard modules.
 /// Use vbext_ct_ClassModule for classes.
 /// vbext_ct_ActiveXDesigner is invalid for the VBE.
 /// </param>
 /// <returns></returns>
 internal static Mock<VBComponent> CreateComponentMock(string name, CodeModule codeModule, vbext_ComponentType componentType, Mock<VBE> vbe)
 {
     var component = new Mock<VBComponent>();
     component.SetupProperty(m => m.Name, name);
     component.SetupGet(m => m.CodeModule).Returns(codeModule);
     component.SetupGet(m => m.Type).Returns(componentType);
     component.SetupGet(m => m.VBE).Returns(vbe.Object);
     return component;
 }
Example #34
0
        /// <summary>
        /// Select components by type
        /// </summary>
        /// <param name="components"></param>
        /// <param name="type">type to select</param>
        /// <returns></returns>
        public static IEnumerable <VBComponent> Select(this VBComponents components, vbext_ComponentType type)
        {
            IEnumerable <VBComponent> list = components.Cast <VBComponent>();

            return(list.Where(c => c.Type == type));
        }
Example #35
0
 public AddComponentEventArgs(vbext_ComponentType type)
 {
     _type = type;
 }
 /// <summary>
 /// Adds a new component to the project.
 /// </summary>
 /// <param name="name">The name of the new component.</param>
 /// <param name="type">The type of component to create.</param>
 /// <param name="content">The VBA code associated to the component.</param>
 /// <param name="selection"></param>
 /// <returns>Returns the <see cref="MockProjectBuilder"/> instance.</returns>
 public MockProjectBuilder AddComponent(string name, vbext_ComponentType type, string content, Selection selection = new Selection())
 {
     var component = CreateComponentMock(name, type, content, selection);
     return AddComponent(component);
 }
Example #37
0
 /// <summary>
 /// Creates a new <see cref="Mock{VBComponent}"/>.
 /// </summary>
 /// <param name="name">The name to return from the <see cref="VBComponent.Name"/> property.</param>
 /// <param name="codeModule">The <see cref="CodeModule"/> to return from the CodeModule property.</param>
 /// <param name="componentType">
 /// The type of component to be simulated.
 /// Use vbext_ct_StdModule for standard modules.
 /// Use vbext_ct_ClassModule for classes.
 /// vbext_ct_ActiveXDesigner is invalid for the VBE.
 /// </param>
 /// <returns></returns>
 internal static Mock<VBComponent> CreateComponentMock(string name, CodeModule codeModule, vbext_ComponentType componentType)
 {
     var component = new Mock<VBComponent>();
     component.SetupProperty(c => c.Name, name);
     component.SetupGet(c => c.CodeModule).Returns(codeModule);
     component.SetupGet(c => c.Type).Returns(componentType);
     return component;
 }