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

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

@ -55,7 +55,7 @@ class DerivedClass : BaseClass { @@ -55,7 +55,7 @@ class DerivedClass : BaseClass {
textEditor.Document.Text = programStart + "override " + programEnd;
textEditor.Caret.Offset = programStart.Length + "override ".Length;
var parseInfo = textEditor.CreateParseInformation();
var pc = new CSharpProjectContent().UpdateProjectContent(null, parseInfo.UnresolvedFile);
var pc = new CSharpProjectContent().AddOrUpdateFiles(parseInfo.UnresolvedFile);
pc = pc.AddAssemblyReferences(new[] { Corlib });
var compilation = pc.CreateCompilation();
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 @@ -374,12 +374,14 @@ namespace ICSharpCode.AvalonEdit.Document
}
}
/// <inheritdoc/>
public void WriteTextTo(System.IO.TextWriter writer)
{
VerifyAccess();
rope.WriteTo(writer, 0, rope.Length);
}
/// <inheritdoc/>
public void WriteTextTo(System.IO.TextWriter writer, int offset, int length)
{
VerifyAccess();

14
src/Libraries/NRefactory/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
src/Libraries/NRefactory/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);

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

@ -163,7 +163,7 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -163,7 +163,7 @@ namespace ICSharpCode.NRefactory.TypeSystem
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.AssemblyAttributes.AddRange(assemblyAttributes);
currentAssembly.ModuleAttributes.AddRange(assemblyAttributes);
@ -253,8 +253,8 @@ namespace ICSharpCode.NRefactory.TypeSystem @@ -253,8 +253,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
src/Libraries/NRefactory/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>

39
src/Libraries/NRefactory/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; }

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

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

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

@ -188,6 +188,8 @@ namespace ICSharpCode.SharpDevelop @@ -188,6 +188,8 @@ namespace ICSharpCode.SharpDevelop
/// </summary>
public static FileName GetReferenceAssemblyLocation(this IAssembly assembly)
{
if (assembly == null)
throw new ArgumentNullException("assembly");
return FileName.Create(assembly.UnresolvedAssembly.Location);
}
@ -200,7 +202,15 @@ namespace ICSharpCode.SharpDevelop @@ -200,7 +202,15 @@ namespace ICSharpCode.SharpDevelop
/// </remarks>
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);
}

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

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

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

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

Loading…
Cancel
Save