Esempio n. 1
0
        private static void AssertBindsToCommonTypes <T>(string queryCombinator)
            where T : QuerySyntax
        {
            var query = $@"
                SELECT  e.EmployeeID * 2.0,
                        e.LastName,
                        e.FirstName,
                        e.ReportsTo
                FROM    Employees e

                {queryCombinator}

                SELECT  e.EmployeeID,
                        e.LastName,
                        e.FirstName,
                        e.ReportsTo * 2.0
                FROM    Employees e
            ";

            var compilation   = CompilationFactory.CreateQuery(query);
            var combinedQuery = compilation.SyntaxTree.Root.DescendantNodes().OfType <T>().Single();
            var semanticModel = compilation.GetSemanticModel();

            var columns = semanticModel.GetOutputColumns(combinedQuery).ToImmutableArray();

            Assert.Equal(4, columns.Length);
            Assert.Equal(typeof(double), columns[0].Type);
            Assert.Equal(typeof(string), columns[1].Type);
            Assert.Equal(typeof(string), columns[2].Type);
            Assert.Equal(typeof(double), columns[3].Type);
        }
Esempio n. 2
0
        /// <summary>
        /// Handles the FinishButtonClick event of the wizardControl1 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void WizardControl1_FinishButtonClick(object sender, EventArgs e)
        {
            //generate the compilation with the tracks.
            ICompilation compilation = CompilationFactory.CreateNew();

            compilation.Title = _tbCollectionName.Text;

            //create tracks
            foreach (string trackMediaFile in _tbTrackMediaFiles.Lines)
            {
                Track newTrack = new Track {
                    Album  = _tbCommonAlbum.Text,
                    Artist = _tbCommonArtist.Text,
                    Name   = Path.GetFileNameWithoutExtension(trackMediaFile),
                    Url    = trackMediaFile
                };
                //create initial cue
                newTrack.Cues.Add(
                    new Cue {
                    Description = "Intro (autogenerated)",
                    Shortcut    = "1",
                    Time        = 0
                });
                compilation.Tracks.Add(newTrack);
            }

            Core.Model.Instance.Compilation = compilation; //assign to model.
            DialogResult = DialogResult.OK;
            Close();
        }
        private static void AssertIsMatch(string sql)
        {
            ImmutableArray <TextSpan> textSpans;
            var query = sql.ParseSpans(out textSpans);

            var compilation   = CompilationFactory.CreateQuery(query);
            var semanticModel = compilation.GetSemanticModel();

            foreach (var span in textSpans)
            {
                var symbolSpan = semanticModel.FindSymbol(span.End).Value;

                Assert.NotNull(symbolSpan.Symbol);
                Assert.Equal(span, symbolSpan.Span);

                var usageSymbolSpans = semanticModel.FindUsages(symbolSpan.Symbol).ToImmutableArray();
                var usageSpans       = usageSymbolSpans.Select(s => s.Span).ToImmutableArray();

                foreach (var usageSymbolSpan in usageSymbolSpans)
                {
                    Assert.Equal(usageSymbolSpan.Symbol, symbolSpan.Symbol);
                }

                foreach (var usageSpan in usageSpans)
                {
                    Assert.Contains(usageSpan, textSpans);
                }

                foreach (var textSpan in textSpans)
                {
                    Assert.Contains(textSpan, usageSpans);
                }
            }
        }
Esempio n. 4
0
        protected void AssertIsMatch(string queryWithMarkers)
        {
            ImmutableArray <TextSpan> spans;
            var query = queryWithMarkers.ParseSpans(out spans);

            var applicableSpan = spans[0];
            var parameterSpans = spans.Skip(1).ToImmutableArray();

            var compilation   = CompilationFactory.CreateQuery(query);
            var semanticModel = compilation.GetSemanticModel();

            var provider  = CreateProvider();
            var providers = new[] { provider };

            for (var i = 0; i < parameterSpans.Length; i++)
            {
                var parameterSpan = parameterSpans[i];
                var start         = parameterSpan.Start;
                var middle        = parameterSpan.Start + parameterSpan.Length / 2;
                var end           = parameterSpan.Start;

                AssertIsMatch(semanticModel, start, providers, applicableSpan, i);
                AssertIsMatch(semanticModel, middle, providers, applicableSpan, i);
                AssertIsMatch(semanticModel, end, providers, applicableSpan, i);
            }
        }
Esempio n. 5
0
 private static TestCaseData VoidPostconditionTestCase(string attributeName, bool isValid)
 {
     return(new TestCaseData(
                CompilationFactory.CompileClassFromText(
                    SourceCodeFactory.ClassWithMembers(
                        SourceCodeFactory.PostconditionMethod("void", attributeName))),
                isValid)
            .SetName($"{fixture}NoPostconditions_{attributeName}"));
 }
Esempio n. 6
0
        protected ImmutableArray <CodeIssue> GetIssues(string query)
        {
            var compilation   = CompilationFactory.CreateQuery(query);
            var semanticModel = compilation.GetSemanticModel();

            var provider  = CreateProvider();
            var providers = new[] { provider };

            return(semanticModel.GetIssues(providers).ToImmutableArray());
        }
Esempio n. 7
0
        public override Task <CodeFile> GetCodeFileAsync(string originalName, Stream stream, bool runAnalysis)
        {
            ZipArchive archive = null;

            try
            {
                Stream dllStream = stream;
                Stream docStream = null;
                List <DependencyInfo> dependencies = new List <DependencyInfo>();

                if (IsNuget(originalName))
                {
                    archive = new ZipArchive(stream, ZipArchiveMode.Read, true);
                    foreach (var entry in archive.Entries)
                    {
                        if (IsDll(entry.Name))
                        {
                            dllStream = entry.Open();
                            var docEntry = archive.GetEntry(Path.ChangeExtension(entry.FullName, ".xml"));
                            if (docEntry != null)
                            {
                                docStream = docEntry.Open();
                            }
                        }
                        else if (IsNuspec(entry.Name))
                        {
                            using var nuspecStream = entry.Open();
                            var document           = XDocument.Load(nuspecStream);
                            var dependencyElements = document.Descendants().Where(e => e.Name.LocalName == "dependency");
                            dependencies.AddRange(
                                dependencyElements.Select(dependency => new DependencyInfo(
                                                              dependency.Attribute("id").Value,
                                                              dependency.Attribute("version").Value)));
                            // filter duplicates and sort
                            dependencies = dependencies
                                           .GroupBy(d => d.Name)
                                           .Select(d => d.First())
                                           .OrderBy(d => d.Name).ToList();
                        }
                    }
                }

                var assemblySymbol = CompilationFactory.GetCompilation(dllStream, docStream);
                if (assemblySymbol == null)
                {
                    return(Task.FromResult(GetDummyReviewCodeFile(originalName, dependencies)));
                }

                return(Task.FromResult(new CodeFileBuilder().Build(assemblySymbol, runAnalysis, dependencies)));
            }
            finally
            {
                archive?.Dispose();
            }
        }
Esempio n. 8
0
        protected override ImmutableArray <ICodeAction> GetActions(string query)
        {
            int position;
            var compilation   = CompilationFactory.CreateQuery(query, out position);
            var semanticModel = compilation.GetSemanticModel();

            var provider  = CreateProvider();
            var providers = new[] { provider };

            return(semanticModel.GetRefactorings(position, providers).ToImmutableArray());
        }
        protected static CompletionModel GetCompletionModel(string query)
        {
            int position;
            var compilation   = CompilationFactory.CreateQuery(query, out position);
            var semanticModel = compilation.GetSemanticModel();

            var provider  = new SymbolCompletionProvider();
            var providers = new[] { provider };

            return(semanticModel.GetCompletionModel(position, providers));
        }