Exemple #1
0
        public UmlTypeMember CreateTypeMember(string sectionName)
        {
            var property = new UmlTypeMember();
            var data     = new UmlTypeMemberData();

            if (sectionName == "Properties")
            {
                var pe = new PropertyElement();
                pe.Type             = "string";
                pe.Name             = "";
                data.Owner          = pe;
                property.DataSource = data;

                typeMemberLookup.Add(pe, property);
                Owner.Type.AddChild(pe);
            }

            if (sectionName == "Methods")
            {
                var pe = new MethodElement();
                pe.Name             = "";
                data.Owner          = pe;
                property.DataSource = data;

                typeMemberLookup.Add(pe, property);
                Owner.Type.AddChild(pe);
            }

            return(property);
        }
            public IMethodElement Method(string name)
            {
                var el = new MethodElement(name);

                _lDesignElements.Add(el);
                return(el);
            }
Exemple #3
0
        public void AddEmptyMethod(MethodElement me)
        {
            //	Console.WriteLine("\t" + me.Name);

            TypeReference    returnType = _resolver.ForceResolve(me.ReturnType);
            MethodDefinition newMethod  = new MethodDefinition(me.Name, MethodAttributes.Public, returnType);

            foreach (ParameterElement pe in me.Parameters)
            {
                TypeReference       paramType = _resolver.ForceResolve(pe.Type);
                ParameterDefinition param     = new ParameterDefinition(paramType);
                param.Name = pe.Name;

                //	Console.WriteLine("\t\t" + param.Name + " :: " + param.ParameterType);

                newMethod.Parameters.Add(param);
            }

            Type            exceptionType = typeof(NotImplementedException);
            MethodReference cons          = _type.Module.Import(exceptionType.GetConstructor(new Type[] {}));

            CilWorker worker = newMethod.Body.CilWorker;

            worker.Append(worker.Create(OpCodes.Nop));
            worker.Append(worker.Create(OpCodes.Newobj, cons));
            worker.Append(worker.Create(OpCodes.Throw));

            _type.Methods.Add(newMethod);
        }
Exemple #4
0
        public void ParseStringLiterals()
        {
            MethodElement method = ParserTestingUtils.GetMethod("..\\..\\Parser\\Parser.UnitTests\\TestFiles\\ShortCSharpFile.txt",
                                                                "LaunchSrcML");

            Assert.IsTrue(method.Body.Contains("Testingphraseola"));
        }
        public UmlTypeMember CreateTypeMember(string sectionName)
        {
            var property = new UmlTypeMember();
            var data = new UmlTypeMemberData();
            if (sectionName == "Properties")
            {
                var pe = new PropertyElement();
                pe.Type = "string";
                pe.Name = "";
                data.Owner = pe;
                property.DataSource = data;

                typeMemberLookup.Add(pe, property);
                Owner.Type.AddChild(pe);
            }

            if (sectionName == "Methods")
            {
                var pe = new MethodElement();
                pe.Name = "";
                data.Owner = pe;
                property.DataSource = data;

                typeMemberLookup.Add(pe, property);
                Owner.Type.AddChild(pe);
            }

            return property;
        }
Exemple #6
0
        private static void CheckParseOfShortCSharpFile(List <ProgramElement> elements)
        {
            bool seenSetLanguageMethod = false;

            foreach (ProgramElement pe in elements)
            {
                if (pe is MethodElement)
                {
                    MethodElement method = (MethodElement)pe;
                    if (method.Name == "SetLanguage")
                    {
                        seenSetLanguageMethod = true;
                        Assert.AreEqual(method.DefinitionLineNumber, 26);
                        Assert.AreEqual(method.ReturnType, "void");
                        Assert.AreEqual(method.AccessLevel, AccessLevel.Public);
                        Assert.AreEqual(method.Arguments, "LanguageEnum language");
                        Assert.AreEqual(method.Body.Trim(),
                                        "{\n\t\t\tLanguage = language;\n\t\t\t//temporary\n\t\t\tif(language==LanguageEnum.CSharp)\n\t\t\t\tLanguage = LanguageEnum.Java;\n\t\t}");
                        Assert.AreNotEqual(method.ClassId, System.Guid.Empty);
                    }
                    if (method.Name == "GenerateSrcML")
                    {
                        seenSetLanguageMethod = true;
                        Assert.AreEqual(method.Body.Trim(),
                                        "{\n\t\t\t//check whether filename exists\n\t\t\tif(!System.IO.File.Exists(filename))\n\t\t\t{\n\t\t\t\tthrow new ParserException(\"parser input file name does not exist: \" + filename);\n\t\t\t}\n\n\t\t\treturn LaunchSrcML(filename);\n\t\t}");
                        Assert.AreNotEqual(method.ClassId, System.Guid.Empty);
                    }
                }
            }
            Assert.IsTrue(seenSetLanguageMethod);
        }
Exemple #7
0
        public void CreateIndexer()
        {
            TestUtils.InitializeDefaultExtensionPoints();

            _indexerPath = Path.GetTempPath() + "luceneindexer";
            Directory.CreateDirectory(_indexerPath);
            _solutionKey = new SolutionKey(Guid.NewGuid(), "C:/SolutionPath");
            ServiceLocator.RegisterInstance(_solutionKey);
            ServiceLocator.RegisterInstance <Analyzer>(new SimpleAnalyzer());
            _indexer = new DocumentIndexer(TimeSpan.FromSeconds(1));
            ServiceLocator.RegisterInstance(_indexer);

            ClassElement classElement = SampleProgramElementFactory.GetSampleClassElement(
                accessLevel: AccessLevel.Public,
                definitionLineNumber: 11,
                extendedClasses: "SimpleClassBase",
                fullFilePath: "C:/Projects/SimpleClass.cs",
                implementedInterfaces: "IDisposable",
                name: "SimpleName",
                namespaceName: "Sanod.Indexer.UnitTests"
                );
            SandoDocument sandoDocument = DocumentFactory.Create(classElement);

            _indexer.AddDocument(sandoDocument);
            MethodElement methodElement = SampleProgramElementFactory.GetSampleMethodElement(
                accessLevel: AccessLevel.Protected,
                name: "SimpleName",
                returnType: "Void",
                fullFilePath: "C:/stuff"
                );

            sandoDocument = DocumentFactory.Create(methodElement);
            _indexer.AddDocument(sandoDocument);
        }
Exemple #8
0
        protected List <TypeElement> CreateTypeElements(NamespaceContext context, List <DefinedType> types)
        {
            List <TypeElement> result = new List <TypeElement>();

            foreach (DefinedType dt in types)
            {
                TypeElement te = new TypeElement();
                te.FromSource  = context.FileName;
                te.EndPos      = dt.EndPos;
                te.Name        = dt.Name;
                te.Namespace   = context.Namespace;
                te.BaseType    = ResolveBaseType(context, dt.BaseType);
                te.Interfaces  = ResolveFullNames(context, dt.Interfaces);
                te.Methods     = ProcessMethods(context, dt.Methods);
                te.Fields      = ProcessFields(context, dt.Fields);
                te.IsClass     = dt.IsClass;
                te.IsInterface = dt.IsInterface;
                te.IsAbstract  = dt.IsAbstract;
                te.IsSealed    = dt.IsSealed;
                te.IsPublic    = dt.IsPublic;
                result.Add(te);

                // set method signatures
                foreach (MethodElement method in te.Methods)
                {
                    method.Signature = MethodElement.GenerateSignature(te.FullName, method);
                }

                ResolveReferencedTypes(context, dt.ReferencedTypes);
                CreateTypeElements(context, dt.DefinedTypes);
            }
            return(result);
        }
Exemple #9
0
        public void ParseVariableDeclarations()
        {
            MethodElement method = ParserTestingUtils.GetMethod("..\\..\\Parser\\Parser.UnitTests\\TestFiles\\ShortCSharpFile.txt",
                                                                "LaunchSrcML");

            Assert.IsTrue(method.Body.Contains("waddow"));
        }
        public void EvaluateElementNameMatchesTest()
        {
            IConditionExpression expression = new BinaryOperatorExpression(
                BinaryExpressionOperator.Matches,
                new ElementAttributeExpression(ElementAttributeType.Name),
                new StringExpression("IDisposable\\..*"));

            MethodElement element = new MethodElement();

            element.Name = "IDisposable.Dispose";

            bool result = ConditionExpressionEvaluator.Instance.Evaluate(
                expression, element);

            Assert.IsTrue(result, "Unexpected expression evaluation result.");

            element.Name = "IDisposable.Test";
            result       = ConditionExpressionEvaluator.Instance.Evaluate(
                expression, element);
            Assert.IsTrue(result, "Unexpected expression evaluation result.");

            element.Name = "IDisposable";
            result       = ConditionExpressionEvaluator.Instance.Evaluate(
                expression, element);
            Assert.IsFalse(result, "Unexpected expression evaluation result.");
        }
Exemple #11
0
        public void ParseParameters()
        {
            MethodElement method = ParserTestingUtils.GetMethod("..\\..\\Parser\\Parser.UnitTests\\TestFiles\\ShortCSharpFile.txt",
                                                                "GenerateSrcML");

            Assert.IsTrue(method.Arguments.Contains("parameterFilename"));
            Assert.IsTrue(method.Arguments.Contains("String"));
        }
Exemple #12
0
        public ProjectElement Parse(String[] inputfiles)
        {
            ProjectElement project = new ProjectElement();

            // Open file
            using (CoverageInfo info = JoinCoverageFiles(inputfiles))
            {
                CoverageDS dataSet = info.BuildDataSet();

                Dictionary <String, PackageElement> packages = new Dictionary <String, PackageElement>();
                Dictionary <uint, string>           files    = new Dictionary <uint, string>();

                // Namespaces
                DataTable namespacesTable = dataSet.Tables["NameSpaceTable"];
                DataTable classesTable    = dataSet.Tables["Class"];
                DataTable filesTable      = dataSet.Tables["SourceFileNames"];

                CreateIndexPackages(project, namespacesTable, packages);
                CreateIndexFiles(filesTable, files);

                foreach (DataRow iclass in classesTable.Rows)
                {
                    string       className = System.Security.SecurityElement.Escape((string)iclass["ClassName"]);
                    ClassElement ce        = new ClassElement(className);

                    DataRow[] methodRows = iclass.GetChildRows("Class_Method");

                    foreach (DataRow imethod in methodRows)
                    {
                        // Get First Line in class
                        DataRow[] lineRows    = imethod.GetChildRows("Method_Lines");
                        bool      includeFile = lineRows.Length < 1 ? false : files.ContainsKey(lineRows[0].Field <uint>("SourceFileID"));

                        if (includeFile)
                        {
                            string        methodName = (string)imethod["MethodName"]; // System.Security.SecurityElement.Escape((string)imethod["MethodName"]);
                            MethodElement me         = new MethodElement(methodName);

                            uint coveredBlocks = (uint)imethod["BlocksCovered"];
                            uint totalBlocks   = coveredBlocks + (uint)imethod["BlocksNotCovered"];
                            uint coveredLines  = (uint)imethod["LinesCovered"];
                            uint totalLines    = coveredLines + (uint)imethod["LinesNotCovered"] + (uint)imethod["LinesPartiallyCovered"];
                            me.Metrics = new MethodMetrics(totalBlocks, coveredBlocks, totalLines, coveredLines);

                            ce.AddMethod(me);
                        }
                    }

                    if (packages.ContainsKey((string)iclass["NamespaceKeyName"]))
                    {
                        PackageElement pe = packages[(string)iclass["NamespaceKeyName"]];
                        pe.AddClass(ce);
                    }
                }
            }

            return(project);
        }
        /// <summary>
        /// Creates the method element by him definitions
        /// </summary>
        /// <param name="methodDef">The method def.</param>
        /// <param name="customControlPath">The custom control path.</param>
        /// <returns></returns>
        protected virtual MethodElement CreateMethodElement(ElementDefs methodDef, string customControlPath)
        {
            MethodElement retVal = new MethodElement(methodDef.Key, methodDef.Descr, methodDef.Descr);

            retVal.CustomControlPath = customControlPath;
            methodDef.Tag            = retVal;

            return(retVal);
        }
Exemple #14
0
            public IMethodElement OverrideMethod(MethodInfo info)
            {
                var el = new MethodElement(info.Name)
                         .ArgTypes(info.GetParameters().Select(p => p.ParameterType).ToArray())
                         .ReturnType(info.ReturnType)
                         .Attributes(MethodAttributes.Virtual | MethodAttributes.Public);

                _lDesignElements.Add(el as DesignElement);
                return(el);
            }
Exemple #15
0
        public void HasMethodBodyTest()
        {
            MethodElement target = new MethodElement();

            bool val = false; // TODO: Assign to an appropriate value for the property


            Assert.AreEqual(val, target.HasMethodBody, "Composestar.StarLight.Entities.LanguageModel.MethodElement.HasMethodBody was not " +
                            "set correctly.");
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Exemple #16
0
        public void FormatTest()
        {
            MethodElement methodElement = new MethodElement();

            methodElement.Name = "Test";

            string formatted = ElementUtilities.Format(
                "End $(ElementType) $(Name)",
                methodElement);

            Assert.AreEqual("End Method Test", formatted, "Unexpected formatted result.");
        }
        /// <summary>
        ///     메서드 요소에 대한 역직렬화를 수행합니다.
        /// </summary>
        /// <param name="element">	컨테이너 요소입니다. </param>
        /// <returns>IoC 컨테이너가 제공하는 메서드에 대한 객체 입니다.</returns>
        protected override object ResolveMethod(MethodElement element)
        {
            List <object> paramList = new List <object>();

            foreach (var p in element.param)
            {
                var obj = this.ResolveParam(p.name, p.Item);
                paramList.Add(obj);
            }

            return(paramList);
        }
        public void InsertByTypeTest()
        {
            SortBy sortBy = new SortBy();

            sortBy.By        = ElementAttributeType.Type;
            sortBy.Direction = SortDirection.Ascending;

            SortedInserter sortedInserter = new SortedInserter(ElementType.Method, sortBy);

            //
            // Create a parent element
            //
            RegionElement regionElement = new RegionElement();

            Assert.AreEqual(0, regionElement.Children.Count, "Parent element should not have any children.");

            //
            // Insert an element with a mid alphabet return type.
            //
            MethodElement method1 = new MethodElement();

            method1.Name = "DoSomething";
            method1.Type = "Nullable<DateTime>";
            sortedInserter.InsertElement(regionElement, method1);
            Assert.AreEqual(1, regionElement.Children.Count, "Element was not inserted into the parent.");
            Assert.AreEqual(0, regionElement.Children.IndexOf(method1), "Element was not inserted at the correct index.");

            //
            // Insert an element that should be sorted toward the end
            //
            MethodElement method2 = new MethodElement();

            method2.Name = "DoSomething";
            method2.Type = "Type";
            sortedInserter.InsertElement(regionElement, method2);
            Assert.AreEqual(2, regionElement.Children.Count, "Element was not inserted into the parent.");
            Assert.AreEqual(0, regionElement.Children.IndexOf(method1), "Element is not at the correct index.");
            Assert.AreEqual(1, regionElement.Children.IndexOf(method2), "Element is not at the correct index.");

            //
            // Insert an element that should be sorted toward the beginning
            //
            MethodElement method3 = new MethodElement();

            method3.Name = "DoSomething";
            method3.Type = "IEnumerable";
            sortedInserter.InsertElement(regionElement, method3);
            Assert.AreEqual(3, regionElement.Children.Count, "Element was not inserted into the parent.");
            Assert.AreEqual(0, regionElement.Children.IndexOf(method3), "Element is not at the correct index.");
            Assert.AreEqual(1, regionElement.Children.IndexOf(method1), "Element is not at the correct index.");
            Assert.AreEqual(2, regionElement.Children.IndexOf(method2), "Element is not at the correct index.");
        }
        public void InsertByElementTypeTest()
        {
            SortBy sortBy = new SortBy();

            sortBy.By        = ElementAttributeType.ElementType;
            sortBy.Direction = SortDirection.Ascending;

            SortedInserter sortedInserter = new SortedInserter(ElementType.NotSpecified, sortBy);

            //
            // Create a parent element
            //
            RegionElement regionElement = new RegionElement();

            Assert.AreEqual(0, regionElement.Children.Count, "Parent element should not have any children.");

            //
            // Insert an element with a middle access.
            //
            ConstructorElement constructor = new ConstructorElement();

            constructor.Name   = "SomeClass";
            constructor.Access = CodeAccess.Public;
            sortedInserter.InsertElement(regionElement, constructor);
            Assert.AreEqual(1, regionElement.Children.Count, "Element was not inserted into the parent.");
            Assert.AreEqual(0, regionElement.Children.IndexOf(constructor), "Element was not inserted at the correct index.");

            //
            // Insert an element that should be sorted toward the end
            //
            MethodElement methodElement = new MethodElement();

            methodElement.Name   = "SomeMethod";
            methodElement.Access = CodeAccess.Public;
            sortedInserter.InsertElement(regionElement, methodElement);
            Assert.AreEqual(2, regionElement.Children.Count, "Element was not inserted into the parent.");
            Assert.AreEqual(0, regionElement.Children.IndexOf(constructor), "Element is not at the correct index.");
            Assert.AreEqual(1, regionElement.Children.IndexOf(methodElement), "Element is not at the correct index.");

            //
            // Insert an element that should be sorted toward the beginning
            //
            FieldElement fieldElement = new FieldElement();

            fieldElement.Name   = "someField";
            fieldElement.Access = CodeAccess.Private;
            sortedInserter.InsertElement(regionElement, fieldElement);
            Assert.AreEqual(3, regionElement.Children.Count, "Element was not inserted into the parent.");
            Assert.AreEqual(0, regionElement.Children.IndexOf(fieldElement), "Element is not at the correct index.");
            Assert.AreEqual(1, regionElement.Children.IndexOf(constructor), "Element is not at the correct index.");
            Assert.AreEqual(2, regionElement.Children.IndexOf(methodElement), "Element is not at the correct index.");
        }
Exemple #20
0
        public void SignatureTest()
        {
            MethodElement target = new MethodElement();

            string val = null; // TODO: Assign to an appropriate value for the property

            target.Signature = val;


            Assert.AreEqual(val, target.Signature, "Composestar.StarLight.Entities.LanguageModel.MethodElement.Signature was not set " +
                            "correctly.");
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Exemple #21
0
        public void ParametersTest()
        {
            MethodElement target = new MethodElement();

            System.Collections.Generic.List <Composestar.StarLight.Entities.LanguageModel.ParameterElement> val = null; // TODO: Assign to an appropriate value for the property

            target.Parameters = val;


            Assert.AreEqual(val, target.Parameters, "Composestar.StarLight.Entities.LanguageModel.MethodElement.Parameters was not set" +
                            " correctly.");
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Exemple #22
0
        private static void CheckParseOfEventFile(SrcMLCppParser parser, string sourceFile, List <ProgramElement> elements)
        {
            bool seenGetTimeMethod = false;
            int  numMethods        = 0;

            foreach (ProgramElement pe in elements)
            {
                if (pe is CppUnresolvedMethodElement)
                {
                    numMethods++;

                    //Resolve
                    bool          isResolved = false;
                    MethodElement method     = null;
                    CppUnresolvedMethodElement unresolvedMethod = (CppUnresolvedMethodElement)pe;
                    foreach (String headerFile in unresolvedMethod.IncludeFileNames)
                    {
                        //it's reasonable to assume that the header file path is relative from the cpp file,
                        //as other included files are unlikely to be part of the same project and therefore
                        //should not need to be parsed
                        string headerPath = System.IO.Path.GetDirectoryName(sourceFile) + "\\" + headerFile;
                        if (!System.IO.File.Exists(headerPath))
                        {
                            continue;
                        }

                        isResolved = unresolvedMethod.TryResolve(unresolvedMethod, parser.Parse(headerPath), out method);
                        if (isResolved == true)
                        {
                            break;
                        }
                    }
                    Assert.IsTrue(isResolved);
                    Assert.IsNotNull(method);

                    //pick one of the resolved methods to see if it seems complete
                    if (method.Name == "getTime")
                    {
                        seenGetTimeMethod = true;
                        Assert.AreEqual(method.DefinitionLineNumber, 13);
                        Assert.AreEqual(method.ReturnType, "double");
                        Assert.AreEqual(method.AccessLevel, AccessLevel.Public);
                        Assert.AreEqual(method.Arguments, String.Empty);
                        Assert.AreEqual(method.Body, "{ \n  return _time; \n}");
                        Assert.AreNotEqual(method.ClassId, System.Guid.Empty);
                    }
                }
            }
            Assert.AreEqual(numMethods, 6);
            Assert.IsTrue(seenGetTimeMethod);
        }
        private void RenderMethod(MethodElement method)
        {
            this.DocumentMethod(method);

            this.output.Write("service.");
            this.output.Write(method.Name.Camelize());
            this.output.Write(" = function(");

            this.output.Write(string.Join(", ", method.GetAllParameters().Select(_ => _.Name)));

            this.output.WriteLine(") {");

            this.output.PushIndent(Tab);

            this.output.Write("return $http.");
            this.output.Write(method.HttpMethod.ToString().ToLower());
            this.output.Write("(utilities.fixUri(apiBaseUri + ");

            this.output.Write(AngularUtility.GetRouteBuilder(method));

            this.output.Write(")");
            if (method.BodyParameter != null)
            {
                this.output.Write(", ");

                if (method.BodyParameter.Type == typeof(string))
                {
                    this.output.Write("JSON.stringify(");
                    this.output.Write(method.BodyParameter.Name);
                    this.output.Write(")");
                }
                else
                {
                    this.output.Write(method.BodyParameter.Name);
                }
            }

            this.output.WriteLine(").catch(function(response) {");

            this.output.PushIndent(Tab);
            this.output.WriteLine("return $q.reject(utilities.getHttpError(response));");
            this.output.PopIndent();
            this.output.WriteLine("});");

            this.output.PopIndent();
            this.output.WriteLine("};");

            this.output.WriteLine(string.Empty);
        }
Exemple #24
0
        public override List <Field> GetFieldsForLucene()
        {
            List <Field>  fields        = new List <Field>();
            MethodElement methodElement = (MethodElement)programElement;

            fields.Add(new Field(SandoField.AccessLevel.ToString(), methodElement.AccessLevel.ToString().ToLower(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            fields.Add(new Field(SandoField.Arguments.ToString(), methodElement.Arguments.ToSandoSearchable(), Field.Store.YES, Field.Index.ANALYZED));
            AddBodyField(fields, new Field(SandoField.Body.ToString(), methodElement.Body.ToSandoSearchable(), Field.Store.NO, Field.Index.ANALYZED));
            fields.Add(new Field(SandoField.ClassId.ToString(), methodElement.ClassId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            fields.Add(new Field(SandoField.ClassName.ToString(), methodElement.ClassName.ToSandoSearchable(), Field.Store.YES, Field.Index.ANALYZED));
            fields.Add(new Field(SandoField.ReturnType.ToString(), methodElement.ReturnType.ToSandoSearchable(), Field.Store.YES, Field.Index.ANALYZED));
            fields.Add(new Field(SandoField.Modifiers.ToString(), methodElement.Modifiers, Field.Store.YES, Field.Index.ANALYZED));
            fields.Add(new Field(SandoField.IsConstructor.ToString(), methodElement.IsConstructor.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
            return(fields);
        }
Exemple #25
0
        private List <MethodElement> GenerateMethods(int methodCount, int parameterCount)
        {
            List <MethodElement> result = new List <MethodElement>();

            for (int i = 0; i < methodCount; i++)
            {
                MethodElement me = new MethodElement();
                me.Name       = String.Format("Method_{0}", i);
                me.ReturnType = String.Format("ReturnTypeOfMethod_{0}", i);

                if (randomizer.Next(0, 2) == 0)
                {
                    me.IsPrivate = true;
                    me.IsPublic  = false;
                }
                else
                {
                    me.IsPrivate = false;
                    me.IsPublic  = true;
                }

                // Add parameters
                for (short k = 0; k < parameterCount; k++)
                {
                    ParameterElement pe = new ParameterElement();
                    pe.Ordinal = k;
                    pe.Name    = String.Format("Method_{0}-Parameter_{1}", i, k);
                    if (k % 3 == 0)
                    {
                        pe.Type = "System.String";
                    }
                    else if (k % 3 == 1)
                    {
                        pe.Type = "System.Boolean";
                    }
                    else
                    {
                        pe.Type = "System.Int32";
                    }

                    me.Parameters.Add(pe);
                }

                result.Add(me);
            }

            return(result);
        }
        public void Then_MethodsGetSerialized()
        {
            var loadedSection = SerializeAndLoadSection("SerializingMethods.config", s =>
            {
                var method0 = new MethodElement
                {
                    Name = "NoArgsMethod"
                };

                var method1 = new MethodElement
                {
                    Name = "OneArgMethod"
                };

                method1.Parameters.Add(new ParameterElement
                {
                    Name = "BasicDependency"
                });
                method1.Parameters.Add(new ParameterElement
                {
                    Name  = "ArrayDependency",
                    Value = new ArrayElement
                    {
                        TypeName = "SomeType"
                    }
                });

                var reg = new RegisterElement
                {
                    TypeName = "MyType"
                };
                reg.InjectionMembers.Add(method0);
                reg.InjectionMembers.Add(method1);
                var container = new ContainerElement();
                container.Registrations.Add(reg);
                s.Containers.Add(container);
            });

            var methods = loadedSection.Containers.Default.Registrations[0].InjectionMembers.Cast <MethodElement>();

            methods.Select(m => m.Name)
            .AssertContainsExactly("NoArgsMethod", "OneArgMethod");

            var oneArgMethod = methods.Where(m => m.Name == "OneArgMethod").First();

            Assert.AreEqual(2, oneArgMethod.Parameters.Count);
        }
        public static SandoDocument GetDocumentForUnresolvedCppMethod(CppUnresolvedMethodElement unresolvedMethod, List <ProgramElement> headerElements)
        {
            bool          isResolved    = false;
            MethodElement methodElement = null;

            isResolved = unresolvedMethod.TryResolve(unresolvedMethod, headerElements, out methodElement);
            if (isResolved == true)
            {
                return(DocumentFactory.Create(methodElement));
            }
            else
            {
                Debug.WriteLine("????? " + unresolvedMethod.Name + " is not resolved, this is bad!!");
                methodElement = unresolvedMethod.Copy();
                return(DocumentFactory.Create(methodElement));
            }
        }
Exemple #28
0
        /// <summary>
        /// Writes the end block for an element.
        /// </summary>
        /// <param name="codeElement">The code element.</param>
        private void WriteEndBlock(CodeElement codeElement)
        {
            TabCount--;

            MemberElement memberElement = codeElement as MemberElement;
            string        blockName     = string.Empty;

            if (memberElement != null)
            {
                if (memberElement.ElementType == ElementType.Method ||
                    memberElement.ElementType == ElementType.Constructor)
                {
                    MethodElement methodElement = memberElement as MethodElement;
                    if (methodElement != null && methodElement.IsOperator)
                    {
                        blockName = VBKeyword.Operator;
                    }
                    else if (memberElement.Type != null)
                    {
                        blockName = VBKeyword.Function;
                    }
                    else
                    {
                        blockName = VBKeyword.Sub;
                    }
                }
            }

            if (string.IsNullOrEmpty(blockName))
            {
                TypeElement typeElement = codeElement as TypeElement;
                if (typeElement != null)
                {
                    blockName = EnumUtilities.ToString(typeElement.Type);
                }

                if (string.IsNullOrEmpty(blockName))
                {
                    blockName = EnumUtilities.ToString(codeElement.ElementType);
                }
            }

            WriteIndented(VBKeyword.End + ' ' + blockName);
        }
        public void CanArrangeTest()
        {
            RegionConfiguration methodRegionConfiguration = new RegionConfiguration();

            methodRegionConfiguration.Name = "Methods";
            ElementConfiguration methodConfiguration = new ElementConfiguration();

            methodConfiguration.ElementType = ElementType.Method;
            methodRegionConfiguration.Elements.Add(methodConfiguration);

            RegionConfiguration propertyRegionConfiguration = new RegionConfiguration();

            propertyRegionConfiguration.Name = "Properties";
            ElementConfiguration propertyConfiguration = new ElementConfiguration();

            propertyConfiguration.ElementType = ElementType.Property;
            propertyRegionConfiguration.Elements.Add(propertyConfiguration);

            ElementConfiguration parentConfiguration = new ElementConfiguration();

            parentConfiguration.ElementType = ElementType.Type;

            RegionArranger methodRegionArranger = new RegionArranger(
                methodRegionConfiguration, parentConfiguration);

            RegionArranger propertyRegionArranger = new RegionArranger(
                propertyRegionConfiguration, parentConfiguration);

            MethodElement method = new MethodElement();

            method.Name = "DoSomething";

            Assert.IsTrue(
                methodRegionArranger.CanArrange(method),
                "Expected region arranger to be able to arrange the element.");

            Assert.IsFalse(
                propertyRegionArranger.CanArrange(method),
                "Expected region arranger to not be able to arrange the element.");

            Assert.IsFalse(
                methodRegionArranger.CanArrange(null),
                "Expected region arranger to not be able to arrange a null element.");
        }
Exemple #30
0
 public void DocumentIndexer_DeleteDocuments()
 {
     try
     {
         TestUtils.ClearDirectory(PathManager.Instance.GetIndexPath(ServiceLocator.Resolve <SolutionKey>()));
         _documentIndexer = new DocumentIndexer(TimeSpan.FromSeconds(1));
         MethodElement sampleMethodElement = SampleProgramElementFactory.GetSampleMethodElement();
         _documentIndexer.AddDocument(DocumentFactory.Create(sampleMethodElement));
         int numDocs = _documentIndexer.GetNumberOfIndexedDocuments();
         Assert.IsTrue(numDocs == 1);
         _documentIndexer.DeleteDocuments(sampleMethodElement.FullFilePath);
         int docs = _documentIndexer.GetNumberOfIndexedDocuments();
         Assert.IsTrue(docs == 0);
     }
     catch (Exception ex)
     {
         Assert.Fail(ex.Message + ". " + ex.StackTrace);
     }
 }
Exemple #31
0
        public void MethodLinksToClassTest()
        {
            return;

            //NOTE: this test fails because of a bug in srcML
            //please turn this test back on once we receive a fix
            //from the srcML guys
            SrcMLCSharpParser parser = new SrcMLCSharpParser();
            var          elements    = parser.Parse("..\\..\\Parser\\Parser.UnitTests\\TestFiles\\ImageCaptureCS.txt");
            ClassElement ImageCaptureClassElement = null;
            bool         foundMethod = false;

            // first find the class element
            foreach (ProgramElement pe in elements)
            {
                if (pe is ClassElement)
                {
                    ClassElement cls = (ClassElement)pe;
                    if (cls.Name == "ImageCapture")
                    {
                        ImageCaptureClassElement = cls;
                    }
                }
            }

            // then the method element that should link to it
            foreach (ProgramElement pe in elements)
            {
                if (pe is MethodElement)
                {
                    MethodElement method = (MethodElement)pe;
                    if (method.Name == "CaptureByHdc")
                    {
                        foundMethod = true;
                        Assert.AreEqual(method.ClassId, ImageCaptureClassElement.Id);
                        Assert.AreEqual(method.ClassName, ImageCaptureClassElement.Name);
                    }
                }
            }

            Assert.IsTrue(foundMethod);
        }
Exemple #32
0
 public string Filename(MethodElement method)
 {
     string parameters = ParametersFilename(method.GetParameters());
     var result = Filename(method.DeclaringType, "M", string.Format(".{0}{1}.html", method.Name, string.IsNullOrEmpty(parameters) ? string.Empty : "-" + parameters));
     return result;
 }