mirror of https://github.com/icsharpcode/ILSpy.git
Browse Source
9675caf ReadOnlyDocument: rename textBuffer->textSource 97d0964 Fixed GetDelegateInvokeMethod() for parameterized types. Fixed copy constructor of DefaultMethod. Fixed handling of "class" constraint in CecilLoader. 42d4d7d fixed some bugs in use explicit type context action. 79b9582 Fixed failing attribute unit tests. 6fb0a90 Added error indicators for missing closing brackets. a11458e Worked on attribute resolving. Some tests fail because of wrongly loaded classes in my system. Daniel: Can you check the constructor attribute cases. I think something doesn't work in the Cecil loader on my system. I only get 1 empty constructor for LoaderOptimization & the name on my system is .ctor instead of #ctor. cf8a412 Use equals. 5c398f2 fixed return types of anonymous type properties. Re-used the var type reference for that. c458e06 Implemented anonymous types. 19653fa Added identifier token property. 96d1b7f fixed check. 1af72c9 GetResolveableNodeAt is now more selective. b74fe93 Set compiler errors to parsed file. b411a2a fixed possible null ref. 7e708a6 Worked on ast formatter tests. fa55d14 Fix adding assembly attributes to SimpleProjectContent. Fixed MemberLookup.IsInvocable(). Add (ignored) unit tests for user-defined binary operators. b368465 fixed bug. 99b60b8 Parser change: Interface members are now Accessibiliy.Public. This is a proposal to solve the <interfaceType>.<InferfaceMember>. ... lookup. dd4f73b Fixed bug in inner type result. 2c2f30d Fixed some issues in the context actions. b01c263 Implemented brace style formatting. aceae1f implemented type parameter getmember methods. 2b726d2 Fixed System.Void output. 67fff9f fixed bug in using statement parsing. ef0d911 Revert "Implemented user defined operator candidates." 9165dfe Implemented user defined operator candidates. 6199ee3 checked outer classes for aceessibility private check. 5fad5f9 Added time stamp to parsed files. 37dbafd fixed mcs bug. 0e1ad6e Started to implement a 'skip bodies' mode for parsing. 62d61ec Implemented GetResolveableNodeAt function. 26946f0 Added DeclarationRegion property to IVariable. 694f373 fix infinite loop. daf0f21 Fixed some bugs related to conversions of type parameters. 5ae4d60 Conversions: add support for user-defined implicit conversions. 7615720 ResolveVisitor: Handle type arguments on IdentifierExpression and MemberReferenceExpression. Add support for PointerReferenceExpression. 3435eec Add ResolveVisitor.GetResolverStateBefore(AstNode). 5b92717 Add GetMembers() to IType; add ParsedFiles to IProjectContent. c923833 Fix build errors. 1037d56 fixed some errors. 7fb7783 Make AbstractAnnotatable implement IAnnotatable. c9d4a5d Rename ITypeResolveContext extension methods to be consistent with the new names of the ITypeResolveContext methods. 350ebaa Fixed NullReferenceException in type inference when passing a "string[]" for a parameter of type "IEnumerable<T>". 823471e Make the end offset of SegmentExtensions.Contains inclusive. b40610d Simplify nested synchronization of CompositeTypeResolveContext. 991bea4 Added IsVerbatim property again. 484c586 Added easy accessible acceess members. a883a3d Added constructors that take an error location/added file header. 77d54ee added some constructors. e8153e0 reduced comment insertion time from O(m log n) to O (m). 44e796a Reduced the memory consumption of identifiers a bit by saving the 'isverbatim' bool. Note: Don't introduce that as virtual property, otherwise the memory saving is lost. 0afc1c6 Updated mcs / included code completion expression lookup. 33d588b Added the ability to specify parser arguments & provided a compiler callback (for getting pre processor directives etc). TODO: Move pre processor directives in the AST. 93b3ebf Implemented type system -> cecil object table. 6a85f0c Renamed GetClass-> GetTypeDefinition; abec118 fix build. c6aa05d Addded GetSubTypeDefinitions method. That's like a routine we had in the old MD dom - it's used for example for finding all exceptions in an assembly. b7fc89c added header. 0cb2388 Separated the annotations from the ast node & added annotations to the project content. af5e2c6 Added extension method GetMembers on IType. 7e29f61 Fix build (however formatting tests will fail). 9d21d1c Renamed GetClasses -> GetTypes. (GetClasess can give enums, structs & delegates too). 51f924f Renamed ITypeDefinition.InnerClasses -> NestedTypes (for more consistency with IType.GetNestedTypes 224f973 Revert "Moved class type to IType / added type parameter class type for type" ba335ed Moved class type to IType / added type parameter class type for type parameters. aa42b1b Added error storage to IParsedFile. bae8765 Added AstLocation Begin/End properties. 9bc76cf Added naive remove type definition. This won't work for partial types. bd4fb10 Added cenecllationtoken work around. Mono crashes on default cancellation token. 40147bc Changed CreateShortType implementation a bit. 1ae1b17 Added gettype/member extension methods that are working on a line/column pair. c744d2f Worked on the way nrefactory contexct actions use the resolver. 1836aa8 Merge branch 'master' of github.com:icsharpcode/NRefactory 1b7906a Worked on context actions. 94b4130 Add IParsedFile to type system. be5139a Added more context actions. 62988d6 Add TypeSystemAstBuilder: IType --> AstType conversion. 530cb0b mhutch: [NRefactory] Fix const modifier on fields 2b5569d use faster string comparer. 0f5f474 worked on context actions. c337048 added missing file. 6e1eaf1 Added monodevelop context actions. 3eb2e5d Added patch from mhutch: [NRefactory] Add some name token accessors 7070e47 corrected output of primitive expressions. Primitive expressions contain a literal value which should be preferred ("0x10" vs "16"). 13acde3 fix build. 8b606d1 Updated mcs/fixed unit test. string literal constants now contain the real 'literal'. b2d2678 Rename ITextBuffer -> ITextSource 3048d66 Added some proposals. 21fcd82 Add ISegment and ITextEditor interfaces. b4bcc80 Add ICSharpCode.Editor assembly. 0afdacd changed to HasModifier. 878dbbf Fixed some issues in resolver; enable resolver unit tests. d36805c fixed assembly attribute csharp test. 67d9bb5 Fixed attribute on method parameter tests. 3685f49 Fixed TypeSystemConvertVisitor for read-only properties. Added some attribute parser tests. 26986f9 Make sure NamespaceEntry.ClassCount stays consistent with the ordinal typeDict at all times, even when there are name clashes in one of the non-ordinal dictionaries. ddc55ad fixed variable declaration statement inside for loops wrong semicolon position. fca4dd0 Added GetTypes method in compilation unit. 0398fd6 Fixed 'GlobalAttributeCSharp' test. 9bcf087 Fixed EnumWithBaseType unit test. 390ed3a Fixed NestedArrays unit test. 1c51b3a Type storage: Fixed handling of namespaces that have sub-namespaces but do not directly contain classes. 07e2896 Make InsertParenthesesVisitorTests independent from indentation of the output. 73a9d8d Merge NRefactory changes from ILSpy. fb57f7d Fixed several issues in the type system convert visitor. a697f19 fixed unboundtypeofexpression test. 93117a1 Added MemberNameToken property. 7cd4526 Added some properties to allow easier access for modifiers. 014ecea Pass the parameter to the event handlers. 42717c9 fix missing method. 6144698 removed exception (shouldn't be in production code). 1365588 passed type parameters to the observable ast visitor. 7a5c7f3 fixed possible null reference exception. 6894e6a Primitive expressions now contain the literal value + updated mcs. 790585c Implemented invert condition function. 7f16970 Added token atrribute. 0648470 Fixed membertpe location. ba4a272 Implemented specific GetNodeAt method. 1feb0fc Added contains method. d4d9ffd Added observer visitor. f761813 Fixing switch section output + it's now possible to track node output in the output visitor. 79f1798 Put embedded statments onto next line. 478faf7 added name token property. d561ccf Merged some changes from monodevelop. 280b79b Fixed return type tokens 8578bad Added easy name token access. dfea089 added bounds check. 2fa40d8 Fixed special constraint expression parsing. eb6f6c1 Make ConvertChar and ConvertString public. b07228e Fixed issues with detection of using statements. a238bf1 When decompiling a field, also decompile constructors to check whether there's an initializer on the field. When decompiling a constructor, display field initializers outside of the constructor. Closes #3. 3974a80 remove isLastLine from interface - use stack instead; fix null reference if resolve of TypeDefinition fails 7738421 Fixed position of XML comments on nested types. 9a35ee4 Applied some of the optimizations suggested by Kris Vandermotten. #150 5997f81 add foldings to documentation comments; closes #165 fc86a67 Fixed relocation bug. 8fc4139 Fixed relocatable bug/removed some debug messages. 8237448 Renamed interface. 99b4726 fix https://github.com/icsharpcode/ILSpy/issues/177 450be5a Corrected locations for parset expressions/statments/type members. cb114b8 Fixed blank line formatting bug. e187185 Merge NRefactory subtree from commit '1e4a1d911cb430db2a4199695ee73dfd89bcc543' 4db670a Merge NRefactory b8330be into ILSpy f70f6a8 Add SaveIndex/LoadFromIndex methods to XmlDocumentationProvider. 4995f48 New XmlDocumentationProvider implementation: f3b9d11 When the last statement in a block is a label, add an EmptyStatement so that the generated code is valid. e68833d Add TestPlugin. b22b3ec C# OutputVisitor: improve indentation of query expressions 2ca7ec2 Fixed output of NamedArgumentExpression within object initializers. 43e33f8 Fixed InsertParenthesesVisitor for casts of negative primitive expressions. f3c52a0 Add OperatorDeclaration.GetOperatorType() helper method. 7cbab5e Merge NRefactory a92606c..56fde51 git-subtree-dir: NRefactory git-subtree-split: 9675caf1e9276391f17536b488148cb668a6cc44pull/297/head
225 changed files with 18537 additions and 8867 deletions
@ -0,0 +1,72 @@
@@ -0,0 +1,72 @@
|
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build"> |
||||
<PropertyGroup> |
||||
<ProjectGuid>{F054A788-B591-4561-A8BA-AE745BBEB817}</ProjectGuid> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">x86</Platform> |
||||
<OutputType>Library</OutputType> |
||||
<RootNamespace>ICSharpCode.Editor</RootNamespace> |
||||
<AssemblyName>ICSharpCode.Editor</AssemblyName> |
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> |
||||
<TargetFrameworkProfile>Client</TargetFrameworkProfile> |
||||
<AppDesignerFolder>Properties</AppDesignerFolder> |
||||
<SignAssembly>False</SignAssembly> |
||||
<DelaySign>False</DelaySign> |
||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent> |
||||
<DocumentationFile>bin\Debug\ICSharpCode.Editor.xml</DocumentationFile> |
||||
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> |
||||
<NoStdLib>False</NoStdLib> |
||||
<WarningLevel>4</WarningLevel> |
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> |
||||
<RunCodeAnalysis>False</RunCodeAnalysis> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Platform)' == 'x86' "> |
||||
<PlatformTarget>x86</PlatformTarget> |
||||
<RegisterForComInterop>False</RegisterForComInterop> |
||||
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies> |
||||
<BaseAddress>4194304</BaseAddress> |
||||
<FileAlignment>4096</FileAlignment> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' "> |
||||
<OutputPath>bin\Debug\</OutputPath> |
||||
<DebugSymbols>true</DebugSymbols> |
||||
<DebugType>Full</DebugType> |
||||
<Optimize>False</Optimize> |
||||
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> |
||||
<DefineConstants>DEBUG;TRACE</DefineConstants> |
||||
<StartAction>Project</StartAction> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' "> |
||||
<OutputPath>bin\Release\</OutputPath> |
||||
<DebugSymbols>False</DebugSymbols> |
||||
<DebugType>None</DebugType> |
||||
<Optimize>True</Optimize> |
||||
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow> |
||||
<DefineConstants>TRACE</DefineConstants> |
||||
</PropertyGroup> |
||||
<ItemGroup> |
||||
<Reference Include="System" /> |
||||
<Reference Include="System.Core"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
<Reference Include="System.Xml" /> |
||||
<Reference Include="System.Xml.Linq"> |
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework> |
||||
</Reference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="IDocument.cs" /> |
||||
<Compile Include="IDocumentLine.cs" /> |
||||
<Compile Include="ISegment.cs" /> |
||||
<Compile Include="ITextEditor.cs" /> |
||||
<Compile Include="ITextSource.cs" /> |
||||
<Compile Include="LinkedElement.cs" /> |
||||
<Compile Include="ReadOnlyDocument.cs" /> |
||||
<Compile Include="StringTextSource.cs" /> |
||||
<Compile Include="TextLocation.cs" /> |
||||
<Compile Include="ITextAnchor.cs" /> |
||||
<Compile Include="Properties\AssemblyInfo.cs" /> |
||||
<Compile Include="TextChangeEventArgs.cs" /> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" /> |
||||
</Project> |
@ -0,0 +1,141 @@
@@ -0,0 +1,141 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.Editor |
||||
{ |
||||
/// <summary>
|
||||
/// A document representing a source code file for refactoring.
|
||||
/// Line and column counting starts at 1.
|
||||
/// Offset counting starts at 0.
|
||||
/// </summary>
|
||||
public interface IDocument : ITextSource, IServiceProvider |
||||
{ |
||||
/// <summary>
|
||||
/// Gets/Sets the text of the whole document..
|
||||
/// </summary>
|
||||
new string Text { get; set; } // hides TextBuffer.Text to add the setter
|
||||
|
||||
/// <summary>
|
||||
/// Is raised when the Text property changes.
|
||||
/// </summary>
|
||||
event EventHandler TextChanged; |
||||
|
||||
/// <summary>
|
||||
/// Gets the total number of lines in the document.
|
||||
/// </summary>
|
||||
int TotalNumberOfLines { get; } |
||||
|
||||
/// <summary>
|
||||
/// Gets the document line with the specified number.
|
||||
/// </summary>
|
||||
/// <param name="lineNumber">The number of the line to retrieve. The first line has number 1.</param>
|
||||
IDocumentLine GetLine(int lineNumber); |
||||
|
||||
/// <summary>
|
||||
/// Gets the document line that contains the specified offset.
|
||||
/// </summary>
|
||||
IDocumentLine GetLineByOffset(int offset); |
||||
|
||||
/// <summary>
|
||||
/// Gets the offset from a text location.
|
||||
/// </summary>
|
||||
/// <seealso cref="GetLocation"/>
|
||||
int GetOffset(int line, int column); |
||||
|
||||
/// <summary>
|
||||
/// Gets the offset from a text location.
|
||||
/// </summary>
|
||||
/// <seealso cref="GetLocation"/>
|
||||
int GetOffset(TextLocation location); |
||||
|
||||
/// <summary>
|
||||
/// Gets the location from an offset.
|
||||
/// </summary>
|
||||
/// <seealso cref="GetOffset(TextLocation)"/>
|
||||
TextLocation GetLocation(int offset); |
||||
|
||||
/// <summary>
|
||||
/// Inserts text.
|
||||
/// </summary>
|
||||
/// <param name="offset">The offset at which the text is inserted.</param>
|
||||
/// <param name="text">The new text.</param>
|
||||
/// <remarks>
|
||||
/// Anchors positioned exactly at the insertion offset will move according to their movement type.
|
||||
/// For AnchorMovementType.Default, they will move behind the inserted text.
|
||||
/// The caret will also move behind the inserted text.
|
||||
/// </remarks>
|
||||
void Insert(int offset, string text); |
||||
|
||||
/// <summary>
|
||||
/// Inserts text.
|
||||
/// </summary>
|
||||
/// <param name="offset">The offset at which the text is inserted.</param>
|
||||
/// <param name="text">The new text.</param>
|
||||
/// <param name="defaultAnchorMovementType">
|
||||
/// Anchors positioned exactly at the insertion offset will move according to the anchor's movement type.
|
||||
/// For AnchorMovementType.Default, they will move according to the movement type specified by this parameter.
|
||||
/// The caret will also move according to the <paramref name="defaultAnchorMovementType"/> parameter.
|
||||
/// </param>
|
||||
void Insert(int offset, string text, AnchorMovementType defaultAnchorMovementType); |
||||
|
||||
/// <summary>
|
||||
/// Removes text.
|
||||
/// </summary>
|
||||
/// <param name="offset">Starting offset of the text to be removed.</param>
|
||||
/// <param name="length">Length of the text to be removed.</param>
|
||||
void Remove(int offset, int length); |
||||
|
||||
/// <summary>
|
||||
/// Replaces text.
|
||||
/// </summary>
|
||||
/// <param name="offset">The starting offset of the text to be replaced.</param>
|
||||
/// <param name="length">The length of the text to be replaced.</param>
|
||||
/// <param name="newText">The new text.</param>
|
||||
void Replace(int offset, int length, string newText); |
||||
|
||||
/// <summary>
|
||||
/// Make the document combine the following actions into a single
|
||||
/// action for undo purposes.
|
||||
/// </summary>
|
||||
void StartUndoableAction(); |
||||
|
||||
/// <summary>
|
||||
/// Ends the undoable action started with <see cref="StartUndoableAction"/>.
|
||||
/// </summary>
|
||||
void EndUndoableAction(); |
||||
|
||||
/// <summary>
|
||||
/// Creates an undo group. Dispose the returned value to close the undo group.
|
||||
/// </summary>
|
||||
/// <returns>An object that closes the undo group when Dispose() is called.</returns>
|
||||
IDisposable OpenUndoGroup(); |
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ITextAnchor"/> at the specified offset.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="ITextAnchor" select="remarks|example"/>
|
||||
ITextAnchor CreateAnchor(int offset); |
||||
|
||||
/// <summary>
|
||||
/// This event is called directly before a change is applied to the document.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// It is invalid to modify the document within this event handler.
|
||||
/// Aborting the change (by throwing an exception) is likely to cause corruption of data structures
|
||||
/// that listen to the Changing and Changed events.
|
||||
/// </remarks>
|
||||
event EventHandler<TextChangeEventArgs> Changing; |
||||
|
||||
/// <summary>
|
||||
/// This event is called directly after a change is applied to the document.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// It is invalid to modify the document within this event handler.
|
||||
/// Aborting the event handler (by throwing an exception) is likely to cause corruption of data structures
|
||||
/// that listen to the Changing and Changed events.
|
||||
/// </remarks>
|
||||
event EventHandler<TextChangeEventArgs> Changed; |
||||
} |
||||
} |
@ -0,0 +1,30 @@
@@ -0,0 +1,30 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.Editor |
||||
{ |
||||
/// <summary>
|
||||
/// A line inside a <see cref="IDocument"/>.
|
||||
/// </summary>
|
||||
public interface IDocumentLine : ISegment |
||||
{ |
||||
/// <summary>
|
||||
/// Gets the length of this line, including the line delimiter.
|
||||
/// </summary>
|
||||
int TotalLength { get; } |
||||
|
||||
/// <summary>
|
||||
/// Gets the length of the line terminator.
|
||||
/// Returns 1 or 2; or 0 at the end of the document.
|
||||
/// </summary>
|
||||
int DelimiterLength { get; } |
||||
|
||||
/// <summary>
|
||||
/// Gets the number of this line.
|
||||
/// The first line has the number 1.
|
||||
/// </summary>
|
||||
int LineNumber { get; } |
||||
} |
||||
} |
@ -0,0 +1,55 @@
@@ -0,0 +1,55 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.Editor |
||||
{ |
||||
/// <summary>
|
||||
/// An (Offset,Length)-pair.
|
||||
/// </summary>
|
||||
public interface ISegment |
||||
{ |
||||
/// <summary>
|
||||
/// Gets the start offset of the segment.
|
||||
/// </summary>
|
||||
int Offset { get; } |
||||
|
||||
/// <summary>
|
||||
/// Gets the length of the segment.
|
||||
/// </summary>
|
||||
/// <remarks>Must not be negative.</remarks>
|
||||
int Length { get; } |
||||
|
||||
/// <summary>
|
||||
/// Gets the end offset of the segment.
|
||||
/// </summary>
|
||||
/// <remarks>EndOffset = Offset + Length;</remarks>
|
||||
int EndOffset { get; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Extension methods for <see cref="ISegment"/>.
|
||||
/// </summary>
|
||||
public static class ISegmentExtensions |
||||
{ |
||||
/// <summary>
|
||||
/// Gets whether the segment contains the offset.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// True, if offset is between segment.Start and segment.End (inclusive); otherwise, false.
|
||||
/// </returns>
|
||||
public static bool Contains (this ISegment segment, int offset) |
||||
{ |
||||
return segment.Offset <= offset && offset <= segment.EndOffset; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// True, if the segment contains the specified segment, false otherwise.
|
||||
/// </summary>
|
||||
public static bool Contains (this ISegment thisSegment, ISegment segment) |
||||
{ |
||||
return segment != null && thisSegment.Offset <= segment.Offset && segment.EndOffset <= thisSegment.EndOffset; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,102 @@
@@ -0,0 +1,102 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.Editor |
||||
{ |
||||
/// <summary>
|
||||
/// The TextAnchor class references an offset (a position between two characters).
|
||||
/// It automatically updates the offset when text is inserted/removed in front of the anchor.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>Use the <see cref="ITextAnchor.Offset"/> property to get the offset from a text anchor.
|
||||
/// Use the <see cref="IDocument.CreateAnchor"/> method to create an anchor from an offset.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The document will automatically update all text anchors; and because it uses weak references to do so,
|
||||
/// the garbage collector can simply collect the anchor object when you don't need it anymore.
|
||||
/// </para>
|
||||
/// <para>Moreover, the document is able to efficiently update a large number of anchors without having to look
|
||||
/// at each anchor object individually. Updating the offsets of all anchors usually only takes time logarithmic
|
||||
/// to the number of anchors. Retrieving the <see cref="ITextAnchor.Offset"/> property also runs in O(lg N).</para>
|
||||
/// </remarks>
|
||||
/// <example>
|
||||
/// Usage:
|
||||
/// <code>TextAnchor anchor = document.CreateAnchor(offset);
|
||||
/// ChangeMyDocument();
|
||||
/// int newOffset = anchor.Offset;
|
||||
/// </code>
|
||||
/// </example>
|
||||
public interface ITextAnchor |
||||
{ |
||||
/// <summary>
|
||||
/// Gets the text location of this anchor.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">Thrown when trying to get the Offset from a deleted anchor.</exception>
|
||||
TextLocation Location { get; } |
||||
|
||||
/// <summary>
|
||||
/// Gets the offset of the text anchor.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">Thrown when trying to get the Offset from a deleted anchor.</exception>
|
||||
int Offset { get; } |
||||
|
||||
/// <summary>
|
||||
/// Controls how the anchor moves.
|
||||
/// </summary>
|
||||
AnchorMovementType MovementType { get; set; } |
||||
|
||||
/// <summary>
|
||||
/// Specifies whether the anchor survives deletion of the text containing it.
|
||||
/// <c>false</c>: The anchor is deleted when the a selection that includes the anchor is deleted.
|
||||
/// <c>true</c>: The anchor is not deleted.
|
||||
/// </summary>
|
||||
bool SurviveDeletion { get; set; } |
||||
|
||||
/// <summary>
|
||||
/// Gets whether the anchor was deleted.
|
||||
/// </summary>
|
||||
bool IsDeleted { get; } |
||||
|
||||
/// <summary>
|
||||
/// Occurs after the anchor was deleted.
|
||||
/// </summary>
|
||||
event EventHandler Deleted; |
||||
|
||||
/// <summary>
|
||||
/// Gets the line number of the anchor.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">Thrown when trying to get the Offset from a deleted anchor.</exception>
|
||||
int Line { get; } |
||||
|
||||
/// <summary>
|
||||
/// Gets the column number of this anchor.
|
||||
/// </summary>
|
||||
/// <exception cref="InvalidOperationException">Thrown when trying to get the Offset from a deleted anchor.</exception>
|
||||
int Column { get; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Defines how a text anchor moves.
|
||||
/// </summary>
|
||||
public enum AnchorMovementType |
||||
{ |
||||
/// <summary>
|
||||
/// When text is inserted at the anchor position, the type of the insertion
|
||||
/// determines where the caret moves to. For normal insertions, the anchor will stay
|
||||
/// behind the inserted text.
|
||||
/// </summary>
|
||||
Default, |
||||
/// <summary>
|
||||
/// Behaves like a start marker - when text is inserted at the anchor position, the anchor will stay
|
||||
/// before the inserted text.
|
||||
/// </summary>
|
||||
BeforeInsertion, |
||||
/// <summary>
|
||||
/// Behave like an end marker - when text is insered at the anchor position, the anchor will move
|
||||
/// after the inserted text.
|
||||
/// </summary>
|
||||
AfterInsertion |
||||
} |
||||
} |
@ -0,0 +1,100 @@
@@ -0,0 +1,100 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Threading.Tasks; |
||||
|
||||
namespace ICSharpCode.Editor |
||||
{ |
||||
/// <summary>
|
||||
/// Interface for text editors.
|
||||
/// </summary>
|
||||
public interface ITextEditor : IServiceProvider |
||||
{ |
||||
/// <summary>
|
||||
/// Gets the document that is being edited.
|
||||
/// </summary>
|
||||
IDocument Document { get; } |
||||
|
||||
/// <summary>
|
||||
/// Gets an object that represents the caret inside this text editor.
|
||||
/// </summary>
|
||||
ITextEditorCaret Caret { get; } |
||||
|
||||
/// <summary>
|
||||
/// Sets the caret to the specified line/column and brings the caret into view.
|
||||
/// </summary>
|
||||
void JumpTo(int line, int column); |
||||
|
||||
/// <summary>
|
||||
/// Gets the start offset of the selection.
|
||||
/// </summary>
|
||||
int SelectionStart { get; } |
||||
|
||||
/// <summary>
|
||||
/// Gets the length of the selection.
|
||||
/// </summary>
|
||||
int SelectionLength { get; } |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the selected text.
|
||||
/// </summary>
|
||||
string SelectedText { get; set; } |
||||
|
||||
/// <summary>
|
||||
/// Sets the selection.
|
||||
/// </summary>
|
||||
/// <param name="selectionStart">Start offset of the selection</param>
|
||||
/// <param name="selectionLength">Length of the selection</param>
|
||||
void Select(int selectionStart, int selectionLength); |
||||
|
||||
/// <summary>
|
||||
/// Shows the specified linked elements, and allows the user to edit them.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// Returns true when the user has finished editing the elements and pressed Return;
|
||||
/// or false when editing is aborted for any reason.
|
||||
/// </returns>
|
||||
/// <remarks>
|
||||
/// The user can also edit other parts of the document (or other documents) while in link mode.
|
||||
/// In case of success (true return value), this method will update the offsets of the linked elements
|
||||
/// to reflect the changes done by the user.
|
||||
/// If the text editor does not support link mode, it will immediately return false.
|
||||
/// </remarks>
|
||||
// Task<bool> ShowLinkedElements(IEnumerable<LinkedElement> linkedElements);
|
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Represents the caret in a text editor.
|
||||
/// </summary>
|
||||
public interface ITextEditorCaret |
||||
{ |
||||
/// <summary>
|
||||
/// Gets/Sets the caret offset;
|
||||
/// </summary>
|
||||
int Offset { get; set; } |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the caret line number.
|
||||
/// Line numbers are counted starting from 1.
|
||||
/// </summary>
|
||||
int Line { get; set; } |
||||
|
||||
/// <summary>
|
||||
/// Gets/Sets the caret column number.
|
||||
/// Column numbers are counted starting from 1.
|
||||
/// </summary>
|
||||
int Column { get; set; } |
||||
|
||||
/// <summary>
|
||||
/// Gets/sets the caret location.
|
||||
/// </summary>
|
||||
TextLocation Location { get; set; } |
||||
|
||||
/// <summary>
|
||||
/// Is raised whenever the location of the caret has changed.
|
||||
/// </summary>
|
||||
event EventHandler LocationChanged; |
||||
} |
||||
} |
@ -0,0 +1,147 @@
@@ -0,0 +1,147 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
|
||||
namespace ICSharpCode.Editor |
||||
{ |
||||
/// <summary>
|
||||
/// A read-only view on a (potentially mutable) text source.
|
||||
/// The IDocument interfaces derives from this interface.
|
||||
/// </summary>
|
||||
public interface ITextSource |
||||
{ |
||||
/// <summary>
|
||||
/// Gets a version identifier for this text source.
|
||||
/// Returns null for unversioned text sources.
|
||||
/// </summary>
|
||||
ITextSourceVersion Version { get; } |
||||
|
||||
/// <summary>
|
||||
/// Creates an immutable snapshot of this text source.
|
||||
/// Unlike all other methods in this interface, this method is thread-safe.
|
||||
/// </summary>
|
||||
ITextSource CreateSnapshot(); |
||||
|
||||
/// <summary>
|
||||
/// Creates an immutable snapshot of a part of this text source.
|
||||
/// Unlike all other methods in this interface, this method is thread-safe.
|
||||
/// </summary>
|
||||
ITextSource CreateSnapshot(int offset, int length); |
||||
|
||||
/// <summary>
|
||||
/// Creates a new TextReader to read from this text source.
|
||||
/// </summary>
|
||||
TextReader CreateReader(); |
||||
|
||||
/// <summary>
|
||||
/// Creates a new TextReader to read from this text source.
|
||||
/// </summary>
|
||||
TextReader CreateReader(int offset, int length); |
||||
|
||||
/// <summary>
|
||||
/// Gets the total text length.
|
||||
/// </summary>
|
||||
/// <returns>The length of the text, in characters.</returns>
|
||||
/// <remarks>This is the same as Text.Length, but is more efficient because
|
||||
/// it doesn't require creating a String object.</remarks>
|
||||
int TextLength { get; } |
||||
|
||||
/// <summary>
|
||||
/// Gets the whole text as string.
|
||||
/// </summary>
|
||||
string Text { get; } |
||||
|
||||
/// <summary>
|
||||
/// Gets a character at the specified position in the document.
|
||||
/// </summary>
|
||||
/// <paramref name="offset">The index of the character to get.</paramref>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Offset is outside the valid range (0 to TextLength-1).</exception>
|
||||
/// <returns>The character at the specified position.</returns>
|
||||
/// <remarks>This is the same as Text[offset], but is more efficient because
|
||||
/// it doesn't require creating a String object.</remarks>
|
||||
char GetCharAt(int offset); |
||||
|
||||
/// <summary>
|
||||
/// Retrieves the text for a portion of the document.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentOutOfRangeException">offset or length is outside the valid range.</exception>
|
||||
/// <remarks>This is the same as Text.Substring, but is more efficient because
|
||||
/// it doesn't require creating a String object for the whole document.</remarks>
|
||||
string GetText(int offset, int length); |
||||
|
||||
/// <summary>
|
||||
/// Retrieves the text for a portion of the document.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentOutOfRangeException">offset or length is outside the valid range.</exception>
|
||||
string GetText(ISegment segment); |
||||
|
||||
/// <summary>
|
||||
/// Gets the index of the first occurrence of any character in the specified array.
|
||||
/// </summary>
|
||||
/// <param name="anyOf">Characters to search for</param>
|
||||
/// <param name="startIndex">Start index of the search.</param>
|
||||
/// <param name="count">Length of the area to search.</param>
|
||||
/// <returns>The first index where any character was found; or -1 if no occurrence was found.</returns>
|
||||
int IndexOfAny(char[] anyOf, int startIndex, int count); |
||||
|
||||
/* What about: |
||||
void Insert (int offset, string value); |
||||
void Remove (int offset, int count); |
||||
void Remove (ISegment segment); |
||||
|
||||
void Replace (int offset, int count, string value); |
||||
|
||||
Or more search operations: |
||||
|
||||
IEnumerable<int> SearchForward (string pattern, int startIndex); |
||||
IEnumerable<int> SearchForwardIgnoreCase (string pattern, int startIndex); |
||||
|
||||
IEnumerable<int> SearchBackward (string pattern, int startIndex); |
||||
IEnumerable<int> SearchBackwardIgnoreCase (string pattern, int startIndex); |
||||
*/ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Represents a version identifier for a text source.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Verions can be used to efficiently detect whether a document has changed and needs reparsing;
|
||||
/// or even to implement incremental parsers.
|
||||
/// It is a separate class from ITextBuffer to allow the GC to collect the text buffer while
|
||||
/// the version checkpoint is still in use.
|
||||
/// </remarks>
|
||||
public interface ITextSourceVersion |
||||
{ |
||||
/// <summary>
|
||||
/// Gets whether this checkpoint belongs to the same document as the other checkpoint.
|
||||
/// </summary>
|
||||
bool BelongsToSameDocumentAs(ITextSourceVersion other); |
||||
|
||||
/// <summary>
|
||||
/// Compares the age of this checkpoint to the other checkpoint.
|
||||
/// </summary>
|
||||
/// <remarks>This method is thread-safe.</remarks>
|
||||
/// <exception cref="ArgumentException">Raised if 'other' belongs to a different document than this version.</exception>
|
||||
/// <returns>-1 if this version is older than <paramref name="other"/>.
|
||||
/// 0 if <c>this</c> version instance represents the same version as <paramref name="other"/>.
|
||||
/// 1 if this version is newer than <paramref name="other"/>.</returns>
|
||||
int CompareAge(ITextSourceVersion other); |
||||
|
||||
/// <summary>
|
||||
/// Gets the changes from this checkpoint to the other checkpoint.
|
||||
/// If 'other' is older than this checkpoint, reverse changes are calculated.
|
||||
/// </summary>
|
||||
/// <remarks>This method is thread-safe.</remarks>
|
||||
/// <exception cref="ArgumentException">Raised if 'other' belongs to a different document than this checkpoint.</exception>
|
||||
IEnumerable<TextChangeEventArgs> GetChangesTo(ITextSourceVersion other); |
||||
|
||||
/// <summary>
|
||||
/// Calculates where the offset has moved in the other buffer version.
|
||||
/// </summary>
|
||||
/// <exception cref="ArgumentException">Raised if 'other' belongs to a different document than this checkpoint.</exception>
|
||||
int MoveOffsetTo(ITextSourceVersion other, int oldOffset, AnchorMovementType movement); |
||||
} |
||||
} |
@ -0,0 +1,68 @@
@@ -0,0 +1,68 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.Editor |
||||
{ |
||||
// I'm not sure if we need this.
|
||||
// How about a method in the context - this method could wrap the internal representation.
|
||||
// public void StartTextLinkMode (int linkLength, IEnumerable<int> offsets)
|
||||
// and maybe then variations taking more than one link element ?
|
||||
|
||||
// /// <summary>
|
||||
// /// Represents an element in the text editor that is either editable, or bound to another editable element.
|
||||
// /// Used with <see cref="ITextEditor.ShowLinkedElements"/>
|
||||
// /// </summary>
|
||||
// public class LinkedElement
|
||||
// {
|
||||
// LinkedElement boundTo;
|
||||
//
|
||||
// /// <summary>
|
||||
// /// Gets/Sets the start offset of this linked element.
|
||||
// /// </summary>
|
||||
// public int StartOffset { get; set; }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// Gets/Sets the end offset of this linked element.
|
||||
// /// </summary>
|
||||
// public int EndOffset { get; set; }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// Gets the linked element to which this element is bound.
|
||||
// /// </summary>
|
||||
// public LinkedElement BoundTo {
|
||||
// get { return boundTo; }
|
||||
// }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// Gets whether this element is editable. Returns true if this element is not bound.
|
||||
// /// </summary>
|
||||
// public bool IsEditable {
|
||||
// get { return boundTo == null; }
|
||||
// }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// Creates a new editable element.
|
||||
// /// </summary>
|
||||
// public LinkedElement(int startOffset, int endOffset)
|
||||
// {
|
||||
// this.StartOffset = startOffset;
|
||||
// this.EndOffset = endOffset;
|
||||
// }
|
||||
//
|
||||
// /// <summary>
|
||||
// /// Creates a new element that is bound to <paramref name="boundTo"/>.
|
||||
// /// </summary>
|
||||
// public LinkedElement(int startOffset, int endOffset, LinkedElement boundTo)
|
||||
// {
|
||||
// if (boundTo == null)
|
||||
// throw new ArgumentNullException("boundTo");
|
||||
// this.StartOffset = startOffset;
|
||||
// this.EndOffset = endOffset;
|
||||
// while (boundTo.boundTo != null)
|
||||
// boundTo = boundTo.boundTo;
|
||||
// this.boundTo = boundTo;
|
||||
// }
|
||||
// }
|
||||
} |
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
#region Using directives
|
||||
|
||||
using System; |
||||
using System.Reflection; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
#endregion
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("ICSharpCode.Editor")] |
||||
[assembly: AssemblyDescription("")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyCompany("")] |
||||
[assembly: AssemblyProduct("ICSharpCode.Editor")] |
||||
[assembly: AssemblyCopyright("Copyright 2011")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
||||
|
||||
// This sets the default COM visibility of types in the assembly to invisible.
|
||||
// If you need to expose a type to COM, use [ComVisible(true)] on that type.
|
||||
[assembly: ComVisible(false)] |
||||
|
||||
// The assembly version has following format :
|
||||
//
|
||||
// Major.Minor.Build.Revision
|
||||
//
|
||||
// You can specify all the values or you can use the default the Revision and
|
||||
// Build Numbers by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.*")] |
@ -0,0 +1,321 @@
@@ -0,0 +1,321 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
|
||||
namespace ICSharpCode.Editor |
||||
{ |
||||
/// <summary>
|
||||
/// Read-only implementation of <see cref="IDocument"/>.
|
||||
/// </summary>
|
||||
public sealed class ReadOnlyDocument : IDocument |
||||
{ |
||||
readonly ITextSource textSource; |
||||
int[] lines; |
||||
|
||||
static readonly char[] newline = { '\r', '\n' }; |
||||
|
||||
/// <summary>
|
||||
/// Creates a new ReadOnlyDocument from the given text source.
|
||||
/// </summary>
|
||||
public ReadOnlyDocument(ITextSource textSource) |
||||
{ |
||||
if (textSource == null) |
||||
throw new ArgumentNullException("textSource"); |
||||
// ensure that underlying buffer is immutable
|
||||
this.textSource = textSource.CreateSnapshot(); |
||||
List<int> lines = new List<int>(); |
||||
lines.Add(0); |
||||
int offset = 0; |
||||
int textLength = textSource.TextLength; |
||||
while ((offset = textSource.IndexOfAny(newline, offset, textLength - offset)) >= 0) { |
||||
offset++; |
||||
if (textSource.GetCharAt(offset - 1) == '\r' && offset < textLength && textSource.GetCharAt(offset) == '\n') { |
||||
offset++; |
||||
} |
||||
lines.Add(offset); |
||||
} |
||||
this.lines = lines.ToArray(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates a new ReadOnlyDocument from the given string.
|
||||
/// </summary>
|
||||
public ReadOnlyDocument(string text) |
||||
: this(new StringTextSource(text)) |
||||
{ |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public IDocumentLine GetLine(int lineNumber) |
||||
{ |
||||
if (lineNumber < 1 || lineNumber > lines.Length) |
||||
throw new ArgumentOutOfRangeException("lineNumber", lineNumber, "Value must be between 1 and " + lines.Length); |
||||
return new ReadOnlyDocumentLine(this, lineNumber); |
||||
} |
||||
|
||||
sealed class ReadOnlyDocumentLine : IDocumentLine |
||||
{ |
||||
readonly ReadOnlyDocument doc; |
||||
readonly int lineNumber; |
||||
readonly int offset, endOffset; |
||||
|
||||
public ReadOnlyDocumentLine(ReadOnlyDocument doc, int lineNumber) |
||||
{ |
||||
this.doc = doc; |
||||
this.lineNumber = lineNumber; |
||||
this.offset = doc.GetStartOffset(lineNumber); |
||||
this.endOffset = doc.GetEndOffset(lineNumber); |
||||
} |
||||
|
||||
public int Offset { |
||||
get { return offset; } |
||||
} |
||||
|
||||
public int Length { |
||||
get { return endOffset - offset; } |
||||
} |
||||
|
||||
public int EndOffset { |
||||
get { return endOffset; } |
||||
} |
||||
|
||||
public int TotalLength { |
||||
get { |
||||
return doc.GetTotalEndOffset(lineNumber) - offset; |
||||
} |
||||
} |
||||
|
||||
public int DelimiterLength { |
||||
get { |
||||
return doc.GetTotalEndOffset(lineNumber) - endOffset; |
||||
} |
||||
} |
||||
|
||||
public int LineNumber { |
||||
get { return lineNumber; } |
||||
} |
||||
} |
||||
|
||||
int GetStartOffset(int lineNumber) |
||||
{ |
||||
return lines[lineNumber-1]; |
||||
} |
||||
|
||||
int GetTotalEndOffset(int lineNumber) |
||||
{ |
||||
return lineNumber < lines.Length ? lines[lineNumber] : textSource.TextLength; |
||||
} |
||||
|
||||
int GetEndOffset(int lineNumber) |
||||
{ |
||||
if (lineNumber == lines.Length) |
||||
return textSource.TextLength; |
||||
int off = lines[lineNumber] - 1; |
||||
if (off > 0 && textSource.GetCharAt(off - 1) == '\r' && textSource.GetCharAt(off) == '\n') |
||||
off--; |
||||
return off; |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public IDocumentLine GetLineByOffset(int offset) |
||||
{ |
||||
return GetLine(GetLineNumberForOffset(offset)); |
||||
} |
||||
|
||||
int GetLineNumberForOffset(int offset) |
||||
{ |
||||
int r = Array.BinarySearch(lines, offset); |
||||
return r < 0 ? ~r : r + 1; |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public int GetOffset(int line, int column) |
||||
{ |
||||
if (line < 1 || line > lines.Length) |
||||
throw new ArgumentOutOfRangeException("line", line, "Value must be between 1 and " + lines.Length); |
||||
int lineStart = GetStartOffset(line); |
||||
if (column <= 0) |
||||
return lineStart; |
||||
int lineEnd = GetEndOffset(line); |
||||
if (column >= lineEnd - lineStart) |
||||
return lineEnd; |
||||
return lineStart + column - 1; |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public int GetOffset(TextLocation location) |
||||
{ |
||||
return GetOffset(location.Line, location.Column); |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public TextLocation GetLocation(int offset) |
||||
{ |
||||
if (offset < 0 || offset > textSource.TextLength) |
||||
throw new ArgumentOutOfRangeException("offset", offset, "Value must be between 0 and " + textSource.TextLength); |
||||
int line = GetLineNumberForOffset(offset); |
||||
return new TextLocation(offset-GetStartOffset(line)+1, line); |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public string Text { |
||||
get { return textSource.Text; } |
||||
set { |
||||
throw new NotSupportedException(); |
||||
} |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public int TotalNumberOfLines { |
||||
get { return lines.Length; } |
||||
} |
||||
|
||||
ITextSourceVersion ITextSource.Version { |
||||
get { return null; } |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public int TextLength { |
||||
get { return textSource.TextLength; } |
||||
} |
||||
|
||||
event EventHandler<TextChangeEventArgs> IDocument.Changing { add {} remove {} } |
||||
|
||||
event EventHandler<TextChangeEventArgs> IDocument.Changed { add {} remove {} } |
||||
|
||||
event EventHandler IDocument.TextChanged { add {} remove {} } |
||||
|
||||
void IDocument.Insert(int offset, string text) |
||||
{ |
||||
throw new NotSupportedException(); |
||||
} |
||||
|
||||
void IDocument.Insert(int offset, string text, AnchorMovementType defaultAnchorMovementType) |
||||
{ |
||||
throw new NotSupportedException(); |
||||
} |
||||
|
||||
void IDocument.Remove(int offset, int length) |
||||
{ |
||||
throw new NotSupportedException(); |
||||
} |
||||
|
||||
void IDocument.Replace(int offset, int length, string newText) |
||||
{ |
||||
throw new NotSupportedException(); |
||||
} |
||||
|
||||
void IDocument.StartUndoableAction() |
||||
{ |
||||
} |
||||
|
||||
void IDocument.EndUndoableAction() |
||||
{ |
||||
} |
||||
|
||||
IDisposable IDocument.OpenUndoGroup() |
||||
{ |
||||
return null; |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public ITextAnchor CreateAnchor(int offset) |
||||
{ |
||||
return new ReadOnlyDocumentTextAnchor(GetLocation(offset), offset); |
||||
} |
||||
|
||||
sealed class ReadOnlyDocumentTextAnchor : ITextAnchor |
||||
{ |
||||
readonly TextLocation location; |
||||
readonly int offset; |
||||
|
||||
public ReadOnlyDocumentTextAnchor(TextLocation location, int offset) |
||||
{ |
||||
this.location = location; |
||||
this.offset = offset; |
||||
} |
||||
|
||||
public event EventHandler Deleted { add {} remove {} } |
||||
|
||||
public TextLocation Location { |
||||
get { return location; } |
||||
} |
||||
|
||||
public int Offset { |
||||
get { return offset; } |
||||
} |
||||
|
||||
public AnchorMovementType MovementType { get; set; } |
||||
|
||||
public bool SurviveDeletion { get; set; } |
||||
|
||||
public bool IsDeleted { |
||||
get { return false; } |
||||
} |
||||
|
||||
public int Line { |
||||
get { return location.Line; } |
||||
} |
||||
|
||||
public int Column { |
||||
get { return location.Column; } |
||||
} |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public ITextSource CreateSnapshot() |
||||
{ |
||||
return textSource; // textBuffer is immutable
|
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public ITextSource CreateSnapshot(int offset, int length) |
||||
{ |
||||
return textSource.CreateSnapshot(offset, length); |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public System.IO.TextReader CreateReader() |
||||
{ |
||||
return textSource.CreateReader(); |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public System.IO.TextReader CreateReader(int offset, int length) |
||||
{ |
||||
return textSource.CreateReader(offset, length); |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public char GetCharAt(int offset) |
||||
{ |
||||
return textSource.GetCharAt(offset); |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public string GetText(int offset, int length) |
||||
{ |
||||
return textSource.GetText(offset, length); |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public string GetText(ISegment segment) |
||||
{ |
||||
return textSource.GetText(segment); |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public int IndexOfAny(char[] anyOf, int startIndex, int count) |
||||
{ |
||||
return textSource.IndexOfAny(anyOf, startIndex, count); |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public object GetService(Type serviceType) |
||||
{ |
||||
return null; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,91 @@
@@ -0,0 +1,91 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace ICSharpCode.Editor |
||||
{ |
||||
/// <summary>
|
||||
/// Implements the ITextSource interface using a string.
|
||||
/// </summary>
|
||||
[Serializable] |
||||
public class StringTextSource : ITextSource |
||||
{ |
||||
readonly string text; |
||||
|
||||
/// <summary>
|
||||
/// Creates a new StringTextSource with the given text.
|
||||
/// </summary>
|
||||
public StringTextSource(string text) |
||||
{ |
||||
if (text == null) |
||||
throw new ArgumentNullException("text"); |
||||
this.text = text; |
||||
} |
||||
|
||||
ITextSourceVersion ITextSource.Version { |
||||
get { return null; } |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public int TextLength { |
||||
get { return text.Length; } |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public string Text { |
||||
get { return text; } |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public ITextSource CreateSnapshot() |
||||
{ |
||||
return this; // StringTextBuffer is immutable
|
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public ITextSource CreateSnapshot(int offset, int length) |
||||
{ |
||||
return new StringTextSource(text.Substring(offset, length)); |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public TextReader CreateReader() |
||||
{ |
||||
return new StringReader(text); |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public TextReader CreateReader(int offset, int length) |
||||
{ |
||||
return new StringReader(text.Substring(offset, length)); |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public char GetCharAt(int offset) |
||||
{ |
||||
return text[offset]; |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public string GetText(int offset, int length) |
||||
{ |
||||
return text.Substring(offset, length); |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public string GetText(ISegment segment) |
||||
{ |
||||
if (segment == null) |
||||
throw new ArgumentNullException("segment"); |
||||
return text.Substring(segment.Offset, segment.Length); |
||||
} |
||||
|
||||
/// <inheritdoc/>
|
||||
public int IndexOfAny(char[] anyOf, int startIndex, int count) |
||||
{ |
||||
return text.IndexOfAny(anyOf, startIndex, count); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.Editor |
||||
{ |
||||
/// <summary>
|
||||
/// Describes a change of the document text.
|
||||
/// This class is thread-safe.
|
||||
/// </summary>
|
||||
[Serializable] |
||||
public class TextChangeEventArgs : EventArgs |
||||
{ |
||||
readonly int offset; |
||||
readonly string removedText; |
||||
readonly string insertedText; |
||||
|
||||
/// <summary>
|
||||
/// The offset at which the change occurs.
|
||||
/// </summary>
|
||||
public int Offset { |
||||
get { return offset; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The text that was inserted.
|
||||
/// </summary>
|
||||
public string RemovedText { |
||||
get { return removedText; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The number of characters removed.
|
||||
/// </summary>
|
||||
public int RemovalLength { |
||||
get { return removedText.Length; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The text that was inserted.
|
||||
/// </summary>
|
||||
public string InsertedText { |
||||
get { return insertedText; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The number of characters inserted.
|
||||
/// </summary>
|
||||
public int InsertionLength { |
||||
get { return insertedText.Length; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Creates a new TextChangeEventArgs object.
|
||||
/// </summary>
|
||||
public TextChangeEventArgs(int offset, string removedText, string insertedText) |
||||
{ |
||||
this.offset = offset; |
||||
this.removedText = removedText ?? string.Empty; |
||||
this.insertedText = insertedText ?? string.Empty; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,173 @@
@@ -0,0 +1,173 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under MIT license (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Globalization; |
||||
|
||||
namespace ICSharpCode.Editor |
||||
{ |
||||
/// <summary>
|
||||
/// A line/column position.
|
||||
/// Text editor lines/columns are counted started from one.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The document provides the methods <see cref="IDocument.GetLocation"/> and
|
||||
/// <see cref="IDocument.GetOffset(TextLocation)"/> to convert between offsets and TextLocations.
|
||||
/// </remarks>
|
||||
[Serializable] |
||||
public struct TextLocation : IComparable<TextLocation>, IEquatable<TextLocation> |
||||
{ |
||||
/// <summary>
|
||||
/// Represents no text location (0, 0).
|
||||
/// </summary>
|
||||
public static readonly TextLocation Empty = new TextLocation(0, 0); |
||||
|
||||
/// <summary>
|
||||
/// Constant of the minimum line.
|
||||
/// </summary>
|
||||
public const int MinLine = 1; |
||||
|
||||
/// <summary>
|
||||
/// Constant of the minimum column.
|
||||
/// </summary>
|
||||
public const int MinColumn = 1; |
||||
|
||||
/// <summary>
|
||||
/// Creates a TextLocation instance.
|
||||
/// </summary>
|
||||
public TextLocation(int line, int column) |
||||
{ |
||||
this.line = line; |
||||
this.column = column; |
||||
} |
||||
|
||||
int column, line; |
||||
|
||||
/// <summary>
|
||||
/// Gets the line number.
|
||||
/// </summary>
|
||||
public int Line { |
||||
get { return line; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the column number.
|
||||
/// </summary>
|
||||
public int Column { |
||||
get { return column; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets whether the TextLocation instance is empty.
|
||||
/// </summary>
|
||||
public bool IsEmpty { |
||||
get { |
||||
return column < MinLine && line < MinColumn; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets a string representation for debugging purposes.
|
||||
/// </summary>
|
||||
public override string ToString() |
||||
{ |
||||
return string.Format(CultureInfo.InvariantCulture, "(Line {1}, Col {0})", this.column, this.line); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets a hash code.
|
||||
/// </summary>
|
||||
public override int GetHashCode() |
||||
{ |
||||
return unchecked (191 * column.GetHashCode() ^ line.GetHashCode()); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Equality test.
|
||||
/// </summary>
|
||||
public override bool Equals(object obj) |
||||
{ |
||||
if (!(obj is TextLocation)) return false; |
||||
return (TextLocation)obj == this; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Equality test.
|
||||
/// </summary>
|
||||
public bool Equals(TextLocation other) |
||||
{ |
||||
return this == other; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Equality test.
|
||||
/// </summary>
|
||||
public static bool operator ==(TextLocation left, TextLocation right) |
||||
{ |
||||
return left.column == right.column && left.line == right.line; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Inequality test.
|
||||
/// </summary>
|
||||
public static bool operator !=(TextLocation left, TextLocation right) |
||||
{ |
||||
return left.column != right.column || left.line != right.line; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Compares two text locations.
|
||||
/// </summary>
|
||||
public static bool operator <(TextLocation left, TextLocation right) |
||||
{ |
||||
if (left.line < right.line) |
||||
return true; |
||||
else if (left.line == right.line) |
||||
return left.column < right.column; |
||||
else |
||||
return false; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Compares two text locations.
|
||||
/// </summary>
|
||||
public static bool operator >(TextLocation left, TextLocation right) |
||||
{ |
||||
if (left.line > right.line) |
||||
return true; |
||||
else if (left.line == right.line) |
||||
return left.column > right.column; |
||||
else |
||||
return false; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Compares two text locations.
|
||||
/// </summary>
|
||||
public static bool operator <=(TextLocation left, TextLocation right) |
||||
{ |
||||
return !(left > right); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Compares two text locations.
|
||||
/// </summary>
|
||||
public static bool operator >=(TextLocation left, TextLocation right) |
||||
{ |
||||
return !(left < right); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Compares two text locations.
|
||||
/// </summary>
|
||||
public int CompareTo(TextLocation other) |
||||
{ |
||||
if (this == other) |
||||
return 0; |
||||
if (this < other) |
||||
return -1; |
||||
else |
||||
return 1; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,95 @@
@@ -0,0 +1,95 @@
|
||||
//
|
||||
// CSharpUtil.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System; |
||||
using ICSharpCode.NRefactory.CSharp; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
public static class CSharpUtil |
||||
{ |
||||
public static Expression InvertCondition (Expression condition) |
||||
{ |
||||
return InvertConditionInternal (condition.Clone ()); |
||||
} |
||||
|
||||
static Expression InvertConditionInternal (Expression condition) |
||||
{ |
||||
if (condition is ParenthesizedExpression) { |
||||
((ParenthesizedExpression)condition).Expression = InvertCondition (((ParenthesizedExpression)condition).Expression); |
||||
return condition; |
||||
} |
||||
|
||||
if (condition is UnaryOperatorExpression) { |
||||
var uOp = (UnaryOperatorExpression)condition; |
||||
if (uOp.Operator == UnaryOperatorType.Not) |
||||
return uOp.Expression; |
||||
return new UnaryOperatorExpression (UnaryOperatorType.Not, uOp); |
||||
} |
||||
|
||||
if (condition is BinaryOperatorExpression) { |
||||
var bOp = (BinaryOperatorExpression)condition; |
||||
switch (bOp.Operator) { |
||||
case BinaryOperatorType.GreaterThan: |
||||
bOp.Operator = BinaryOperatorType.LessThanOrEqual; |
||||
return bOp; |
||||
case BinaryOperatorType.GreaterThanOrEqual: |
||||
bOp.Operator = BinaryOperatorType.LessThan; |
||||
return bOp; |
||||
case BinaryOperatorType.Equality: |
||||
bOp.Operator = BinaryOperatorType.InEquality; |
||||
return bOp; |
||||
case BinaryOperatorType.InEquality: |
||||
bOp.Operator = BinaryOperatorType.Equality; |
||||
return bOp; |
||||
case BinaryOperatorType.LessThan: |
||||
bOp.Operator = BinaryOperatorType.GreaterThanOrEqual; |
||||
return bOp; |
||||
case BinaryOperatorType.LessThanOrEqual: |
||||
bOp.Operator = BinaryOperatorType.GreaterThan; |
||||
return bOp; |
||||
default: |
||||
return new UnaryOperatorExpression (UnaryOperatorType.Not, new ParenthesizedExpression (condition)); |
||||
} |
||||
} |
||||
|
||||
if (condition is ConditionalExpression) { |
||||
var cEx = condition as ConditionalExpression; |
||||
cEx.Condition = InvertCondition (cEx.Condition); |
||||
return cEx; |
||||
} |
||||
if (condition is PrimitiveExpression) { |
||||
var pex = condition as PrimitiveExpression; |
||||
if (pex.Value is bool) { |
||||
pex.Value = !((bool)pex.Value); |
||||
return pex; |
||||
} |
||||
} |
||||
|
||||
return new UnaryOperatorExpression (UnaryOperatorType.Not, condition); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// ErrorNode.cs
|
||||
//
|
||||
// Author:
|
||||
// Mike Krüger <mkrueger@novell.com>
|
||||
//
|
||||
// Copyright (c) 2011 Xamarin (http://www.xamarin.com);
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.NRefactory.CSharp |
||||
{ |
||||
/// <summary>
|
||||
/// Represents a parsing error in the ast. At the moment it only represents missing closing bracket.
|
||||
/// This closing bracket is replaced by a node at the highest possible position.
|
||||
/// (To make GetAstNodeAt (line, col) working).
|
||||
/// </summary>
|
||||
public class ErrorNode : AstNode |
||||
{ |
||||
static AstLocation maxLoc = new AstLocation (int.MaxValue, int.MaxValue); |
||||
|
||||
public override NodeType NodeType { |
||||
get { |
||||
return NodeType.Unknown; |
||||
} |
||||
} |
||||
|
||||
public override AstLocation StartLocation { |
||||
get { |
||||
return maxLoc; |
||||
} |
||||
} |
||||
|
||||
public override AstLocation EndLocation { |
||||
get { |
||||
return maxLoc; |
||||
} |
||||
} |
||||
|
||||
public ErrorNode () |
||||
{ |
||||
} |
||||
|
||||
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data) |
||||
{ |
||||
// nothing
|
||||
return default (S); |
||||
} |
||||
|
||||
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match) |
||||
{ |
||||
var o = other as ErrorNode; |
||||
return o != null; |
||||
} |
||||
|
||||
public override string ToString () |
||||
{ |
||||
return "[ErrorNode]"; |
||||
} |
||||
} |
||||
} |
||||
|
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue