Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@170 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
12 changed files with 372 additions and 199 deletions
@ -0,0 +1,117 @@
@@ -0,0 +1,117 @@
|
||||
using System; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.Core |
||||
{ |
||||
public class ParseProjectContent : DefaultProjectContent |
||||
{ |
||||
internal static ParseProjectContent CreateUninitalized(IProject project) |
||||
{ |
||||
ParseProjectContent newProjectContent = new ParseProjectContent(); |
||||
newProjectContent.project = project; |
||||
newProjectContent.Language = project.LanguageProperties; |
||||
newProjectContent.ReferencedContents.Add(ProjectContentRegistry.GetMscorlibContent()); |
||||
newProjectContent.initializing = true; |
||||
return newProjectContent; |
||||
} |
||||
|
||||
public static ParseProjectContent Create(IProject project) |
||||
{ |
||||
ParseProjectContent newProjectContent = CreateUninitalized(project); |
||||
newProjectContent.Initialize1(); |
||||
newProjectContent.Initialize2(); |
||||
return newProjectContent; |
||||
} |
||||
|
||||
IProject project; |
||||
bool initializing; |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return string.Format("[{0}: {1}]", GetType().Name, project.Name); |
||||
} |
||||
|
||||
internal void Initialize1() |
||||
{ |
||||
ProjectItem[] items = project.Items.ToArray(); |
||||
ProjectService.ReferenceAdded += OnReferenceAdded; |
||||
foreach (ProjectItem item in items) { |
||||
if (!initializing) return; // abort initialization
|
||||
switch (item.ItemType) { |
||||
case ItemType.Reference: |
||||
case ItemType.ProjectReference: |
||||
AddReference(item as ReferenceProjectItem); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
|
||||
delegate void AddReferenceDelegate(ReferenceProjectItem reference); |
||||
|
||||
void AddReference(ReferenceProjectItem reference) |
||||
{ |
||||
try { |
||||
IProjectContent referencedContent = ProjectContentRegistry.GetProjectContentForReference(reference); |
||||
if (referencedContent != null) { |
||||
ReferencedContents.Add(referencedContent); |
||||
} |
||||
if (referencedContent is ReflectionProjectContent) { |
||||
((ReflectionProjectContent)referencedContent).InitializeReferences(); |
||||
} |
||||
} catch (Exception e) { |
||||
MessageService.ShowError(e); |
||||
} |
||||
} |
||||
|
||||
void OnReferenceAdded(object sender, ProjectReferenceEventArgs e) |
||||
{ |
||||
if (e.Project != project) return; |
||||
new AddReferenceDelegate(AddReference).BeginInvoke(e.ReferenceProjectItem, null, null); |
||||
} |
||||
|
||||
internal int GetInitializationWorkAmount() |
||||
{ |
||||
return project.Items.Count; |
||||
} |
||||
|
||||
internal void Initialize2() |
||||
{ |
||||
if (!initializing) return; |
||||
int progressStart = StatusBarService.ProgressMonitor.WorkDone; |
||||
ParseableFileContentEnumerator enumerator = new ParseableFileContentEnumerator(project); |
||||
try { |
||||
StatusBarService.ProgressMonitor.TaskName = "Parsing " + project.Name + "..."; |
||||
|
||||
foreach (IProjectContent referencedContent in ReferencedContents) { |
||||
if (referencedContent is ReflectionProjectContent) { |
||||
((ReflectionProjectContent)referencedContent).InitializeReferences(); |
||||
} |
||||
} |
||||
|
||||
while (enumerator.MoveNext()) { |
||||
int i = enumerator.Index; |
||||
if ((i % 5) == 2) |
||||
StatusBarService.ProgressMonitor.WorkDone = progressStart + i; |
||||
|
||||
ParserService.ParseFile(this, enumerator.CurrentFileName, enumerator.CurrentFileContent, true, false); |
||||
|
||||
if (!initializing) return; |
||||
} |
||||
} finally { |
||||
initializing = false; |
||||
StatusBarService.ProgressMonitor.WorkDone = progressStart + enumerator.ItemCount; |
||||
enumerator.Dispose(); |
||||
} |
||||
} |
||||
|
||||
public override void Dispose() |
||||
{ |
||||
ProjectService.ReferenceAdded -= OnReferenceAdded; |
||||
initializing = false; |
||||
base.Dispose(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
using System; |
||||
using System.IO; |
||||
using System.Threading; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Reflection; |
||||
|
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.Core |
||||
{ |
||||
public class ReflectionProjectContent : DefaultProjectContent |
||||
{ |
||||
Assembly assembly; |
||||
|
||||
public ReflectionProjectContent(Assembly assembly) |
||||
{ |
||||
this.assembly = assembly; |
||||
|
||||
ICompilationUnit assemblyCompilationUnit = new DefaultCompilationUnit(this); |
||||
|
||||
foreach (Type type in assembly.GetTypes()) { |
||||
if (!type.FullName.StartsWith("<") && type.IsPublic) { |
||||
AddClassToNamespaceListInternal(new ReflectionClass(assemblyCompilationUnit, type, null)); |
||||
} |
||||
} |
||||
string fileName = LookupLocalizedXmlDoc(assembly.Location); |
||||
// Not found -> look in runtime directory.
|
||||
if (fileName == null) { |
||||
string runtimeDirectory = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(); |
||||
fileName = LookupLocalizedXmlDoc(Path.Combine(runtimeDirectory, Path.GetFileName(assembly.Location))); |
||||
} |
||||
|
||||
if (fileName != null) { |
||||
xmlDoc = XmlDoc.Load(fileName); |
||||
} |
||||
} |
||||
|
||||
bool initialized = false; |
||||
|
||||
public void InitializeReferences() |
||||
{ |
||||
if (initialized) return; |
||||
initialized = true; |
||||
foreach (AssemblyName name in assembly.GetReferencedAssemblies()) { |
||||
IProjectContent content = ProjectContentRegistry.GetExistingProjectContent(name); |
||||
if (content != null) { |
||||
ReferencedContents.Add(content); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public override string ToString() |
||||
{ |
||||
return string.Format("[{0}: {1}]", GetType().Name, assembly.FullName); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue