diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2011-12-02 21:43:01 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2011-12-02 21:43:01 +0400 |
commit | 0233088e6bda9f55567d4070d4d0999a8cd22f68 (patch) | |
tree | ecd66272f754ec7bfcf2c06050be44b29d4382d1 /main/src | |
parent | 6a71bc1cfc9ba1945d874380276a16c1c64dc476 (diff) |
[MacDev] Tracked nrefactory API/model changes.
Diffstat (limited to 'main/src')
16 files changed, 180 insertions, 133 deletions
diff --git a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Gui/AspNetEditorExtension.cs b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Gui/AspNetEditorExtension.cs index 24d1decd03..4900384798 100644..100755 --- a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Gui/AspNetEditorExtension.cs +++ b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Gui/AspNetEditorExtension.cs @@ -110,7 +110,7 @@ namespace MonoDevelop.AspNet.Gui info.AspNetDocument.RootNode.AcceptVisit (v); var t = new ICSharpCode.NRefactory.TypeSystem.Implementation.DefaultUnresolvedTypeDefinition (info.ClassName); var dom = refman.TypeCtx.Compilation; - var baseType = dom.FindType (info.BaseType); + var baseType = dom.LookupType (info.BaseType); foreach (var m in CodeBehind.GetDesignerMembers (v.Members.Values, baseType, null)) { t.Members.Add (new ICSharpCode.NRefactory.TypeSystem.Implementation.DefaultUnresolvedField (t, m.Name) { Accessibility = Accessibility.Protected, @@ -343,7 +343,7 @@ namespace MonoDevelop.AspNet.Gui if (!HasDoc) { AddAspBeginExpressions (list); string aspPrefix = "asp:"; - foreach (var cls in WebTypeContext.ListSystemControlClasses (TypeSystemService.GetCompilation (project).FindType ("System.Web.UI.Control"), project)) + foreach (var cls in WebTypeContext.ListSystemControlClasses (TypeSystemService.GetCompilation (project).LookupType ("System.Web.UI", "Control"), project)) list.Add (new AspTagCompletionData (aspPrefix, cls)); base.GetElementCompletions (list); @@ -454,7 +454,7 @@ namespace MonoDevelop.AspNet.Gui if (meth != null) { IType argType = meth.Parameters [0].Type; - if (argType != null && argType.IsBaseType (argType.GetDefinition ().Compilation.FindType ("System.Web.UI.Control"))) { + if (argType != null && argType.IsBaseType (argType.GetDefinition ().Compilation.LookupType ("System.Web.UI", "Control"))) { list.AddRange (refman.GetControlCompletionData (argType)); return; } @@ -600,7 +600,7 @@ namespace MonoDevelop.AspNet.Gui IType controlClass = refman.GetControlType (name.Prefix, name.Name); if (controlClass == null) { - controlClass = database.FindType ("System.Web.UI.WebControls.WebControl"); + controlClass = database.LookupType ("System.Web.UI.WebControls", "WebControl"); if (controlClass == null) { LoggingService.LogWarning ("Could not obtain IType for System.Web.UI.WebControls.WebControl"); return; @@ -638,7 +638,7 @@ namespace MonoDevelop.AspNet.Gui LoggingService.LogWarning ("Could not obtain IType for {0}", tagName.FullName); var database = WebTypeContext.GetSystemWebDom (project); - controlClass = database.FindType ("System.Web.UI.WebControls.WebControl"); + controlClass = database.LookupType ("System.Web.UI.WebControls", "WebControl"); if (controlClass == null) { LoggingService.LogWarning ("Could not obtain IType for System.Web.UI.WebControls.WebControl"); diff --git a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Parser/DocumentReferenceManager.cs b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Parser/DocumentReferenceManager.cs index 8d1939142b..b4ddf45846 100644..100755 --- a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Parser/DocumentReferenceManager.cs +++ b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Parser/DocumentReferenceManager.cs @@ -149,7 +149,7 @@ namespace MonoDevelop.AspNet.Parser public IEnumerable<CompletionData> GetControlCompletionData () { - return GetControlCompletionData (TypeSystemService.GetCompilation (Project).FindType ("System.Web.UI.Control")); + return GetControlCompletionData (TypeSystemService.GetCompilation (Project).LookupType ("System.Web.UI", "Control")); } public IEnumerable<CompletionData> GetControlCompletionData (IType baseType) diff --git a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/AspNetAppProject.cs b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/AspNetAppProject.cs index 3c7841e7d6..0554111fb8 100644..100755 --- a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/AspNetAppProject.cs +++ b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/AspNetAppProject.cs @@ -692,7 +692,7 @@ namespace MonoDevelop.AspNet if (typeName != null) { var dom = TypeSystemService.GetCompilation (this); if (dom != null) - return dom.FindType (typeName); + return dom.LookupType (typeName); } return null; } diff --git a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/CodeBehind.cs b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/CodeBehind.cs index 3e8d1b545f..7ed9cd1dc7 100644..100755 --- a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/CodeBehind.cs +++ b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/CodeBehind.cs @@ -155,7 +155,7 @@ namespace MonoDevelop.AspNet return ccu; var dom = refman.TypeCtx.Compilation; - var cls = dom.FindType (className); + var cls = dom.LookupType (className); var members = GetDesignerMembers (memberList.Members.Values, cls, filename); //add fields for each control in the page diff --git a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/WebTypeManager.cs b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/WebTypeManager.cs index c8f6874877..dabe647beb 100644..100755 --- a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/WebTypeManager.cs +++ b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/WebTypeManager.cs @@ -296,7 +296,7 @@ namespace MonoDevelop.AspNet { var str = HtmlControlLookup (tagName, typeAttribute); if (str != null) { - return SystemWebDom.FindType (str); + return SystemWebDom.LookupType (str); } return null; } diff --git a/main/src/addins/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport/ClassOutlineNodeComparer.cs b/main/src/addins/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport/ClassOutlineNodeComparer.cs index b1fb62dc38..3621634b7f 100644..100755 --- a/main/src/addins/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport/ClassOutlineNodeComparer.cs +++ b/main/src/addins/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport/ClassOutlineNodeComparer.cs @@ -288,6 +288,9 @@ namespace MonoDevelop.DesignerSupport var m = o as IEntity; if (m != null) return m.BodyRegion.IsEmpty ? m.Region : m.BodyRegion; + var m2 = o as IUnresolvedEntity; + if (m2 != null) + return m2.BodyRegion.IsEmpty ? m2.Region : m2.BodyRegion; return ((FoldingRegion)o).Region; } diff --git a/main/src/addins/MonoDevelop.GtkCore/MonoDevelop.GtkCore/WidgetParser.cs b/main/src/addins/MonoDevelop.GtkCore/MonoDevelop.GtkCore/WidgetParser.cs index a5a0f709d6..1ac195b025 100644..100755 --- a/main/src/addins/MonoDevelop.GtkCore/MonoDevelop.GtkCore/WidgetParser.cs +++ b/main/src/addins/MonoDevelop.GtkCore/MonoDevelop.GtkCore/WidgetParser.cs @@ -35,6 +35,7 @@ using System.Collections.Generic; using System.Collections.Specialized; using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.Semantics; +using MonoDevelop.TypeSystem; namespace MonoDevelop.GtkCore { @@ -58,7 +59,7 @@ namespace MonoDevelop.GtkCore { Dictionary<string, ITypeDefinition> tb_items = new Dictionary<string, ITypeDefinition> (); - var wt = ctx.FindType ("Gtk.Widget"); + var wt = ctx.LookupType ("Gtk", "Widget"); if (wt != null) { foreach (var t in wt.GetSubTypeDefinitions ()) { if (IsToolboxWidget (t)) diff --git a/main/src/addins/MonoDevelop.MacDev/ObjCIntegration/NSObjectInfoService.cs b/main/src/addins/MonoDevelop.MacDev/ObjCIntegration/NSObjectInfoService.cs index 90bae4d754..467ff15089 100644..100755 --- a/main/src/addins/MonoDevelop.MacDev/ObjCIntegration/NSObjectInfoService.cs +++ b/main/src/addins/MonoDevelop.MacDev/ObjCIntegration/NSObjectInfoService.cs @@ -50,10 +50,11 @@ namespace MonoDevelop.MacDev.ObjCIntegration static readonly char[] whitespaceChars = { ' ', '\t', '\n', '\r' }; static readonly char[] splitActionParamsChars = { ' ', '\t', '\n', '\r', '*', '(', ')' }; - readonly ITypeReference nsobjectType, registerAttType, connectAttType, exportAttType, modelAttType, + readonly string typeNamespace; + readonly string nsobjectType, registerAttType, connectAttType, exportAttType, modelAttType, iboutletAttType, ibactionAttType; - static Dictionary<ITypeResolveContext,NSObjectProjectInfo> infos = new Dictionary<ITypeResolveContext, NSObjectProjectInfo> (); + static Dictionary<TypeSystemService.ProjectContentWrapper,NSObjectProjectInfo> infos = new Dictionary<TypeSystemService.ProjectContentWrapper, NSObjectProjectInfo> (); static NSObjectInfoService () { @@ -63,31 +64,30 @@ namespace MonoDevelop.MacDev.ObjCIntegration public NSObjectInfoService (string wrapperRoot) { this.WrapperRoot = wrapperRoot; - string foundation = wrapperRoot + ".Foundation"; - connectAttType = new GetClassTypeReference (foundation, "ConnectAttribute"); - exportAttType = new GetClassTypeReference (foundation, "ExportAttribute"); - iboutletAttType = new GetClassTypeReference (foundation, "OutletAttribute"); - ibactionAttType = new GetClassTypeReference (foundation, "ActionAttribute"); - registerAttType = new GetClassTypeReference (foundation, "RegisterAttribute"); - modelAttType = new GetClassTypeReference (foundation, "ModelAttribute"); - nsobjectType = new GetClassTypeReference (foundation, "NSObject"); + typeNamespace = wrapperRoot + ".Foundation"; + connectAttType = "ConnectAttribute"; + exportAttType = "ExportAttribute"; + iboutletAttType = "OutletAttribute"; + ibactionAttType = "ActionAttribute"; + registerAttType = "RegisterAttribute"; + modelAttType = "ModelAttribute"; + nsobjectType = "NSObject"; } public string WrapperRoot { get; private set; } - public NSObjectProjectInfo GetProjectInfo (DotNetProject project) + public NSObjectProjectInfo GetProjectInfo (DotNetProject project, IAssembly lookinAssembly = null) { - var dom = TypeSystemService.GetContext (project); + var dom = TypeSystemService.GetProjectContentWrapper (project); if (dom == null) return null; - TypeSystemService.ForceUpdate (dom); project.ReferenceAddedToProject += HandleDomReferencesUpdated; project.ReferenceRemovedFromProject += HandleDomReferencesUpdated; - return GetProjectInfo (dom); + return GetProjectInfo (dom, lookinAssembly); } - public NSObjectProjectInfo GetProjectInfo (ITypeResolveContext dom) + public NSObjectProjectInfo GetProjectInfo (TypeSystemService.ProjectContentWrapper dom, IAssembly lookinAssembly = null) { NSObjectProjectInfo info; @@ -95,14 +95,14 @@ namespace MonoDevelop.MacDev.ObjCIntegration if (infos.TryGetValue (dom, out info)) return info; + var nso = dom.Compilation.LookupType (typeNamespace, nsobjectType); //only include DOMs that can resolve NSObject - var nso = nsobjectType.Resolve (dom); - if (nso == null || nso == SharedTypes.UnknownType) { + if (nso == null || nso.Kind == TypeKind.Unknown) { infos[dom] = null; return null; } - info = new NSObjectProjectInfo (dom, this); + info = new NSObjectProjectInfo (dom, this, lookinAssembly); infos[dom] = info; } return info; @@ -111,7 +111,7 @@ namespace MonoDevelop.MacDev.ObjCIntegration static void HandleDomReferencesUpdated (object sender, ProjectReferenceEventArgs e) { var project = (DotNetProject)sender; - var dom = TypeSystemService.GetContext (project); + var dom = TypeSystemService.GetProjectContentWrapper (project); NSObjectProjectInfo info; lock (infos) { if (!infos.TryGetValue (dom, out info)) @@ -123,7 +123,7 @@ namespace MonoDevelop.MacDev.ObjCIntegration static void HandleDomUnloaded (object sender, ProjectEventArgs e) { var project = (DotNetProject)e.Project; - var dom = TypeSystemService.GetContext (project); + var dom = TypeSystemService.GetProjectContentWrapper (project); lock (infos) { project.ReferenceAddedToProject -= HandleDomReferencesUpdated; project.ReferenceRemovedFromProject -= HandleDomReferencesUpdated; @@ -131,78 +131,80 @@ namespace MonoDevelop.MacDev.ObjCIntegration } } - internal IEnumerable<NSObjectTypeInfo> GetRegisteredObjects (ITypeResolveContext dom) + internal IEnumerable<NSObjectTypeInfo> GetRegisteredObjects (TypeSystemService.ProjectContentWrapper dom, IAssembly assembly) { - var nso = nsobjectType.Resolve (dom); - if (nso == null || nso == SharedTypes.UnknownType) + var nso = dom.Compilation.LookupType (typeNamespace, nsobjectType); + if (nso == null || nso.Kind == TypeKind.Unknown) throw new Exception ("Could not get NSObject from type database"); //FIXME: only emit this for the wrapper NS // yield return new NSObjectTypeInfo ("NSObject", nso.GetDefinition ().FullName, null, null, false, false, false); + int cnt = 0, infcnt=0, models=0; - foreach (var type in nso.GetDefinition ().GetSubTypeDefinitions (dom)) { - var info = ConvertType (dom, type); - if (info != null) - yield return info; + foreach (var contextType in assembly.GetAllTypeDefinitions ()) { + if (contextType.IsDerivedFrom (nso)) { + var info = ConvertType (dom, contextType); + if (info != null) + yield return info; + } } } - NSObjectTypeInfo ConvertType (ITypeResolveContext dom, ITypeDefinition type) + NSObjectTypeInfo ConvertType (TypeSystemService.ProjectContentWrapper dom, ITypeDefinition type) { string objcName = null; bool isModel = false; bool registeredInDesigner = true; - foreach (var part in type.GetParts ()) { - foreach (var att in part.Attributes) { - var attType = att.AttributeType.Resolve (dom); - if (attType.Equals (registerAttType.Resolve (dom))) { - if (type.GetProjectContent () != null) { - registeredInDesigner &= - MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (part.Region.FileName); - } - - //type registered with an explicit type name are up to the user to provide a valid name - var posArgs = att.GetPositionalArguments (dom); - if (posArgs.Count == 1 || posArgs.Count == 2) - objcName = posArgs[0].ConstantValue as string; - //non-nested types in the root namespace have names accessible from obj-c - else if (string.IsNullOrEmpty (type.Namespace) && type.Name.IndexOf ('.') < 0) - objcName = type.Name; - } - if (attType.Equals (modelAttType.Resolve (dom))) { - isModel = true; + foreach (var att in type.Attributes) { + var attType = att.AttributeType; + if (attType.Equals (dom.Compilation.LookupType (typeNamespace, registerAttType))) { + if (type.GetProjectContent () != null) { + registeredInDesigner &= + MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (att.Region.FileName); } + + //type registered with an explicit type name are up to the user to provide a valid name + var posArgs = att.PositionalArguments; + if (posArgs.Count == 1 || posArgs.Count == 2) + objcName = posArgs[0].ConstantValue as string; + //non-nested types in the root namespace have names accessible from obj-c + else if (string.IsNullOrEmpty (type.Namespace) && type.Name.IndexOf ('.') < 0) + objcName = type.Name; + } + if (attType.Equals (dom.Compilation.LookupType (typeNamespace, modelAttType))) { + isModel = true; } } if (string.IsNullOrEmpty (objcName)) return null; - - var info = new NSObjectTypeInfo (objcName, type.FullName, null, type.BaseTypes.First ().Resolve (dom).FullName, isModel, + string baseType = type.DirectBaseTypes.First ().FullName; + if (baseType == "System.Object") + baseType = null; + var info = new NSObjectTypeInfo (objcName, type.FullName, null, baseType, isModel, type.GetSourceProject () != null, registeredInDesigner); if (info.IsUserType) { UpdateTypeMembers (dom, info, type); - info.DefinedIn = type.GetParts ().Select (p => (string) p.Region.FileName).ToArray (); + info.DefinedIn = type.Parts.Select (p => (string) p.Region.FileName).ToArray (); } return info; } - void UpdateTypeMembers (ITypeResolveContext dom, NSObjectTypeInfo info, ITypeDefinition type) + void UpdateTypeMembers (TypeSystemService.ProjectContentWrapper dom, NSObjectTypeInfo info, ITypeDefinition type) { info.Actions.Clear (); info.Outlets.Clear (); - foreach (var prop in type.Properties) { foreach (var att in prop.Attributes) { - var attType = att.AttributeType.Resolve (dom); - bool isIBOutlet = iboutletAttType.Resolve (dom).Equals (attType); + var attType = att.AttributeType; + bool isIBOutlet = attType.Equals (dom.Compilation.LookupType (typeNamespace, iboutletAttType)); if (!isIBOutlet) { - if (connectAttType.Resolve (dom).Equals (attType)) + if (attType.Equals (dom.Compilation.LookupType (typeNamespace, connectAttType))) continue; } string name = null; - var posArgs = att.GetPositionalArguments (dom); + var posArgs = att.PositionalArguments; if (posArgs.Count == 1) name = posArgs[0].ConstantValue as string; if (string.IsNullOrEmpty (name)) @@ -212,10 +214,10 @@ namespace MonoDevelop.MacDev.ObjCIntegration // with the name 'view' on subclasses of MonoTouch.UIKit.UIViewController to avoid // conflicts with the view property mapped there if (name == "view") - if (type.GetAllBaseTypeDefinitions (dom).Any (p => p.FullName == "MonoTouch.UIKit.UIViewController")) + if (type.GetAllBaseTypeDefinitions ().Any (p => p.FullName == "MonoTouch.UIKit.UIViewController")) continue; - var ol = new IBOutlet (name, prop.Name, null, prop.ReturnType.Resolve (dom).FullName); + var ol = new IBOutlet (name, prop.Name, null, prop.ReturnType.FullName); if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (prop.DeclaringTypeDefinition.Region.FileName)) ol.IsDesigner = true; info.Outlets.Add (ol); @@ -225,10 +227,10 @@ namespace MonoDevelop.MacDev.ObjCIntegration foreach (var meth in type.Methods) { foreach (var att in meth.Attributes) { - var attType = att.AttributeType.Resolve (dom); - bool isIBAction = ibactionAttType.Resolve (dom).Equals (attType); + var attType = att.AttributeType; + bool isIBAction = attType.Equals (dom.Compilation.LookupType (typeNamespace, ibactionAttType)); if (!isIBAction) { - if (exportAttType.Resolve (dom).Equals (attType)) + if (attType.Equals (dom.Compilation.LookupType (typeNamespace, exportAttType))) continue; } bool isDesigner = MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile ( @@ -238,8 +240,8 @@ namespace MonoDevelop.MacDev.ObjCIntegration continue; string[] name = null; - var posArgs = att.GetPositionalArguments (dom); - if (posArgs.Count == 1) { + var posArgs = att.PositionalArguments; + if (posArgs.Count == 1 || posArgs.Count == 2) { var n = posArgs[0].ConstantValue as string; if (!string.IsNullOrEmpty (n)) name = n.Split (colonChar); @@ -250,7 +252,7 @@ namespace MonoDevelop.MacDev.ObjCIntegration string label = name != null && i < name.Length? name[i] : null; if (label != null && label.Length == 0) label = null; - action.Parameters.Add (new IBActionParameter (label, param.Name, null, param.Type.Resolve (dom).FullName)); + action.Parameters.Add (new IBActionParameter (label, param.Name, null, param.Type.FullName)); } if (MonoDevelop.DesignerSupport.CodeBehind.IsDesignerFile (meth.DeclaringTypeDefinition.Region.FileName)) action.IsDesigner = true; diff --git a/main/src/addins/MonoDevelop.MacDev/ObjCIntegration/NSObjectProjectInfo.cs b/main/src/addins/MonoDevelop.MacDev/ObjCIntegration/NSObjectProjectInfo.cs index 1356bddaad..eb2a132495 100644..100755 --- a/main/src/addins/MonoDevelop.MacDev/ObjCIntegration/NSObjectProjectInfo.cs +++ b/main/src/addins/MonoDevelop.MacDev/ObjCIntegration/NSObjectProjectInfo.cs @@ -45,15 +45,19 @@ namespace MonoDevelop.MacDev.ObjCIntegration { Dictionary<string,NSObjectTypeInfo> objcTypes = new Dictionary<string,NSObjectTypeInfo> (); Dictionary<string,NSObjectTypeInfo> cliTypes = new Dictionary<string,NSObjectTypeInfo> (); + Dictionary<string,NSObjectTypeInfo> refCliTypes = new Dictionary<string,NSObjectTypeInfo> (); + Dictionary<string,NSObjectTypeInfo> refObjcTypes = new Dictionary<string,NSObjectTypeInfo> (); NSObjectInfoService infoService; - ITypeResolveContext dom; + TypeSystemService.ProjectContentWrapper dom; + IAssembly lookinAssembly; bool needsUpdating; - public NSObjectProjectInfo (ITypeResolveContext dom, NSObjectInfoService infoService) + public NSObjectProjectInfo (TypeSystemService.ProjectContentWrapper dom, NSObjectInfoService infoService, IAssembly lookinAssembly) { this.infoService = infoService; this.dom = dom; + this.lookinAssembly = lookinAssembly; needsUpdating = true; } @@ -69,32 +73,17 @@ namespace MonoDevelop.MacDev.ObjCIntegration Update (); } - static IEnumerable<DotNetProject> GetReferencedProjects (DotNetProject project) - { - // is there an easier way doing that ? - foreach (var r in project.References.Where (rf => rf.ReferenceType == ReferenceType.Project)) { - var refProject = project.ParentSolution.GetAllProjects ().First (p => p.Name == r.Reference) as DotNetProject; - if (refProject != null) - yield return refProject; - } - } - internal void Update () { if (!needsUpdating) return; - foreach (var r in References) { - var info = infoService.GetProjectInfo (r); - if (info != null) - info.Update (); - } - objcTypes.Clear (); cliTypes.Clear (); + refObjcTypes.Clear (); + refCliTypes.Clear (); - - foreach (var type in infoService.GetRegisteredObjects (dom)) { + foreach (var type in infoService.GetRegisteredObjects (dom, dom.Compilation.MainAssembly)) { if (objcTypes.ContainsKey (type.ObjCName)) { var other = objcTypes[type.ObjCName]; throw new ArgumentException (string.Format ("Multiple types ({0} and {1}) registered with the same Objective-C name: {2}", type.CliName, other.CliName, type.ObjCName)); @@ -104,6 +93,18 @@ namespace MonoDevelop.MacDev.ObjCIntegration cliTypes.Add (type.CliName, type); } + foreach (var refAssembly in dom.Compilation.ReferencedAssemblies) { + foreach (var type in infoService.GetRegisteredObjects (dom, refAssembly)) { + if (refObjcTypes.ContainsKey (type.ObjCName)) { + var other = refObjcTypes[type.ObjCName]; + throw new ArgumentException (string.Format ("Multiple types ({0} and {1}) registered with the same Objective-C name: {2}", type.CliName, other.CliName, type.ObjCName)); + } + + refObjcTypes.Add (type.ObjCName, type); + refCliTypes.Add (type.CliName, type); + } + } + foreach (var type in cliTypes.Values) ResolveCliToObjc (type); @@ -134,24 +135,12 @@ namespace MonoDevelop.MacDev.ObjCIntegration cliTypes[type.CliName] = type; } - IEnumerable<ITypeResolveContext> References { - get { - var compCtx = dom as ICSharpCode.NRefactory.TypeSystem.Implementation.CompositeTypeResolveContext; - if (compCtx == null) - return Enumerable.Empty<ITypeResolveContext> (); - return compCtx.Children.Take (1); - } - } - bool TryResolveCliToObjc (string cliType, out NSObjectTypeInfo resolved) { if (cliTypes.TryGetValue (cliType, out resolved)) return true; - foreach (var r in References) { - var rDom = infoService.GetProjectInfo (r); - if (rDom != null && rDom.cliTypes.TryGetValue (cliType, out resolved)) - return true; - } + if (refCliTypes.TryGetValue (cliType, out resolved)) + return true; resolved = null; return false; } @@ -160,11 +149,8 @@ namespace MonoDevelop.MacDev.ObjCIntegration { if (objcTypes.TryGetValue (objcType, out resolved)) return true; - foreach (var r in References) { - var rDom = infoService.GetProjectInfo (r); - if (rDom != null && rDom.objcTypes.TryGetValue (objcType, out resolved)) - return true; - } + if (refObjcTypes.TryGetValue (objcType, out resolved)) + return true; #if false var msg = new StringBuilder ("Can't resolve "+ objcType + Environment.NewLine); foreach (var r in dom.References) { @@ -206,8 +192,8 @@ namespace MonoDevelop.MacDev.ObjCIntegration //managed classes many have implicitly registered base classes with a name not //expressible in obj-c. In this case, the best we can do is walk down the //hierarchy until we find a valid base class - var baseCliType = new GetClassTypeReference (type.BaseCliType).Resolve (dom); - foreach (var bt in baseCliType.GetAllBaseTypeDefinitions (dom)) { + var baseCliType = dom.Compilation.LookupType (type.BaseCliType); + foreach (var bt in baseCliType.GetAllBaseTypeDefinitions ()) { if (bt.Kind != TypeKind.Class) continue; @@ -273,7 +259,7 @@ namespace MonoDevelop.MacDev.ObjCIntegration if (TryResolveObjcToCli (type.BaseObjCType, out resolved)) { type.BaseCliType = resolved.CliName; } else { - type.BaseCliType = new GetClassTypeReference (defaultNamespace, provider.CreateValidIdentifier (type.BaseObjCType)).Resolve (dom).FullName; + type.BaseCliType = dom.Compilation.LookupType (defaultNamespace, provider.CreateValidIdentifier (type.BaseObjCType)).FullName; monitor.ReportWarning (string.Format ("Failed to resolve Objective-C type {0} to CLI type on type {1}", type.BaseObjCType, type.ObjCName)); } diff --git a/main/src/addins/MonoDevelop.MacDev/ObjCIntegration/NSObjectTypeInfo.cs b/main/src/addins/MonoDevelop.MacDev/ObjCIntegration/NSObjectTypeInfo.cs index 9dca26ea8c..dfa1d0db53 100644..100755 --- a/main/src/addins/MonoDevelop.MacDev/ObjCIntegration/NSObjectTypeInfo.cs +++ b/main/src/addins/MonoDevelop.MacDev/ObjCIntegration/NSObjectTypeInfo.cs @@ -389,6 +389,11 @@ namespace MonoDevelop.MacDev.ObjCIntegration return meth; } + + public override string ToString () + { + return string.Format ("[NSObjectTypeInfo: ObjCName={0}, CliName={1}, IsModel={2}, BaseObjCType={3}, BaseCliType={4}, BaseIsModel={5}, IsUserType={6}, IsRegisteredInDesigner={7}, Outlets={8}, Actions={9}, DefinedIn={10}, UserTypeReferences={11}]", ObjCName, CliName, IsModel, BaseObjCType, BaseCliType, BaseIsModel, IsUserType, IsRegisteredInDesigner, Outlets, Actions, DefinedIn, UserTypeReferences); + } } class ObjectiveCGenerationException : Exception diff --git a/main/src/addins/MonoDevelop.Moonlight/MonoDevelop.Moonlight.Gui/MoonlightOptionsPanelWidget.cs b/main/src/addins/MonoDevelop.Moonlight/MonoDevelop.Moonlight.Gui/MoonlightOptionsPanelWidget.cs index 155afdb78e..3ad1524b12 100644..100755 --- a/main/src/addins/MonoDevelop.Moonlight/MonoDevelop.Moonlight.Gui/MoonlightOptionsPanelWidget.cs +++ b/main/src/addins/MonoDevelop.Moonlight/MonoDevelop.Moonlight.Gui/MoonlightOptionsPanelWidget.cs @@ -95,7 +95,7 @@ namespace MonoDevelop.Moonlight.Gui classesFilled = true; try { var dom = TypeSystemService.GetCompilation (project); - IType appType = dom.FindType ("System.Windows.Application"); + IType appType = dom.LookupType ("System.Windows", "Application"); if (appType == null) return; foreach (IType type in appType.GetAllBaseTypes ()) diff --git a/main/src/addins/MonoDevelop.Moonlight/MonoDevelop.Moonlight/MoonlightEditorExtension.cs b/main/src/addins/MonoDevelop.Moonlight/MonoDevelop.Moonlight/MoonlightEditorExtension.cs index 7b0b7b1861..5496c66dc5 100644..100755 --- a/main/src/addins/MonoDevelop.Moonlight/MonoDevelop.Moonlight/MoonlightEditorExtension.cs +++ b/main/src/addins/MonoDevelop.Moonlight/MonoDevelop.Moonlight/MoonlightEditorExtension.cs @@ -59,7 +59,7 @@ namespace MonoDevelop.Moonlight if (database == null) yield break; - var swd = database.FindType ("System.Windows.DependencyObject"); + var swd = database.LookupType ("System.Windows", "DependencyObject"); //return classes if they derive from system.web.ui.control foreach (var cls in namespac.Types) { @@ -125,7 +125,7 @@ namespace MonoDevelop.Moonlight if (database == null) return; - IType type = database.FindType ("System.Windows.DependencyObject"); + IType type = database.LookupType ("System.Windows", "DependencyObject"); if (type == null) return; diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/CodeTemplate.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/CodeTemplate.cs index 3787c8d692..180b8aba09 100644..100755 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/CodeTemplate.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/CodeTemplate.cs @@ -393,7 +393,6 @@ namespace MonoDevelop.Ide.CodeTemplates /// </summary> public TemplateResult InsertTemplateContents (MonoDevelop.Ide.Gui.Document document) { - var dom = document.TypeResolveContext; var doc = document.UpdateParseDocument (); Mono.TextEditor.TextEditorData data = document.Editor; @@ -403,7 +402,6 @@ namespace MonoDevelop.Ide.CodeTemplates TemplateContext context = new TemplateContext { Template = this, Document = document, - Ctx = dom, ParsedDocument = doc, InsertPosition = data.Caret.Location, LineIndent = data.Document.GetLineIndent (data.Caret.Line), diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/ExpansionObject.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/ExpansionObject.cs index f93dd4b054..2c98ea1d2c 100644..100755 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/ExpansionObject.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.CodeTemplates/ExpansionObject.cs @@ -47,9 +47,10 @@ namespace MonoDevelop.Ide.CodeTemplates set; } - public IProjectContent Ctx { - get; - set; + public ICompilation Compilation { + get { + return Document.Compilation; + } } public IParsedFile ParsedDocument { @@ -137,7 +138,7 @@ namespace MonoDevelop.Ide.CodeTemplates return pt.TypeArguments[0]; } } else if (baseTypeDef.Namespace == "System.Collections" && baseTypeDef.TypeParameterCount == 0) { - return CurrentContext.Ctx.CreateCompilation ().FindType (KnownTypeCode.Object); + return CurrentContext.Compilation.FindType (KnownTypeCode.Object); } } } @@ -171,7 +172,6 @@ namespace MonoDevelop.Ide.CodeTemplates { var result = new List<CodeTemplateVariableValue> (); var ext = CurrentContext.Document.GetContent <CompletionTextEditorExtension> (); - var ctx = CurrentContext.Ctx; if (ext != null) { if (list == null) list = ext.CodeCompletionCommand (CurrentContext.Document.GetContent <MonoDevelop.Ide.CodeCompletion.ICompletionWidget> ().CurrentCodeCompletionContext); @@ -233,7 +233,7 @@ namespace MonoDevelop.Ide.CodeTemplates name = name.Substring (0, idx); } - var type = CurrentContext.Ctx.CreateCompilation ().FindType (string.IsNullOrEmpty (ns) ? name : ns + "." + name); + var type = CurrentContext.Compilation.LookupType (ns, name); if (type == null || type.Kind == TypeKind.Unknown) return fullTypeName; var generator = CodeGenerator.CreateGenerator (CurrentContext.Document.Editor); diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/NetAmbience.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/NetAmbience.cs index 5ab371c335..f8ab0d3a8e 100644..100755 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/NetAmbience.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/NetAmbience.cs @@ -90,7 +90,7 @@ namespace MonoDevelop.TypeSystem result.Append (settings.Markup (" : ")); bool first = true; foreach (var baseType in type.DirectBaseTypes) { - if (baseType.Equals (type.Compilation.FindType (typeof(object)))) + if (baseType.Equals (type.Compilation.FindType (KnownTypeCode.Object))) continue; if (!first) result.Append (settings.Markup (", ")); diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/TypeSystemService.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/TypeSystemService.cs index a63f8779f3..bda5c520f2 100644..100755 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/TypeSystemService.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/TypeSystemService.cs @@ -99,6 +99,33 @@ namespace MonoDevelop.TypeSystem var ctx = pf.GetTypeResolveContext (TypeSystemService.GetCompilation (project), def.Region.Begin); return def.Resolve (ctx); } + + public static ITypeDefinition LookupType (this ICompilation compilation, string ns, string name, int typeParameterCount = 0) + { + var result = compilation.MainAssembly.GetTypeDefinition (ns, name, typeParameterCount); + if (result != null) + return result; + foreach (var refAsm in compilation.ReferencedAssemblies) { + result = refAsm.GetTypeDefinition (ns, name, typeParameterCount); + if (result != null) + return result; + } + return null; + } + + public static ITypeDefinition LookupType (this ICompilation compilation, string fullName, int typeParameterCount = 0) + { + int idx = fullName.LastIndexOf ('.'); + string ns, name; + if (idx > 0) { + ns = fullName.Substring (0, idx); + name = fullName.Substring (idx + 1); + } else { + ns = ""; + name = fullName; + } + return compilation.LookupType (ns, name, typeParameterCount); + } } public static class TypeSystemService @@ -462,11 +489,30 @@ namespace MonoDevelop.TypeSystem } } + public Project Project { + get { + foreach (var pair in projectContents){ + if (pair.Value == this) + return pair.Key; + } + return null; + } + } + public ProjectContentWrapper (IProjectContent content) { this.content = content; } + + public IEnumerable<Project> GetReferencedProjects (Project project) + { + foreach (var pr in project.GetReferencedItems (ConfigurationSelector.Default)) { + var referencedProject = pr as Project; + if (referencedProject != null) + yield return referencedProject; + } + } public void ReloadAssemblyReferences (Project project) { @@ -475,10 +521,7 @@ namespace MonoDevelop.TypeSystem return; var contexts = new List<IAssemblyReference> (); - foreach (var pr in project.GetReferencedItems (ConfigurationSelector.Default)) { - var referencedProject = pr as Project; - if (referencedProject == null) - continue; + foreach (var referencedProject in GetReferencedProjects (project)) { ProjectContentWrapper wrapper; if (projectContents.TryGetValue (referencedProject, out wrapper)) contexts.Add (wrapper.Compilation.MainAssembly.UnresolvedAssembly); @@ -914,6 +957,15 @@ namespace MonoDevelop.TypeSystem return content.Compilation; } + public static ProjectContentWrapper GetProjectContentWrapper (Project project) + { + if (project == null) + return null; + ProjectContentWrapper content; + projectContents.TryGetValue (project, out content); + return content; + } + public static IProjectContent GetContext (FilePath file, string mimeType, string text) { using (var reader = new StringReader (text)) { @@ -927,7 +979,7 @@ namespace MonoDevelop.TypeSystem static Dictionary<Project, ITypeResolveContext> cachedProjectContents = new Dictionary<Project, ITypeResolveContext> (); static Dictionary<string, AssemblyContext> cachedAssemblyContents = new Dictionary<string, AssemblyContext> (); - public static void ForceUpdate (ITypeResolveContext context) + public static void ForceUpdate (ProjectContentWrapper context) { CheckModifiedFiles (); } |