From 24ffc48dbae593c2e74892fc606314ea67b5e301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Kr=C3=BCger?= Date: Sun, 24 Feb 2013 08:14:00 +0100 Subject: [PATCH] Fixed EventDeclaration colors. --- .../Analysis/SemanticHighlightingVisitor.cs | 2 + .../Analysis/SemanticHighlightingTests.cs | 121 +++++++++++++++--- 2 files changed, 107 insertions(+), 16 deletions(-) diff --git a/ICSharpCode.NRefactory.CSharp/Analysis/SemanticHighlightingVisitor.cs b/ICSharpCode.NRefactory.CSharp/Analysis/SemanticHighlightingVisitor.cs index b43eafb691..58ce400d61 100644 --- a/ICSharpCode.NRefactory.CSharp/Analysis/SemanticHighlightingVisitor.cs +++ b/ICSharpCode.NRefactory.CSharp/Analysis/SemanticHighlightingVisitor.cs @@ -561,6 +561,8 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis VisitChildrenUntil(variableInitializer, nameToken); if (variableInitializer.Parent is FieldDeclaration) { Colorize(nameToken, fieldDeclarationColor); + } else if (variableInitializer.Parent is EventDeclaration) { + Colorize(nameToken, eventDeclarationColor); } else { Colorize(nameToken, variableDeclarationColor); } diff --git a/ICSharpCode.NRefactory.Tests/CSharp/Analysis/SemanticHighlightingTests.cs b/ICSharpCode.NRefactory.Tests/CSharp/Analysis/SemanticHighlightingTests.cs index 55a7328369..9ef7d783b1 100644 --- a/ICSharpCode.NRefactory.Tests/CSharp/Analysis/SemanticHighlightingTests.cs +++ b/ICSharpCode.NRefactory.Tests/CSharp/Analysis/SemanticHighlightingTests.cs @@ -35,20 +35,36 @@ using ICSharpCode.NRefactory.Editor; namespace ICSharpCode.NRefactory.CSharp.Analysis { [TestFixture] - public class SemanticHighlightingTests + public class SemanticHighlightingTests : SemanticHighlightingVisitor { + static void SetupColors(object o) + { + var fields = typeof(SemanticHighlightingVisitor).GetFields(BindingFlags.NonPublic | BindingFlags.Instance); + foreach (var field in fields) { + if (field.FieldType == typeof(FieldInfo)) + field.SetValue(o, field); + } + } + protected override void Colorize(TextLocation start, TextLocation end, FieldInfo color) + { + throw new NotImplementedException (); + } + + [SetUp] + public void Setup () + { + SetupColors (this); + } + class TestSemanticHighlightingVisitor : SemanticHighlightingVisitor { + public TestSemanticHighlightingVisitor(CSharpAstResolver resolver) { base.resolver = resolver; this.regionStart = new TextLocation (1, 1); this.regionEnd = new TextLocation (int.MaxValue, int.MaxValue); - var fields = typeof (TestSemanticHighlightingVisitor).GetFields (BindingFlags.NonPublic | BindingFlags.Instance); - foreach (var field in fields) { - if (field.FieldType == typeof (FieldInfo)) - field.SetValue (this, field); - } + SetupColors(this); } List> colors = new List> (); @@ -85,7 +101,7 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis return result; } - void TestColor(string text, string keywordColor) + void TestColor(string text, FieldInfo keywordColor) { var sb = new StringBuilder (); var offsets = new List (); @@ -102,24 +118,96 @@ namespace ICSharpCode.NRefactory.CSharp.Analysis foreach (var offset in offsets) { var loc = doc.GetLocation (offset); var color = visitor.GetColor (loc); - Assert.AreEqual (keywordColor, color, "Color at " + loc + " is wrong:" + color); + Assert.AreEqual (keywordColor.Name, color, "Color at " + loc + " is wrong:" + color); } } [Test] - public void TestValueInPropertySetter() + public void TestClassDeclaration() + { + TestColor (@"class $Class { }", referenceTypeColor); + } + + [Test] + public void TestStructDeclaration() + { + TestColor (@"struct $Class { }", valueTypeColor); + } + + [Test] + public void TestInterfaceDeclaration() + { + TestColor (@"interface $Class { }", interfaceTypeColor); + } + + [Test] + public void TestEnumDeclaration() + { + TestColor (@"enum $Class { }", enumerationTypeColor); + } + + [Test] + public void TestDelegateDeclaration() + { + TestColor (@"delegate void $Class();", delegateTypeColor); + } + + [Test] + public void TestMethodDeclaration() { - TestColor (@"class Class { int Property { get {} set { test = $value; } } }", "valueKeywordColor"); + TestColor (@"class Class { void $Foo () {} }", methodDeclarationColor); } [Test] - public void TestValueInPropertyGetter() + public void TestFieldDeclaration() { - TestColor (@"class Class { int value; int Property { get { return $value; } set { } } }", "fieldAccessColor"); + TestColor (@"class Class { int $foo; }", fieldDeclarationColor); } [Test] - public void TestValueInCustomEvent() + public void TestPropertyDeclaration() + { + TestColor (@"class Class { int $Foo { get; set; } }", propertyDeclarationColor); + } + + [Test] + public void TestEventDeclaration() + { + TestColor (@"class Class { event System.EventHandler $Foo, $Bar; }", eventDeclarationColor); + } + + [Test] + public void TestCustomEventDeclaration() + { + TestColor (@"class Class { event System.EventHandler $Foo { add {} remove {} } }", eventDeclarationColor); + } + + [Test] + public void TestMethodParameterDeclaration() + { + TestColor (@"class Class { void Foo (int $a, string $b) {} }", parameterDeclarationColor); + } + + [Test] + public void TestIndexerParameterDeclaration() + { + TestColor (@"class Class { int this[int $a, string $b] { get { } } }", parameterDeclarationColor); + } + + [Test] + public void TestValueKeywordInPropertySetter() + { + TestColor (@"class Class { int Property { get {} set { test = $value; } } }", valueKeywordColor); + } + + [Test] + public void TestValueKeywordInPropertyGetter() + { + TestColor (@"class Class { int value; int Property { get { return $value; } set { } } }", fieldAccessColor); + } + + [Test] + public void TestValueKeywordInCustomEvent() { TestColor (@"using System; class Class { @@ -127,14 +215,15 @@ class Class { add { Console.WriteLine ($value); } remove { Console.WriteLine ($value); } } -}", "valueKeywordColor"); +}", valueKeywordColor); } [Test] - public void TestExternAliasColor() + public void TestExternAliasKeyword() { - TestColor (@"extern $alias FooBar;", "externAliasKeywordColor"); + TestColor (@"extern $alias FooBar;", externAliasKeywordColor); } + } }