Skip to content

Commit

Permalink
Merge pull request #34 from semdiffdotnet/error-messages
Browse files Browse the repository at this point in the history
Set up dummy error messages
  • Loading branch information
shawn-fontaine committed Feb 12, 2016
2 parents 5b905ac + f8c1ac1 commit 488e158
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 11 deletions.
43 changes: 36 additions & 7 deletions SemDiff.Core/Diagnostics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading;

namespace SemDiff.Core
{
Expand All @@ -10,25 +11,53 @@ namespace SemDiff.Core
/// </summary>
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);

/// <summary>
/// The Diagnostics we support, provided for the SupportedDiagnostics property of DiagnosticAnalyzer
/// </summary>
public static ImmutableArray<DiagnosticDescriptor> Supported { get; internal set; }
public static ImmutableArray<DiagnosticDescriptor> Supported { get; } = ImmutableArray.Create(FalsePositive, FalseNegative);

/// <summary>
/// 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
/// </summary>
public static void Report(IEnumerable<DetectedFalsePositive> fps, Action<Diagnostic> reporter)
public static void Report(IEnumerable<DetectedFalseNegative> fps, Action<Diagnostic> 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"));
}

/// <summary>
/// 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
/// </summary>
public static void Report(IEnumerable<DetectedFalseNegative> fps, Action<Diagnostic> reporter)
public static void Report(IEnumerable<DetectedFalsePositive> fps, Action<Diagnostic> 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"));
}
}
}
4 changes: 2 additions & 2 deletions SemDiff.Core/SemDiffAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
75 changes: 73 additions & 2 deletions SemDiff.Test/Diff3Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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() +
Expand All @@ -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() +
Expand All @@ -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() +
Expand All @@ -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
Expand Down

0 comments on commit 488e158

Please sign in to comment.