Browse Source

Add FullAssemblyName to IAssembly.

newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
2f99cb14ac
  1. 2
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs
  2. 2
      src/AddIns/BackendBindings/CSharpBinding/Tests/OverrideCompletionTests.cs
  3. 2
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextDocument.cs
  4. 14
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/CSharpProjectContent.cs
  5. 4
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/TypeSystem/CSharpAssembly.cs
  6. 6
      src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs
  7. 12
      src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/IAssembly.cs
  8. 39
      src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/Implementation/DefaultUnresolvedAssembly.cs
  9. 2
      src/Main/Base/Project/Src/Services/ParserService/IGlobalAssemblyCacheService.cs
  10. 11
      src/Main/Base/Project/Src/Services/ParserService/ParseProjectContent.cs
  11. 12
      src/Main/Base/Project/Src/Util/ExtensionMethods.cs
  12. 5
      src/Main/SharpDevelop/Parser/GlobalAssemblyCacheService.cs
  13. 4
      src/Main/SharpDevelop/Workbench/WorkbenchStartup.cs

2
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs

@ -169,7 +169,7 @@ namespace CSharpBinding.Parser
{ {
return new CSharpProjectContent() return new CSharpProjectContent()
.AddAssemblyReferences(defaultReferences.Value) .AddAssemblyReferences(defaultReferences.Value)
.UpdateProjectContent(null, unresolvedFile) .AddOrUpdateFiles(unresolvedFile)
.CreateCompilation(); .CreateCompilation();
} }

2
src/AddIns/BackendBindings/CSharpBinding/Tests/OverrideCompletionTests.cs

@ -55,7 +55,7 @@ class DerivedClass : BaseClass {
textEditor.Document.Text = programStart + "override " + programEnd; textEditor.Document.Text = programStart + "override " + programEnd;
textEditor.Caret.Offset = programStart.Length + "override ".Length; textEditor.Caret.Offset = programStart.Length + "override ".Length;
var parseInfo = textEditor.CreateParseInformation(); var parseInfo = textEditor.CreateParseInformation();
var pc = new CSharpProjectContent().UpdateProjectContent(null, parseInfo.UnresolvedFile); var pc = new CSharpProjectContent().AddOrUpdateFiles(parseInfo.UnresolvedFile);
pc = pc.AddAssemblyReferences(new[] { Corlib }); pc = pc.AddAssemblyReferences(new[] { Corlib });
var compilation = pc.CreateCompilation(); var compilation = pc.CreateCompilation();
SD.Services.AddService(typeof(IParserService), MockRepository.GenerateStrictMock<IParserService>()); SD.Services.AddService(typeof(IParserService), MockRepository.GenerateStrictMock<IParserService>());

2
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Document/TextDocument.cs

@ -374,12 +374,14 @@ namespace ICSharpCode.AvalonEdit.Document
} }
} }
/// <inheritdoc/>
public void WriteTextTo(System.IO.TextWriter writer) public void WriteTextTo(System.IO.TextWriter writer)
{ {
VerifyAccess(); VerifyAccess();
rope.WriteTo(writer, 0, rope.Length); rope.WriteTo(writer, 0, rope.Length);
} }
/// <inheritdoc/>
public void WriteTextTo(System.IO.TextWriter writer, int offset, int length) public void WriteTextTo(System.IO.TextWriter writer, int offset, int length)
{ {
VerifyAccess(); VerifyAccess();

14
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/CSharpProjectContent.cs

@ -31,6 +31,7 @@ namespace ICSharpCode.NRefactory.CSharp
public class CSharpProjectContent : IProjectContent public class CSharpProjectContent : IProjectContent
{ {
string assemblyName; string assemblyName;
string fullAssemblyName;
string projectFileName; string projectFileName;
string location; string location;
Dictionary<string, IUnresolvedFile> unresolvedFiles; Dictionary<string, IUnresolvedFile> unresolvedFiles;
@ -48,6 +49,7 @@ namespace ICSharpCode.NRefactory.CSharp
protected CSharpProjectContent(CSharpProjectContent pc) protected CSharpProjectContent(CSharpProjectContent pc)
{ {
this.assemblyName = pc.assemblyName; this.assemblyName = pc.assemblyName;
this.fullAssemblyName = pc.fullAssemblyName;
this.projectFileName = pc.projectFileName; this.projectFileName = pc.projectFileName;
this.location = pc.location; this.location = pc.location;
this.unresolvedFiles = new Dictionary<string, IUnresolvedFile>(pc.unresolvedFiles, Platform.FileNameComparer); this.unresolvedFiles = new Dictionary<string, IUnresolvedFile>(pc.unresolvedFiles, Platform.FileNameComparer);
@ -71,6 +73,10 @@ namespace ICSharpCode.NRefactory.CSharp
get { return assemblyName; } get { return assemblyName; }
} }
public string FullAssemblyName {
get { return fullAssemblyName; }
}
public string Location { public string Location {
get { return location; } get { return location; }
} }
@ -128,10 +134,16 @@ namespace ICSharpCode.NRefactory.CSharp
return new CSharpProjectContent(this); 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) public IProjectContent SetAssemblyName(string newAssemblyName)
{ {
CSharpProjectContent pc = Clone(); 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; return pc;
} }

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

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

6
src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/CecilLoader.cs

@ -163,7 +163,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
moduleAttributes = this.InterningProvider.InternList(moduleAttributes); moduleAttributes = this.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.Location = assemblyDefinition.MainModule.FullyQualifiedName;
currentAssembly.AssemblyAttributes.AddRange(assemblyAttributes); currentAssembly.AssemblyAttributes.AddRange(assemblyAttributes);
currentAssembly.ModuleAttributes.AddRange(assemblyAttributes); currentAssembly.ModuleAttributes.AddRange(assemblyAttributes);
@ -253,8 +253,8 @@ namespace ICSharpCode.NRefactory.TypeSystem
{ {
readonly IDocumentationProvider documentationProvider; readonly IDocumentationProvider documentationProvider;
public CecilUnresolvedAssembly(string assemblyName, IDocumentationProvider documentationProvider) public CecilUnresolvedAssembly(AssemblyNameDefinition assemblyName, IDocumentationProvider documentationProvider)
: base(assemblyName) : base(assemblyName.FullName)
{ {
Debug.Assert(assemblyName != null); Debug.Assert(assemblyName != null);
this.documentationProvider = documentationProvider; this.documentationProvider = documentationProvider;

12
src/Libraries/NRefactory/ICSharpCode.NRefactory/TypeSystem/IAssembly.cs

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

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

@ -36,6 +36,7 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
public class DefaultUnresolvedAssembly : AbstractFreezable, IUnresolvedAssembly public class DefaultUnresolvedAssembly : AbstractFreezable, IUnresolvedAssembly
{ {
string assemblyName; string assemblyName;
string fullAssemblyName;
IList<IUnresolvedAttribute> assemblyAttributes; IList<IUnresolvedAttribute> assemblyAttributes;
IList<IUnresolvedAttribute> moduleAttributes; IList<IUnresolvedAttribute> moduleAttributes;
Dictionary<FullNameAndTypeParameterCount, IUnresolvedTypeDefinition> typeDefinitions = new Dictionary<FullNameAndTypeParameterCount, IUnresolvedTypeDefinition>(FullNameAndTypeParameterCountComparer.Ordinal); Dictionary<FullNameAndTypeParameterCount, IUnresolvedTypeDefinition> typeDefinitions = new Dictionary<FullNameAndTypeParameterCount, IUnresolvedTypeDefinition>(FullNameAndTypeParameterCountComparer.Ordinal);
@ -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) public DefaultUnresolvedAssembly(string assemblyName)
{ {
if (assemblyName == null) if (assemblyName == null)
throw new ArgumentNullException("assemblyName"); 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.assemblyAttributes = new List<IUnresolvedAttribute>();
this.moduleAttributes = 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 { public string AssemblyName {
get { return assemblyName; } get { return assemblyName; }
set { set {
@ -69,7 +83,24 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
assemblyName = value; 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; string location;
public string Location { public string Location {
get { get {
@ -287,6 +318,10 @@ namespace ICSharpCode.NRefactory.TypeSystem.Implementation
get { return unresolvedAssembly.AssemblyName; } get { return unresolvedAssembly.AssemblyName; }
} }
public string FullAssemblyName {
get { return unresolvedAssembly.FullAssemblyName; }
}
public IList<IAttribute> AssemblyAttributes { get; private set; } public IList<IAttribute> AssemblyAttributes { get; private set; }
public IList<IAttribute> ModuleAttributes { get; private set; } public IList<IAttribute> ModuleAttributes { get; private set; }

2
src/Main/Base/Project/Src/Services/ParserService/IGlobalAssemblyCacheService.cs

@ -27,6 +27,6 @@ namespace ICSharpCode.SharpDevelop.Parser
/// Gets the file name for an assembly stored in the GAC. /// Gets the file name for an assembly stored in the GAC.
/// Returns null if the assembly cannot be found. /// Returns null if the assembly cannot be found.
/// </summary> /// </summary>
string FindAssemblyInNetGac(DomAssemblyName reference); FileName FindAssemblyInNetGac(DomAssemblyName reference);
} }
} }

11
src/Main/Base/Project/Src/Services/ParserService/ParseProjectContent.cs

@ -105,16 +105,16 @@ namespace ICSharpCode.SharpDevelop.Parser
delegate { delegate {
pc = pc.RemoveAssemblyReferences(pc.AssemblyReferences); pc = pc.RemoveAssemblyReferences(pc.AssemblyReferences);
int serializableFileCount = 0; int serializableFileCount = 0;
List<IUnresolvedFile> nonSerializableUnresolvedFiles = new List<IUnresolvedFile>(); List<string> nonSerializableUnresolvedFiles = new List<string>();
foreach (var unresolvedFile in pc.Files) { foreach (var unresolvedFile in pc.Files) {
if (IsSerializable(unresolvedFile)) if (IsSerializable(unresolvedFile))
serializableFileCount++; serializableFileCount++;
else else
nonSerializableUnresolvedFiles.Add(unresolvedFile); nonSerializableUnresolvedFiles.Add(unresolvedFile.FileName);
} }
// remove non-serializable parsed files // remove non-serializable parsed files
if (nonSerializableUnresolvedFiles.Count > 0) if (nonSerializableUnresolvedFiles.Count > 0)
pc = pc.UpdateProjectContent(nonSerializableUnresolvedFiles, null); pc = pc.RemoveFiles(nonSerializableUnresolvedFiles);
if (serializableFileCount > 3) { if (serializableFileCount > 3) {
LoggingService.Debug("Serializing " + serializableFileCount + " files to " + cacheFileName); LoggingService.Debug("Serializing " + serializableFileCount + " files to " + cacheFileName);
SaveToCache(cacheFileName, pc); SaveToCache(cacheFileName, pc);
@ -230,7 +230,10 @@ namespace ICSharpCode.SharpDevelop.Parser
// This method is called by the parser service within the parser service (per-file) lock. // This method is called by the parser service within the parser service (per-file) lock.
lock (lockObj) { lock (lockObj) {
if (!disposed) { if (!disposed) {
projectContent = projectContent.UpdateProjectContent(oldFile, newFile); if (newFile != null)
projectContent = projectContent.AddOrUpdateFiles(newFile);
else
projectContent = projectContent.RemoveFiles(oldFile.FileName);
serializedProjectContentIsUpToDate = false; serializedProjectContentIsUpToDate = false;
SD.ParserService.InvalidateCurrentSolutionSnapshot(); SD.ParserService.InvalidateCurrentSolutionSnapshot();
} }

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

@ -188,6 +188,8 @@ namespace ICSharpCode.SharpDevelop
/// </summary> /// </summary>
public static FileName GetReferenceAssemblyLocation(this IAssembly assembly) public static FileName GetReferenceAssemblyLocation(this IAssembly assembly)
{ {
if (assembly == null)
throw new ArgumentNullException("assembly");
return FileName.Create(assembly.UnresolvedAssembly.Location); return FileName.Create(assembly.UnresolvedAssembly.Location);
} }
@ -200,7 +202,15 @@ namespace ICSharpCode.SharpDevelop
/// </remarks> /// </remarks>
public static FileName GetRuntimeAssemblyLocation(this IAssembly assembly) public static FileName GetRuntimeAssemblyLocation(this IAssembly assembly)
{ {
#warning Find and use GAC assembly if possible if (assembly == null)
throw new ArgumentNullException("assembly");
IUnresolvedAssembly asm = assembly.UnresolvedAssembly;
if (!(asm is IProjectContent)) {
// assembly might be in the GAC
var location = SD.GlobalAssemblyCache.FindAssemblyInNetGac(new DomAssemblyName(assembly.FullAssemblyName));
if (location != null)
return location;
}
return FileName.Create(assembly.UnresolvedAssembly.Location); return FileName.Create(assembly.UnresolvedAssembly.Location);
} }

5
src/Main/SharpDevelop/Parser/GlobalAssemblyCacheService.cs

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text; using System.Text;
using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.Parser namespace ICSharpCode.SharpDevelop.Parser
{ {
@ -72,7 +73,7 @@ namespace ICSharpCode.SharpDevelop.Parser
/// <summary> /// <summary>
/// Gets the file name for an assembly stored in the GAC. /// Gets the file name for an assembly stored in the GAC.
/// </summary> /// </summary>
public string FindAssemblyInNetGac (DomAssemblyName reference) public FileName FindAssemblyInNetGac (DomAssemblyName reference)
{ {
// without public key, it can't be in the GAC // without public key, it can't be in the GAC
if (reference.PublicKeyToken == null) if (reference.PublicKeyToken == null)
@ -83,7 +84,7 @@ namespace ICSharpCode.SharpDevelop.Parser
var gac = Path.Combine (gac_paths [i], gacs [j]); var gac = Path.Combine (gac_paths [i], gacs [j]);
var file = GetAssemblyFile (reference, prefixes [i], gac); var file = GetAssemblyFile (reference, prefixes [i], gac);
if (File.Exists (file)) if (File.Exists (file))
return file; return FileName.Create(file);
} }
} }

4
src/Main/SharpDevelop/Workbench/WorkbenchStartup.cs

@ -145,8 +145,8 @@ class Test {
}"), "test.cs"); }"), "test.cs");
// warm up the type system // warm up the type system
var unresolvedFile = cu.ToTypeSystem(); var unresolvedFile = cu.ToTypeSystem();
var pc = new ICSharpCode.NRefactory.CSharp.CSharpProjectContent().UpdateProjectContent(null, unresolvedFile); var pc = new ICSharpCode.NRefactory.CSharp.CSharpProjectContent().AddOrUpdateFiles(unresolvedFile);
pc = pc.AddAssemblyReferences(new[] { ICSharpCode.NRefactory.TypeSystem.Implementation.MinimalCorlib.Instance }); pc = pc.AddAssemblyReferences(ICSharpCode.NRefactory.TypeSystem.Implementation.MinimalCorlib.Instance);
var compilation = pc.CreateCompilation(); var compilation = pc.CreateCompilation();
// warm up the resolver // warm up the resolver
var resolver = new ICSharpCode.NRefactory.CSharp.Resolver.CSharpAstResolver(compilation, cu, unresolvedFile); var resolver = new ICSharpCode.NRefactory.CSharp.Resolver.CSharpAstResolver(compilation, cu, unresolvedFile);

Loading…
Cancel
Save