From 077f00a8c11d95103dc844bd799b02d34b103fe7 Mon Sep 17 00:00:00 2001 From: Cody Ray Freeman Hoeft Date: Mon, 8 Feb 2016 22:01:37 -0800 Subject: [PATCH 1/2] Set up dummy error messages --- SemDiff.Core/Diagnostics.cs | 43 +++++++++++++++++++++++++++------ SemDiff.Core/SemDiffAnalyzer.cs | 4 +-- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/SemDiff.Core/Diagnostics.cs b/SemDiff.Core/Diagnostics.cs index 52ec576..e606c91 100644 --- a/SemDiff.Core/Diagnostics.cs +++ b/SemDiff.Core/Diagnostics.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; +using System.Threading; namespace SemDiff.Core { @@ -10,25 +11,53 @@ namespace SemDiff.Core /// public class Diagnostics { + //Shared Values + private const string Category = "Conflicts"; //Not sure where this shows up yet + + //False-Negative + public const string FalseNegativeDiagnosticId = "SemDiffFN"; //Like the error code (just like missing semicolon is CS1002) + + private const string FalseNegativeDescription = "False-Negatives occur text based tools fail to detect a conflict that affects the semantics of the application. i.e., when the semantics of a dependant item (a called method, a base class, a variable used) has been changed in a way that changes the runtime of the application when the changes are merged."; + + private const string FalseNegativeMessageFormat = "False-Negatives for type '{0}' between '{1}' and '({2})[{3}]'"; + + private const string FalseNegativeTitle = "Possible False-Negative condition detected"; + + //False-Positive + public const string FalsePositiveDiagnosticId = "SemDiffFP"; + + private const string FalsePositiveDescription = "False-Positives occur text based tools detect a conflict that affects the semantics of the application. i.e., when merge conflicts may occur, but there are no semantic differences between the conflicting changes."; + + private const string FalsePositiveMessageFormat = "False-Positive between '{0}' and '({1})[{2}]'"; + + private const string FalsePositiveTitle = "Possible False-Positive condition detected"; //Not sure where this comes up yet + + //similar to fp + private static readonly DiagnosticDescriptor FalseNegative = new DiagnosticDescriptor(FalseNegativeDiagnosticId, FalseNegativeTitle, FalseNegativeMessageFormat, Category, DiagnosticSeverity.Warning, isEnabledByDefault: true, description: FalseNegativeDescription); + + //0 is name of file, 1 is title of pull request, 2 is url of pull request //Actual error message text (formatable string) + //There is a option to show this in the error list for more info + private static readonly DiagnosticDescriptor FalsePositive = new DiagnosticDescriptor(FalsePositiveDiagnosticId, FalsePositiveTitle, FalsePositiveMessageFormat, Category, DiagnosticSeverity.Warning, isEnabledByDefault: true, description: FalsePositiveDescription); + /// /// The Diagnostics we support, provided for the SupportedDiagnostics property of DiagnosticAnalyzer /// - public static ImmutableArray Supported { get; internal set; } + public static ImmutableArray Supported { get; } = ImmutableArray.Create(FalsePositive, FalseNegative); /// - /// Converts `DetectedFalsePositive`s to Diagnostics (the class provided by Roslyn) and sends them to the function provided + /// Converts `DetectedFalseNegative`s to Diagnostics (the class provided by Roslyn) and sends them to the function provided /// - public static void Report(IEnumerable fps, Action reporter) + public static void Report(IEnumerable fps, Action reporter) { - throw new NotImplementedException(); + reporter(Diagnostic.Create(FalseNegative, Location.None, "FileName", @"dir\dir\FileName.cs", "My pull request title", "https://github.com/semdiffdotnet/semdiff/pull/33")); } /// - /// Converts `DetectedFalseNegative`s to Diagnostics (the class provided by Roslyn) and sends them to the function provided + /// Converts `DetectedFalsePositive`s to Diagnostics (the class provided by Roslyn) and sends them to the function provided /// - public static void Report(IEnumerable fps, Action reporter) + public static void Report(IEnumerable fps, Action reporter) { - throw new NotImplementedException(); + reporter(Diagnostic.Create(FalsePositive, Location.None, @"dir\dir\FileName.cs", "My pull request title", "https://github.com/semdiffdotnet/semdiff/pull/33")); } } } \ No newline at end of file diff --git a/SemDiff.Core/SemDiffAnalyzer.cs b/SemDiff.Core/SemDiffAnalyzer.cs index c083c05..0c23a8e 100644 --- a/SemDiff.Core/SemDiffAnalyzer.cs +++ b/SemDiff.Core/SemDiffAnalyzer.cs @@ -21,7 +21,7 @@ private static void OnSyntaxTree(SyntaxTreeAnalysisContext context) { var filePath = context.Tree.FilePath; var repo = Repo.GetRepoFor(filePath); - if (repo == null) + if (repo != null) { var fps = Analysis.ForFalsePositive(repo, context.Tree, filePath); Diagnostics.Report(fps, context.ReportDiagnostic); @@ -32,7 +32,7 @@ private static void OnSemanticModel(SemanticModelAnalysisContext context) { var filePath = context.SemanticModel.SyntaxTree.FilePath; var repo = Repo.GetRepoFor(filePath); - if (repo == null) + if (repo != null) { var fns = Analysis.ForFalseNegative(repo, context.SemanticModel); Diagnostics.Report(fns, context.ReportDiagnostic); From f8c1ac17bc5ad9f3e8ed3a73f0f565844811563b Mon Sep 17 00:00:00 2001 From: Cody Ray Freeman Hoeft Date: Wed, 10 Feb 2016 19:26:59 -0800 Subject: [PATCH 2/2] Clean up commented test for report (no semantic change) --- SemDiff.Test/Diff3Tests.cs | 75 +++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/SemDiff.Test/Diff3Tests.cs b/SemDiff.Test/Diff3Tests.cs index 437aced..4af921b 100644 --- a/SemDiff.Test/Diff3Tests.cs +++ b/SemDiff.Test/Diff3Tests.cs @@ -110,6 +110,7 @@ public void CompareInsertsTest() //[TestMethod] //public void CompareMethodsTest() //{ + // //This is our base (the common ancestor) // var original = ( // "return;".Method("Member1") + 3.BlankLines() + // "return;".Method("Member3") + 3.BlankLines() + @@ -119,8 +120,10 @@ public void CompareInsertsTest() // "return;".Method("Member7") + 3.BlankLines() + // "return;".Method("Member2") + 3.BlankLines() + // "return;".Method("Member8") + 3.BlankLines() + // //Utilities for producing valid syntaxtree // ).WrapWithClass().Parse(); - // var changed1 = ( + // //This is like a local developer that moves a method (method 2) + // var local = ( // "return;".Method("Member1") + // "return;".Method("Member2") + // "return;".Method("Member3") + 3.BlankLines() + @@ -130,7 +133,8 @@ public void CompareInsertsTest() // "return;".Method("Member7") + 3.BlankLines() + // "return;".Method("Member8") + 3.BlankLines() // ).WrapWithClass().Parse(); - // var changed2 = ( + // //This is like a pull request that modifies a method (method 2) + // var remote = ( // "return;".Method("Member1") + 3.BlankLines() + // "return;".Method("Member3") + 3.BlankLines() + // "return;".Method("Member4") + 3.BlankLines() + @@ -140,6 +144,73 @@ public void CompareInsertsTest() // "var x = 10; return;".Method("Member2") + // "return;".Method("Member8") // ).WrapWithClass().Parse(); + + // //Run through the Diff3 logic to get the changes and the conflicts + // var diff3Result = Diff3.Compare(original, local, remote); + + // //Conflict captures method that was both removed and edited + // //Assume that there is only one for this test! + // var conflict = diff3Result.Conflicts.Single(); + // //Assume that we have captured a whole method in our conflict + // var orig = conflict.Ancestor.Node as MethodDeclarationSyntax; + // Assert.IsNotNull(orig); + // //Check that it is removed locally + // Assert.AreEqual(0, conflict.Local.Span.Length); + // //Get changed method! + // var rem = conflict.Remote.Node as MethodDeclarationSyntax; + // Assert.IsNotNull(rem); + + // //Look in the non-conflicting change that represents the method + // // being added somewhere else (move destination) + // var loc = diff3Result.Local + // //Make sure there is nothing there before + // .Where(diff => string.IsNullOrWhiteSpace(diff.Ancestor.Text)) + // //Make sure there is a method there afterwards + // .Select(diff => diff.Changed.Node as MethodDeclarationSyntax) + // .Where(method => method != null) + // //Make sure that it matches our method's name + // .First(method => method.Identifier.Text == rem.Identifier.Text); + // Assert.IsNotNull(loc); + + // //Now we diff the insides of the methods + // var diff3ResultInner = Diff3.Compare(orig, loc, rem); + // //Since there is no conflicts inside the method, this is a false-positive! + // Assert.IsFalse(diff3ResultInner.Conflicts.Any()); + //} + + //[TestMethod] + //public void CompareMethods2Test() + //{ + // var original = ( + // "return;".Method("Member1") + + // "return;".Method("Member3") + + // "return;".Method("Member4") + + // "return;".Method("Member5") + + // "return;".Method("Member6") + + // "return;".Method("Member7") + + // "return;".Method("Member2") + + // "return;".Method("Member8") + // ).WrapWithClass().Parse(); + // var changed1 = ( + // "return;".Method("Member1") + + // "return;".Method("Member2") + + // "return;".Method("Member3") + + // "return;".Method("Member4") + + // "return;".Method("Member5") + + // "return;".Method("Member6") + + // "return;".Method("Member7") + + // "return;".Method("Member8") + // ).WrapWithClass().Parse(); + // var changed2 = ( + // "return;".Method("Member1") + + // "return;".Method("Member3") + + // "return;".Method("Member4") + + // "return;".Method("Member5") + + // "return;".Method("Member6") + + // "return;".Method("Member7") + + // "var x = 10; return;".Method("Member2") + + // "return;".Method("Member8") + // ).WrapWithClass().Parse(); // var diff3Result = Diff3.Compare(original, changed1, changed2); // //Conflict captures method that was both removed and edited