Browse Source

Move some types to the new folder structure.

newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
e2c38c531e
  1. 109
      TODOnewNR.txt
  2. 4
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingStrategy.cs
  3. 0
      src/Main/Base/Project/Editor/DocumentServiceAttribute.cs
  4. 2
      src/Main/Base/Project/Editor/HighlighterKnownSpanNames.cs
  5. 0
      src/Main/Base/Project/Editor/IEditorControlService.cs
  6. 0
      src/Main/Base/Project/Editor/IEditorUIService.cs
  7. 0
      src/Main/Base/Project/Editor/IFileDocumentProvider.cs
  8. 0
      src/Main/Base/Project/Editor/ITextEditor.cs
  9. 0
      src/Main/Base/Project/Editor/ITextMarker.cs
  10. 15
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  11. 58
      src/Main/Base/Project/Src/Editor/AddInHighlightingResource.cs
  12. 39
      src/Main/Base/Project/Src/Util/ExtensionMethods.cs
  13. 68
      src/Main/Base/Project/Src/Util/ReactiveExtensions.cs
  14. 163
      src/Main/Base/Test/Highlighting/AddInHighlightingResourceTests.cs
  15. 1
      src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj

109
TODOnewNR.txt

@ -25,13 +25,27 @@ Stuff that was renamed/moved: @@ -25,13 +25,27 @@ Stuff that was renamed/moved:
ICSharpCode.SharpDevelop.Dom -> the type system and resolvers now are part of ICSharpCode.NRefactory
IDocument -> moved to ICSharpCode.NRefactory.Editor
IClass -> ITypeDefinition
ISyntaxTree -> IUnresolvedFile
ICompilationUnit -> IUnresolvedFile
ITextBuffer -> ITextSource (in ICSharpCode.NRefactory.Editor)
IReturnType -> ITypeReference (unresolved) or IType (resolved)
Location -> TextLocation in ICSharpCode.NRefactory
TextLocation -> moved to ICSharpCode.NRefactory
Functionality changes:
SharpDevelop.Dom was replaced by NRefactory 5:
Apart from plenty of API changes, there are also a couple of architectural changes
to look out for.
Most importantly, the type system has been split up into an unresolved and a resolved
version. When porting code using SD.Dom, be careful which one of the two you choose.
If possible, try to avoid using the unresolved type system. The planned observable code model
(will be implemented for the 5.0 class browser) might be a better alternative in some cases.
Features related to the type system / refactorings should probably wait for this code model
before they are ported to 5.0.
NRefactory 5 introduction: http://www.codeproject.com/Articles/408663/Using-NRefactory-for-analyzing-Csharp-code
Static services replaced with interfaces:
To make writing unit tests easier, the static services in SharpDevelop are getting
@ -39,7 +53,7 @@ Functionality changes: @@ -39,7 +53,7 @@ Functionality changes:
to the services, so the call "ResourceService.GetString()" becomes "SD.ResourceService.GetString()".
In unit tests, Rhino.Mocks can be used to easily create mocks of the services:
SD.InitializeForUnitTests(); // removes services from previous test cases
SD.InitializeForUnitTests(); // initialize container and remove services from previous test cases
SD.Services.AddService(typeof(IParserService), MockRepository.GenerateStrictMock<IParserService>());
SD.ParserService.Stub(p => p.GetCachedParseInformation(textEditor.FileName)).Return(parseInfo);
SD.ParserService.Stub(p => p.GetCompilationForFile(textEditor.FileName)).Return(compilation);
@ -52,6 +66,30 @@ Functionality changes: @@ -52,6 +66,30 @@ Functionality changes:
and have the implementation details in SharpDevelop.exe (which AddIns aren't supposed to reference).
ICSharpCode.Core.WinForms hidden behind service interfaces:
This is an extension of the previous point.
The whole assembly ICSharpCode.Core.WinForms still exists and has the old static services,
which makes porting old AddIns a bit easier.
However, it should no longer be used in new code and AddIns should get rid of the reference
to ICSharpCode.Core.WinForms if possible.
The services in SD.WinForms provide the same functionality.
Namespaces in ICSharpCode.SharpDevelop reorganized:
I'm currently moving types around in ICSharpCode.SharpDevelop, so you'll have to update
plenty of usings.
The idea behind the new namespaces is that grouping the code into 'Gui' and 'Services'
isn't very useful; so I'm getting rid of those namespaces and the old folder structure,
and re-group the types into feature areas.
Within the ICSharpCode.SharpDevelop project, the 'Src' folder contains the old code
that hasn't been cleaned up yet and may still be in an old namespace.
When I'm done cleaning up a code file, I'm moving to out of the 'Src' folder into one of
the new folders corresponding to the new namespace.
As part of this cleanup, I'm also replacing static services with service interfaces (see above).
SD.MainThread:
The new best way to invoke a call on the main thread is:
SD.MainThread.InvokeAsync(delegate { ... }).FireAndForget();
@ -60,6 +98,17 @@ Functionality changes: @@ -60,6 +98,17 @@ Functionality changes:
executing the delegate, they will get stored in the task object. This can cause the exception to get
silently ignored if the task object isn't used later. The "FireAndForget()" extension method solves
this problem by reporting any (future) errors to the message service.
It is also often possible to avoid explicit thread switches alltogether by using the C# 5 async/await feature.
ICSharpCode.Core.ICommand replaced with WPF ICommand
New menu commands should derive from 'SimpleCommand' instead of 'AbstractMenuCommand'.
If 'IsEnabled'-handling is required, new commands should just implement ICommand directly without using any base class.
The old class AbstractMenuCommand still exist and simulates the old API, which makes porting AddIns a bit easier.
I'm thinking about writing a tool that automatically ports AbstractMenuCommand-derived classes to SimpleCommand,
so you don't need to bother updating your commands manually.
SD.PropertyService:
@ -71,6 +120,10 @@ Functionality changes: @@ -71,6 +120,10 @@ Functionality changes:
However, a nested properties container still is connected with its parent, and any changes done
to the nested container will get saves without having to call the SetNestedProperties() method.
The property service now uses XAML serialization instead of XML serialization. This might require
some changes to your classes to ensure they get serialized correctly, for example
you need to use public properties instead of public fields.
SD.ParserService:
@ -81,6 +134,58 @@ Functionality changes: @@ -81,6 +134,58 @@ Functionality changes:
The IUnresolvedFile is stored permanently (both in ParserService and in the IProjectContents).
Text editor and document services:
In SharpDevelop 4.x it was possible to use IDocument.GetService(typeof(ITextEditor)) to find the
editor that presents the document.
This is no longer possible in SharpDevelop 5, as the same IDocument may be used by
multiple editors (e.g. split view).
ITextEditor and IDocument now use separate service containers.
ITextEditor.GetService() will also return document services, but not the other way around.
The attributes [DocumentService] and [TextEditorService] are used to mark the service interfaces
that are available in the document and in the editor respectively.
The attributes exist purely for documentation, and some services may not use them
(for example the service interfaces defined in AvalonEdit, where the attributes aren't referenced).
View content services:
Instead of casting a view content to an interface "var x = viewContent as IEditable;",
code should use the viewContent.GetService() method.
This allows the view content implementation to be flexible where the interface is implemented,
it no longer is necessary to implement everything in the same class.
Interfaces that are supposed to be used as view content services are marked with the
[ViewContentService] attribute.
In the case of the AvalonEditViewContent, all text editor and document services are
also available via IViewContent.GetService().
If split view is in use, the view content will return the services from the editor that has the focus.
XML Forms:
Classic .xfrm still exists and can be used in SD 5.0.
However XML forms support should be considered a temporary feature for making AddIns easier to port,
we still plan to get rid of all .xfrms and the associated infrastructure by the time SD 5.0 ships.
Simply porting an .xfrm to a regular WinForms control with InitializeComponents() is acceptable,
but porting it to WPF is preferred.
What wasn't changed:
SD-1234 still makes implementing view contents difficult by preventing them from loading/saving
files when they want to. I'd like to fix this, but this likely won't fit into 5.0 and will have to wait for 5.1.
The IProject/ProjectItem model is mostly unchanged and still does not provide proper change notifications
(apart from those in the static ProjectService).
Lacking a good project model, we also haven't started moving the project browser to WPF.
This is a major refactoring on top of the already existing major changes in 5.0, so it doesn't fit.
But it's definitely a goal for 5.1.
Context Actions vs. Member Context Menu:
Members context menu should include refactoring options that can be applied from the outside,
for example in the classes pad when the code file isn't open.

4
src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingStrategy.cs

@ -347,8 +347,8 @@ namespace CSharpBinding.FormattingStrategy @@ -347,8 +347,8 @@ namespace CSharpBinding.FormattingStrategy
bool isInMultilineString = false;
if (highlighter != null && lineAbove != null) {
var spanStack = highlighter.GetColorStack(lineNr).Select(c => c.Name).ToArray();
isInMultilineComment = spanStack.Contains(SyntaxHighlighterKnownSpanNames.Comment);
isInMultilineString = spanStack.Contains(SyntaxHighlighterKnownSpanNames.String);
isInMultilineComment = spanStack.Contains(HighlighterKnownSpanNames.Comment);
isInMultilineString = spanStack.Contains(HighlighterKnownSpanNames.String);
}
bool isInNormalCode = !(isInMultilineComment || isInMultilineString);

0
src/Main/Base/Project/Src/Editor/DocumentServiceAttribute.cs → src/Main/Base/Project/Editor/DocumentServiceAttribute.cs

2
src/Main/Base/Project/Src/Editor/SyntaxHighlighterKnownSpanNames.cs → src/Main/Base/Project/Editor/HighlighterKnownSpanNames.cs

@ -9,7 +9,7 @@ using ICSharpCode.NRefactory.Editor; @@ -9,7 +9,7 @@ using ICSharpCode.NRefactory.Editor;
namespace ICSharpCode.SharpDevelop.Editor
{
public static class SyntaxHighlighterKnownSpanNames
public static class HighlighterKnownSpanNames
{
public const string Comment = "Comment";
public const string String = "String";

0
src/Main/Base/Project/Src/Editor/IEditorControlService.cs → src/Main/Base/Project/Editor/IEditorControlService.cs

0
src/Main/Base/Project/Src/Editor/IEditorUIService.cs → src/Main/Base/Project/Editor/IEditorUIService.cs

0
src/Main/Base/Project/Src/Editor/IFileDocumentProvider.cs → src/Main/Base/Project/Editor/IFileDocumentProvider.cs

0
src/Main/Base/Project/Src/Editor/ITextEditor.cs → src/Main/Base/Project/Editor/ITextEditor.cs

0
src/Main/Base/Project/Src/Editor/ITextMarker.cs → src/Main/Base/Project/Editor/ITextMarker.cs

15
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -97,11 +97,17 @@ @@ -97,11 +97,17 @@
</Compile>
<Compile Include="Dom\IModelCollection.cs" />
<Compile Include="Dom\ITreeNodeFactory.cs" />
<Compile Include="Editor\DocumentServiceAttribute.cs" />
<Compile Include="Editor\IEditorControlService.cs" />
<Compile Include="Editor\IEditorUIService.cs" />
<Compile Include="Editor\IFileDocumentProvider.cs" />
<Compile Include="Editor\ITextEditor.cs" />
<Compile Include="Editor\ITextMarker.cs" />
<Compile Include="Editor\OnDiskTextSourceVersion.cs" />
<Compile Include="Editor\HighlighterKnownSpanNames.cs" />
<Compile Include="Src\Gui\FileService.cs" />
<Compile Include="Src\Commands\SharpDevelopRoutedCommands.cs" />
<Compile Include="Src\Commands\ViewInBrowser.cs" />
<Compile Include="Src\Editor\AddInHighlightingResource.cs" />
<Compile Include="Src\Editor\AvalonEdit\AvalonEditTextEditorAdapter.cs" />
<Compile Include="Src\Editor\AvalonEdit\IndentationStrategyAdapter.cs" />
<Compile Include="Src\Editor\AvalonEdit\ISnippetElementProvider.cs" />
@ -117,10 +123,7 @@ @@ -117,10 +123,7 @@
<Compile Include="Src\Editor\Commands\FindReferencesCommand.cs" />
<Compile Include="Src\Editor\Commands\GotoLineNumber.cs" />
<Compile Include="Src\Editor\Commands\SymbolUnderCaretMenuCommand.cs" />
<Compile Include="Src\Editor\DocumentServiceAttribute.cs" />
<Compile Include="Src\Editor\IDocumentBaseVersionProvider.cs" />
<Compile Include="Src\Editor\IEditorControlService.cs" />
<Compile Include="Src\Editor\IEditorUIService.cs" />
<Compile Include="Src\Editor\CodeCompletion\AttributesItemProvider.cs" />
<Compile Include="Src\Editor\CodeCompletion\CodeCompletionBinding.cs" />
<Compile Include="Src\Editor\CodeCompletion\CodeCompletionDataUsageCache.cs" />
@ -152,15 +155,11 @@ @@ -152,15 +155,11 @@
<Compile Include="Src\Editor\Commands\ShowColorDialog.cs" />
<Compile Include="Src\Editor\DocumentUtilitites.cs" />
<Compile Include="Src\Editor\IBracketSearcher.cs" />
<Compile Include="Src\Editor\IFileDocumentProvider.cs" />
<Compile Include="Src\Editor\IFormattingStrategy.cs" />
<Compile Include="Src\Editor\PermanentAnchor.cs" />
<Compile Include="Src\Editor\SyntaxHighlighterKnownSpanNames.cs" />
<Compile Include="Src\Editor\ITextAreaToolTipProvider.cs">
<DependentUpon>ToolTipService.cs</DependentUpon>
</Compile>
<Compile Include="Src\Editor\ITextEditor.cs" />
<Compile Include="Src\Editor\ITextMarker.cs" />
<Compile Include="Src\Editor\ITooltip.cs">
<DependentUpon>ToolTipService.cs</DependentUpon>
</Compile>

58
src/Main/Base/Project/Src/Editor/AddInHighlightingResource.cs

@ -1,58 +0,0 @@ @@ -1,58 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.IO;
using System.Reflection;
using System.Xml;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.Editor
{
public class AddInHighlightingResource
{
Runtime[] runtimes;
public AddInHighlightingResource(Runtime[] runtimes)
{
this.runtimes = runtimes;
}
public Stream OpenStream(string name)
{
foreach (Runtime runtime in runtimes) {
Assembly assembly = runtime.LoadedAssembly;
if (assembly != null) {
Stream stream = assembly.GetManifestResourceStream(name);
if (stream != null) {
return stream;
}
}
}
ThrowFileNotFoundException(name);
return null;
}
void ThrowFileNotFoundException(string name)
{
string message = String.Format("The resource file '{0}' was not found.", name);
throw new FileNotFoundException(message);
}
public IHighlightingDefinition LoadHighlighting(string name, IHighlightingDefinitionReferenceResolver resolver)
{
if (resolver == null) {
throw new ArgumentNullException("resolver");
}
using (Stream stream = OpenStream(name)) {
using (XmlTextReader reader = new XmlTextReader(stream)) {
return HighlightingLoader.Load(reader, resolver);
}
}
}
}
}

39
src/Main/Base/Project/Src/Util/ExtensionMethods.cs

@ -2,7 +2,6 @@ @@ -2,7 +2,6 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
@ -11,10 +10,10 @@ using System.Text; @@ -11,10 +10,10 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Media;
using System.Xml;
using System.Xml.Linq;
using ICSharpCode.Core;
using ICSharpCode.Core.Presentation;
using ICSharpCode.NRefactory;
@ -22,7 +21,6 @@ using ICSharpCode.NRefactory.Editor; @@ -22,7 +21,6 @@ using ICSharpCode.NRefactory.Editor;
using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.Utils;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Parser;
using ICSharpCode.SharpDevelop.Project;
@ -369,40 +367,7 @@ namespace ICSharpCode.SharpDevelop @@ -369,40 +367,7 @@ namespace ICSharpCode.SharpDevelop
return AmbienceService.GetCurrentAmbience();
}
#endregion
#region WPF SetContent
/*
/// <summary>
/// Sets the Content property of the specified ControlControl to the specified content.
/// If the content is a Windows-Forms control, it is wrapped in a WindowsFormsHost.
/// If the content control already contains a WindowsFormsHost with that content,
/// the old WindowsFormsHost is kept.
/// When a WindowsFormsHost is replaced with another content, the host is disposed (but the control
/// inside the host isn't)
/// </summary>
public static void SetContent(this ContentControl contentControl, object content)
{
SetContent(contentControl, content, null);
}
public static void SetContent(this ContentPresenter contentControl, object content)
{
SetContent(contentControl, content, null);
}
public static void SetContent(this ContentControl contentControl, object content, object serviceObject)
{
}
public static void SetContent(this ContentPresenter contentControl, object content, object serviceObject)
{
}
*/
#endregion
#region DPI independence
public static Rect TransformToDevice(this Rect rect, Visual visual)
{

68
src/Main/Base/Project/Src/Util/ReactiveExtensions.cs

@ -16,19 +16,33 @@ namespace ICSharpCode.SharpDevelop @@ -16,19 +16,33 @@ namespace ICSharpCode.SharpDevelop
/// </summary>
public static class ReactiveExtensions
{
#region ObserveOnUIThread
public static IObservable<T> ObserveOnUIThread<T>(this IObservable<T> source)
{
return new AnonymousObservable<T>(
observer => source.Subscribe(
new AnonymousObserver<T>(
value => WorkbenchSingleton.SafeThreadAsyncCall(delegate { observer.OnNext(value); }),
exception => WorkbenchSingleton.SafeThreadAsyncCall(delegate { observer.OnError(exception); }),
() => WorkbenchSingleton.SafeThreadAsyncCall(delegate { observer.OnCompleted(); })
)
)
);
return new UIThreadObservable<T>(source, SD.MainThread.SynchronizationContext);
}
class UIThreadObservable<T> : IObservable<T>
{
readonly IObservable<T> source;
readonly SynchronizationContext synchronizationContext;
public UIThreadObservable(IObservable<T> source, SynchronizationContext synchronizationContext)
{
this.source = source;
this.synchronizationContext = synchronizationContext;
}
public IDisposable Subscribe(IObserver<T> observer)
{
return source.Subscribe(value => synchronizationContext.Post(state => observer.OnNext((T)state), value),
ex => synchronizationContext.Post(state => observer.OnError((Exception)state), ex),
() => synchronizationContext.Post(state => observer.OnCompleted(), null));
}
}
#endregion
#region Create Observable from Task + Callback Delegate
public static IObservable<T> CreateObservable<T>(Func<CancellationToken, Action<T>, Task> func)
{
return new AnonymousObservable<T>(observer => new TaskToObserverSubscription<T>(func, observer));
@ -85,29 +99,36 @@ namespace ICSharpCode.SharpDevelop @@ -85,29 +99,36 @@ namespace ICSharpCode.SharpDevelop
cts.Cancel();
}
}
#endregion
public static IDisposable Subscribe<T>(this IObservable<T> source, Action<T> onNext, Action<Exception> onError, Action onCompleted)
#region ToListAsync
/// <summary>
/// Converts the observable into a List.
/// </summary>
public static async Task<List<T>> ToListAsync<T>(this IObservable<T> source, CancellationToken cancellationToken)
{
return source.Subscribe(new AnonymousObserver<T>(onNext, onError, onCompleted));
var tcs = new TaskCompletionSource<List<T>>();
List<T> results = new List<T>();
using (source.Subscribe(item => results.Add(item),
exception => tcs.TrySetException(exception),
() => tcs.TrySetResult(results)))
{
using (cancellationToken.Register(() => tcs.SetCanceled())) {
return await tcs.Task.ConfigureAwait(false);
}
}
}
#endregion
public static List<T> ToList<T>(this IObservable<T> source, CancellationToken cancellationToken)
#region AnonymousObserver
public static IDisposable Subscribe<T>(this IObservable<T> source, Action<T> onNext, Action<Exception> onError, Action onCompleted)
{
List<T> results = new List<T>();
ManualResetEventSlim ev = new ManualResetEventSlim();
ExceptionDispatchInfo error = null;
using (source.Subscribe(item => results.Add(item),
exception => { error = ExceptionDispatchInfo.Capture(exception); ev.Set(); },
() => ev.Set()))
ev.Wait(cancellationToken);
if (error != null)
error.Throw();
return results;
return source.Subscribe(new AnonymousObserver<T>(onNext, onError, onCompleted));
}
class AnonymousObservable<T> : IObservable<T>
{
Func<IObserver<T>, IDisposable> subscribe;
readonly Func<IObserver<T>, IDisposable> subscribe;
public AnonymousObservable(Func<IObserver<T>, IDisposable> subscribe)
{
@ -154,5 +175,6 @@ namespace ICSharpCode.SharpDevelop @@ -154,5 +175,6 @@ namespace ICSharpCode.SharpDevelop
onCompleted();
}
}
#endregion
}
}

163
src/Main/Base/Test/Highlighting/AddInHighlightingResourceTests.cs

@ -1,163 +0,0 @@ @@ -1,163 +0,0 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.AvalonEdit.Highlighting.Xshd;
using ICSharpCode.Core;
using ICSharpCode.Core.Tests.Utils;
using ICSharpCode.SharpDevelop.Editor;
using ICSharpCode.SharpDevelop.Tests.Utils;
using NUnit.Framework;
using Rhino.Mocks;
namespace ICSharpCode.SharpDevelop.Tests.Highlighting
{
[TestFixture]
public class AddInHighlightingResourceTests
{
AddInHighlightingResource highlightingResource;
Stream predefinedManifestResourceStream;
MockAssembly assembly;
DerivedRuntime testRuntime;
DerivedRuntime unloadedRuntime;
[SetUp]
public void Init()
{
// Create assembly.
byte[] bytes = UnicodeEncoding.UTF8.GetBytesWithPreamble(GetHighlightingDefinitionXml());
predefinedManifestResourceStream = new MemoryStream(bytes);
assembly = new MockAssembly();
assembly.AddManifestResourceStream("ICSharpCode.Xml.xshd", predefinedManifestResourceStream);
// Create addins.
IAddInTree addInTree = MockRepository.GenerateStrictMock<IAddInTree>();
AddIn addIn = AddIn.Load(addInTree, new StringReader(GetAddInXml()));
addIn.FileName = @"D:\SharpDevelop\AddIns\MyAddIn.addin";
addIn.Enabled = true;
// Create runtimes.
testRuntime = new DerivedRuntime(addInTree, "MyAddIn.dll", String.Empty);
testRuntime.AssemblyFileNames.Add("MyAddIn.dll", assembly);
unloadedRuntime = new DerivedRuntime(addInTree, "UnLoadedAssembly.dll", String.Empty);
unloadedRuntime.AssemblyFileNames.Add("UnLoadedAssembly.dll", null);
unloadedRuntime.LoadAssemblyFromExceptionToThrow = new FileNotFoundException("UnloadedAssembly.dll not found.");
List<Runtime> runtimes = new List<Runtime>();
runtimes.Add(testRuntime);
runtimes.Add(unloadedRuntime);
// Create addin highlighting resource.
highlightingResource = new AddInHighlightingResource(runtimes.ToArray());
}
string GetHighlightingDefinitionXml()
{
return
"<SyntaxDefinition name = \"BAT\" extensions = \".bat\">\r\n" +
" <Environment>\r\n" +
" <Default color = \"Yellow\" bgcolor = \"Black\"/>\r\n" +
" <Selection color = \"White\" bgcolor = \"Purple\"/>\r\n" +
" <InvalidLines color = \"Red\"/>\r\n" +
" <LineNumbers color = \"Gray\" bgcolor = \"Black\"/>\r\n" +
" <SelectedFoldLine color = \"Green\" bgcolor=\"Black\"/>\r\n" +
" </Environment>\r\n" +
"\r\n" +
" <Digits name = \"Digits\" bold = \"false\" italic = \"false\" color = \"Yellow\"/>\r\n" +
"\r\n" +
" <RuleSets>\r\n" +
" <RuleSet ignorecase = \"false\">\r\n" +
" <Delimiters> </Delimiters>\r\n" +
" </RuleSet>\r\n" +
" </RuleSets>\r\n" +
"</SyntaxDefinition>";
}
string GetAddInXml()
{
return
"<AddIn name = \"My AddIn\"\r\n" +
" author = \"\"\r\n" +
" copyright = \"prj:///doc/copyright.txt\"\r\n" +
" description = \"\"\r\n" +
" addInManagerHidden = \"preinstalled\">\r\n" +
"\r\n" +
" <Manifest>\r\n" +
" <Identity name = \"ICSharpCode.MyAddIn\"/>\r\n" +
" </Manifest>\r\n" +
"\r\n" +
" <Runtime>\r\n" +
" <Import assembly = \":ICSharpCode.SharpDevelop\"/>\r\n" +
" <Import assembly = \"UnLoadedAssembly.dll\"/>\r\n" +
" <Import assembly = \"MyAddIn.dll\"/>\r\n" +
" </Runtime>\r\n" +
"</AddIn>";
}
[TearDown]
public void TearDown()
{
predefinedManifestResourceStream.Dispose();
}
[Test]
public void OpenStreamThrowsFileNotFoundExceptionForUnknownManifestResourceName()
{
string expectedMessage = "The resource file 'Unknown' was not found.";
FileNotFoundException ex =
Assert.Throws<FileNotFoundException>(delegate { highlightingResource.OpenStream("Unknown"); });
Assert.AreEqual(expectedMessage, ex.Message);
}
[Test]
public void OpenStreamReturnsAssemblyManifestResourceStreamForKnownManifestResourceName()
{
Stream stream = highlightingResource.OpenStream("ICSharpCode.Xml.xshd");
Assert.AreSame(predefinedManifestResourceStream, stream);
}
[Test]
public void MockAssemblyReturnedFromMyAddInRuntime()
{
Assert.IsInstanceOf(typeof(MockAssembly), testRuntime.LoadedAssembly);
}
[Test]
public void UnloadedRunTimeReturnsNullFromLoadedAssembly()
{
Assert.IsNull(unloadedRuntime.LoadedAssembly);
}
[Test]
public void HighlightingDefinitionCanBeLoadedFromXmlViaMemoryStream()
{
using (XmlTextReader reader = new XmlTextReader(predefinedManifestResourceStream)) {
XshdSyntaxDefinition xshd = HighlightingLoader.LoadXshd(reader);
Assert.AreEqual("BAT", xshd.Name);
}
}
[Test]
public void HighlightingDefinitionReturnedFromLoadHighlightingMethod()
{
HighlightingManager manager = new HighlightingManager();
IHighlightingDefinition highlighting = highlightingResource.LoadHighlighting("ICSharpCode.Xml.xshd", manager);
Assert.AreEqual("BAT", highlighting.Name);
}
[Test]
public void LoadHighlightingThrowsArgumentNullExceptionIfResolverParameterIsNull()
{
ArgumentNullException ex =
Assert.Throws<ArgumentNullException>(
delegate { highlightingResource.LoadHighlighting("ICSharpCode.Xml.xshd", null); });
Assert.AreEqual("resolver", ex.ParamName);
}
}
}

1
src/Main/Base/Test/ICSharpCode.SharpDevelop.Tests.csproj

@ -82,7 +82,6 @@ @@ -82,7 +82,6 @@
<Compile Include="ExceptionClassOverridesTestFixture.cs" />
<Compile Include="GenerateOverrideMethodTests.cs" />
<Compile Include="GetElementByReflectionNameTests.cs" />
<Compile Include="Highlighting\AddInHighlightingResourceTests.cs" />
<Compile Include="Highlighting\SyntaxDoozerAddsHighlightingToHighlightingManagerTestFixture.cs" />
<Compile Include="MimeDetectionTests.cs" />
<Compile Include="CollectionClassOverridesTestFixture.cs" />

Loading…
Cancel
Save