diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2011-12-01 16:34:22 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2011-12-01 16:34:22 +0400 |
commit | e671ab729696d6b66baa6bffad8ca01e8596bd45 (patch) | |
tree | e721d7908caa397c95dbbae6fe6c3f05960f32cd /main/src | |
parent | 1dab32d1174d225b14989c9e4776c53fb8e20b44 (diff) |
[AspNet] Track nrefactory API changes.
Diffstat (limited to 'main/src')
22 files changed, 342 insertions, 347 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 4f02606d52..24d1decd03 100644 --- a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Gui/AspNetEditorExtension.cs +++ b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Gui/AspNetEditorExtension.cs @@ -95,26 +95,26 @@ namespace MonoDevelop.AspNet.Gui if (documentBuilder != null) { var usings = refman.GetUsings (); - documentInfo = new DocumentInfo (document.TypeResolveContext, aspDoc, usings, refman.GetDoms ()); + documentInfo = new DocumentInfo (document.Compilation, aspDoc, usings, refman.GetDoms ()); documentInfo.ParsedDocument = documentBuilder.BuildDocument (documentInfo, Editor); documentInfo.CodeBesideClass = CreateCodeBesideClass (documentInfo, refman); - var domWrapper = new AspProjectDomWrapper (documentInfo); +/* var domWrapper = new AspProjectDomWrapper (documentInfo); if (localDocumentInfo != null) - localDocumentInfo.HiddenDocument.HiddenContext = domWrapper; + localDocumentInfo.HiddenDocument.HiddenContext = domWrapper;*/ } } - static ITypeDefinition CreateCodeBesideClass (DocumentInfo info, DocumentReferenceManager refman) + static IUnresolvedTypeDefinition CreateCodeBesideClass (DocumentInfo info, DocumentReferenceManager refman) { var v = new MemberListVisitor (info.AspNetDocument, refman); info.AspNetDocument.RootNode.AcceptVisit (v); - var t = new ICSharpCode.NRefactory.TypeSystem.Implementation.DefaultTypeDefinition (null, info.ClassName); - var dom = refman.TypeCtx.TypeResolveContext; - var baseType = dom.GetTypeDefinition ("", info.BaseType, 0, StringComparer.Ordinal); - foreach (var m in CodeBehind.GetDesignerMembers (v.Members.Values, baseType, null, dom, null)) { - t.Fields.Add (new ICSharpCode.NRefactory.TypeSystem.Implementation.DefaultField (t, m.Name) { + var t = new ICSharpCode.NRefactory.TypeSystem.Implementation.DefaultUnresolvedTypeDefinition (info.ClassName); + var dom = refman.TypeCtx.Compilation; + var baseType = dom.FindType (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, - ReturnType = m.Type + ReturnType = m.Type.ToTypeReference () }); } return t; @@ -238,8 +238,7 @@ namespace MonoDevelop.AspNet.Gui var workbenchWindow = new MonoDevelop.Ide.Gui.HiddenWorkbenchWindow (); workbenchWindow.ViewContent = viewContent; localDocumentInfo.HiddenDocument = new HiddenDocument (workbenchWindow) { - HiddenParsedDocument = localDocumentInfo.ParsedLocalDocument, - HiddenContext = domWrapper + HiddenParsedDocument = localDocumentInfo.ParsedLocalDocument }; } @@ -257,7 +256,7 @@ namespace MonoDevelop.AspNet.Gui ICompletionWidget defaultCompletionWidget; MonoDevelop.Ide.Gui.Document defaultDocument; - AspProjectDomWrapper domWrapper; +// AspProjectDomWrapper domWrapper; public override void Initialize () { base.Initialize (); @@ -344,7 +343,7 @@ namespace MonoDevelop.AspNet.Gui if (!HasDoc) { AddAspBeginExpressions (list); string aspPrefix = "asp:"; - foreach (var cls in WebTypeContext.ListSystemControlClasses (TypeSystemService.GetContext (project).GetTypeDefinition ("System.Web.UI", "Control", 0, StringComparer.Ordinal), project)) + foreach (var cls in WebTypeContext.ListSystemControlClasses (TypeSystemService.GetCompilation (project).FindType ("System.Web.UI.Control"), project)) list.Add (new AspTagCompletionData (aspPrefix, cls)); base.GetElementCompletions (list); @@ -382,9 +381,8 @@ namespace MonoDevelop.AspNet.Gui return; } - var ctx = controlClass.GetProjectContent (); string defaultProp; - bool childrenAsProperties = AreChildrenAsProperties (ctx, controlClass, out defaultProp); + bool childrenAsProperties = AreChildrenAsProperties (controlClass, out defaultProp); if (defaultProp != null && defaultProp.Length == 0) defaultProp = null; @@ -407,7 +405,7 @@ namespace MonoDevelop.AspNet.Gui string propName = defaultProp ?? parentName.Name; IProperty property = - GetAllProperties (controlClass.GetProjectContent (), controlClass) + controlClass.GetProperties () .Where (x => string.Compare (propName, x.Name, StringComparison.OrdinalIgnoreCase) == 0) .FirstOrDefault (); @@ -415,7 +413,7 @@ namespace MonoDevelop.AspNet.Gui return; //sanity checks on attributes - switch (GetPersistenceMode (ctx, property)) { + switch (GetPersistenceMode (property)) { case System.Web.UI.PersistenceMode.Attribute: case System.Web.UI.PersistenceMode.EncodedInnerDefaultProperty: return; @@ -444,19 +442,19 @@ namespace MonoDevelop.AspNet.Gui //to be able to resolve the correct child types here //so we assume it's a list and have a quick hack to find arguments of strongly typed ILists - IType collectionType = property.ReturnType.Resolve (controlClass.GetProjectContent ()); + IType collectionType = property.ReturnType; if (collectionType == null) { list.AddRange (refman.GetControlCompletionData ()); return; } string addStr = "Add"; - IMethod meth = GetAllMethods (ctx, collectionType) + IMethod meth = collectionType.GetMethods () .Where (m => m.Parameters.Count == 1 && m.Name == addStr).FirstOrDefault (); if (meth != null) { - IType argType = meth.Parameters [0].Type.Resolve (ctx); - if (argType != null && argType.IsBaseType (ctx, ctx.GetTypeDefinition ("System.Web.UI", "Control", 0, StringComparer.Ordinal))) { + IType argType = meth.Parameters [0].Type; + if (argType != null && argType.IsBaseType (argType.GetDefinition ().Compilation.FindType ("System.Web.UI.Control"))) { list.AddRange (refman.GetControlCompletionData (argType)); return; } @@ -472,8 +470,8 @@ namespace MonoDevelop.AspNet.Gui LoggingService.LogWarning ("IType {0} does not have a SourceProjectDom", controlClass); } - foreach (IProperty prop in GetUniqueMembers<IProperty> (GetAllProperties (controlClass.GetProjectContent (), controlClass))) - if (GetPersistenceMode (ctx, prop) != System.Web.UI.PersistenceMode.Attribute) + foreach (IProperty prop in GetUniqueMembers<IProperty> (controlClass.GetProperties ())) + if (GetPersistenceMode (prop) != System.Web.UI.PersistenceMode.Attribute) list.Add (prop.Name, prop.GetStockIcon (), prop.Documentation); return; } @@ -536,8 +534,8 @@ namespace MonoDevelop.AspNet.Gui { if (!(expr is AspNetDataBindingExpression || expr is AspNetRenderExpression)) return null; - ITypeDefinition codeBehindClass; - ITypeResolveContext projectDatabase; + IType codeBehindClass; + ICompilation projectDatabase; GetCodeBehind (out codeBehindClass, out projectDatabase); if (codeBehindClass == null) @@ -545,25 +543,25 @@ namespace MonoDevelop.AspNet.Gui //list just the class's properties, not properties on base types CompletionDataList list = new CompletionDataList (); - list.AddRange (from p in codeBehindClass.GetProperties (projectDatabase) + list.AddRange (from p in codeBehindClass.GetProperties () where p.IsPublic || p.IsPublic select new CompletionData (p.Name, "md-property")); - list.AddRange (from p in codeBehindClass.GetFields (projectDatabase) + list.AddRange (from p in codeBehindClass.GetFields () where p.IsProtected || p.IsPublic select new CompletionData (p.Name, "md-property")); return list.Count > 0? list : null; } - void GetCodeBehind (out ITypeDefinition codeBehindClass, out ITypeResolveContext projectDatabase) + void GetCodeBehind (out IType codeBehindClass, out ICompilation projectDatabase) { codeBehindClass = null; projectDatabase = null; if (HasDoc && !string.IsNullOrEmpty (aspDoc.Info.InheritedClass)) { - projectDatabase = TypeSystemService.GetContext (project); + projectDatabase = TypeSystemService.GetCompilation (project); if (projectDatabase != null) - codeBehindClass = projectDatabase.GetTypeDefinition ("", aspDoc.Info.InheritedClass, 0, StringComparer.Ordinal); + codeBehindClass = projectDatabase.FindType (aspDoc.Info.InheritedClass); } } @@ -593,7 +591,7 @@ namespace MonoDevelop.AspNet.Gui Debug.Assert (name.IsValid); Debug.Assert (name.HasPrefix); - var database = TypeSystemService.GetContext (project); + var database = TypeSystemService.GetCompilation (project); if (database == null) { LoggingService.LogWarning ("Could not obtain project DOM in AddAspAttributeCompletionData"); @@ -602,27 +600,27 @@ namespace MonoDevelop.AspNet.Gui IType controlClass = refman.GetControlType (name.Prefix, name.Name); if (controlClass == null) { - controlClass = database.GetTypeDefinition ("System.Web.UI.WebControls", "WebControl", 0 , StringComparer.Ordinal); + controlClass = database.FindType ("System.Web.UI.WebControls.WebControl"); if (controlClass == null) { LoggingService.LogWarning ("Could not obtain IType for System.Web.UI.WebControls.WebControl"); return; } } - AddControlMembers (list, database, controlClass, existingAtts); + AddControlMembers (list, controlClass, existingAtts); } - void AddControlMembers (CompletionDataList list, ITypeResolveContext database, IType controlClass, + void AddControlMembers (CompletionDataList list, IType controlClass, Dictionary<string, string> existingAtts) { //add atts only if they're not already in the tag - foreach (var prop in GetUniqueMembers<IProperty> (GetAllProperties (database, controlClass))) + foreach (var prop in GetUniqueMembers<IProperty> (controlClass.GetProperties ())) if (prop.Accessibility == Accessibility.Public && (existingAtts == null || !existingAtts.ContainsKey (prop.Name))) - if (GetPersistenceMode (database, prop) == System.Web.UI.PersistenceMode.Attribute) + if (GetPersistenceMode (prop) == System.Web.UI.PersistenceMode.Attribute) list.Add (prop.Name, prop.GetStockIcon (), prop.Documentation); //similarly add events - foreach (var eve in GetUniqueMembers<IEvent> (GetAllEvents (database, controlClass))) { + foreach (var eve in GetUniqueMembers<IEvent> (controlClass.GetEvents ())) { string eveName = "On" + eve.Name; if (eve.Accessibility == Accessibility.Public && (existingAtts == null || !existingAtts.ContainsKey (eveName))) list.Add (eveName, eve.GetStockIcon (), eve.Documentation); @@ -640,7 +638,7 @@ namespace MonoDevelop.AspNet.Gui LoggingService.LogWarning ("Could not obtain IType for {0}", tagName.FullName); var database = WebTypeContext.GetSystemWebDom (project); - controlClass = database.GetTypeDefinition ("System.Web.UI.WebControls", "WebControl", 0, StringComparer.Ordinal); + controlClass = database.FindType ("System.Web.UI.WebControls.WebControl"); if (controlClass == null) { LoggingService.LogWarning ("Could not obtain IType for System.Web.UI.WebControls.WebControl"); @@ -649,22 +647,22 @@ namespace MonoDevelop.AspNet.Gui } //find the codebehind class - ITypeDefinition codeBehindClass; - ITypeResolveContext projectDatabase; + IType codeBehindClass; + ICompilation projectDatabase; GetCodeBehind (out codeBehindClass, out projectDatabase); //if it's an event, suggest compatible methods if (codeBehindClass != null && attName.Name.StartsWith ("On")) { string eventName = attName.Name.Substring (2); - foreach (IEvent ev in GetAllEvents (projectDatabase, controlClass)) { + foreach (IEvent ev in controlClass.GetEvents ()) { if (ev.Name == eventName) { - var domMethod = BindingService.MDDomToCodeDomMethod (projectDatabase, ev); + var domMethod = BindingService.MDDomToCodeDomMethod (ev); if (domMethod == null) return; foreach (IMethod meth - in BindingService.GetCompatibleMethodsInClass (projectDatabase, codeBehindClass, ev)) + in BindingService.GetCompatibleMethodsInClass (codeBehindClass, ev)) { list.Add (meth.Name, "md-method", GettextCatalog.GetString ("A compatible method in the CodeBehind class")); @@ -678,7 +676,7 @@ namespace MonoDevelop.AspNet.Gui } domMethod.Name = BindingService.GenerateIdentifierUniqueInClass - (projectDatabase, codeBehindClass, suggestedIdentifier); + (codeBehindClass, suggestedIdentifier); domMethod.Attributes = (domMethod.Attributes & ~System.CodeDom.MemberAttributes.AccessMask) | System.CodeDom.MemberAttributes.Family; @@ -701,17 +699,17 @@ namespace MonoDevelop.AspNet.Gui } //if it's a property and is an enum or bool, suggest valid values - foreach (IProperty prop in GetAllProperties (projectDatabase, controlClass)) { + foreach (IProperty prop in controlClass.GetProperties ()) { if (prop.Name != attName.Name) continue; //boolean completion - if (prop.ReturnType.Resolve (projectDatabase).Equals (projectDatabase.GetTypeDefinition (typeof (bool)))) { + if (prop.ReturnType.Equals (projectDatabase.FindType (KnownTypeCode.Boolean))) { AddBooleanCompletionData (list); return; } //color completion - if (prop.ReturnType.Resolve (projectDatabase).Equals (projectDatabase.GetTypeDefinition (typeof (System.Drawing.Color)))) { + if (prop.ReturnType.Equals (projectDatabase.FindType (typeof (System.Drawing.Color)))) { System.Drawing.ColorConverter conv = new System.Drawing.ColorConverter (); foreach (System.Drawing.Color c in conv.GetStandardValues (null)) { if (c.IsSystemColor) @@ -723,9 +721,9 @@ namespace MonoDevelop.AspNet.Gui } //enum completion - IType retCls = prop.ReturnType.Resolve (projectDatabase); - if (retCls != null && retCls.IsEnum ()) { - foreach (var enumVal in retCls.GetFields (projectDatabase)) + IType retCls = prop.ReturnType; + if (retCls != null && retCls.Kind == TypeKind.Enum) { + foreach (var enumVal in retCls.GetFields ()) if (enumVal.IsPublic && enumVal.IsStatic) list.Add (enumVal.Name, "md-literal", enumVal.Documentation); return; @@ -744,27 +742,6 @@ namespace MonoDevelop.AspNet.Gui } } - static IEnumerable<IProperty> GetAllProperties ( - ITypeResolveContext projectDatabase, - IType cls) - { - return cls.GetProperties (projectDatabase); - } - - static IEnumerable<IEvent> GetAllEvents ( - ITypeResolveContext projectDatabase, - IType cls) - { - return cls.GetEvents (projectDatabase); - } - - static IEnumerable<IMethod> GetAllMethods ( - ITypeResolveContext projectDatabase, - IType cls) - { - return cls.GetMethods (projectDatabase); - } - static void AddBooleanCompletionData (CompletionDataList list) { list.Add ("true", "md-literal"); @@ -775,11 +752,11 @@ namespace MonoDevelop.AspNet.Gui #region Querying types' attributes - static System.Web.UI.PersistenceMode GetPersistenceMode (ITypeResolveContext projectDatabase, IProperty prop) + static System.Web.UI.PersistenceMode GetPersistenceMode (IProperty prop) { foreach (var att in prop.Attributes) { - if (att.AttributeType.Resolve (projectDatabase).ReflectionName == "System.Web.UI.PersistenceModeAttribute") { - var expr = att.GetPositionalArguments (projectDatabase).FirstOrDefault (); + if (att.AttributeType.ReflectionName == "System.Web.UI.PersistenceModeAttribute") { + var expr = att.PositionalArguments.FirstOrDefault (); if (expr == null) { LoggingService.LogWarning ("Unknown expression type {0} in IAttribute parameter", expr); return System.Web.UI.PersistenceMode.Attribute; @@ -787,7 +764,7 @@ namespace MonoDevelop.AspNet.Gui return (System.Web.UI.PersistenceMode) expr.ConstantValue; } - else if (att.AttributeType.Resolve (projectDatabase).ReflectionName == "System.Web.UI.TemplateContainerAttribute") + else if (att.AttributeType.ReflectionName == "System.Web.UI.TemplateContainerAttribute") { return System.Web.UI.PersistenceMode.InnerProperty; } @@ -795,13 +772,13 @@ namespace MonoDevelop.AspNet.Gui return System.Web.UI.PersistenceMode.Attribute; } - static bool AreChildrenAsProperties (ITypeResolveContext ctx, IType type, out string defaultProperty) + static bool AreChildrenAsProperties (IType type, out string defaultProperty) { bool childrenAsProperties = false; defaultProperty = ""; - IAttribute att = GetAttributes (ctx, type, "System.Web.UI.ParseChildrenAttribute").FirstOrDefault (); - var posArgs = att.GetPositionalArguments (ctx); + IAttribute att = GetAttributes (type, "System.Web.UI.ParseChildrenAttribute").FirstOrDefault (); + var posArgs = att.PositionalArguments; if (att == null || posArgs.Count == 0) return childrenAsProperties; @@ -830,25 +807,25 @@ namespace MonoDevelop.AspNet.Gui defaultProperty = (string)expr.ConstantValue; } - var namedArgs = att.GetNamedArguments (ctx); + var namedArgs = att.NamedArguments; if (namedArgs.Count > 0) { - if (namedArgs.Any (p => p.Key == "ChildrenAsProperties")) { - var expr = namedArgs.First (p => p.Key == "ChildrenAsProperties").Value; + if (namedArgs.Any (p => p.Key.Name == "ChildrenAsProperties")) { + var expr = namedArgs.First (p => p.Key.Name == "ChildrenAsProperties").Value; if (expr == null) { LoggingService.LogWarning ("Unknown expression type {0} in IAttribute parameter", expr); return false; } childrenAsProperties = (bool)expr.ConstantValue; } - if (namedArgs.Any (p => p.Key == "DefaultProperty")) { - var expr = namedArgs.First (p => p.Key == "DefaultProperty").Value; + if (namedArgs.Any (p => p.Key.Name == "DefaultProperty")) { + var expr = namedArgs.First (p => p.Key.Name == "DefaultProperty").Value; if (expr == null) { LoggingService.LogWarning ("Unknown expression type {0} in IAttribute parameter", expr); return false; } defaultProperty = (string)expr.ConstantValue; } - if (namedArgs.Any (p => p.Key == "ChildControlType")) { + if (namedArgs.Any (p => p.Key.Name == "ChildControlType")) { //TODO: implement this LoggingService.LogWarning ("ASP.NET completion does not yet handle ParseChildrenAttribute (Type)"); return false; @@ -858,10 +835,10 @@ namespace MonoDevelop.AspNet.Gui return childrenAsProperties; } - static IEnumerable<IAttribute> GetAttributes (ITypeResolveContext ctx, IType type, string attName) + static IEnumerable<IAttribute> GetAttributes (IType type, string attName) { foreach (var att in type.GetDefinition ().Attributes) { - if (att.AttributeType.Resolve (ctx).ReflectionName == attName) + if (att.AttributeType.ReflectionName == attName) yield return att; } @@ -870,9 +847,9 @@ namespace MonoDevelop.AspNet.Gui yield break; } - foreach (IType t2 in type.GetAllBaseTypes (ctx)) { + foreach (IType t2 in type.GetAllBaseTypes ()) { foreach (IAttribute att in t2.GetDefinition ().Attributes) - if (att.AttributeType.Resolve (ctx).ReflectionName == attName) + if (att.AttributeType.ReflectionName == attName) yield return att; } } diff --git a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Gui/AspProjectDom.cs b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Gui/AspProjectDom.cs index 01a797e7f0..6b29cee292 100644 --- a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Gui/AspProjectDom.cs +++ b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Gui/AspProjectDom.cs @@ -1,84 +1,84 @@ -// -// AspProjectDom.cs -// -// Author: -// Michael Hutchinson <mhutchinson@novell.com> -// -// Copyright (c) 2010 Novell, Inc. (http://www.novell.com) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -using System; -using System.Collections.Generic; -using System.Linq; -using ICSharpCode.NRefactory.TypeSystem; -using ICSharpCode.NRefactory.TypeSystem.Implementation; - - -namespace MonoDevelop.AspNet.Gui -{ - /// <summary> - /// This wraps a project dom and adds the compilation information from the ASP.NET page to the DOM to lookup members - /// on the page. - /// </summary> - class AspProjectDomWrapper : TypeResolveContextDecorator - { - DocumentInfo info; - - //FIXME: use all the doms - //FIXME: merge the items from the members visitor too - public AspProjectDomWrapper (DocumentInfo info) : base (info.References[0]) - { - this.info = info; - } - - ITypeDefinition constructedType = null; - ITypeDefinition CheckType (ITypeDefinition type) - { - if (type == null) - return null; - var cu = info.ParsedDocument; - var firstType = cu.TopLevelTypeDefinitions.FirstOrDefault (); - if (firstType != null && firstType.FullName == type.FullName) { - if (constructedType != null) - return constructedType; - constructedType = CompoundTypeDefinition.Create (new [] { firstType, type, info.CodeBesideClass }); -// constructedType.GetProjectContent () = this; - return constructedType; - } - return type; - } - - public override ITypeDefinition GetTypeDefinition (string nameSpace, string name, int typeParameterCount, StringComparer nameComparer) - { - return CheckType (base.GetTypeDefinition (nameSpace, name, typeParameterCount, nameComparer)); - } - - public override IEnumerable<ITypeDefinition> GetTypes() - { - return base.GetTypes ().Select (t => CheckType (t)); - } - - public override IEnumerable<ITypeDefinition> GetTypes(string nameSpace, StringComparer nameComparer) - { - return base.GetTypes (nameSpace, nameComparer).Select (t => CheckType (t)); - } - - } -} - +//// +//// AspProjectDom.cs +//// +//// Author: +//// Michael Hutchinson <mhutchinson@novell.com> +//// +//// Copyright (c) 2010 Novell, Inc. (http://www.novell.com) +//// +//// Permission is hereby granted, free of charge, to any person obtaining a copy +//// of this software and associated documentation files (the "Software"), to deal +//// in the Software without restriction, including without limitation the rights +//// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +//// copies of the Software, and to permit persons to whom the Software is +//// furnished to do so, subject to the following conditions: +//// +//// The above copyright notice and this permission notice shall be included in +//// all copies or substantial portions of the Software. +//// +//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +//// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +//// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +//// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +//// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +//// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +//// THE SOFTWARE. +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using ICSharpCode.NRefactory.TypeSystem; +//using ICSharpCode.NRefactory.TypeSystem.Implementation; +// +// +//namespace MonoDevelop.AspNet.Gui +//{ +// /// <summary> +// /// This wraps a project dom and adds the compilation information from the ASP.NET page to the DOM to lookup members +// /// on the page. +// /// </summary> +// class AspProjectDomWrapper : TypeResolveContextDecorator +// { +// DocumentInfo info; +// +// //FIXME: use all the doms +// //FIXME: merge the items from the members visitor too +// public AspProjectDomWrapper (DocumentInfo info) : base (info.References[0]) +// { +// this.info = info; +// } +// +// ITypeDefinition constructedType = null; +// ITypeDefinition CheckType (ITypeDefinition type) +// { +// if (type == null) +// return null; +// var cu = info.ParsedDocument; +// var firstType = cu.TopLevelTypeDefinitions.FirstOrDefault (); +// if (firstType != null && firstType.FullName == type.FullName) { +// if (constructedType != null) +// return constructedType; +// constructedType = CompoundTypeDefinition.Create (new [] { firstType, type, info.CodeBesideClass }); +//// constructedType.GetProjectContent () = this; +// return constructedType; +// } +// return type; +// } +// +// public override ITypeDefinition GetTypeDefinition (string nameSpace, string name, int typeParameterCount, StringComparer nameComparer) +// { +// return CheckType (base.GetTypeDefinition (nameSpace, name, typeParameterCount, nameComparer)); +// } +// +// public override IEnumerable<ITypeDefinition> GetTypes() +// { +// return base.GetTypes ().Select (t => CheckType (t)); +// } +// +// public override IEnumerable<ITypeDefinition> GetTypes(string nameSpace, StringComparer nameComparer) +// { +// return base.GetTypes (nameSpace, nameComparer).Select (t => CheckType (t)); +// } +// +// } +//} +// diff --git a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Gui/ILanguageCompletionBuilder.cs b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Gui/ILanguageCompletionBuilder.cs index 8d6928b13f..5cd5ef1d8f 100644 --- a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Gui/ILanguageCompletionBuilder.cs +++ b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Gui/ILanguageCompletionBuilder.cs @@ -97,8 +97,8 @@ namespace MonoDevelop.AspNet.Gui /// </summary> public class DocumentInfo { - public DocumentInfo (ITypeResolveContext dom, AspNetParsedDocument aspNetParsedDocument, IEnumerable<string> imports, - IList<ITypeResolveContext> references) + public DocumentInfo (ICompilation dom, AspNetParsedDocument aspNetParsedDocument, IEnumerable<string> imports, + IList<ICompilation> references) { this.Dom = dom; this.AspNetDocument = aspNetParsedDocument; @@ -111,15 +111,15 @@ namespace MonoDevelop.AspNet.Gui IType codeBesideClass; - public ITypeResolveContext Dom { get; private set; } + public ICompilation Dom { get; private set; } public AspNetParsedDocument AspNetDocument { get; private set; } public ParsedDocument ParsedDocument { get; set; } public List<ExpressionNode> Expressions { get; private set; } public List<TagNode> ScriptBlocks { get; private set; } - public IList<ITypeResolveContext> References { get; set; } + public IList<ICompilation> References { get; set; } public IEnumerable<string> Imports { get; private set; } - public ITypeDefinition CodeBesideClass { get; set; } + public IUnresolvedTypeDefinition CodeBesideClass { get; set; } public string BaseType { get { @@ -225,13 +225,6 @@ namespace MonoDevelop.AspNet.Gui public class HiddenDocument : MonoDevelop.Ide.Gui.Document { - internal ICSharpCode.NRefactory.TypeSystem.ITypeResolveContext HiddenContext; - public override ICSharpCode.NRefactory.TypeSystem.ITypeResolveContext TypeResolveContext { - get { - return HiddenContext; - } - } - internal ParsedDocument HiddenParsedDocument; public override ParsedDocument ParsedDocument { get { diff --git a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Gui/TypeResolveContextDecorator.cs b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Gui/TypeResolveContextDecorator.cs index 4c95957253..a29c814bf4 100644 --- a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Gui/TypeResolveContextDecorator.cs +++ b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Gui/TypeResolveContextDecorator.cs @@ -1,87 +1,82 @@ -// -// TypeResolveContextDecorator.cs -// -// Author: -// Mike Krüger <mkrueger@novell.com> -// -// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com> -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -using System; -using System.Collections.Generic; -using System.Diagnostics.Contracts; - -using ICSharpCode.NRefactory.Utils; -using ICSharpCode.NRefactory.TypeSystem; - -namespace MonoDevelop.AspNet.Gui -{ - public class TypeResolveContextDecorator : ITypeResolveContext - { - protected ITypeResolveContext ctx; - - public TypeResolveContextDecorator (ITypeResolveContext ctx) - { - this.ctx = ctx; - } - - public virtual ITypeDefinition GetKnownTypeDefinition (TypeCode typeCode) - { - return ctx.GetKnownTypeDefinition (typeCode); - } - - public virtual ITypeDefinition GetTypeDefinition(string nameSpace, string name, int typeParameterCount, StringComparer nameComparer) - { - return ctx.GetTypeDefinition(nameSpace, name, typeParameterCount, nameComparer); - } - - public virtual IEnumerable<ITypeDefinition> GetTypes() - { - return ctx.GetTypes(); - } - - public virtual IEnumerable<ITypeDefinition> GetTypes(string nameSpace, StringComparer nameComparer) - { - return ctx.GetTypes(nameSpace, nameComparer); - } - - public virtual IEnumerable<string> GetNamespaces() - { - return ctx.GetNamespaces(); - } - - public virtual string GetNamespace(string nameSpace, StringComparer nameComparer) - { - return ctx.GetNamespace(nameSpace, nameComparer); - } - - public virtual ISynchronizedTypeResolveContext Synchronize() - { - return ctx.Synchronize(); - } - - public virtual CacheManager CacheManager { - get { - return ctx.CacheManager; - } - } - } -} - +//// +//// TypeResolveContextDecorator.cs +//// +//// Author: +//// Mike Krüger <mkrueger@novell.com> +//// +//// Copyright (c) 2011 Mike Krüger <mkrueger@novell.com> +//// +//// Permission is hereby granted, free of charge, to any person obtaining a copy +//// of this software and associated documentation files (the "Software"), to deal +//// in the Software without restriction, including without limitation the rights +//// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +//// copies of the Software, and to permit persons to whom the Software is +//// furnished to do so, subject to the following conditions: +//// +//// The above copyright notice and this permission notice shall be included in +//// all copies or substantial portions of the Software. +//// +//// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +//// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +//// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +//// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +//// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +//// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +//// THE SOFTWARE. +// +//using System; +//using System.Collections.Generic; +//using System.Diagnostics.Contracts; +// +//using ICSharpCode.NRefactory.Utils; +//using ICSharpCode.NRefactory.TypeSystem; +// +//namespace MonoDevelop.AspNet.Gui +//{ +// public class TypeResolveContextDecorator : ITypeResolveContext +// { +// protected ITypeResolveContext ctx; +// +// public TypeResolveContextDecorator (ITypeResolveContext ctx) +// { +// this.ctx = ctx; +// } +// +// public virtual ITypeDefinition GetKnownTypeDefinition (TypeCode typeCode) +// { +// return ctx.GetKnownTypeDefinition (typeCode); +// } +// +// public virtual ITypeDefinition GetTypeDefinition(string nameSpace, string name, int typeParameterCount, StringComparer nameComparer) +// { +// return ctx.GetTypeDefinition(nameSpace, name, typeParameterCount, nameComparer); +// } +// +// public virtual IEnumerable<ITypeDefinition> GetTypes() +// { +// return ctx.GetTypes(); +// } +// +// public virtual IEnumerable<ITypeDefinition> GetTypes(string nameSpace, StringComparer nameComparer) +// { +// return ctx.GetTypes(nameSpace, nameComparer); +// } +// +// public virtual IEnumerable<string> GetNamespaces() +// { +// return ctx.GetNamespaces(); +// } +// +// public virtual string GetNamespace(string nameSpace, StringComparer nameComparer) +// { +// return ctx.GetNamespace(nameSpace, nameComparer); +// } +// +// public virtual CacheManager CacheManager { +// get { +// return ctx.CacheManager; +// } +// } +// } +//} +// diff --git a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Parser/AspNetParser.cs b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Parser/AspNetParser.cs index fee48790e9..501abd3321 100644 --- a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Parser/AspNetParser.cs +++ b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Parser/AspNetParser.cs @@ -34,12 +34,13 @@ using System.Collections.Generic; using MonoDevelop.Core; using MonoDevelop.TypeSystem; using ICSharpCode.NRefactory.TypeSystem; +using MonoDevelop.Projects; namespace MonoDevelop.AspNet.Parser { public class AspNetParser : AbstractTypeSystemParser { - public override ParsedDocument Parse (IProjectContent projectContent, bool storeAst, string fileName, TextReader tr) + public override ParsedDocument Parse (bool storeAst, string fileName, TextReader tr, Project project = null) { var info = new PageInfo (); var rootNode = new RootNode (); 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 912760e505..8d1939142b 100644 --- a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Parser/DocumentReferenceManager.cs +++ b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Parser/DocumentReferenceManager.cs @@ -88,7 +88,7 @@ namespace MonoDevelop.AspNet.Parser var ard = rd as AssemblyRegisterDirective; if (ard != null) { - ITypeResolveContext dom = TypeCtx.ResolveAssembly (ard.Assembly); + var dom = TypeCtx.ResolveAssembly (ard.Assembly); if (dom == null) continue; @@ -149,7 +149,7 @@ namespace MonoDevelop.AspNet.Parser public IEnumerable<CompletionData> GetControlCompletionData () { - return GetControlCompletionData (TypeSystemService.GetContext (Project).GetTypeDefinition ("System.Web.UI", "Control", 0, StringComparer.Ordinal)); + return GetControlCompletionData (TypeSystemService.GetCompilation (Project).FindType ("System.Web.UI.Control")); } public IEnumerable<CompletionData> GetControlCompletionData (IType baseType) @@ -210,7 +210,7 @@ namespace MonoDevelop.AspNet.Parser AssemblyRegisterDirective ard = rd as AssemblyRegisterDirective; if (ard != null) { string assembly = ard.Assembly; - ITypeResolveContext dom = TypeCtx.ResolveAssembly (ard.Assembly); + var dom = TypeCtx.ResolveAssembly (ard.Assembly); if (dom == null) continue; type = WebTypeContext.AssemblyTypeLookup (dom, ard.Namespace, tagName); @@ -414,20 +414,20 @@ namespace MonoDevelop.AspNet.Parser return usings; } - public IList<ITypeResolveContext> GetDoms () + public IList<ICompilation> GetDoms () { var asms = new HashSet<string> (Project.RegistrationCache.GetAssembliesForPath (DirectoryPath)); foreach (var s in Doc.Info.Assemblies) asms.Add (s.Name); - var doms = new List<ITypeResolveContext> (); - doms.Add (TypeCtx.TypeResolveContext); - + var doms = new List<ICompilation> (); + doms.Add (TypeCtx.Compilation); +/* foreach (var asmName in asms) { var dom = TypeCtx.ResolveAssembly (asmName); if (dom != null) doms.Add (dom); - } + }*/ return doms; } } diff --git a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Parser/SuggestedHandlerCompletionData.cs b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Parser/SuggestedHandlerCompletionData.cs index 14dbb1c924..6776d8a017 100644 --- a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Parser/SuggestedHandlerCompletionData.cs +++ b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet.Parser/SuggestedHandlerCompletionData.cs @@ -33,6 +33,7 @@ using MonoDevelop.Projects; using MonoDevelop.Ide.CodeCompletion; using MonoDevelop.DesignerSupport; using ICSharpCode.NRefactory.TypeSystem; +using System.Linq; namespace MonoDevelop.AspNet.Parser { @@ -40,10 +41,10 @@ namespace MonoDevelop.AspNet.Parser { Project project; CodeMemberMethod methodInfo; - ITypeDefinition codeBehindClass; - ITypeDefinition codeBehindClassPart; + IType codeBehindClass; + IUnresolvedTypeDefinition codeBehindClassPart; - public SuggestedHandlerCompletionData (Project project, CodeMemberMethod methodInfo, ITypeDefinition codeBehindClass, ITypeDefinition codeBehindClassPart) + public SuggestedHandlerCompletionData (Project project, CodeMemberMethod methodInfo, IType codeBehindClass, IUnresolvedTypeDefinition codeBehindClassPart) { this.project = project; this.methodInfo = methodInfo; @@ -86,9 +87,9 @@ namespace MonoDevelop.AspNet.Parser //generate the codebehind method if (codeBehindClassPart != null && project != null) - BindingService.AddMemberToClass (project, codeBehindClass, codeBehindClassPart, methodInfo, false); + BindingService.AddMemberToClass (project, codeBehindClass.GetDefinition (), codeBehindClassPart, methodInfo, false); else - BindingService.AddMemberToClass (project, codeBehindClass, codeBehindClass, methodInfo, false); + BindingService.AddMemberToClass (project, codeBehindClass.GetDefinition (), codeBehindClass.GetDefinition ().Parts.First (), methodInfo, false); } } } 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 6d1041e510..3c7841e7d6 100644 --- a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/AspNetAppProject.cs +++ b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/AspNetAppProject.cs @@ -332,7 +332,7 @@ namespace MonoDevelop.AspNet #endregion - public ITypeResolveContext ResolveAssemblyDom (string assemblyName) + public ICompilation ResolveAssemblyDom (string assemblyName) { var parsed = SystemAssemblyService.ParseAssemblyName (assemblyName); if (string.IsNullOrEmpty (parsed.Name)) @@ -351,7 +351,7 @@ namespace MonoDevelop.AspNet LoggingService.LogWarning ("Project '{0}' referenced from '{1}' could not be found", reference.Reference, this.Name); continue; } - return TypeSystemService.GetContext (p); + return TypeSystemService.GetCompilation (p); } } @@ -690,9 +690,9 @@ namespace MonoDevelop.AspNet { string typeName = GetCodebehindTypeName (fileName); if (typeName != null) { - var dom = TypeSystemService.GetContext (this); + var dom = TypeSystemService.GetCompilation (this); if (dom != null) - return dom.GetTypeDefinition ("", typeName, 0, StringComparer.Ordinal); + return dom.FindType (typeName); } return null; } @@ -712,7 +712,7 @@ namespace MonoDevelop.AspNet protected override string GenerateInfo (string filename) { try { - var doc = TypeSystemService.ParseFile (TypeSystemService.GetProjectContext (Project), filename, DesktopService.GetMimeTypeForUri (filename), File.ReadAllText (filename)) as AspNetParsedDocument; + var doc = TypeSystemService.ParseFile (filename, DesktopService.GetMimeTypeForUri (filename), File.ReadAllText (filename)) as AspNetParsedDocument; if (doc != null && !string.IsNullOrEmpty (doc.Info.InheritedClass)) return doc.Info.InheritedClass; } catch (Exception ex) { diff --git a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/AspNetToolboxNode.cs b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/AspNetToolboxNode.cs index d00b335e09..c51107803d 100644 --- a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/AspNetToolboxNode.cs +++ b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/AspNetToolboxNode.cs @@ -124,9 +124,9 @@ namespace MonoDevelop.AspNet //FIXME: only do this on the insert, not the preview - or remove it afterwards RegisterReference (document.Project); - var database = document.TypeResolveContext; + var database = document.Compilation; - var cls = database.GetTypeDefinition (Type.Load ()); + var cls = database.FindType (Type.Load ()); if (cls == null) return tag; 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 e094514706..3e8d1b545f 100644 --- a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/CodeBehind.cs +++ b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/CodeBehind.cs @@ -154,9 +154,9 @@ namespace MonoDevelop.AspNet if (memberList.Members.Count == 0) return ccu; - var dom = refman.TypeCtx.TypeResolveContext; - var cls = dom.GetTypeDefinition ("", className, 0, StringComparer.Ordinal); - var members = GetDesignerMembers (memberList.Members.Values, cls, filename, dom, dom); + var dom = refman.TypeCtx.Compilation; + var cls = dom.FindType (className); + var members = GetDesignerMembers (memberList.Members.Values, cls, filename); //add fields for each control in the page @@ -176,21 +176,20 @@ namespace MonoDevelop.AspNet /// <returns>The filtered list of non-conflicting members.</returns> // TODO: check compatibilty with existing members public static IEnumerable<CodeBehindMember> GetDesignerMembers ( - IEnumerable<CodeBehindMember> members, IType cls, string designerFile, ITypeResolveContext resolveDom, - ITypeResolveContext internalDom) + IEnumerable<CodeBehindMember> members, IType cls, string designerFile) { var existingMembers = new HashSet<string> (); while (cls != null) { - foreach (var member in cls.GetDefinition ().Members) { - if (member.Accessibility == Accessibility.Private || (member.Accessibility == Accessibility.Internal && member.DeclaringType.GetProjectContent () != internalDom)) + foreach (var member in cls.GetMembers ()) { + if (member.Accessibility == Accessibility.Private || member.Accessibility == Accessibility.Internal) continue; if (member.DeclaringType.GetDefinition ().Region.FileName == designerFile) continue; existingMembers.Add (member.Name); } - if (!cls.GetBaseTypes (internalDom).Any ()) + if (!cls.GetAllBaseTypeDefinitions ().Any ()) break; - cls = cls.GetBaseTypes (internalDom).First (); + cls = cls.GetAllBaseTypeDefinitions ().First (); } return members.Where (m => !existingMembers.Contains (m.Name)); } 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 19763ed529..c8f6874877 100644 --- a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/WebTypeManager.cs +++ b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.AspNet/WebTypeManager.cs @@ -44,6 +44,7 @@ using MonoDevelop.Ide.CodeCompletion; using MonoDevelop.Core.Assemblies; using ICSharpCode.NRefactory.TypeSystem; using MonoDevelop.TypeSystem; +using ICSharpCode.NRefactory.TypeSystem.Implementation; namespace MonoDevelop.AspNet { @@ -57,26 +58,26 @@ namespace MonoDevelop.AspNet throw new ArgumentException ("project"); Project = project; SystemWebDom = GetSystemWebDom (project); - TypeResolveContext = TypeSystemService.GetContext ( project); - if (TypeResolveContext == null) + Compilation = TypeSystemService.GetCompilation (project); + if (Compilation == null) throw new InvalidOperationException ("Could not load parse database for project"); } public AspNetAppProject Project { get; private set; } - public ITypeResolveContext SystemWebDom { get; private set; } - public ITypeResolveContext TypeResolveContext { get; private set; } + public ICompilation SystemWebDom { get; private set; } + public ICompilation Compilation { get; private set; } public TargetFramework TargetFramework { get { return Project.TargetFramework; } } //FIXME: this shouldn't be public - public static ITypeResolveContext GetSystemWebDom (AspNetAppProject project) + public static ICompilation GetSystemWebDom (AspNetAppProject project) { return GetSystemWebDom (project.TargetRuntime, project.TargetFramework); } - static ITypeResolveContext GetSystemWebDom (TargetRuntime runtime, TargetFramework targetFramework) + static ICompilation GetSystemWebDom (TargetRuntime runtime, TargetFramework targetFramework) { string file = runtime.AssemblyContext.GetAssemblyNameForVersion (sysWebAssemblyName, targetFramework); if (string.IsNullOrEmpty (file)) @@ -84,7 +85,7 @@ namespace MonoDevelop.AspNet file = runtime.AssemblyContext.GetAssemblyLocation (file, targetFramework); if (string.IsNullOrEmpty (file)) throw new Exception ("System.Web assembly file not found for framework " + targetFramework.Id); - ITypeResolveContext dom = TypeSystemService.LoadAssemblyContext (runtime, file); + var dom = TypeSystemService.LoadAssemblyContext (runtime, file); if (dom == null) throw new Exception ("System.Web parse database not found for framework " + targetFramework.Id + " file '" + file + "'"); return dom; @@ -92,11 +93,11 @@ namespace MonoDevelop.AspNet #region Assembly resolution - Dictionary<string,ITypeResolveContext> cachedDoms = new Dictionary<string, ITypeResolveContext> (); + Dictionary<string,ICompilation> cachedDoms = new Dictionary<string, ICompilation> (); - public ITypeResolveContext ResolveAssembly (string assemblyName) + public ICompilation ResolveAssembly (string assemblyName) { - ITypeResolveContext dom; + ICompilation dom; if (!cachedDoms.TryGetValue (assemblyName, out dom)) { cachedDoms [assemblyName] = dom = Project.ResolveAssemblyDom (assemblyName); if (dom == null) @@ -295,7 +296,7 @@ namespace MonoDevelop.AspNet { var str = HtmlControlLookup (tagName, typeAttribute); if (str != null) { - return SystemWebDom.GetTypeDefinition ("", str, 0, StringComparer.OrdinalIgnoreCase); + return SystemWebDom.FindType (str); } return null; } @@ -309,18 +310,18 @@ namespace MonoDevelop.AspNet return ListControlClasses (baseType, GetSystemWebDom (project), "System.Web.UI.WebControls"); } - public static IEnumerable<IType> ListControlClasses (IType baseType, ITypeResolveContext database, string namespac) + public static IEnumerable<IType> ListControlClasses (IType baseType, ICompilation database, string namespac) { if (database == null) yield break; var baseTypeDefinition = baseType.GetDefinition (); //return classes if they derive from system.web.ui.control - foreach (var type in baseTypeDefinition.GetSubTypeDefinitions (database).Where (t => t.Namespace == namespac)) + foreach (var type in baseTypeDefinition.GetSubTypeDefinitions ().Where (t => t.Namespace == namespac)) if (!type.IsAbstract && type.IsPublic) yield return type; if (!baseTypeDefinition.IsAbstract && baseTypeDefinition.IsPublic && baseTypeDefinition.Namespace == namespac) { - yield return baseType.Resolve (database); + yield return baseType; } } @@ -339,17 +340,17 @@ namespace MonoDevelop.AspNet return AssemblyTypeLookup (SystemWebDom, "System.Web.UI.WebControls", tagName); } - public static string AssemblyTypeNameLookup (ITypeResolveContext assemblyDatabase, string namespac, string tagName) + public static string AssemblyTypeNameLookup (ICompilation assemblyDatabase, string namespac, string tagName) { - IType cls = AssemblyTypeLookup (assemblyDatabase, namespac, tagName); + var cls = AssemblyTypeLookup (assemblyDatabase, namespac, tagName); return cls != null? cls.FullName : null; } - public static IType AssemblyTypeLookup (ITypeResolveContext assemblyDatabase, string namespac, string tagName) + public static IType AssemblyTypeLookup (ICompilation assemblyDatabase, string namespac, string tagName) { return (assemblyDatabase == null) ? null - : assemblyDatabase.GetTypeDefinition (namespac, tagName, 0, StringComparer.OrdinalIgnoreCase); + : assemblyDatabase.MainAssembly.GetTypeDefinition (namespac, tagName, 0); } #endregion diff --git a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.Html/HtmlParser.cs b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.Html/HtmlParser.cs index 37f39358d2..6fe01bcbc1 100644 --- a/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.Html/HtmlParser.cs +++ b/main/src/addins/AspNet/MonoDevelop.AspNet/MonoDevelop.Html/HtmlParser.cs @@ -34,12 +34,13 @@ using MonoDevelop.Xml.StateEngine; using MonoDevelop.AspNet.StateEngine; using MonoDevelop.TypeSystem; using ICSharpCode.NRefactory.TypeSystem; +using MonoDevelop.Projects; namespace MonoDevelop.Html { public class HtmlParser : AbstractTypeSystemParser { - public override ParsedDocument Parse (IProjectContent projectContent, bool storeAst, string fileName, TextReader tr) + public override ParsedDocument Parse (bool storeAst, string fileName, TextReader tr, Project project = null) { var doc = new XmlParsedDocument (fileName); // doc.Flags = ParsedDocumentFlags.NonSerializable; diff --git a/main/src/addins/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport/BindingService.cs b/main/src/addins/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport/BindingService.cs index 2b7337ae4d..b0c85743ac 100644 --- a/main/src/addins/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport/BindingService.cs +++ b/main/src/addins/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport/BindingService.cs @@ -187,16 +187,16 @@ namespace MonoDevelop.DesignerSupport // return cr; // } - public static IEnumerable<IMethod> GetCompatibleMethodsInClass (ITypeResolveContext ctx, IType cls, IEvent eve) + public static IEnumerable<IMethod> GetCompatibleMethodsInClass (IType cls, IEvent eve) { - IMethod eveMeth = GetMethodSignature (ctx, eve); + IMethod eveMeth = GetMethodSignature (eve); if (eveMeth == null) return new IMethod[0]; - return GetCompatibleMethodsInClass (ctx, cls, eveMeth); + return GetCompatibleMethodsInClass (cls, eveMeth); } //TODO: check accessibility - public static IEnumerable<IMethod> GetCompatibleMethodsInClass (ITypeResolveContext ctx, IType cls, IMethod matchMeth) + public static IEnumerable<IMethod> GetCompatibleMethodsInClass (IType cls, IMethod matchMeth) { IType[] pars = new IType[matchMeth.Parameters.Count]; List<IType>[] baseTypes = new List<IType>[matchMeth.Parameters.Count]; @@ -229,18 +229,18 @@ namespace MonoDevelop.DesignerSupport } } - public static bool IdentifierExistsInClass (ITypeResolveContext parserContext, ITypeDefinition cls, string identifier) + public static bool IdentifierExistsInClass (IType cls, string identifier) { return cls.GetMembers ().Any (m => m.Name == identifier); } - public static string GenerateIdentifierUniqueInClass (ITypeResolveContext parserContext, ITypeDefinition cls, string trialIdentifier) + public static string GenerateIdentifierUniqueInClass (IType cls, string trialIdentifier) { string trialValue = trialIdentifier; for (int suffix = 1; suffix <= int.MaxValue; suffix++) { - if (!IdentifierExistsInClass (parserContext, cls, trialValue)) + if (!IdentifierExistsInClass (cls, trialValue)) return trialValue; trialValue = trialIdentifier + suffix.ToString (); @@ -312,7 +312,7 @@ namespace MonoDevelop.DesignerSupport return newMethod; } - public static IMethod GetMethodSignature (ITypeResolveContext context, IEvent ev) + public static IMethod GetMethodSignature (IEvent ev) { if (ev.ReturnType == null) return null; @@ -346,10 +346,10 @@ namespace MonoDevelop.DesignerSupport return meth; } - public static CodeMemberMethod MDDomToCodeDomMethod (ITypeResolveContext context, IEvent eve) + public static CodeMemberMethod MDDomToCodeDomMethod (IEvent eve) { - IMethod meth = GetMethodSignature (context, eve); - return meth != null ? MDDomToCodeDomMethod (context, meth) : null; + IMethod meth = GetMethodSignature (eve); + return meth != null ? MDDomToCodeDomMethod (meth) : null; } static void CodeDomModifiersToMDDom (DefaultUnresolvedMethod method, MemberAttributes modifiers) @@ -436,7 +436,7 @@ namespace MonoDevelop.DesignerSupport } - public static System.CodeDom.CodeMemberMethod MDDomToCodeDomMethod (ITypeResolveContext ctx, IMethod mi) + public static System.CodeDom.CodeMemberMethod MDDomToCodeDomMethod (IMethod mi) { CodeMemberMethod newMethod = new CodeMemberMethod (); newMethod.Name = mi.Name; diff --git a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/FindDerivedClassesHandler.cs b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/FindDerivedClassesHandler.cs index 87c405c0e6..521950ad0f 100644 --- a/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/FindDerivedClassesHandler.cs +++ b/main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring/FindDerivedClassesHandler.cs @@ -58,9 +58,7 @@ namespace MonoDevelop.Refactoring using (var monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor (true, true)) { var cache = new Dictionary<string, TextEditorData> (); foreach (var p in projects) { - if (p.Item2 == null) // may happen for cecil contexts - continue; - foreach (var type in TypeSystemService.GetCompilation (p.Item1).GetAllTypeDefinitions ()) { + foreach (var type in TypeSystemService.GetCompilation (p).GetAllTypeDefinitions ()) { if (!type.IsDerivedFrom (cls)) continue; TextEditorData textFile; @@ -68,7 +66,7 @@ namespace MonoDevelop.Refactoring cache[type.Region.FileName] = textFile = TextFileProvider.Instance.GetTextEditorData (type.Region.FileName); } int position = textFile.LocationToOffset (type.Region.BeginLine, type.Region.BeginColumn); - monitor.ReportResult (new MonoDevelop.Ide.FindInFiles.SearchResult (new FileProvider (type.Region.FileName, p.Item1), position, 0)); + monitor.ReportResult (new MonoDevelop.Ide.FindInFiles.SearchResult (new FileProvider (type.Region.FileName, p), position, 0)); } } foreach (var tf in cache.Values) { diff --git a/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.XmlEditor/XmlDocumentParser.cs b/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.XmlEditor/XmlDocumentParser.cs index cd951b123b..b0486b2fc0 100644 --- a/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.XmlEditor/XmlDocumentParser.cs +++ b/main/src/addins/MonoDevelop.XmlEditor/MonoDevelop.XmlEditor/XmlDocumentParser.cs @@ -39,7 +39,7 @@ namespace MonoDevelop.XmlEditor { public class XmlDocumentParser : ITypeSystemParser { - ParsedDocument ITypeSystemParser.Parse (ICSharpCode.NRefactory.TypeSystem.IProjectContent projectContent, bool storeAst, string fileName, TextReader content) + ParsedDocument ITypeSystemParser.Parse (bool storeAst, string fileName, TextReader content, MonoDevelop.Projects.Project project = null) { XmlParsedDocument doc = new XmlParsedDocument (fileName); doc.Flags |= ParsedDocumentFlags.NonSerializable; diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Text/DocGenerator.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Text/DocGenerator.cs index e5251a4b25..c89eb2c7fa 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Text/DocGenerator.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Text/DocGenerator.cs @@ -37,7 +37,9 @@ namespace MonoDevelop.Projects.Text private set; } - public abstract string GenerateDocumentation (ITypeResolveContext ctx, IMember member, string linePrefix); + public abstract string GenerateDocumentation (IMember member, string linePrefix); + + public abstract string GenerateDocumentation (IUnresolvedMember member, string linePrefix); static DocGenerator () { diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/ReferencesFinder.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/ReferencesFinder.cs index 128ec74dab..4a5265cc68 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/ReferencesFinder.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/ReferencesFinder.cs @@ -136,7 +136,7 @@ namespace MonoDevelop.Ide.FindInFiles public static List<Project> GetAllReferencingProjects (Solution solution, Project sourceProject) { var projects = new List<Project> (); - projects.Add (Tuple.Create (sourceProject, TypeSystemService.GetProjectContext (sourceProject))); + projects.Add (sourceProject); foreach (var project in solution.GetAllProjects ()) { if (project.GetReferencedItems (ConfigurationSelector.Default).Any (prj => prj == sourceProject)) projects.Add (project); diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/CodeGenerator.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/CodeGenerator.cs index 224a3c15da..66f5d31654 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/CodeGenerator.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/CodeGenerator.cs @@ -259,7 +259,9 @@ namespace MonoDevelop.TypeSystem public abstract string WrapInRegions (string regionName, string text); public abstract CodeGeneratorMemberResult CreateMemberImplementation (IUnresolvedTypeDefinition implementingType, IUnresolvedMember member, bool explicitDeclaration); - public abstract string CreateFieldEncapsulation (IUnresolvedTypeDefinition implementingType, IUnresolvedField field, string propertyName, Accessibility modifiers, bool readOnly); + public abstract CodeGeneratorMemberResult CreateMemberImplementation (IUnresolvedTypeDefinition implementingType, IMember member, bool explicitDeclaration); + + public abstract string CreateFieldEncapsulation (IUnresolvedTypeDefinition implementingType, IField field, string propertyName, Accessibility modifiers, bool readOnly); public abstract void AddGlobalNamespaceImport (MonoDevelop.Ide.Gui.Document doc, string nsName); public abstract void AddLocalNamespaceImport (MonoDevelop.Ide.Gui.Document doc, string nsName, TextLocation caretLocation); diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/ITypeSystemParser.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/ITypeSystemParser.cs index 6aa61ca8ed..cbcf7b5b19 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/ITypeSystemParser.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/ITypeSystemParser.cs @@ -26,17 +26,18 @@ using System; using System.IO; using ICSharpCode.NRefactory.TypeSystem; +using MonoDevelop.Projects; namespace MonoDevelop.TypeSystem { public interface ITypeSystemParser { - ParsedDocument Parse (bool storeAst, string fileName, TextReader content); + ParsedDocument Parse (bool storeAst, string fileName, TextReader content, Project project = null); } public abstract class AbstractTypeSystemParser : ITypeSystemParser { - public virtual ParsedDocument Parse (bool storeAst, string fileName, TextReader content) + public virtual ParsedDocument Parse (bool storeAst, string fileName, TextReader content, Project project = null) { return null; } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/ParsedDocument.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/ParsedDocument.cs index cf2095d60d..41c794d3d0 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/ParsedDocument.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/ParsedDocument.cs @@ -57,7 +57,7 @@ namespace MonoDevelop.TypeSystem public virtual IParsedFile ParsedFile { get { return this; } - protected set { throw new InvalidOperationException (); } + set { throw new InvalidOperationException (); } } public IList<Comment> Comments { @@ -330,7 +330,7 @@ namespace MonoDevelop.TypeSystem public override IParsedFile ParsedFile { get { return parsedFile; } - protected set { parsedFile = value; FileName = parsedFile.FileName; } + set { parsedFile = value; FileName = parsedFile.FileName; } } public ParsedDocumentDecorator (IParsedFile parsedFile) : base (parsedFile.FileName) diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/StockIcons.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/StockIcons.cs index 178b3dba1e..898bfd018f 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/StockIcons.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/StockIcons.cs @@ -134,6 +134,24 @@ namespace MonoDevelop.TypeSystem } } + public static string GetStockIcon (this IUnresolvedTypeDefinition def) + { + switch (def.Kind) { + case TypeKind.Class: + return typeIconTable [0, ModifierToOffset (def.Accessibility)]; + case TypeKind.Enum: + return typeIconTable [1, ModifierToOffset (def.Accessibility)]; + case TypeKind.Interface: + return typeIconTable [2, ModifierToOffset (def.Accessibility)]; + case TypeKind.Struct: + return typeIconTable [3, ModifierToOffset (def.Accessibility)]; + case TypeKind.Delegate: + return typeIconTable [4, ModifierToOffset (def.Accessibility)]; + default: + return typeIconTable [0, ModifierToOffset (def.Accessibility)]; + } + } + public static string GetStockIcon (this IField field) { return GetStockIcon ((IEntity)field); @@ -149,7 +167,7 @@ namespace MonoDevelop.TypeSystem return Field; } - public static string GetStockIcon (this ITypeParameter parameter) + public static string GetStockIcon (this IUnresolvedTypeParameter parameter) { return Field; } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/TypeSystemService.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/TypeSystemService.cs index c157f0f95b..e85f9820e7 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/TypeSystemService.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.TypeSystem/TypeSystemService.cs @@ -76,7 +76,7 @@ namespace MonoDevelop.TypeSystem return "TODO"; } - public static bool IsBaseType (this IType type, ITypeResolveContext ctx, IType potentialBase) + public static bool IsBaseType (this IType type, IType potentialBase) { return type.GetAllBaseTypes ().Any (t => t.Equals (potentialBase)); } @@ -86,6 +86,12 @@ namespace MonoDevelop.TypeSystem // TODO: Implement me! return false; } + + public static bool IsObsolete (this IUnresolvedEntity member) + { + // TODO: Implement me! + return false; + } } public static class TypeSystemService |