[Monodevelop-patches-list] r1549 - in branches/MonoDevelop-generate-what/src/Main/Base: . Services/ParserService
commit-watcher at mono-cvs.ximian.com
commit-watcher at mono-cvs.ximian.com
Thu Apr 29 09:46:56 EDT 2004
Author: iainmc
Date: 2004-04-29 09:46:55 -0400 (Thu, 29 Apr 2004)
New Revision: 1549
Added:
branches/MonoDevelop-generate-what/src/Main/Base/Services/ParserService/CompletionDataServiceBase.cs
Modified:
branches/MonoDevelop-generate-what/src/Main/Base/ChangeLog
branches/MonoDevelop-generate-what/src/Main/Base/Makefile.am
branches/MonoDevelop-generate-what/src/Main/Base/Services/ParserService/DatabaseBackedCompletionDataService.cs
Log:
Factored generic completion data service stuff into a base class
Modified: branches/MonoDevelop-generate-what/src/Main/Base/ChangeLog
===================================================================
--- branches/MonoDevelop-generate-what/src/Main/Base/ChangeLog 2004-04-29 13:32:13 UTC (rev 1548)
+++ branches/MonoDevelop-generate-what/src/Main/Base/ChangeLog 2004-04-29 13:46:55 UTC (rev 1549)
@@ -1,4 +1,10 @@
2004-04-29 Iain McCoy <iain at mccoy.id.au>
+ * Makefile.am:
+ * Services/ParserService/DatabaseBackedCompletionDataService.cs:
+ * Services/ParserService/CompletionDataServiceBase.cs: Factored
+ generic CompletionDataService bits into a base class
+
+2004-04-29 Iain McCoy <iain at mccoy.id.au>
* Makefile.am
* Services/ParserService/ICompletionDataService.cs:
* Services/ParserService/IParserService.cs:
Modified: branches/MonoDevelop-generate-what/src/Main/Base/Makefile.am
===================================================================
--- branches/MonoDevelop-generate-what/src/Main/Base/Makefile.am 2004-04-29 13:32:13 UTC (rev 1548)
+++ branches/MonoDevelop-generate-what/src/Main/Base/Makefile.am 2004-04-29 13:46:55 UTC (rev 1549)
@@ -210,6 +210,7 @@
./Services/ParserService/DefaultParserService.cs \
./Services/ParserService/IParserService.cs \
./Services/ParserService/DatabaseBackedCompletionDataService.cs \
+./Services/ParserService/CompletionDataServiceBase.cs \
./Services/ParserService/ICompletionDataService.cs \
./Services/ParserService/ClassProxyCollection.cs \
./Services/ParserService/ClassProxy.cs \
Added: branches/MonoDevelop-generate-what/src/Main/Base/Services/ParserService/CompletionDataServiceBase.cs
===================================================================
--- branches/MonoDevelop-generate-what/src/Main/Base/Services/ParserService/CompletionDataServiceBase.cs 2004-04-29 13:32:13 UTC (rev 1548)
+++ branches/MonoDevelop-generate-what/src/Main/Base/Services/ParserService/CompletionDataServiceBase.cs 2004-04-29 13:46:55 UTC (rev 1549)
@@ -0,0 +1,201 @@
+using System;
+using System.IO;
+using System.Threading;
+using System.Collections;
+using System.Collections.Utility;
+using System.Diagnostics;
+using System.Reflection;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Formatters;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.Security;
+using System.Security.Permissions;
+using System.Security.Policy;
+using System.Xml;
+
+using MonoDevelop.Core.Properties;
+using MonoDevelop.Core.Services;
+using MonoDevelop.Services;
+using MonoDevelop.Core.AddIns;
+using MonoDevelop.Internal.Project;
+using MonoDevelop.Gui;
+using MonoDevelop.Internal.Parser;
+
+namespace MonoDevelop.Services
+{
+ abstract class CompletionDataServiceBase : AbstractService
+ {
+ protected Hashtable classes = new Hashtable();
+ protected Hashtable caseInsensitiveClasses = new Hashtable();
+
+ /// <remarks>
+ /// The keys are the assemblies loaded. This hash table ensures that no
+ /// assembly is loaded twice. I know that strong naming might be better but
+ /// the use case isn't there. No one references 2 differnt files if he references
+ /// the same assembly.
+ /// </remarks>
+ protected Hashtable loadedAssemblies = new Hashtable();
+
+ // used to map 'real' namespace hashtable inside case insensitive hashtable
+ protected const string CaseInsensitiveKey = "__CASE_INSENSITIVE_HASH";
+ protected Hashtable caseInsensitiveNamespaces = new Hashtable();
+ protected Hashtable namespaces = new Hashtable();
+
+ protected ClassProxyCollection classProxies = new ClassProxyCollection();
+ protected readonly static string[] assemblyList = {
+ "Microsoft.VisualBasic",
+ //"Microsoft.JScript",
+ "mscorlib",
+ "System.Data",
+ "System.Design",
+ "System.DirectoryServices",
+ "System.Drawing.Design",
+ "System.Drawing",
+ "System.EnterpriseServices",
+ "System.Management",
+ "System.Messaging",
+ "System.Runtime.Remoting",
+ "System.Runtime.Serialization.Formatters.Soap",
+
+ "System.Security",
+ "System.ServiceProcess",
+ "System.Web.Services",
+ "System.Web",
+ //"System.Windows.Forms",
+ "System",
+ "System.Xml",
+ "glib-sharp",
+ "atk-sharp",
+ "pango-sharp",
+ "gdk-sharp",
+ "gtk-sharp",
+ "gnome-sharp",
+ "gconf-sharp",
+ "gtkhtml-sharp",
+ };
+
+ public static string[] AssemblyList {
+ get {
+ return assemblyList;
+ }
+ }
+ /// <remarks>
+ /// The initialize method writes the location of the code completion proxy
+ /// file to this string.
+ /// </remarks>
+ protected string codeCompletionProxyFile;
+ protected string codeCompletionMainFile;
+
+ public void SetClasses(Hashtable classes, Hashtable caseInsensitiveClasses) {
+ this.classes = classes;
+ this.caseInsensitiveClasses = caseInsensitiveClasses;
+ }
+
+
+ public override void InitializeService() {
+ IProjectService projectService = (IProjectService)MonoDevelop.Core.Services.ServiceManager.Services.GetService(typeof(IProjectService));
+ projectService.CombineOpened += new CombineEventHandler(OpenCombine);
+ }
+
+ public void AddReferenceToCompletionLookup(IProject project, ProjectReference reference)
+ {
+ if (reference.ReferenceType != ReferenceType.Project) {
+ string fileName = reference.GetReferencedFileName(project);
+ if (fileName == null || fileName.Length == 0) {
+ return;
+ }
+ foreach (string assemblyName in assemblyList) {
+ if (Path.GetFileNameWithoutExtension(fileName).ToUpper() == assemblyName.ToUpper()) {
+ return;
+ }
+ }
+ // HACK : Don't load references for non C# projects
+ if (project.ProjectType != "C#") {
+ return;
+ }
+ if (File.Exists(fileName)) {
+ Thread t = new Thread(new ThreadStart(new AssemblyLoader(this, fileName).LoadAssemblyParseInformations));
+ t.Start();
+ }
+ }
+ }
+
+ class AssemblyLoader
+ {
+ CompletionDataServiceBase completionDataService;
+ string assemblyFileName;
+
+ public AssemblyLoader(CompletionDataServiceBase completionDataService, string assemblyFileName)
+ {
+ this.completionDataService = completionDataService;
+ this.assemblyFileName = assemblyFileName;
+ }
+
+ public void LoadAssemblyParseInformations()
+ {
+ if (completionDataService.loadedAssemblies[assemblyFileName] != null) {
+ return;
+ }
+ completionDataService.loadedAssemblies[assemblyFileName] = true;
+ try {
+ AssemblyInformation assemblyInformation = new AssemblyInformation();
+ assemblyInformation.Load(assemblyFileName, true);
+ foreach (IClass newClass in assemblyInformation.Classes) {
+ completionDataService.AddClassToNamespaceList(newClass);
+ lock (completionDataService.classes) {
+ completionDataService.caseInsensitiveClasses[newClass.FullyQualifiedName.ToLower()] = completionDataService.classes[newClass.FullyQualifiedName] = new ClasstableEntry(null, null, newClass);
+ }
+ }
+ } catch (Exception e) {
+ Console.WriteLine("Can't add reference : " + e.ToString());
+ }
+ }
+ }
+
+ public void OpenCombine(object sender, CombineEventArgs e)
+ {
+ ArrayList projects = Combine.GetAllProjects(e.Combine);
+ foreach (ProjectCombineEntry entry in projects) {
+ foreach (ProjectReference r in entry.Project.ProjectReferences) {
+ AddReferenceToCompletionLookup(entry.Project, r);
+ }
+ }
+ }
+
+
+ public Hashtable AddClassToNamespaceList(IClass addClass)
+ {
+ string nSpace = addClass.Namespace;
+ if (nSpace == null) {
+ nSpace = String.Empty;
+ }
+
+ string[] path = nSpace.Split('.');
+
+ lock (namespaces) {
+ Hashtable cur = namespaces;
+ Hashtable caseInsensitiveCur = caseInsensitiveNamespaces;
+
+ for (int i = 0; i < path.Length; ++i) {
+ if (cur[path[i]] == null) {
+ Hashtable hashTable = new Hashtable();
+ Hashtable caseInsensitivehashTable = new Hashtable();
+ cur[path[i]] = hashTable;
+ caseInsensitiveCur[path[i].ToLower()] = caseInsensitivehashTable;
+ caseInsensitivehashTable[CaseInsensitiveKey] = hashTable;
+ } else {
+ if (!(cur[path[i]] is Hashtable)) {
+ return null;
+ }
+ }
+ cur = (Hashtable)cur[path[i]];
+ caseInsensitiveCur = (Hashtable)caseInsensitiveCur[path[i].ToLower()];
+ }
+ caseInsensitiveCur[addClass.Name.ToLower()] = cur[addClass.Name] = addClass;
+ return cur;
+ }
+ }
+
+
+ }
+}
Modified: branches/MonoDevelop-generate-what/src/Main/Base/Services/ParserService/DatabaseBackedCompletionDataService.cs
===================================================================
--- branches/MonoDevelop-generate-what/src/Main/Base/Services/ParserService/DatabaseBackedCompletionDataService.cs 2004-04-29 13:32:13 UTC (rev 1548)
+++ branches/MonoDevelop-generate-what/src/Main/Base/Services/ParserService/DatabaseBackedCompletionDataService.cs 2004-04-29 13:46:55 UTC (rev 1549)
@@ -23,75 +23,10 @@
namespace MonoDevelop.Services
{
- class DatabaseBackedCompletionDataService : AbstractService, ICompletionDataService
+ class DatabaseBackedCompletionDataService : CompletionDataServiceBase, ICompletionDataService
{
- Hashtable classes = new Hashtable();
- Hashtable caseInsensitiveClasses = new Hashtable();
-
- /// <remarks>
- /// The keys are the assemblies loaded. This hash table ensures that no
- /// assembly is loaded twice. I know that strong naming might be better but
- /// the use case isn't there. No one references 2 differnt files if he references
- /// the same assembly.
- /// </remarks>
- Hashtable loadedAssemblies = new Hashtable();
- // used to map 'real' namespace hashtable inside case insensitive hashtable
- const string CaseInsensitiveKey = "__CASE_INSENSITIVE_HASH";
- Hashtable caseInsensitiveNamespaces = new Hashtable();
- Hashtable namespaces = new Hashtable();
-
- ClassProxyCollection classProxies = new ClassProxyCollection();
- readonly static string[] assemblyList = {
- "Microsoft.VisualBasic",
- //"Microsoft.JScript",
- "mscorlib",
- "System.Data",
- "System.Design",
- "System.DirectoryServices",
- "System.Drawing.Design",
- "System.Drawing",
- "System.EnterpriseServices",
- "System.Management",
- "System.Messaging",
- "System.Runtime.Remoting",
- "System.Runtime.Serialization.Formatters.Soap",
- "System.Security",
- "System.ServiceProcess",
- "System.Web.Services",
- "System.Web",
- //"System.Windows.Forms",
- "System",
- "System.Xml",
- "glib-sharp",
- "atk-sharp",
- "pango-sharp",
- "gdk-sharp",
- "gtk-sharp",
- "gnome-sharp",
- "gconf-sharp",
- "gtkhtml-sharp",
- };
-
- public static string[] AssemblyList {
- get {
- return assemblyList;
- }
- }
-
-
- /// <remarks>
- /// The initialize method writes the location of the code completion proxy
- /// file to this string.
- /// </remarks>
- string codeCompletionProxyFile;
- string codeCompletionMainFile;
-
- public void SetClasses(Hashtable classes, Hashtable caseInsensitiveClasses) {
- this.classes = classes;
- this.caseInsensitiveClasses = caseInsensitiveClasses;
- }
private bool ContinueWithProcess(IProgressMonitor progressMonitor)
{
@@ -198,114 +133,14 @@
public override void InitializeService()
{
+ base.InitializeService();
Thread myThread = new Thread(new ThreadStart(LoadThread));
myThread.IsBackground = true;
myThread.Priority = ThreadPriority.Lowest;
myThread.Start();
- IProjectService projectService = (IProjectService)MonoDevelop.Core.Services.ServiceManager.Services.GetService(typeof(IProjectService));
- projectService.CombineOpened += new CombineEventHandler(OpenCombine);
}
- public void AddReferenceToCompletionLookup(IProject project, ProjectReference reference)
- {
- if (reference.ReferenceType != ReferenceType.Project) {
- string fileName = reference.GetReferencedFileName(project);
- if (fileName == null || fileName.Length == 0) {
- return;
- }
- foreach (string assemblyName in assemblyList) {
- if (Path.GetFileNameWithoutExtension(fileName).ToUpper() == assemblyName.ToUpper()) {
- return;
- }
- }
- // HACK : Don't load references for non C# projects
- if (project.ProjectType != "C#") {
- return;
- }
- if (File.Exists(fileName)) {
- Thread t = new Thread(new ThreadStart(new AssemblyLoader(this, fileName).LoadAssemblyParseInformations));
- t.Start();
- }
- }
- }
-
- class AssemblyLoader
- {
- DatabaseBackedCompletionDataService completionDataService;
- string assemblyFileName;
-
- public AssemblyLoader(DatabaseBackedCompletionDataService completionDataService, string assemblyFileName)
- {
- this.completionDataService = completionDataService;
- this.assemblyFileName = assemblyFileName;
- }
-
- public void LoadAssemblyParseInformations()
- {
- if (completionDataService.loadedAssemblies[assemblyFileName] != null) {
- return;
- }
- completionDataService.loadedAssemblies[assemblyFileName] = true;
- try {
- AssemblyInformation assemblyInformation = new AssemblyInformation();
- assemblyInformation.Load(assemblyFileName, true);
- foreach (IClass newClass in assemblyInformation.Classes) {
- completionDataService.AddClassToNamespaceList(newClass);
- lock (completionDataService.classes) {
- completionDataService.caseInsensitiveClasses[newClass.FullyQualifiedName.ToLower()] = completionDataService.classes[newClass.FullyQualifiedName] = new ClasstableEntry(null, null, newClass);
- }
- }
- } catch (Exception e) {
- Console.WriteLine("Can't add reference : " + e.ToString());
- }
- }
- }
-
- public void OpenCombine(object sender, CombineEventArgs e)
- {
- ArrayList projects = Combine.GetAllProjects(e.Combine);
- foreach (ProjectCombineEntry entry in projects) {
- foreach (ProjectReference r in entry.Project.ProjectReferences) {
- AddReferenceToCompletionLookup(entry.Project, r);
- }
- }
- }
-
-
- public Hashtable AddClassToNamespaceList(IClass addClass)
- {
- string nSpace = addClass.Namespace;
- if (nSpace == null) {
- nSpace = String.Empty;
- }
-
- string[] path = nSpace.Split('.');
-
- lock (namespaces) {
- Hashtable cur = namespaces;
- Hashtable caseInsensitiveCur = caseInsensitiveNamespaces;
-
- for (int i = 0; i < path.Length; ++i) {
- if (cur[path[i]] == null) {
- Hashtable hashTable = new Hashtable();
- Hashtable caseInsensitivehashTable = new Hashtable();
- cur[path[i]] = hashTable;
- caseInsensitiveCur[path[i].ToLower()] = caseInsensitivehashTable;
- caseInsensitivehashTable[CaseInsensitiveKey] = hashTable;
- } else {
- if (!(cur[path[i]] is Hashtable)) {
- return null;
- }
- }
- cur = (Hashtable)cur[path[i]];
- caseInsensitiveCur = (Hashtable)caseInsensitiveCur[path[i].ToLower()];
- }
- caseInsensitiveCur[addClass.Name.ToLower()] = cur[addClass.Name] = addClass;
- return cur;
- }
- }
-
public IClass GetClass(string typeName)
{
return GetClass(typeName, true);
More information about the Monodevelop-patches-list
mailing list