Browse Source

NRefactory changes from SharpDevelop: add IDocument.FileName and IAssembly.FullAssemblyName,

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
6682aa6f92
  1. 14
      ICSharpCode.NRefactory.CSharp/CSharpProjectContent.cs
  2. 4
      ICSharpCode.NRefactory.CSharp/TypeSystem/CSharpAssembly.cs
  3. 11
      ICSharpCode.NRefactory/Editor/IDocument.cs
  4. 17
      ICSharpCode.NRefactory/Editor/ReadOnlyDocument.cs
  5. 12
      ICSharpCode.NRefactory/Editor/StringBuilderDocument.cs
  6. 6
      ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs
  7. 12
      ICSharpCode.NRefactory/TypeSystem/IAssembly.cs
  8. 2
      ICSharpCode.NRefactory/TypeSystem/ISupportsInterning.cs
  9. 39
      ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedAssembly.cs
  10. 21
      ICSharpCode.NRefactory/Utils/KeyComparer.cs
  11. 20
      ICSharpCode.NRefactory/Utils/MultiDictionary.cs

14
ICSharpCode.NRefactory.CSharp/CSharpProjectContent.cs

@ -31,6 +31,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -31,6 +31,7 @@ namespace ICSharpCode.NRefactory.CSharp
public class CSharpProjectContent : IProjectContent
{
string assemblyName;
string fullAssemblyName;
string projectFileName;
string location;
Dictionary<string, IUnresolvedFile> unresolvedFiles;
@ -48,6 +49,7 @@ namespace ICSharpCode.NRefactory.CSharp @@ -48,6 +49,7 @@ namespace ICSharpCode.NRefactory.CSharp
protected CSharpProjectContent(CSharpProjectContent pc)
{
this.assemblyName = pc.assemblyName;
this.fullAssemblyName = pc.fullAssemblyName;
this.projectFileName = pc.projectFileName;
this.location = pc.location;
this.unresolvedFiles = new Dictionary<string, IUnresolvedFile>(pc.unresolvedFiles, Platform.FileNameComparer);
@ -71,6 +73,10 @@ namespace ICSharpCode.NRefactory.CSharp @@ -71,6 +73,10 @@ namespace ICSharpCode.NRefactory.CSharp
get { return assemblyName; }
}
public string FullAssemblyName {
get { return fullAssemblyName; }
}
public string Location {
get { return location; }
}
@ -128,10 +134,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -128,10 +134,16 @@ namespace ICSharpCode.NRefactory.CSharp
return new CSharpProjectContent(this);
}
/// <summary>
/// Sets both the short and the full assembly names.
/// </summary>
/// <param name="newAssemblyName">New full assembly name.</param>
public IProjectContent SetAssemblyName(string newAssemblyName)
{
CSharpProjectContent pc = Clone();
pc.assemblyName = newAssemblyName;
pc.fullAssemblyName = newAssemblyName;
int pos = newAssemblyName != null ? newAssemblyName.IndexOf(',') : -1;
pc.assemblyName = pos < 0 ? newAssemblyName : newAssemblyName.Substring(0, pos);
return pc;
}

4
ICSharpCode.NRefactory.CSharp/TypeSystem/CSharpAssembly.cs

@ -54,6 +54,10 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem @@ -54,6 +54,10 @@ namespace ICSharpCode.NRefactory.CSharp.TypeSystem
get { return projectContent.AssemblyName; }
}
public string FullAssemblyName {
get { return projectContent.FullAssemblyName; }
}
public IList<IAttribute> AssemblyAttributes {
get {
return GetAttributes(ref assemblyAttributes, true);

11
ICSharpCode.NRefactory/Editor/IDocument.cs

@ -190,5 +190,16 @@ namespace ICSharpCode.NRefactory.Editor @@ -190,5 +190,16 @@ namespace ICSharpCode.NRefactory.Editor
/// </summary>
/// <inheritdoc cref="ITextAnchor" select="remarks|example"/>
ITextAnchor CreateAnchor(int offset);
/// <summary>
/// Gets the name of the file the document is stored in.
/// Could also be a non-existent dummy file name or null if no name has been set.
/// </summary>
string FileName { get; }
/// <summary>
/// Fired when the file name of the document changes.
/// </summary>
event EventHandler FileNameChanged;
}
}

17
ICSharpCode.NRefactory/Editor/ReadOnlyDocument.cs

@ -28,6 +28,7 @@ namespace ICSharpCode.NRefactory.Editor @@ -28,6 +28,7 @@ namespace ICSharpCode.NRefactory.Editor
public sealed class ReadOnlyDocument : IDocument
{
readonly ITextSource textSource;
readonly string fileName;
int[] lines;
static readonly char[] newline = { '\r', '\n' };
@ -35,12 +36,13 @@ namespace ICSharpCode.NRefactory.Editor @@ -35,12 +36,13 @@ namespace ICSharpCode.NRefactory.Editor
/// <summary>
/// Creates a new ReadOnlyDocument from the given text source.
/// </summary>
public ReadOnlyDocument(ITextSource textSource)
public ReadOnlyDocument(ITextSource textSource, string fileName = null)
{
if (textSource == null)
throw new ArgumentNullException("textSource");
// ensure that underlying buffer is immutable
this.textSource = textSource.CreateSnapshot();
this.fileName = fileName;
List<int> lines = new List<int>();
lines.Add(0);
int offset = 0;
@ -58,8 +60,8 @@ namespace ICSharpCode.NRefactory.Editor @@ -58,8 +60,8 @@ namespace ICSharpCode.NRefactory.Editor
/// <summary>
/// Creates a new ReadOnlyDocument from the given string.
/// </summary>
public ReadOnlyDocument(string text)
: this(new StringTextSource(text))
public ReadOnlyDocument(string text, string fileName = null)
: this(new StringTextSource(text), fileName)
{
}
@ -423,5 +425,14 @@ namespace ICSharpCode.NRefactory.Editor @@ -423,5 +425,14 @@ namespace ICSharpCode.NRefactory.Editor
{
return null;
}
/// <inheritdoc/>
/// <remarks>Will never be raised on <see cref="ReadOnlyDocument" />.</remarks>
public event EventHandler FileNameChanged { add {} remove {} }
/// <inheritdoc/>
public string FileName {
get { return fileName; }
}
}
}

12
ICSharpCode.NRefactory/Editor/StringBuilderDocument.cs

@ -312,13 +312,13 @@ namespace ICSharpCode.NRefactory.Editor @@ -312,13 +312,13 @@ namespace ICSharpCode.NRefactory.Editor
/// <inheritdoc/>
public string Text {
get {
get {
if (cachedText == null)
cachedText = b.ToString();
return cachedText;
}
set {
Replace(0, b.Length, value);
Replace(0, b.Length, value);
}
}
@ -481,5 +481,13 @@ namespace ICSharpCode.NRefactory.Editor @@ -481,5 +481,13 @@ namespace ICSharpCode.NRefactory.Editor
{
return null;
}
/// <inheritdoc/>
public virtual event EventHandler FileNameChanged { add {} remove {} }
/// <inheritdoc/>
public virtual string FileName {
get { return string.Empty; }
}
}
}

6
ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs

@ -175,7 +175,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -175,7 +175,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
assemblyAttributes = interningProvider.InternList(assemblyAttributes);
moduleAttributes = interningProvider.InternList(moduleAttributes);
this.currentAssembly = new CecilUnresolvedAssembly(assemblyDefinition.Name.Name, this.DocumentationProvider);
this.currentAssembly = new CecilUnresolvedAssembly(assemblyDefinition.Name, this.DocumentationProvider);
currentAssembly.Location = assemblyDefinition.MainModule.FullyQualifiedName;
currentAssembly.AssemblyAttributes.AddRange(assemblyAttributes);
currentAssembly.ModuleAttributes.AddRange(assemblyAttributes);
@ -267,8 +267,8 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -267,8 +267,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
{
readonly IDocumentationProvider documentationProvider;
public CecilUnresolvedAssembly(string assemblyName, IDocumentationProvider documentationProvider)
: base(assemblyName)
public CecilUnresolvedAssembly(AssemblyNameDefinition assemblyName, IDocumentationProvider documentationProvider)
: base(assemblyName.FullName)
{
Debug.Assert(assemblyName != null);
this.documentationProvider = documentationProvider;

12
ICSharpCode.NRefactory/TypeSystem/IAssembly.cs

@ -30,7 +30,12 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -30,7 +30,12 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// Gets the assembly name (short name).
/// </summary>
string AssemblyName { get; }
/// <summary>
/// Gets the full assembly name (including public key token etc.)
/// </summary>
string FullAssemblyName { get; }
/// <summary>
/// Gets the path to the assembly location.
/// For projects it is the same as the output path.
@ -81,6 +86,11 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -81,6 +86,11 @@ namespace ICSharpCode.NRefactory.TypeSystem
/// </summary>
string AssemblyName { get; }
/// <summary>
/// Gets the full assembly name (including public key token etc.)
/// </summary>
string FullAssemblyName { get; }
/// <summary>
/// Gets the list of all assembly attributes in the project.
/// </summary>

2
ICSharpCode.NRefactory/TypeSystem/ISupportsInterning.cs

@ -22,7 +22,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -22,7 +22,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
{
/// <summary>
/// Interface for TypeSystem objects that support interning.
/// See <see cref="IInterningProvider"/> for more information.
/// See <see cref="InterningProvider"/> for more information.
/// </summary>
public interface ISupportsInterning
{

39
ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedAssembly.cs

@ -36,6 +36,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -36,6 +36,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public class DefaultUnresolvedAssembly : AbstractFreezable, IUnresolvedAssembly
{
string assemblyName;
string fullAssemblyName;
IList<IUnresolvedAttribute> assemblyAttributes;
IList<IUnresolvedAttribute> moduleAttributes;
Dictionary<FullNameAndTypeParameterCount, IUnresolvedTypeDefinition> typeDefinitions = new Dictionary<FullNameAndTypeParameterCount, IUnresolvedTypeDefinition>(FullNameAndTypeParameterCountComparer.Ordinal);
@ -51,15 +52,28 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -51,15 +52,28 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
}
}
/// <summary>
/// Creates a new unresolved assembly.
/// </summary>
/// <param name="assemblyName">Full assembly name</param>
public DefaultUnresolvedAssembly(string assemblyName)
{
if (assemblyName == null)
throw new ArgumentNullException("assemblyName");
this.assemblyName = assemblyName;
this.fullAssemblyName = assemblyName;
int pos = assemblyName != null ? assemblyName.IndexOf(',') : -1;
this.assemblyName = pos < 0 ? assemblyName : assemblyName.Substring(0, pos);
this.assemblyAttributes = new List<IUnresolvedAttribute>();
this.moduleAttributes = new List<IUnresolvedAttribute>();
}
/// <summary>
/// Gets/Sets the short assembly name.
/// </summary>
/// <remarks>
/// This class handles the short and the full name independently;
/// if you change the short name, you should also change the full name.
/// </remarks>
public string AssemblyName {
get { return assemblyName; }
set {
@ -69,7 +83,24 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -69,7 +83,24 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
assemblyName = value;
}
}
/// <summary>
/// Gets/Sets the full assembly name.
/// </summary>
/// <remarks>
/// This class handles the short and the full name independently;
/// if you change the full name, you should also change the short name.
/// </remarks>
public string FullAssemblyName {
get { return fullAssemblyName; }
set {
if (value == null)
throw new ArgumentNullException("value");
FreezableHelper.ThrowIfFrozen(this);
fullAssemblyName = value;
}
}
string location;
public string Location {
get {
@ -287,6 +318,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation @@ -287,6 +318,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
get { return unresolvedAssembly.AssemblyName; }
}
public string FullAssemblyName {
get { return unresolvedAssembly.FullAssemblyName; }
}
public IList<IAttribute> AssemblyAttributes { get; private set; }
public IList<IAttribute> ModuleAttributes { get; private set; }

21
ICSharpCode.NRefactory/Utils/KeyComparer.cs

@ -27,6 +27,21 @@ namespace ICSharpCode.NRefactory.Utils @@ -27,6 +27,21 @@ namespace ICSharpCode.NRefactory.Utils
{
return new KeyComparer<TElement, TKey>(keySelector, Comparer<TKey>.Default, EqualityComparer<TKey>.Default);
}
public static KeyComparer<TElement, TKey> Create<TElement, TKey>(Func<TElement, TKey> keySelector, IComparer<TKey> comparer, IEqualityComparer<TKey> equalityComparer)
{
return new KeyComparer<TElement, TKey>(keySelector, comparer, equalityComparer);
}
public static IComparer<TElement> Create<TElement, TKey>(Func<TElement, TKey> keySelector, IComparer<TKey> comparer)
{
return new KeyComparer<TElement, TKey>(keySelector, comparer, EqualityComparer<TKey>.Default);
}
public static IEqualityComparer<TElement> Create<TElement, TKey>(Func<TElement, TKey> keySelector, IEqualityComparer<TKey> equalityComparer)
{
return new KeyComparer<TElement, TKey>(keySelector, Comparer<TKey>.Default, equalityComparer);
}
}
public class KeyComparer<TElement, TKey> : IComparer<TElement>, IEqualityComparer<TElement>
@ -37,6 +52,12 @@ namespace ICSharpCode.NRefactory.Utils @@ -37,6 +52,12 @@ namespace ICSharpCode.NRefactory.Utils
public KeyComparer(Func<TElement, TKey> keySelector, IComparer<TKey> keyComparer, IEqualityComparer<TKey> keyEqualityComparer)
{
if (keySelector == null)
throw new ArgumentNullException("keySelector");
if (keyComparer == null)
throw new ArgumentNullException("keyComparer");
if (keyEqualityComparer == null)
throw new ArgumentNullException("keyEqualityComparer");
this.keySelector = keySelector;
this.keyComparer = keyComparer;
this.keyEqualityComparer = keyEqualityComparer;

20
ICSharpCode.NRefactory/Utils/MultiDictionary.cs

@ -62,6 +62,15 @@ namespace ICSharpCode.NRefactory.Utils @@ -62,6 +62,15 @@ namespace ICSharpCode.NRefactory.Utils
return false;
}
/// <summary>
/// Removes all entries with the specified key.
/// </summary>
/// <returns>Returns true if at least one entry was removed.</returns>
public bool RemoveAll(TKey key)
{
return dict.Remove(key);
}
public void Clear()
{
dict.Clear();
@ -81,10 +90,21 @@ namespace ICSharpCode.NRefactory.Utils @@ -81,10 +90,21 @@ namespace ICSharpCode.NRefactory.Utils
}
}
/// <summary>
/// Returns the number of different keys.
/// </summary>
public int Count {
get { return dict.Count; }
}
public ICollection<TKey> Keys {
get { return dict.Keys; }
}
public IEnumerable<TValue> Values {
get { return dict.Values.SelectMany(list => list); }
}
IEnumerable<TValue> ILookup<TKey, TValue>.this[TKey key] {
get { return this[key]; }
}

Loading…
Cancel
Save