diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2011-12-01 15:49:40 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2011-12-01 15:49:40 +0400 |
commit | 00bdd40362a5f9d1ddfd00c8f407dd5a1c07491f (patch) | |
tree | dc5538f940f97b3d469aa8761aea669dfe6476dc /main/src/addins/CSharpBinding | |
parent | c1c3e6cd7921e158bf5826b6cf7a08e1967e19e1 (diff) |
[CSharpBinding] Track nrefactory API changes.
Diffstat (limited to 'main/src/addins/CSharpBinding')
32 files changed, 525 insertions, 501 deletions
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/CSharpCompletionTextEditorExtension.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/CSharpCompletionTextEditorExtension.cs index 95aca8c521..143f87379b 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/CSharpCompletionTextEditorExtension.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/CSharpCompletionTextEditorExtension.cs @@ -45,6 +45,7 @@ using ICSharpCode.NRefactory.Semantics; using ICSharpCode.NRefactory; using ICSharpCode.NRefactory.Completion; using ICSharpCode.NRefactory.CSharp.Completion; +using ICSharpCode.NRefactory.CSharp.TypeSystem; namespace MonoDevelop.CSharp.Completion { @@ -52,11 +53,6 @@ namespace MonoDevelop.CSharp.Completion public class CSharpCompletionTextEditorExtension : CompletionTextEditorExtension, ICompletionDataFactory, IParameterCompletionDataFactory { internal Mono.TextEditor.TextEditorData textEditorData; - internal ITypeResolveContext ctx { - get { - return document.TypeResolveContext; - } - } CompilationUnit unit; static readonly CompilationUnit emptyUnit = new CompilationUnit (); @@ -179,7 +175,6 @@ namespace MonoDevelop.CSharp.Completion return null; var list = new CompletionDataList (); var engine = new CSharpCompletionEngine (textEditorData.Document, this); - engine.ctx = ctx; engine.Unit = Unit; engine.CSharpParsedFile = CSharpParsedFile; engine.FormattingPolicy = FormattingPolicy.CreateOptions (); @@ -321,7 +316,6 @@ namespace MonoDevelop.CSharp.Completion if (Unit == null || CSharpParsedFile == null) return null; var engine = new CSharpParameterCompletionEngine (textEditorData.Document, this); - engine.ctx = ctx; engine.Unit = Unit; engine.CSharpParsedFile = CSharpParsedFile; engine.ProjectContent = Document.GetProjectContext (); @@ -334,11 +328,12 @@ namespace MonoDevelop.CSharp.Completion var result = new List<string> (); while (scope != null) { result.Add (scope.NamespaceName); + var ctx = CSharpParsedFile.GetResolver (Document.Compilation, scope.Region.Begin); foreach (var u in scope.Usings) { var ns = u.ResolveNamespace (ctx); if (ns == null) continue; - result.Add (ns.NamespaceName); + result.Add (ns.FullName); } scope = scope.Parent; } @@ -386,7 +381,6 @@ namespace MonoDevelop.CSharp.Completion public override int GetCurrentParameterIndex (CodeCompletionContext completionCtx) { var engine = new CSharpParameterCompletionEngine (textEditorData.Document, this); - engine.ctx = ctx; engine.Unit = Unit; engine.CSharpParsedFile = CSharpParsedFile; engine.ProjectContent = Document.GetProjectContext (); @@ -440,7 +434,7 @@ namespace MonoDevelop.CSharp.Completion #region ICompletionDataFactory implementation ICompletionData ICompletionDataFactory.CreateEntityCompletionData (IEntity entity) { - return new MemberCompletionData (this, entity as IMember, OutputFlags.IncludeGenerics | OutputFlags.HideArrayBrackets | OutputFlags.IncludeParameterName) { + return new MemberCompletionData (this, entity, OutputFlags.IncludeGenerics | OutputFlags.HideArrayBrackets | OutputFlags.IncludeParameterName) { HideExtensionParameter = true }; } @@ -449,12 +443,33 @@ namespace MonoDevelop.CSharp.Completion { return new CompletionData (text, entity.GetStockIcon (), null, text); } + + ICompletionData ICompletionDataFactory.CreateEntityCompletionData (IUnresolvedEntity entity) + { + // TODO: Type system conversion +/* return new MemberCompletionData (this, entity, OutputFlags.IncludeGenerics | OutputFlags.HideArrayBrackets | OutputFlags.IncludeParameterName) { + HideExtensionParameter = true + };*/ + return null; + } + + ICompletionData ICompletionDataFactory.CreateEntityCompletionData (IUnresolvedEntity entity, string text) + { + // TODO: Type system conversion + //return new CompletionData (text, entity.GetStockIcon (), null, text); + return null; + } ICompletionData ICompletionDataFactory.CreateTypeCompletionData (IType type, string shortType) { return new CompletionData (shortType, type.GetStockIcon ()); } + ICompletionData ICompletionDataFactory.CreateTypeCompletionData (IUnresolvedTypeDefinition type, string shortType) + { + return new CompletionData (shortType, type.GetStockIcon ()); + } + ICompletionData ICompletionDataFactory.CreateLiteralCompletionData (string title, string description, string insertText) { return new CompletionData (title, "md-keyword", description, insertText ?? title); @@ -470,17 +485,17 @@ namespace MonoDevelop.CSharp.Completion return new VariableCompletionData (variable); } - ICompletionData ICompletionDataFactory.CreateVariableCompletionData (ITypeParameter parameter) + ICompletionData ICompletionDataFactory.CreateVariableCompletionData (IUnresolvedTypeParameter parameter) { return new CompletionData (parameter.Name, parameter.GetStockIcon ()); } - ICompletionData ICompletionDataFactory.CreateEventCreationCompletionData (string varName, IType delegateType, IEvent evt, string parameterDefinition, IMember currentMember, ITypeDefinition currentType) + ICompletionData ICompletionDataFactory.CreateEventCreationCompletionData (string varName, IType delegateType, IEvent evt, string parameterDefinition, IUnresolvedMember currentMember, IUnresolvedTypeDefinition currentType) { return new EventCreationCompletionData (this, varName, delegateType, evt, parameterDefinition, currentMember, currentType); } - ICompletionData ICompletionDataFactory.CreateNewOverrideCompletionData (int declarationBegin, ITypeDefinition type, IMember m) + ICompletionData ICompletionDataFactory.CreateNewOverrideCompletionData (int declarationBegin, IUnresolvedTypeDefinition type, IMember m) { return new NewOverrideCompletionData (this, declarationBegin, type, m); } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/ConstructorParameterDataProvider.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/ConstructorParameterDataProvider.cs index 6d2d365e79..42eb1a9989 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/ConstructorParameterDataProvider.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/ConstructorParameterDataProvider.cs @@ -36,7 +36,7 @@ namespace MonoDevelop.CSharp.Completion public ConstructorParameterDataProvider (CSharpCompletionTextEditorExtension ext, IType type) : base (ext) { this.type = type; - foreach (var method in type.GetConstructors (ext.ctx, m => m.IsPublic)) { + foreach (var method in type.GetConstructors (m => m.IsPublic)) { methods.Add (method); } } @@ -44,7 +44,7 @@ namespace MonoDevelop.CSharp.Completion protected override string GetPrefix (IMethod method) { var flags = OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup | OutputFlags.IncludeGenerics; - return ambience.GetString (ext.ctx, type, flags) + "."; + return ambience.GetString (type, flags) + "."; } } } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/DelegateDataProvider.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/DelegateDataProvider.cs index 9f51f2d996..fa81272269 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/DelegateDataProvider.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/DelegateDataProvider.cs @@ -67,7 +67,7 @@ namespace MonoDevelop.CSharp.Completion string name = delegateType.Name; var parameters = new StringBuilder (); int curLen = 0; - string prefix = !delegateMethod.IsConstructor ? ambience.GetString (ext.ctx, delegateMethod.ReturnType, flags) + " " : ""; + string prefix = !delegateMethod.IsConstructor ? ambience.GetString (delegateMethod.ReturnType, flags) + " " : ""; foreach (string parameter in parameterMarkup) { if (parameters.Length > 0) @@ -121,13 +121,13 @@ namespace MonoDevelop.CSharp.Completion } if (curParameter != null) { - var returnType = curParameter.Type.Resolve (ext.ctx); - if (returnType.IsDelegate ()) { + var returnType = curParameter.Type; + if (returnType.Kind == TypeKind.Delegate) { sb.AppendLine (); sb.AppendLine (); sb.Append ("<small>"); sb.AppendLine (GettextCatalog.GetString ("Delegate information")); - sb.Append (ambience.GetString (ext.ctx, returnType, OutputFlags.ReformatDelegates | OutputFlags.IncludeReturnType | OutputFlags.IncludeParameters | OutputFlags.IncludeParameterName)); + sb.Append (ambience.GetString (returnType, OutputFlags.ReformatDelegates | OutputFlags.IncludeReturnType | OutputFlags.IncludeParameters | OutputFlags.IncludeParameterName)); sb.Append ("</small>"); } } @@ -139,7 +139,7 @@ namespace MonoDevelop.CSharp.Completion if (paramIndex < 0 || paramIndex >= delegateMethod.Parameters.Count) return ""; - return ambience.GetString (ext.ctx, delegateMethod, delegateMethod.Parameters [paramIndex], OutputFlags.AssemblyBrowserDescription | OutputFlags.HideExtensionsParameter | OutputFlags.IncludeGenerics | OutputFlags.IncludeModifiers | OutputFlags.HighlightName); + return ambience.GetString (delegateMethod, delegateMethod.Parameters [paramIndex], OutputFlags.AssemblyBrowserDescription | OutputFlags.HideExtensionsParameter | OutputFlags.IncludeGenerics | OutputFlags.IncludeModifiers | OutputFlags.HighlightName); } public int GetParameterCount (int overload) diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/EventCreationCompletionData.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/EventCreationCompletionData.cs index 351ba37975..dbe397449c 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/EventCreationCompletionData.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/EventCreationCompletionData.cs @@ -41,13 +41,13 @@ namespace MonoDevelop.CSharp.Completion public class EventCreationCompletionData : CompletionData { string parameterList; - IMember callingMember; + IUnresolvedMember callingMember; CSharpCompletionTextEditorExtension ext; int initialOffset; public bool AddSemicolon = true; TextEditorData editor; - public EventCreationCompletionData (CSharpCompletionTextEditorExtension ext, string varName, IType delegateType, IEvent evt, string parameterList, IMember callingMember, IType declaringType) : base (null) + public EventCreationCompletionData (CSharpCompletionTextEditorExtension ext, string varName, IType delegateType, IEvent evt, string parameterList, IUnresolvedMember callingMember, IUnresolvedTypeDefinition declaringType) : base (null) { if (string.IsNullOrEmpty (varName)) { this.DisplayText = "Handle" + (evt != null ? evt.Name : ""); @@ -55,9 +55,9 @@ namespace MonoDevelop.CSharp.Completion this.DisplayText = "Handle" + Char.ToUpper (varName[0]) + varName.Substring (1) + (evt != null ? evt.Name : ""); } - if (declaringType != null && declaringType.GetMembers (ext.ctx).Any (m => m.Name == this.DisplayText)) { + if (declaringType != null && declaringType.Members.Any (m => m.Name == this.DisplayText)) { for (int i = 1; i < 10000; i++) { - if (!declaringType.GetMembers (ext.ctx).Any (m => m.Name == this.DisplayText + i)) { + if (!declaringType.Members.Any (m => m.Name == this.DisplayText + i)) { this.DisplayText = this.DisplayText + i.ToString (); break; } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/IndexerParameterDataProvider.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/IndexerParameterDataProvider.cs index 2294db2099..ad0f31159c 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/IndexerParameterDataProvider.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/IndexerParameterDataProvider.cs @@ -56,7 +56,7 @@ namespace MonoDevelop.CSharp.Completion this.ext = ext; this.resolvedExpression = resolvedExpression; - indexers = new List<IProperty> (type.GetProperties (ext.ctx, p => p.IsIndexer)); + indexers = new List<IProperty> (type.GetProperties (p => p.IsIndexer)); } #region IParameterDataProvider implementation @@ -64,7 +64,7 @@ namespace MonoDevelop.CSharp.Completion { StringBuilder result = new StringBuilder (); // int curLen = 0; - result.Append (ambience.GetString (ext.ctx, indexers[overload].ReturnType, OutputFlags.ClassBrowserEntries)); + result.Append (ambience.GetString (indexers[overload].ReturnType, OutputFlags.ClassBrowserEntries)); result.Append (' '); result.Append ("<b>"); result.Append (resolvedExpression); @@ -105,7 +105,7 @@ namespace MonoDevelop.CSharp.Completion if (paramIndex < 0 || paramIndex >= indexer.Parameters.Count) return ""; - return ambience.GetString (ext.ctx, indexer, indexer.Parameters [paramIndex], OutputFlags.AssemblyBrowserDescription | OutputFlags.HideExtensionsParameter | OutputFlags.IncludeGenerics | OutputFlags.IncludeModifiers | OutputFlags.IncludeParameterName | OutputFlags.HighlightName); + return ambience.GetString (indexer, indexer.Parameters [paramIndex], OutputFlags.AssemblyBrowserDescription | OutputFlags.HideExtensionsParameter | OutputFlags.IncludeGenerics | OutputFlags.IncludeModifiers | OutputFlags.IncludeParameterName | OutputFlags.HighlightName); } public int GetParameterCount (int overload) diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/MemberCompletionData.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/MemberCompletionData.cs index 541d802a6f..b9ae32d526 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/MemberCompletionData.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/MemberCompletionData.cs @@ -83,7 +83,7 @@ namespace MonoDevelop.CSharp.Completion public override string DisplayText { get { if (displayText == null) { - displayText = ambience.GetString (editorCompletion.ctx, Entity, flags | OutputFlags.HideGenericParameterNames); + displayText = ambience.GetString (Entity, flags | OutputFlags.HideGenericParameterNames); } return displayText; } @@ -135,16 +135,16 @@ namespace MonoDevelop.CSharp.Completion bool HasNonMethodMembersWithSameName (IMember member) { - return member.DeclaringType.GetFields (editorCompletion.ctx).Cast<INamedElement> () - .Concat (member.DeclaringType.GetProperties (editorCompletion.ctx).Cast<INamedElement> ()) - .Concat (member.DeclaringType.GetEvents (editorCompletion.ctx).Cast<INamedElement> ()) - .Concat (member.DeclaringType.GetNestedTypes (editorCompletion.ctx).Cast<INamedElement> ()) + return member.DeclaringType.GetFields ().Cast<INamedElement> () + .Concat (member.DeclaringType.GetProperties ().Cast<INamedElement> ()) + .Concat (member.DeclaringType.GetEvents ().Cast<INamedElement> ()) + .Concat (member.DeclaringType.GetNestedTypes ().Cast<INamedElement> ()) .Any (e => e.Name == member.Name); } bool HasAnyOverloadWithParameters (IMethod method) { - return method.DeclaringType.GetMethods (editorCompletion.ctx).Any (m => m.Parameters.Count > 0); + return method.DeclaringType.GetMethods ().Any (m => m.Parameters.Count > 0); } public override void InsertCompletionText (CompletionListWindow window, ref KeyActions ka, Gdk.Key closeChar, char keyChar, Gdk.ModifierType modifier) @@ -244,7 +244,7 @@ namespace MonoDevelop.CSharp.Completion if (entity is IParameter) { this.completionString = ((IParameter)entity).Name; } else { - this.completionString = ambience.GetString (editorCompletion.ctx, entity, OutputFlags.None); + this.completionString = ambience.GetString (entity, OutputFlags.None); } descriptionCreated = false; displayText = entity.Name; @@ -260,7 +260,7 @@ namespace MonoDevelop.CSharp.Completion descriptionCreated = true; if (Entity is IMethod && ((IMethod)Entity).IsExtensionMethod) sb.Append (GettextCatalog.GetString ("(Extension) ")); - sb.Append (ambience.GetString (editorCompletion.ctx, Entity, + sb.Append (ambience.GetString (Entity, OutputFlags.ClassBrowserEntries | OutputFlags.IncludeReturnType | OutputFlags.IncludeKeywords | OutputFlags.UseFullName | OutputFlags.IncludeParameterName | OutputFlags.IncludeMarkup | (HideExtensionParameter ? OutputFlags.HideExtensionsParameter : OutputFlags.None))); var m = (IMember)Entity; @@ -270,11 +270,11 @@ namespace MonoDevelop.CSharp.Completion DisplayFlags |= DisplayFlags.Obsolete; } - var returnType = m.ReturnType.Resolve (editorCompletion.ctx); + var returnType = m.ReturnType; if (returnType.Kind == TypeKind.Delegate) { sb.AppendLine (); sb.AppendLine (GettextCatalog.GetString ("Delegate information")); - sb.Append (ambience.GetString (editorCompletion.ctx, returnType, OutputFlags.ReformatDelegates | OutputFlags.IncludeReturnType | OutputFlags.IncludeParameters | OutputFlags.IncludeParameterName)); + sb.Append (ambience.GetString (returnType, OutputFlags.ReformatDelegates | OutputFlags.IncludeReturnType | OutputFlags.IncludeParameters | OutputFlags.IncludeParameterName)); } string docMarkup = AmbienceService.GetDocumentationMarkup ("<summary>" + AmbienceService.GetDocumentationSummary ((IMember)Entity) + "</summary>", new AmbienceService.DocumentationFormatOptions { @@ -294,11 +294,9 @@ namespace MonoDevelop.CSharp.Completion class OverloadSorter : IComparer<ICompletionData> { OutputFlags flags = OutputFlags.ClassBrowserEntries | OutputFlags.IncludeParameterName; - ITypeResolveContext ctx; - public OverloadSorter (ITypeResolveContext ctx) + public OverloadSorter () { - this.ctx = ctx; } public int Compare (ICompletionData x, ICompletionData y) @@ -323,8 +321,8 @@ namespace MonoDevelop.CSharp.Completion return result; } - string sx = ambience.GetString (ctx, mx, flags); - string sy = ambience.GetString (ctx, my, flags); + string sx = ambience.GetString (mx, flags); + string sy = ambience.GetString (my, flags); result = sx.Length.CompareTo (sy.Length); return result == 0? string.Compare (sx, sy) : result; } @@ -337,7 +335,7 @@ namespace MonoDevelop.CSharp.Completion var sorted = new List<ICompletionData> (overloads.Values); sorted.Add (this); - sorted.Sort (new OverloadSorter (editorCompletion.ctx)); + sorted.Sort (new OverloadSorter ()); return sorted; } } @@ -361,8 +359,8 @@ namespace MonoDevelop.CSharp.Completion // note that the overload tree is traversed top down. var member = Entity as IMember; if ((member.IsVirtual || member.IsOverride) && member.DeclaringType != null && ((IMember)overload.Entity).DeclaringType != null && member.DeclaringType.ReflectionName != ((IMember)overload.Entity).DeclaringType.ReflectionName) { - string str1 = ambience.GetString (editorCompletion.ctx, member as IMember, flags); - string str2 = ambience.GetString (editorCompletion.ctx, overload.Entity as IMember, flags); + string str1 = ambience.GetString (member as IMember, flags); + string str2 = ambience.GetString (overload.Entity as IMember, flags); if (str1 == str2) { if (string.IsNullOrEmpty (AmbienceService.GetDocumentationSummary ((IMember)Entity)) && !string.IsNullOrEmpty (AmbienceService.GetDocumentationSummary ((IMember)overload.Entity))) SetMember (overload.Entity as IMember); @@ -372,8 +370,8 @@ namespace MonoDevelop.CSharp.Completion string MemberId = (overload.Entity as IMember).GetHelpUrl (); if (Entity is IMethod && overload.Entity is IMethod) { - string signature1 = ambience.GetString (editorCompletion.ctx, Entity as IMember, OutputFlags.IncludeParameters | OutputFlags.IncludeGenerics | OutputFlags.GeneralizeGenerics); - string signature2 = ambience.GetString (editorCompletion.ctx, overload.Entity as IMember, OutputFlags.IncludeParameters | OutputFlags.IncludeGenerics | OutputFlags.GeneralizeGenerics); + string signature1 = ambience.GetString (Entity as IMember, OutputFlags.IncludeParameters | OutputFlags.IncludeGenerics | OutputFlags.GeneralizeGenerics); + string signature2 = ambience.GetString (overload.Entity as IMember, OutputFlags.IncludeParameters | OutputFlags.IncludeGenerics | OutputFlags.GeneralizeGenerics); if (signature1 == signature2) return; } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/MethodParameterDataProvider.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/MethodParameterDataProvider.cs index 4deb4e298c..ce7855ddd8 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/MethodParameterDataProvider.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/MethodParameterDataProvider.cs @@ -67,7 +67,7 @@ namespace MonoDevelop.CSharp.Completion foreach (var method in resolveResult.Methods) { if (method.IsConstructor) continue; - string str = ambience.GetString (ext.ctx, method, OutputFlags.IncludeParameters | OutputFlags.GeneralizeGenerics | OutputFlags.IncludeGenerics); + string str = ambience.GetString (method, OutputFlags.IncludeParameters | OutputFlags.GeneralizeGenerics | OutputFlags.IncludeGenerics); if (alreadyAdded.Contains (str)) continue; alreadyAdded.Add (str); @@ -195,7 +195,7 @@ namespace MonoDevelop.CSharp.Completion protected virtual string GetPrefix (IMethod method) { var flags = OutputFlags.ClassBrowserEntries | OutputFlags.IncludeMarkup | OutputFlags.IncludeGenerics; - return ambience.GetString (ext.ctx, method.ReturnType, flags) + " "; + return ambience.GetString (method.ReturnType, flags) + " "; } public string GetMethodMarkup (int overload, string[] parameterMarkup, int currentParameter) @@ -267,13 +267,13 @@ namespace MonoDevelop.CSharp.Completion } if (curParameter != null) { - var returnType = curParameter.Type.Resolve (ext.ctx); - if (returnType.IsDelegate ()) { + var returnType = curParameter.Type; + if (returnType.Kind == TypeKind.Delegate) { sb.AppendLine (); sb.AppendLine (); sb.Append ("<small>"); sb.AppendLine (GettextCatalog.GetString ("Delegate information")); - sb.Append (ambience.GetString (ext.ctx, returnType, OutputFlags.ReformatDelegates | OutputFlags.IncludeReturnType | OutputFlags.IncludeParameters | OutputFlags.IncludeParameterName)); + sb.Append (ambience.GetString (returnType, OutputFlags.ReformatDelegates | OutputFlags.IncludeReturnType | OutputFlags.IncludeParameters | OutputFlags.IncludeParameterName)); sb.Append ("</small>"); } } @@ -287,7 +287,7 @@ namespace MonoDevelop.CSharp.Completion if (paramIndex < 0 || paramIndex >= method.Parameters.Count) return ""; - return ambience.GetString (ext.ctx, method, method.Parameters [paramIndex], OutputFlags.AssemblyBrowserDescription | OutputFlags.HideExtensionsParameter | OutputFlags.IncludeGenerics | OutputFlags.IncludeModifiers | OutputFlags.HighlightName); + return ambience.GetString (method, method.Parameters [paramIndex], OutputFlags.AssemblyBrowserDescription | OutputFlags.HideExtensionsParameter | OutputFlags.IncludeGenerics | OutputFlags.IncludeModifiers | OutputFlags.HighlightName); } public int GetParameterCount (int overload) diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/NewOverrideCompletionData.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/NewOverrideCompletionData.cs index 1c98404fe7..cea18ab564 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/NewOverrideCompletionData.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Completion/NewOverrideCompletionData.cs @@ -44,11 +44,11 @@ namespace MonoDevelop.CSharp.Completion IMember member; static Ambience ambience = new CSharpAmbience (); int declarationBegin; - ITypeDefinition type; + IUnresolvedTypeDefinition type; public bool GenerateBody { get; set; } - public NewOverrideCompletionData (CSharpCompletionTextEditorExtension ext, int declarationBegin, ITypeDefinition type, IMember member) : base (null) + public NewOverrideCompletionData (CSharpCompletionTextEditorExtension ext, int declarationBegin, IUnresolvedTypeDefinition type, IMember member) : base (null) { this.ext = ext; this.type = type; @@ -57,7 +57,7 @@ namespace MonoDevelop.CSharp.Completion this.declarationBegin = declarationBegin; this.GenerateBody = true; this.Icon = member.GetStockIcon (); - this.DisplayText = ambience.GetString (ext.ctx, member, OutputFlags.IncludeParameters | OutputFlags.IncludeGenerics | OutputFlags.HideExtensionsParameter); + this.DisplayText = ambience.GetString (member, OutputFlags.IncludeParameters | OutputFlags.IncludeGenerics | OutputFlags.HideExtensionsParameter); this.CompletionText = member.Name; } @@ -68,13 +68,13 @@ namespace MonoDevelop.CSharp.Completion bool isExplicit = false; if (member.DeclaringTypeDefinition.Kind == TypeKind.Interface) { foreach (var m in type.Members) { - if (m.Name == member.Name && !m.ReturnType.Resolve (ext.ctx).Equals (member.ReturnType.Resolve (ext.ctx))) { + if (m.Name == member.Name && !m.ReturnType.Equals (member.ReturnType)) { isExplicit = true; break; } } - } - var result = generator.CreateMemberImplementation (ext.ctx, type, member, isExplicit); + }// TODO: Type system conversion. + var result = generator.CreateMemberImplementation (type, member, isExplicit); string sb = result.Code.TrimStart (); int trimStart = result.Code.Length - sb.Length; sb = sb.TrimEnd (); diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.ContextAction/ContextActionExtensions.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.ContextAction/ContextActionExtensions.cs index 7a3c7eb1c2..2b54bd3325 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.ContextAction/ContextActionExtensions.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.ContextAction/ContextActionExtensions.cs @@ -62,7 +62,7 @@ namespace MonoDevelop.CSharp.ContextAction public static void FormatText (this AstNode node, MonoDevelop.Ide.Gui.Document doc) { doc.UpdateParseDocument (); - MonoDevelop.CSharp.Formatting.OnTheFlyFormatter.Format (doc, doc.TypeResolveContext, node.StartLocation); + MonoDevelop.CSharp.Formatting.OnTheFlyFormatter.Format (doc, node.StartLocation); } } } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.ContextAction/MDRefactoringContext.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.ContextAction/MDRefactoringContext.cs index 6d6893f744..d38695f5ee 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.ContextAction/MDRefactoringContext.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.ContextAction/MDRefactoringContext.cs @@ -40,6 +40,7 @@ using System.Linq; using MonoDevelop.TypeSystem; using ICSharpCode.NRefactory; using ICSharpCode.NRefactory.Semantics; +using ICSharpCode.NRefactory.CSharp.TypeSystem; namespace MonoDevelop.CSharp.ContextAction { @@ -66,12 +67,6 @@ namespace MonoDevelop.CSharp.ContextAction } } - public override ITypeResolveContext TypeResolveContext { - get { - return Document.TypeResolveContext; - } - } - public override CSharpFormattingOptions FormattingOptions { get { return Document.GetFormattingOptions (); @@ -376,6 +371,7 @@ namespace MonoDevelop.CSharp.ContextAction { return new MdScript (this); } + CSharpParsedFile CSharpParsedFile { get; set; } public MDRefactoringContext (MonoDevelop.Ide.Gui.Document document, TextLocation loc) @@ -390,12 +386,12 @@ namespace MonoDevelop.CSharp.ContextAction public override AstType CreateShortType (IType fullType) { - var csResolver = new CSharpResolver (TypeResolveContext, System.Threading.CancellationToken.None); - csResolver.CurrentMember = CSharpParsedFile.GetMember (Location); - csResolver.CurrentTypeDefinition = CSharpParsedFile.GetInnermostTypeDefinition (Location); - csResolver.CurrentUsingScope = CSharpParsedFile.GetUsingScope (Location); - TypeSystemAstBuilder builder = new TypeSystemAstBuilder (csResolver); - return builder.ConvertType (fullType); + var parsedFile = Document.ParsedDocument.ParsedFile as CSharpParsedFile; + + var csResolver = parsedFile.GetResolver (Document.Compilation, Document.Editor.Caret.Location); + + var builder = new ICSharpCode.NRefactory.CSharp.Refactoring.TypeSystemAstBuilder (csResolver); + return builder.ConvertType (fullType); } /* @@ -416,13 +412,11 @@ namespace MonoDevelop.CSharp.ContextAction public override ResolveResult Resolve (AstNode node) { - var pf = ParsedDocument.Annotation<CSharpParsedFile> (); - var csResolver = new CSharpResolver (TypeResolveContext, System.Threading.CancellationToken.None); - var navigator = new NodeListResolveVisitorNavigator (new[] { node }); + var parsedFile = Document.ParsedDocument.ParsedFile as CSharpParsedFile; + var cu = Document.ParsedDocument.Annotation<CompilationUnit> (); - var visitor = new ICSharpCode.NRefactory.CSharp.Resolver.ResolveVisitor (csResolver, pf, navigator); - visitor.Scan (Unit); - return visitor.GetResolveResult (node); + var resolver = new CSharpAstResolver (Document.Compilation, cu, parsedFile); + return resolver.Resolve (node); } public override void ReplaceReferences (ICSharpCode.NRefactory.TypeSystem.IMember member, MemberDeclaration replaceWidth) diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/CSharpTextEditorIndentation.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/CSharpTextEditorIndentation.cs index ae64e0d835..55d98ddd15 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/CSharpTextEditorIndentation.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/CSharpTextEditorIndentation.cs @@ -111,11 +111,8 @@ namespace MonoDevelop.CSharp.Formatting { if (PropertyService.Get ("OnTheFlyFormatting", true) && textEditorData != null && Document != null) { // textEditorData.Document.TextReplaced -= TextCut; - var dom = Document.TypeResolveContext; var loc = textEditorData.Document.OffsetToLocation (offset); - var location = new TextLocation (loc.Line, loc.Column); - // CSharpFormatter.Format (textEditorData, dom, Document.CompilationUnit, location); - OnTheFlyFormatter.Format (Document, dom, location); + OnTheFlyFormatter.Format (Document, loc); // textEditorData.Document.TextReplaced += TextCut; } } @@ -502,10 +499,9 @@ namespace MonoDevelop.CSharp.Formatting if (PropertyService.Get ("OnTheFlyFormatting", true) && textEditorData != null && !(textEditorData.CurrentMode is TextLinkEditMode)) { // textEditorData.Document.TextReplaced -= TextCut; - var dom = Document.TypeResolveContext; TextLocation location = new TextLocation (textEditorData.Caret.Location.Line + (lastCharInserted == '\n' ? -1 : 0), textEditorData.Caret.Location.Column); // CSharpFormatter.Format (textEditorData, dom, Document.CompilationUnit, location); - OnTheFlyFormatter.Format (Document, dom, location, lastCharInserted == '\n'); + OnTheFlyFormatter.Format (Document, location, lastCharInserted == '\n'); // textEditorData.Document.TextReplaced += TextCut; } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/OnTheFlyFormatter.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/OnTheFlyFormatter.cs index 584f9e6477..92cf39d5d8 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/OnTheFlyFormatter.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Formatting/OnTheFlyFormatter.cs @@ -38,29 +38,30 @@ using ICSharpCode.NRefactory; using ICSharpCode.NRefactory.CSharp.Refactoring; using MonoDevelop.CSharp.ContextAction; using ICSharpCode.NRefactory.TypeSystem; +using ICSharpCode.NRefactory.CSharp.TypeSystem; namespace MonoDevelop.CSharp.Formatting { public class OnTheFlyFormatter { - public static void Format (MonoDevelop.Ide.Gui.Document data, ITypeResolveContext dom) + public static void Format (MonoDevelop.Ide.Gui.Document data) { - Format (data, dom, TextLocation.Empty, false); + Format (data, TextLocation.Empty, false); } - public static void Format (MonoDevelop.Ide.Gui.Document data, ITypeResolveContext dom, TextLocation location, bool runAferCR = false) + public static void Format (MonoDevelop.Ide.Gui.Document data, TextLocation location, bool runAferCR = false) { - Format (data, dom, location, false, runAferCR); + Format (data, location, false, runAferCR); } - public static void Format (MonoDevelop.Ide.Gui.Document data, ITypeResolveContext dom, TextLocation location, bool correctBlankLines, bool runAferCR = false) + public static void Format (MonoDevelop.Ide.Gui.Document data, TextLocation location, bool correctBlankLines, bool runAferCR = false) { var policyParent = data.Project != null ? data.Project.Policies : PolicyService.DefaultPolicies; var mimeTypeChain = DesktopService.GetMimeTypeInheritanceChain (CSharpFormatter.MimeType); - Format (policyParent, mimeTypeChain, data, dom, location, correctBlankLines, runAferCR); + Format (policyParent, mimeTypeChain, data, location, correctBlankLines, runAferCR); } - public static void Format (PolicyContainer policyParent, IEnumerable<string> mimeTypeChain, MonoDevelop.Ide.Gui.Document data, ITypeResolveContext dom, TextLocation location, bool correctBlankLines, bool runAferCR/* = false*/) + public static void Format (PolicyContainer policyParent, IEnumerable<string> mimeTypeChain, MonoDevelop.Ide.Gui.Document data, TextLocation location, bool correctBlankLines, bool runAferCR/* = false*/) { if (data.ParsedDocument == null) return; diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Highlighting/CSharpSyntaxMode.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Highlighting/CSharpSyntaxMode.cs index 0f1f7471bc..eb5bfebcf3 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Highlighting/CSharpSyntaxMode.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Highlighting/CSharpSyntaxMode.cs @@ -47,6 +47,7 @@ using ICSharpCode.NRefactory.CSharp.Resolver; using System.IO; using ICSharpCode.NRefactory.Semantics; using ICSharpCode.NRefactory; +using ICSharpCode.NRefactory.CSharp.TypeSystem; namespace MonoDevelop.CSharp.Highlighting @@ -202,7 +203,6 @@ namespace MonoDevelop.CSharp.Highlighting HashSet<string> tags = new HashSet<string> (); MonoDevelop.Ide.Gui.Document document; CompilationUnit unit; - ResolveVisitor visitor; static HashSet<string> contextualKeywords = new HashSet<string> (); static CSharpChunkParser () @@ -255,6 +255,7 @@ namespace MonoDevelop.CSharp.Highlighting dict.Clear (); } }*/ + CSharpAstResolver visitor; public CSharpChunkParser (SpanParser spanParser, Mono.TextEditor.Document doc, ColorSheme style, SyntaxMode mode, LineSegment line) : base (spanParser, doc, style, mode, line) { @@ -265,15 +266,7 @@ namespace MonoDevelop.CSharp.Highlighting } if (document != null && document.ParsedDocument != null && MonoDevelop.Core.PropertyService.Get ("EnableSemanticHighlighting", true)) { unit = document.ParsedDocument.Annotation<CompilationUnit> (); - - if ((visitor = document.ParsedDocument.Annotation <ResolveVisitor> ()) == null) { - var resolver = new CSharpResolver (document.TypeResolveContext, System.Threading.CancellationToken.None); - visitor = new ResolveVisitor (resolver, document.ParsedDocument.Annotation <CSharpParsedFile> (), this); - visitor.Scan (unit); - document.ParsedDocument.AddAnnotation (visitor); - } else { - visitor = document.ParsedDocument.Annotation<ResolveVisitor> (); - } + visitor = new CSharpAstResolver (document.Compilation, unit, document.ParsedDocument.Annotation <CSharpParsedFile> ()); } } @@ -341,7 +334,7 @@ namespace MonoDevelop.CSharp.Highlighting if (node is SimpleType) { var st = (SimpleType)node; - var result = visitor.GetResolveResult (st); + var result = visitor.Resolve (st); if (result is TypeResolveResult && st.IdentifierToken.Contains (loc.Line, loc.Column) && unit.GetNodeAt<UsingDeclaration> (loc.Line, loc.Column) == null) { endOffset = doc.LocationToOffset (st.IdentifierToken.EndLocation.Line, st.IdentifierToken.EndLocation.Column); @@ -352,7 +345,7 @@ namespace MonoDevelop.CSharp.Highlighting if (node is ICSharpCode.NRefactory.CSharp.MemberType) { var mt = (ICSharpCode.NRefactory.CSharp.MemberType)node; - var result = visitor.GetResolveResult (mt); + var result = visitor.Resolve (mt); if (result is TypeResolveResult && mt.MemberNameToken.Contains (loc.Line, loc.Column) && unit.GetNodeAt<UsingDeclaration> (loc.Line, loc.Column) == null) { endOffset = doc.LocationToOffset (mt.MemberNameToken.EndLocation.Line, mt.MemberNameToken.EndLocation.Column); @@ -374,7 +367,7 @@ namespace MonoDevelop.CSharp.Highlighting } var id = node as IdentifierExpression; if (id != null) { - var result = visitor.GetResolveResult (id); + var result = visitor.Resolve (id); if (result is MemberResolveResult) { var member = ((MemberResolveResult)result).Member; if (member is IField) { @@ -395,7 +388,7 @@ namespace MonoDevelop.CSharp.Highlighting if (!memberReferenceExpression.MemberNameToken.Contains (loc.Line, loc.Column)) return null; - var result = visitor.GetResolveResult (memberReferenceExpression); + var result = visitor.Resolve (memberReferenceExpression); if (result is MemberResolveResult) { var member = ((MemberResolveResult)result).Member; if (member is IField) { diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Highlighting/HighlightUsagesExtension.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Highlighting/HighlightUsagesExtension.cs index 62481b2d35..3b37df8870 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Highlighting/HighlightUsagesExtension.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Highlighting/HighlightUsagesExtension.cs @@ -43,8 +43,6 @@ namespace MonoDevelop.CSharp.Highlighting { public class HighlightUsagesExtension : TextEditorExtension, IQuickTaskProvider { - ITypeResolveContext dom; - TextEditorData textEditorData; ITextEditorResolver textEditorResolver; @@ -52,8 +50,6 @@ namespace MonoDevelop.CSharp.Highlighting { base.Initialize (); - dom = Document.TypeResolveContext; - textEditorResolver = base.Document.GetContent<ITextEditorResolver> (); textEditorData = base.Document.Editor; textEditorData.Caret.PositionChanged += HandleTextEditorDataCaretPositionChanged; diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Inspection/CallGraph.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Inspection/CallGraph.cs index 921c472e7b..89129d5e63 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Inspection/CallGraph.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Inspection/CallGraph.cs @@ -34,6 +34,7 @@ using MonoDevelop.TypeSystem; using ICSharpCode.NRefactory.Semantics; using ICSharpCode.NRefactory.TypeSystem; using MonoDevelop.CSharp.Refactoring; +using ICSharpCode.NRefactory.CSharp.TypeSystem; namespace MonoDevelop.CSharp.Inspection { @@ -46,7 +47,8 @@ namespace MonoDevelop.CSharp.Inspection public CSharpResolver CSharpResolver; public VisitNamespaceNodesNavigator Navigator; - public ResolveVisitor Visitor; + public CSharpAstResolver Resolver; + System.Threading.CancellationToken token; public CallGraph (System.Threading.CancellationToken token) @@ -56,7 +58,7 @@ namespace MonoDevelop.CSharp.Inspection public ResolveResult Resolve (AstNode node) { - return Visitor.GetResolveResult (node); + return Resolver.Resolve (node); } public void Inspect (MonoDevelop.Ide.Gui.Document doc, ParsedDocument parsedDocument) @@ -64,10 +66,10 @@ namespace MonoDevelop.CSharp.Inspection var pf = parsedDocument.Annotation<CSharpParsedFile> (); var unit = parsedDocument.Annotation<CompilationUnit> (); var ctx = doc.TypeResolveContext; - CSharpResolver = new CSharpResolver (ctx, token); + + Resolver = new CSharpAstResolver (doc.Compilation, unit, pf); + Navigator = new VisitNamespaceNodesNavigator (); - Visitor = new ResolveVisitor (CSharpResolver, pf, Navigator); - Visitor.Scan (unit); /*unit.AcceptVisitor (visitor, null); diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Inspection/CodeAnalysis.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Inspection/CodeAnalysis.cs index 34fe9407bf..b1daca4ffc 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Inspection/CodeAnalysis.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Inspection/CodeAnalysis.cs @@ -63,12 +63,12 @@ namespace MonoDevelop.CSharp.Inspection public CSharpResolver GetResolverStateBefore (AstNode node) { - return Graph.Visitor.GetResolverStateBefore (node); + return Graph.Resolver.GetResolverStateBefore (node); } public ResolveResult GetResolveResult (AstNode node) { - return Graph.Visitor.GetResolveResult (node); + return Graph.Resolver.Resolve (node); } } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Inspection/Inspectors/RedundantThisInspector.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Inspection/Inspectors/RedundantThisInspector.cs index 60f7987a23..b10fb8e2ce 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Inspection/Inspectors/RedundantThisInspector.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Inspection/Inspectors/RedundantThisInspector.cs @@ -47,8 +47,8 @@ namespace MonoDevelop.CSharp.Inspection var memberReference = expr.Parent as MemberReferenceExpression;
if (memberReference == null)
return;
- var state = data.Graph.Visitor.GetResolverStateBefore (expr);
- var wholeResult = data.Graph.Visitor.GetResolveResult (memberReference) as MemberResolveResult;
+ var state = data.Graph.Resolver.GetResolverStateBefore (expr);
+ var wholeResult = data.Graph.Resolver.Resolve (memberReference) as MemberResolveResult;
var result = state.LookupSimpleNameOrTypeName (memberReference.MemberName, new List<IType> (), SimpleNameLookupMode.Expression) as MemberResolveResult;
if (result == null || wholeResult == null)
return;
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Inspection/Inspectors/UnusedUsingInspector.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Inspection/Inspectors/UnusedUsingInspector.cs index 74eac4e480..c44d82b754 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Inspection/Inspectors/UnusedUsingInspector.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Inspection/Inspectors/UnusedUsingInspector.cs @@ -40,12 +40,12 @@ namespace MonoDevelop.CSharp.Inspection void HandleVisitorUsingDeclarationVisited (UsingDeclaration node, InspectionData data) { - if (!data.Graph.Navigator.GetsUsed (data.Document.TypeResolveContext, data.Graph.CSharpResolver, node.StartLocation, node.Namespace)) { + if (!data.Graph.Navigator.GetsUsed (data.Graph.CSharpResolver, node.StartLocation, node.Namespace)) { AddResult (data, new DomRegion (node.StartLocation, node.EndLocation), GettextCatalog.GetString ("Remove unused usings"), delegate { - var options = new RefactoringOptions () { Document = data.Document, Dom = data.Document.TypeResolveContext}; + var options = new RefactoringOptions () { Document = data.Document}; new RemoveUnusedImportsRefactoring ().Run (options); } ); diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Parser/TypeSystemProvider.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Parser/TypeSystemProvider.cs index 98bb04138a..0c07901a81 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Parser/TypeSystemProvider.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Parser/TypeSystemProvider.cs @@ -39,9 +39,9 @@ namespace MonoDevelop.CSharp.Parser { public class TypeSystemParser : ITypeSystemParser { - public ParsedDocument Parse (IProjectContent projectContent, bool storeAst, string fileName, System.IO.TextReader content) + public ParsedDocument Parse (bool storeAst, string fileName, System.IO.TextReader content, MonoDevelop.Projects.Project project = null) { - var parser = new ICSharpCode.NRefactory.CSharp.CSharpParser (GetCompilerArguments (projectContent)); + var parser = new ICSharpCode.NRefactory.CSharp.CSharpParser (GetCompilerArguments (project)); parser.GenerateTypeSystemMode = !storeAst; var result = new ParsedDocumentDecorator (); @@ -59,13 +59,13 @@ namespace MonoDevelop.CSharp.Parser } }; - var unit = parser.Parse (content); - var visitor = new TypeSystemConvertVisitor (projectContent, fileName); - unit.AcceptVisitor (visitor, null); - result.ParsedFile = visitor.ParsedFile; + var unit = parser.Parse (content, fileName); + var pf = unit.ToTypeSystem (); + result.ParsedFile = pf; + if (storeAst) { result.AddAnnotation (unit); - result.AddAnnotation (visitor.ParsedFile); + result.AddAnnotation (pf); } return result; } @@ -188,12 +188,11 @@ namespace MonoDevelop.CSharp.Parser } } - string[] GetCompilerArguments (IProjectContent projectContent) + string[] GetCompilerArguments (MonoDevelop.Projects.Project project) { + if (project == null) + return new string[0]; var compilerArguments = new List<string> (); - var project = projectContent.GetProject (); - if (project == null || MonoDevelop.Ide.IdeApp.Workspace == null) - return compilerArguments.ToArray (); var configuration = project.GetConfiguration (MonoDevelop.Ide.IdeApp.Workspace.ActiveConfiguration) as DotNetProjectConfiguration; var par = configuration != null ? configuration.CompilationParameters as CSharpCompilerParameters : null; diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CompilerOptionsPanelWidget.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CompilerOptionsPanelWidget.cs index a831f249d8..b17c392230 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CompilerOptionsPanelWidget.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Project/CompilerOptionsPanelWidget.cs @@ -203,11 +203,11 @@ namespace MonoDevelop.CSharp.Project void FillClasses ()
{
try { - ITypeResolveContext ctx = TypeSystemService.GetProjectContext (project); + var ctx = TypeSystemService.GetCompilation (project); if (ctx == null) // Project not found in parser database return; - foreach (var c in ctx.GetAllTypes ()) {
+ foreach (var c in ctx.GetAllTypeDefinitions ()) {
if (c.Methods != null) {
foreach (var m in c.Methods) {
if (m.IsStatic && m.Name == "Main")
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CSharpCodeGenerator.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CSharpCodeGenerator.cs index 87c69095b6..9a9aca175f 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CSharpCodeGenerator.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CSharpCodeGenerator.cs @@ -35,6 +35,7 @@ using MonoDevelop.TypeSystem; using ICSharpCode.NRefactory.CSharp.Resolver; using ICSharpCode.NRefactory; using Mono.TextEditor; +using ICSharpCode.NRefactory.CSharp.TypeSystem; namespace MonoDevelop.CSharp.Refactoring @@ -57,8 +58,7 @@ namespace MonoDevelop.CSharp.Refactoring class CodeGenerationOptions { public bool ExplicitDeclaration { get; set; } - public ITypeDefinition ImplementingType { get; set; } - public ITypeResolveContext Ctx { get; set; } + public IUnresolvedTypeDefinition ImplementingType { get; set; } } public override string WrapInRegions (string regionName, string text) @@ -75,14 +75,32 @@ namespace MonoDevelop.CSharp.Refactoring return result.ToString (); } - public override CodeGeneratorMemberResult CreateMemberImplementation (ITypeResolveContext ctx, ITypeDefinition implementingType, IMember member, + public override CodeGeneratorMemberResult CreateMemberImplementation (IUnresolvedTypeDefinition implementingType, IUnresolvedMember member, bool explicitDeclaration) { SetIndentTo (implementingType); var options = new CodeGenerationOptions () { ExplicitDeclaration = explicitDeclaration, - ImplementingType = implementingType, - Ctx = ctx + ImplementingType = implementingType + }; + if (member is IMethod) + return GenerateCode ((IMethod)member, options); + if (member is IProperty) + return GenerateCode ((IProperty)member, options); + if (member is IField) + return GenerateCode ((IField)member, options); + if (member is IEvent) + return GenerateCode ((IEvent)member, options); + throw new NotSupportedException ("member " + member + " is not supported."); + } + + public override CodeGeneratorMemberResult CreateMemberImplementation (IUnresolvedTypeDefinition implementingType, IMember member, + bool explicitDeclaration) + { + SetIndentTo (implementingType); + var options = new CodeGenerationOptions () { + ExplicitDeclaration = explicitDeclaration, + ImplementingType = implementingType }; if (member is IMethod) return GenerateCode ((IMethod)member, options); @@ -162,26 +180,23 @@ namespace MonoDevelop.CSharp.Refactoring result.Append (GetIndent (IndentLevel)); } - void AppendReturnType (StringBuilder result, ITypeDefinition implementingType, ITypeReference type) + void AppendReturnType (StringBuilder result, IUnresolvedTypeDefinition implementingType, IType type) { if (type == null) throw new ArgumentNullException ("type"); - if (type == SharedTypes.UnknownType) - throw new ArgumentException ("type is unknown", "type"); var loc = implementingType.Region.Begin; - var pf = implementingType.ProjectContent.GetFile (implementingType.Region.FileName); - if (pf is ParsedDocumentDecorator) - pf = ((ParsedDocumentDecorator)pf).ParsedFile; + var pf = implementingType.ParsedFile; var file = pf as CSharpParsedFile; - var project = implementingType.ProjectContent.Annotation<MonoDevelop.Projects.Project> (); - var ctx = TypeSystemService.GetContext (project); - var resolved = type.Resolve (ctx); - if (resolved == SharedTypes.UnknownType) { + var resolved = type; + if (resolved.Kind == TypeKind.Unknown) { result.Append (type.ToString ()); return; } - var shortType = CreateShortType (ctx, file, loc, resolved); + //TODO: Type system conversion + +/* var shortType = CreateShortType (file, loc, resolved); + using (var stringWriter = new System.IO.StringWriter ()) { var formatter = new TextWriterOutputFormatter (stringWriter); stringWriter.NewLine = EolMarker; @@ -191,7 +206,7 @@ namespace MonoDevelop.CSharp.Refactoring if (typeString.StartsWith ("global::")) typeString = typeString.Substring ("global::".Length); result.Append (typeString); - } + }*/ } /* @@ -232,7 +247,7 @@ namespace MonoDevelop.CSharp.Refactoring AppendReturnType (result, options.ImplementingType, evt.ReturnType); result.Append (" "); if (options.ExplicitDeclaration) { - result.Append (ambience.GetString (options.Ctx, (ITypeReference)evt.DeclaringTypeDefinition, OutputFlags.IncludeGenerics)); + result.Append (ambience.GetString (evt.DeclaringTypeDefinition, OutputFlags.IncludeGenerics)); result.Append ("."); } result.Append (evt.Name); @@ -267,7 +282,9 @@ namespace MonoDevelop.CSharp.Refactoring AppendIndent (result); bodyStartOffset = result.Length; result.Append ("throw new "); - AppendReturnType (result, options.ImplementingType, options.Ctx.GetTypeDefinition (typeof (System.NotImplementedException))); + // TODO: Type system conversion. + result.Append ("System.NotImplementedException"); +// AppendReturnType (result, options.ImplementingType, options.Ctx.GetTypeDefinition (typeof (System.NotImplementedException))); if (Policy.BeforeMethodCallParentheses) result.Append (" "); result.Append ("();"); @@ -314,16 +331,13 @@ namespace MonoDevelop.CSharp.Refactoring var typeParameters = method.TypeParameters; foreach (var p in typeParameters) { - Console.WriteLine (p.GetEffectiveBaseClass (options.Ctx)); + Console.WriteLine (p.EffectiveBaseClass); } - if (typeParameters.Any (p => p.GetConstraints (options.Ctx).Any () /*|| (p.TypeParameterModifier & TypeParameterModifier.HasDefaultConstructorConstraint) != 0*/)) { + + if (typeParameters.Any (p => p.HasDefaultConstructorConstraint || p.HasReferenceTypeConstraint || p.HasValueTypeConstraint || p.DirectBaseTypes.Any ())) { result.Append (" where "); int typeParameterCount = 0; foreach (var p in typeParameters) { - var bc = p.GetEffectiveBaseClass (options.Ctx); - - if (!p.GetConstraints (options.Ctx).Any () /*&& (p.TypeParameterModifier & TypeParameterModifier.HasDefaultConstructorConstraint) == 0*/) - continue; if (typeParameterCount != 0) result.Append (", "); @@ -331,27 +345,30 @@ namespace MonoDevelop.CSharp.Refactoring result.Append (p.Name); result.Append (" : "); int constraintCount = 0; -// if ((p.TypeParameterModifier & TypeParameterModifier.HasDefaultConstructorConstraint) != 0) { -// result.Append ("new ()"); -// constraintCount++; -// } - foreach (var c in p.GetConstraints (options.Ctx)) { - if (c == SharedTypes.UnknownType) - continue; + if (p.HasDefaultConstructorConstraint) { + result.Append ("new ()"); + constraintCount++; + } + + if (p.HasValueTypeConstraint) { + if (constraintCount != 0) + result.Append (", "); + result.Append ("struct"); + constraintCount++; + } + + if (p.HasReferenceTypeConstraint) { + if (constraintCount != 0) + result.Append (", "); + result.Append ("class"); + constraintCount++; + } + + foreach (var c in p.DirectBaseTypes) { if (constraintCount != 0) result.Append (", "); constraintCount++; - var ct = c.Resolve (options.Ctx); - if (ct.Equals (options.Ctx.GetTypeDefinition (typeof (System.ValueType)))) { - result.Append ("struct"); - continue; - } - if (ct.Equals (options.Ctx.GetTypeDefinition (typeof (System.Object)))) { - result.Append ("class"); - continue; - } - AppendReturnType (result, options.ImplementingType, c); } } @@ -369,7 +386,7 @@ namespace MonoDevelop.CSharp.Refactoring result.Append (" "); result.Append ("(\"["); result.Append (options.ImplementingType.Name); - if (options.ImplementingType.Properties.Count > 0) + if (options.ImplementingType.Properties.Any ()) result.Append (": "); int i = 0; foreach (IProperty property in options.ImplementingType.Properties) { @@ -392,14 +409,14 @@ namespace MonoDevelop.CSharp.Refactoring result.Append (");"); bodyEndOffset = result.Length; AppendLine (result); - } else if (IsMonoTouchModelMember (options.Ctx, method)) { + } else if (IsMonoTouchModelMember (method)) { AppendMonoTouchTodo (result, out bodyStartOffset, out bodyEndOffset); } else if (method.IsAbstract || !(method.IsVirtual || method.IsOverride) || method.DeclaringTypeDefinition.Kind == TypeKind.Interface) { AppendNotImplementedException (result, options, out bodyStartOffset, out bodyEndOffset); } else { AppendIndent (result); bodyStartOffset = result.Length; - if (!method.ReturnType.Resolve (options.Ctx).Equals (KnownTypeReference.Void.Resolve (options.Ctx))) + if (method.ReturnType.ReflectionName != typeof(void).FullName) result.Append ("return "); result.Append ("base."); result.Append (method.Name); @@ -426,7 +443,7 @@ namespace MonoDevelop.CSharp.Refactoring return new CodeGeneratorMemberResult (result.ToString (), bodyStartOffset, bodyEndOffset); } - void AppendParameterList (StringBuilder result, ITypeDefinition implementingType, IList<IParameter> parameters) + void AppendParameterList (StringBuilder result, IUnresolvedTypeDefinition implementingType, IList<IParameter> parameters) { for (int i = 0; i < parameters.Count; i++) { if (i > 0) @@ -445,14 +462,14 @@ namespace MonoDevelop.CSharp.Refactoring } } - static string GetModifiers (IType implementingType, IMember member) + static string GetModifiers (IUnresolvedTypeDefinition implementingType, IMember member) { StringBuilder result = new StringBuilder (); if (member.IsPublic || (member.DeclaringType != null && member.DeclaringTypeDefinition.Kind == TypeKind.Interface)) { result.Append ("public "); } else if (member.IsProtectedAndInternal) { result.Append ("protected internal "); - } else if (member.IsProtectedOrInternal && (member.DeclaringType != null && implementingType.GetProjectContent () == member.DeclaringType.GetProjectContent ())) { + } else if (member.IsProtectedOrInternal) { result.Append ("internal protected "); } else if (member.IsProtected) { result.Append ("protected "); @@ -476,16 +493,17 @@ namespace MonoDevelop.CSharp.Refactoring bool isFromInterface = false; if (member.DeclaringType != null && member.DeclaringTypeDefinition.Kind == TypeKind.Interface) { isFromInterface = true; - if (options.ImplementingType != null) { - foreach (var type in options.ImplementingType.GetAllBaseTypeDefinitions (options.Ctx)) { - if (type.Kind == TypeKind.Interface) - continue; - if (type.Members.Any (m => m.Name == member.Name && member.EntityType == m.EntityType /* && DomMethod.ParameterListEquals (member.Parameters, m.Parameters)*/ )) { - isFromInterface = false; - break; - } - } - } +// TODO: Type system conversion. +// if (options.ImplementingType != null) { +// foreach (var type in options.ImplementingType.BaseTypes) { +// if (type.Kind == TypeKind.Interface) +// continue; +// if (type.Members.Any (m => m.Name == member.Name && member.EntityType == m.EntityType /* && DomMethod.ParameterListEquals (member.Parameters, m.Parameters)*/ )) { +// isFromInterface = false; +// break; +// } +// } +// } } if (!isFromInterface && (member.IsVirtual || member.IsAbstract)) result.Append ("override "); @@ -504,7 +522,7 @@ namespace MonoDevelop.CSharp.Refactoring result.Append ("]"); } else { if (options.ExplicitDeclaration) { - result.Append (ambience.GetString (options.Ctx, (ITypeReference)property.DeclaringType, OutputFlags.IncludeGenerics)); + result.Append (ambience.GetString (property.DeclaringType, OutputFlags.IncludeGenerics)); result.Append ("."); } result.Append (property.Name); @@ -518,7 +536,7 @@ namespace MonoDevelop.CSharp.Refactoring result.AppendLine (";"); } else { AppendBraceStart (result, Policy.PropertyGetBraceStyle); - if (IsMonoTouchModelMember (options.Ctx, property)) { + if (IsMonoTouchModelMember (property)) { AppendMonoTouchTodo (result, out bodyStartOffset, out bodyEndOffset); } else if (property.IsAbstract || property.DeclaringTypeDefinition.Kind == TypeKind.Interface) { AppendNotImplementedException (result, options, out bodyStartOffset, out bodyEndOffset); @@ -545,7 +563,7 @@ namespace MonoDevelop.CSharp.Refactoring result.AppendLine (";"); } else { AppendBraceStart (result, Policy.PropertyGetBraceStyle); - if (IsMonoTouchModelMember (options.Ctx, property)) { + if (IsMonoTouchModelMember (property)) { AppendMonoTouchTodo (result, out bodyStartOffset, out bodyEndOffset); } else if (property.IsAbstract || property.DeclaringTypeDefinition.Kind == TypeKind.Interface) { AppendNotImplementedException (result, options, out bodyStartOffset, out bodyEndOffset); @@ -567,14 +585,14 @@ namespace MonoDevelop.CSharp.Refactoring return new CodeGeneratorMemberResult (result.ToString (), regions); } - static bool IsMonoTouchModelMember (ITypeResolveContext ctx, IMember member) + static bool IsMonoTouchModelMember (IMember member) { if (member == null || member.DeclaringType == null) return false; - return member.DeclaringTypeDefinition.Attributes.Any (attr => attr.AttributeType != null && attr.AttributeType.Resolve (ctx).Equals (ctx.GetTypeDefinition ("MonoTouch.Foundation", "ModelAttribute", 0, StringComparer.Ordinal))); + return member.DeclaringTypeDefinition.Attributes.Any (attr => attr.AttributeType != null && attr.AttributeType.ReflectionName == "MonoTouch.Foundation.ModelAttribute"); } - public override string CreateFieldEncapsulation (ITypeDefinition implementingType, IField field, string propertyName, Accessibility modifiers, bool readOnly) + public override string CreateFieldEncapsulation (IUnresolvedTypeDefinition implementingType, IField field, string propertyName, Accessibility modifiers, bool readOnly) { SetIndentTo (implementingType); StringBuilder result = new StringBuilder (); @@ -726,8 +744,7 @@ namespace MonoDevelop.CSharp.Refactoring public override string GetShortTypeString (MonoDevelop.Ide.Gui.Document doc, IType type) { - var loc = new TextLocation (doc.Editor.Caret.Line, doc.Editor.Caret.Column); - AstType shortType = CreateShortType (doc.TypeResolveContext, doc.ParsedDocument.Annotation<CSharpParsedFile> (), loc, type); + var shortType = CreateShortType (doc.Compilation, doc.ParsedDocument.Annotation<CSharpParsedFile> (), doc.Editor.Caret.Location, type); return OutputNode (doc, shortType); } @@ -745,16 +762,11 @@ namespace MonoDevelop.CSharp.Refactoring } - static AstType CreateShortType (ITypeResolveContext ctx, CSharpParsedFile file, TextLocation loc, IType fullType) + public AstType CreateShortType (ICompilation compilation, CSharpParsedFile parsedFile, TextLocation loc, IType fullType) { - var csResolver = new CSharpResolver (ctx, System.Threading.CancellationToken.None); - - csResolver.CurrentMember = file.GetMember (loc); - csResolver.CurrentTypeDefinition = file.GetInnermostTypeDefinition (loc); - csResolver.CurrentUsingScope = file.GetUsingScope (loc); - + var csResolver = parsedFile.GetResolver (compilation, loc); var builder = new ICSharpCode.NRefactory.CSharp.Refactoring.TypeSystemAstBuilder (csResolver); - return builder.ConvertType (fullType); + return builder.ConvertType (fullType); } public override void CompleteStatement (MonoDevelop.Ide.Gui.Document doc) diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CSharpReferenceFinder.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CSharpReferenceFinder.cs index d1c0a6cc7b..186b5e068d 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CSharpReferenceFinder.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CSharpReferenceFinder.cs @@ -39,6 +39,8 @@ using System.IO; using MonoDevelop.TypeSystem; using ICSharpCode.NRefactory.Semantics; using Mono.TextEditor; +using ICSharpCode.NRefactory.CSharp.TypeSystem; +using System.Threading; namespace MonoDevelop.CSharp.Refactoring @@ -140,15 +142,15 @@ namespace MonoDevelop.CSharp.Refactoring foreach (var obj in searchedMembers) { if (obj is IEntity) { - refFinder.FindReferencesInFile (refFinder.GetSearchScopes ((IEntity)obj), file, unit, ctx, (astNode, r) => { + refFinder.FindReferencesInFile (refFinder.GetSearchScopes ((IEntity)obj), file, unit, (astNode, r) => { if (IsNodeValid (obj, astNode)) result.Add (GetReference (r, astNode, editor.FileName, editor)); - }); + }, CancellationToken.None); } else if (obj is IVariable) { - refFinder.FindLocalReferences ((IVariable)obj, file, unit, ctx, (astNode, r) => { + refFinder.FindLocalReferences ((IVariable)obj, file, unit, doc.Compilation, (astNode, r) => { if (IsNodeValid (obj, astNode)) result.Add (GetReference (r, astNode, editor.FileName, editor)); - }); + }, CancellationToken.None); } } return result; @@ -156,7 +158,10 @@ namespace MonoDevelop.CSharp.Refactoring public override IEnumerable<MemberReference> FindReferences () { - var entity = searchedMembers.First () as IEntity; + // TODO: Type system conversion. + yield break; + +/* var entity = searchedMembers.First () as IEntity; var scopes = entity != null ? refFinder.GetSearchScopes (entity) : null; List<MemberReference> refs = new List<MemberReference> (); Project prj = null; @@ -198,7 +203,7 @@ namespace MonoDevelop.CSharp.Refactoring } } - return refs; + return refs;*/ } } } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CreateMethod/CreateMethodCodeGenerator.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CreateMethod/CreateMethodCodeGenerator.cs index e1ff035d49..ef5069dfdc 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CreateMethod/CreateMethodCodeGenerator.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/CreateMethod/CreateMethodCodeGenerator.cs @@ -77,10 +77,10 @@ namespace MonoDevelop.CSharp.Refactoring.CreateMethod bool AnalyzeTargetExpression (RefactoringOptions options, ICSharpCode.NRefactory.CSharp.CompilationUnit unit) { var data = options.GetTextEditorData (); - var ctx = options.Document.TypeResolveContext; var target = unit.GetNodeAt (data.Caret.Line, data.Caret.Column); if (target == null) return false; + IType type = null; if (target.Parent is MemberReferenceExpression && ((MemberReferenceExpression)target.Parent).GetChildByRole (MemberReferenceExpression.Roles.Identifier) == target) { var memberReference = (MemberReferenceExpression)target.Parent; target = memberReference.Target; @@ -89,16 +89,18 @@ namespace MonoDevelop.CSharp.Refactoring.CreateMethod // modifiers = MonoDevelop.Projects.Dom.Modifiers.Static; if (targetResult == null) return false; - var type = targetResult.Type.Resolve (ctx); + type = targetResult.Type; if (type == null || type.GetDefinition () == null) return false; - declaringType = type.GetDefinition ().GetParts ().First (); + declaringType = type.GetDefinition ().Parts.First (); methodName = memberReference.MemberName; } else if (target is Identifier) { declaringType = options.Document.ParsedDocument.GetInnermostTypeDefinition (options.Location); methodName = data.GetTextBetween (target.StartLocation.Line, target.StartLocation.Column, target.EndLocation.Line, target.EndLocation.Column); + type = null; // TODO: Type system conversion } - return declaringType != null && !HasCompatibleMethod (ctx, declaringType, methodName, invocation); + + return declaringType != null && !HasCompatibleMethod (type, methodName, invocation); } IType GetDelegateType (RefactoringOptions options, ICSharpCode.NRefactory.CSharp.CompilationUnit unit) @@ -116,8 +118,8 @@ namespace MonoDevelop.CSharp.Refactoring.CreateMethod var resolveResult = ResolveAssignment (options, assignment); if (resolveResult == null) return null; - IType type = resolveResult.Type.Resolve (options.Document.TypeResolveContext); - if (type == null || !type.IsDelegate ()) + IType type = resolveResult.Type; + if (type == null || type.Kind != TypeKind.Delegate) return null; return type; } @@ -126,13 +128,13 @@ namespace MonoDevelop.CSharp.Refactoring.CreateMethod return null; } - public bool HasCompatibleMethod (ITypeResolveContext ctx, IType type, string methodName, InvocationExpression invocation) + public bool HasCompatibleMethod (IType type, string methodName, InvocationExpression invocation) { // TODO: add argument type check for overloads. if (invocation == null || type == null) return false; int invocationArguments = invocation.Arguments.Count (); - return type.GetMethods (ctx).Any (m => m.Name == methodName && m.Parameters.Count == invocationArguments); + return type.GetMethods ().Any (m => m.Name == methodName && m.Parameters.Count == invocationArguments); } ResolveResult ResolveAssignment (RefactoringOptions options, AssignmentExpression assignment) @@ -165,15 +167,16 @@ namespace MonoDevelop.CSharp.Refactoring.CreateMethod if (resolveResult != null) { return resolveResult.Type; } - return options.Document.TypeResolveContext.GetTypeDefinition (typeof(object)); + return options.Document.Compilation.FindType (KnownTypeCode.Object); } var callingMember = options.Document.ParsedDocument.GetMember (options.Location); if (node.Parent is ReturnStatement && callingMember != null) - return callingMember.ReturnType.Resolve (options.Document.TypeResolveContext); + return null; // TODO: Type system conversion + //return callingMember.CreateResolved (op) .ReturnType; node = node.Parent; } - return KnownTypeReference.Void.Resolve (options.Document.TypeResolveContext); + return options.Document.Compilation.FindType (KnownTypeCode.Void); } public bool Analyze (RefactoringOptions options) @@ -219,14 +222,14 @@ namespace MonoDevelop.CSharp.Refactoring.CreateMethod return true; } - ITypeDefinition declaringType; - public ITypeDefinition DeclaringType { + IUnresolvedTypeDefinition declaringType; + public IUnresolvedTypeDefinition DeclaringType { get { return this.declaringType; } } - ITypeReference returnType; + IType returnType; string methodName; InvocationExpression invocation; @@ -246,7 +249,7 @@ namespace MonoDevelop.CSharp.Refactoring.CreateMethod public override void Run (RefactoringOptions options) { - fileName = declaringType.GetDefinition ().Region.FileName; + fileName = declaringType.Region.FileName; var openDocument = IdeApp.Workbench.OpenDocument (fileName); if (openDocument == null) { @@ -330,101 +333,106 @@ namespace MonoDevelop.CSharp.Refactoring.CreateMethod IMethod ConstructMethodFromDelegate (RefactoringOptions options) { - var result = new DefaultMethod (declaringType, methodName); - var invocation = delegateType.GetDelegateInvokeMethod (); - foreach (var arg in invocation.Parameters) { - result.Parameters.Add (arg); - } - result.Accessibility = accessibility; - result.ReturnType = invocation.ReturnType; - return result; + // TODO: Type system conversion + return null; +// var result = new DefaultMethod (declaringType, methodName); +// var invocation = delegateType.GetDelegateInvokeMethod (); +// foreach (var arg in invocation.Parameters) { +// result.Parameters.Add (arg); +// } +// result.Accessibility = accessibility; +// result.ReturnType = invocation.ReturnType; +// return result; } IMethod ConstructMethodFromInvocation (RefactoringOptions options) { - var result = new DefaultMethod (declaringType, methodName); - result.Accessibility = accessibility; - result.ReturnType = returnType; - int i = 1; - foreach (var argument in invocation.Arguments) { - string name; - if (argument is MemberReferenceExpression) { - name = ((MemberReferenceExpression)argument).MemberName; - } else if (argument is IdentifierExpression) { - name = ((IdentifierExpression)argument).Identifier; - int idx = name.LastIndexOf ('.'); - if (idx >= 0) - name = name.Substring (idx + 1); - } else { - name = "par" + i++; - } - - name = char.ToLower (name[0]) + name.Substring (1); - - ITypeReference type; - var resolveResult = options.Resolve (argument); - if (resolveResult != null && !resolveResult.IsError) { - type = resolveResult.Type; - } else { - type = KnownTypeReference.Object; - } - - var newArgument = new DefaultParameter (type, name); - if (argument is DirectionExpression) { - var de = (DirectionExpression)argument; - newArgument.IsOut = de.FieldDirection == FieldDirection.Out; - newArgument.IsRef = de.FieldDirection == FieldDirection.Ref; - } - result.Parameters.Add (newArgument); - } - return result; + // TODO: Type system conversion + return null; +// var result = new DefaultMethod (declaringType, methodName); +// result.Accessibility = accessibility; +// result.ReturnType = returnType; +// int i = 1; +// foreach (var argument in invocation.Arguments) { +// string name; +// if (argument is MemberReferenceExpression) { +// name = ((MemberReferenceExpression)argument).MemberName; +// } else if (argument is IdentifierExpression) { +// name = ((IdentifierExpression)argument).Identifier; +// int idx = name.LastIndexOf ('.'); +// if (idx >= 0) +// name = name.Substring (idx + 1); +// } else { +// name = "par" + i++; +// } +// +// name = char.ToLower (name[0]) + name.Substring (1); +// +// ITypeReference type; +// var resolveResult = options.Resolve (argument); +// if (resolveResult != null && !resolveResult.IsError) { +// type = resolveResult.Type; +// } else { +// type = KnownTypeReference.Object; +// } +// +// var newArgument = new DefaultParameter (type, name); +// if (argument is DirectionExpression) { +// var de = (DirectionExpression)argument; +// newArgument.IsOut = de.FieldDirection == FieldDirection.Out; +// newArgument.IsRef = de.FieldDirection == FieldDirection.Ref; +// } +// result.Parameters.Add (newArgument); +// } +// return result; } public override List<Change> PerformChanges (RefactoringOptions options, object prop) { - if (data == null) - data = options.GetTextEditorData (); - List<Change> result = new List<Change> (); - TextReplaceChange insertNewMethod = new TextReplaceChange (); - insertNewMethod.FileName = fileName; - insertNewMethod.RemovedChars = 0;//insertionPoint.LineBefore == NewLineInsertion.Eol ? 0 : insertionPoint.Location.Column - 1; - int insertionOffset = data.Document.LocationToOffset (insertionPoint.Location); - insertNewMethod.Offset = insertionOffset /*- insertNewMethod.RemovedChars*/; - - StringBuilder sb = new StringBuilder (); - switch (insertionPoint.LineBefore) { - case NewLineInsertion.Eol: - sb.Append (data.EolMarker); - break; - case NewLineInsertion.BlankLine: - sb.Append (data.EolMarker); - sb.Append (indent); - sb.Append (data.EolMarker); - break; - } - - var generator = options.CreateCodeGenerator (); - sb.Append (generator.CreateMemberImplementation (options.Document.TypeResolveContext, declaringType, ConstructMethod (options), false).Code); - sb.Append (data.EolMarker); - switch (insertionPoint.LineAfter) { - case NewLineInsertion.Eol: - break; - case NewLineInsertion.BlankLine: - sb.Append (indent); - sb.Append (data.EolMarker); - break; - } - insertNewMethod.InsertedText = sb.ToString (); - result.Add (insertNewMethod); - selectionStart = selectionEnd = insertNewMethod.Offset; - int idx = insertNewMethod.InsertedText.IndexOf ("throw"); - if (idx >= 0) { - selectionStart = insertNewMethod.Offset + idx; - selectionEnd = insertNewMethod.Offset + insertNewMethod.InsertedText.IndexOf (';', idx) + 1; - } else { - selectionStart = selectionEnd = insertNewMethod.Offset; - } - return result; + return new List<Change> (); +// if (data == null) +// data = options.GetTextEditorData (); +// List<Change> result = new List<Change> (); +// TextReplaceChange insertNewMethod = new TextReplaceChange (); +// insertNewMethod.FileName = fileName; +// insertNewMethod.RemovedChars = 0;//insertionPoint.LineBefore == NewLineInsertion.Eol ? 0 : insertionPoint.Location.Column - 1; +// int insertionOffset = data.Document.LocationToOffset (insertionPoint.Location); +// insertNewMethod.Offset = insertionOffset /*- insertNewMethod.RemovedChars*/; +// +// StringBuilder sb = new StringBuilder (); +// switch (insertionPoint.LineBefore) { +// case NewLineInsertion.Eol: +// sb.Append (data.EolMarker); +// break; +// case NewLineInsertion.BlankLine: +// sb.Append (data.EolMarker); +// sb.Append (indent); +// sb.Append (data.EolMarker); +// break; +// } +// +// var generator = options.CreateCodeGenerator (); +// sb.Append (generator.CreateMemberImplementation (options.Document.TypeResolveContext, declaringType, ConstructMethod (options), false).Code); +// sb.Append (data.EolMarker); +// switch (insertionPoint.LineAfter) { +// case NewLineInsertion.Eol: +// break; +// case NewLineInsertion.BlankLine: +// sb.Append (indent); +// sb.Append (data.EolMarker); +// break; +// } +// insertNewMethod.InsertedText = sb.ToString (); +// result.Add (insertNewMethod); +// selectionStart = selectionEnd = insertNewMethod.Offset; +// int idx = insertNewMethod.InsertedText.IndexOf ("throw"); +// if (idx >= 0) { +// selectionStart = insertNewMethod.Offset + idx; +// selectionEnd = insertNewMethod.Offset + insertNewMethod.InsertedText.IndexOf (';', idx) + 1; +// } else { +// selectionStart = selectionEnd = insertNewMethod.Offset; +// } +// return result; } } } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/DeclareLocal/DeclareLocalCodeGenerator.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/DeclareLocal/DeclareLocalCodeGenerator.cs index 177b6f0dca..76df70034a 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/DeclareLocal/DeclareLocalCodeGenerator.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/DeclareLocal/DeclareLocalCodeGenerator.cs @@ -177,11 +177,11 @@ namespace MonoDevelop.CSharp.Refactoring.DeclareLocal string varName; int varCount; - public ITypeReference GetResolvedType (RefactoringOptions options, ResolveResult resolveResult) + public IType GetResolvedType (RefactoringOptions options, ResolveResult resolveResult) { - ITypeReference result = resolveResult.Type; - if (result == null) - result = KnownTypeReference.Object; +// var result = resolveResult.Type; +// if (result == null) +// result = KnownTypeReference.Object; // if (resolveResult is MethodGroupResolveResult) { // var mrr = (MethodGroupResolveResult)resolveResult; // var method = options.SelectedItem as IMethod ?? mrr.Methods.FirstOrDefault (); @@ -200,110 +200,112 @@ namespace MonoDevelop.CSharp.Refactoring.DeclareLocal // type.AddTypeParameter (method.ReturnType); // result = type; // } - return result; +// return result; + return null; } public override List<Change> PerformChanges (RefactoringOptions options, object prop) { - varCount = 0; - selectionStart = selectionEnd = -1; - - List<Change > result = new List<Change> (); - TextEditorData data = options.GetTextEditorData (); - if (data == null) - return result; - - DocumentLocation endPoint; - if (data.IsSomethingSelected) { - endPoint = data.MainSelection.Anchor < data.MainSelection.Lead ? data.MainSelection.Lead : data.MainSelection.Anchor; - } else { - endPoint = data.Caret.Location; - } - ResolveResult resolveResult; - LineSegment lineSegment; - var unit = options.Document.ParsedDocument.Annotation<CompilationUnit> (); - var visitor = new VariableLookupVisitor (options, new TextLocation (endPoint.Line, endPoint.Column)); - var ctx = options.Document.TypeResolveContext; - if (options.ResolveResult == null) { - LoggingService.LogError ("Declare local error: resolve result == null"); - return result; - } - IMember callingMember = options.Document.ParsedDocument.GetMember (options.Location); - if (callingMember != null) - visitor.MemberLocation = callingMember.Region.Begin; - unit.AcceptVisitor (visitor, null); - resolveResult = options.Resolve (selectedExpression); - if (resolveResult == null) - return result; - var resolvedType = resolveResult.Type.Resolve (ctx); - - AstType returnType; - if (resolveResult.Type == null) { - returnType = new SimpleType ("var"); - } else { - returnType = options.CreateShortType (resolvedType); - } - - varName = CreateVariableName (resolvedType, visitor); - - // insert local variable declaration - TextReplaceChange insert = new TextReplaceChange (); - insert.FileName = options.Document.FileName; - insert.Description = GettextCatalog.GetString ("Insert variable declaration"); - - var varDecl = new VariableDeclarationStatement (returnType, varName, selectedExpression.Clone ()); - - var node = unit.GetNodeAt (endPoint.Line, endPoint.Column); - - var containing = node.Parent; - while (!(containing.Parent is BlockStatement)) { - containing = containing.Parent; - } - - if (containing is BlockStatement) { - lineSegment = data.Document.GetLine (data.Caret.Line); - } else { - lineSegment = data.Document.GetLine (containing.StartLocation.Line); - } - insert.Offset = lineSegment.Offset; - insert.InsertedText = options.GetWhitespaces (lineSegment.Offset) + options.OutputNode (varDecl); - var insertOffset = insert.Offset + options.GetWhitespaces (lineSegment.Offset).Length + options.OutputNode (varDecl.Type).Length + " ".Length; - offsets.Add (insertOffset); - result.Add (insert); - varCount++; - - // replace main selection - TextReplaceChange replace = new TextReplaceChange (); - replace.FileName = options.Document.FileName; - int startOffset = options.Document.Editor.LocationToOffset (selectedExpression.StartLocation.Line, selectedExpression.StartLocation.Column); - int endOffset = options.Document.Editor.LocationToOffset (selectedExpression.EndLocation.Line, selectedExpression.EndLocation.Column); - replace.Offset = startOffset; - replace.RemovedChars = endOffset - startOffset; - replace.InsertedText = varName; - result.Add (replace); - int delta = insert.InsertedText.Length - insert.RemovedChars; - offsets.Add (replace.Offset + delta); - delta += varName.Length - replace.RemovedChars; - varCount++; - selectionStart = insert.Offset; - - if (replaceAll) { - matches.Sort ((x, y) => x.StartLocation.CompareTo (y.StartLocation)); - foreach (var match in matches) { - replace = new TextReplaceChange (); - replace.FileName = options.Document.FileName; - int start = data.LocationToOffset (match.StartLocation.Line, match.StartLocation.Column); - int end = data.LocationToOffset (match.EndLocation.Line, match.EndLocation.Column); - - replace.Offset = start; - replace.RemovedChars = end - start; - replace.InsertedText = varName; - result.Add (replace); - offsets.Add (start + delta); - delta += varName.Length - replace.RemovedChars; - } - } - return result; + return new List<Change> (); +// varCount = 0; +// selectionStart = selectionEnd = -1; +// +// List<Change > result = new List<Change> (); +// TextEditorData data = options.GetTextEditorData (); +// if (data == null) +// return result; +// +// DocumentLocation endPoint; +// if (data.IsSomethingSelected) { +// endPoint = data.MainSelection.Anchor < data.MainSelection.Lead ? data.MainSelection.Lead : data.MainSelection.Anchor; +// } else { +// endPoint = data.Caret.Location; +// } +// ResolveResult resolveResult; +// LineSegment lineSegment; +// var unit = options.Document.ParsedDocument.Annotation<CompilationUnit> (); +// var visitor = new VariableLookupVisitor (options, new TextLocation (endPoint.Line, endPoint.Column)); +// var ctx = options.Document.TypeResolveContext; +// if (options.ResolveResult == null) { +// LoggingService.LogError ("Declare local error: resolve result == null"); +// return result; +// } +// IMember callingMember = options.Document.ParsedDocument.GetMember (options.Location); +// if (callingMember != null) +// visitor.MemberLocation = callingMember.Region.Begin; +// unit.AcceptVisitor (visitor, null); +// resolveResult = options.Resolve (selectedExpression); +// if (resolveResult == null) +// return result; +// var resolvedType = resolveResult.Type.Resolve (ctx); +// +// AstType returnType; +// if (resolveResult.Type == null) { +// returnType = new SimpleType ("var"); +// } else { +// returnType = options.CreateShortType (resolvedType); +// } +// +// varName = CreateVariableName (resolvedType, visitor); +// +// // insert local variable declaration +// TextReplaceChange insert = new TextReplaceChange (); +// insert.FileName = options.Document.FileName; +// insert.Description = GettextCatalog.GetString ("Insert variable declaration"); +// +// var varDecl = new VariableDeclarationStatement (returnType, varName, selectedExpression.Clone ()); +// +// var node = unit.GetNodeAt (endPoint.Line, endPoint.Column); +// +// var containing = node.Parent; +// while (!(containing.Parent is BlockStatement)) { +// containing = containing.Parent; +// } +// +// if (containing is BlockStatement) { +// lineSegment = data.Document.GetLine (data.Caret.Line); +// } else { +// lineSegment = data.Document.GetLine (containing.StartLocation.Line); +// } +// insert.Offset = lineSegment.Offset; +// insert.InsertedText = options.GetWhitespaces (lineSegment.Offset) + options.OutputNode (varDecl); +// var insertOffset = insert.Offset + options.GetWhitespaces (lineSegment.Offset).Length + options.OutputNode (varDecl.Type).Length + " ".Length; +// offsets.Add (insertOffset); +// result.Add (insert); +// varCount++; +// +// // replace main selection +// TextReplaceChange replace = new TextReplaceChange (); +// replace.FileName = options.Document.FileName; +// int startOffset = options.Document.Editor.LocationToOffset (selectedExpression.StartLocation.Line, selectedExpression.StartLocation.Column); +// int endOffset = options.Document.Editor.LocationToOffset (selectedExpression.EndLocation.Line, selectedExpression.EndLocation.Column); +// replace.Offset = startOffset; +// replace.RemovedChars = endOffset - startOffset; +// replace.InsertedText = varName; +// result.Add (replace); +// int delta = insert.InsertedText.Length - insert.RemovedChars; +// offsets.Add (replace.Offset + delta); +// delta += varName.Length - replace.RemovedChars; +// varCount++; +// selectionStart = insert.Offset; +// +// if (replaceAll) { +// matches.Sort ((x, y) => x.StartLocation.CompareTo (y.StartLocation)); +// foreach (var match in matches) { +// replace = new TextReplaceChange (); +// replace.FileName = options.Document.FileName; +// int start = data.LocationToOffset (match.StartLocation.Line, match.StartLocation.Column); +// int end = data.LocationToOffset (match.EndLocation.Line, match.EndLocation.Column); +// +// replace.Offset = start; +// replace.RemovedChars = end - start; +// replace.InsertedText = varName; +// result.Add (replace); +// offsets.Add (start + delta); +// delta += varName.Length - replace.RemovedChars; +// } +// } +// return result; } static bool SearchSubExpression (string expression, string subexpression, int startOffset, out int offset, out int length) @@ -434,7 +436,7 @@ namespace MonoDevelop.CSharp.Refactoring.DeclareLocal set; } - public ITypeReference ReturnType { + public IType ReturnType { get; set; } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/ExtractMethod/ExtractMethodDialog.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/ExtractMethod/ExtractMethodDialog.cs index 79a6c0c061..e3a6dc38c0 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/ExtractMethod/ExtractMethodDialog.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/ExtractMethod/ExtractMethodDialog.cs @@ -37,6 +37,7 @@ using MonoDevelop.Refactoring; using ICSharpCode.NRefactory.CSharp; using ICSharpCode.NRefactory.TypeSystem; using MonoDevelop.TypeSystem; +using System.Linq; namespace MonoDevelop.CSharp.Refactoring.ExtractMethod { @@ -149,7 +150,7 @@ namespace MonoDevelop.CSharp.Refactoring.ExtractMethod bool HasMember (string name) { var ctx = options.Document.TypeResolveContext; - foreach (var member in properties.DeclaringMember.DeclaringType.GetMembers (ctx, m => m.Name == name)) { + foreach (var member in properties.DeclaringMember.DeclaringType.GetMembers (m => m.Name == name)) { var method = member as IMethod; if (method == null) continue; @@ -157,7 +158,7 @@ namespace MonoDevelop.CSharp.Refactoring.ExtractMethod continue; bool equals = true; for (int i = 0; i < method.Parameters.Count; i++) { - if (!properties.Parameters[i].ReturnType.Resolve (ctx).Equals (method.Parameters[i].Type.Resolve (ctx))) { + if (!properties.Parameters[i].ReturnType.Equals (method.Parameters[i].Type)) { equals = false; break; } @@ -203,7 +204,7 @@ namespace MonoDevelop.CSharp.Refactoring.ExtractMethod Mono.TextEditor.TextEditor editor = data.Parent; // Insertion cursor mode test: if (editor != null) { - var type = properties.DeclaringMember.DeclaringTypeDefinition; + var type = properties.DeclaringMember.DeclaringTypeDefinition.Parts.First (); var mode = new InsertionCursorEditMode (editor, CodeGenerationService.GetInsertionPoints (options.Document, type)); for (int i = 0; i < mode.InsertionPoints.Count; i++) { @@ -234,7 +235,7 @@ namespace MonoDevelop.CSharp.Refactoring.ExtractMethod properties.InsertionPoint = args.InsertionPoint; List<Change> changes = extractMethod.PerformChanges (options, properties); IProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetBackgroundProgressMonitor (this.Title, null); - RefactoringService.AcceptChanges (monitor, options.Dom, changes); + RefactoringService.AcceptChanges (monitor, changes); } }; } @@ -248,7 +249,7 @@ namespace MonoDevelop.CSharp.Refactoring.ExtractMethod SetProperties (); List<Change> changes = extractMethod.PerformChanges (options, properties); ((Widget)this).Destroy (); - MessageService.ShowCustomDialog (new RefactoringPreviewDialog (options.Dom, changes)); + MessageService.ShowCustomDialog (new RefactoringPreviewDialog (changes)); } } } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/ExtractMethod/ExtractMethodRefactoring.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/ExtractMethod/ExtractMethodRefactoring.cs index 74a6db47d6..10a7ab4a80 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/ExtractMethod/ExtractMethodRefactoring.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/ExtractMethod/ExtractMethodRefactoring.cs @@ -113,12 +113,13 @@ namespace MonoDevelop.CSharp.Refactoring.ExtractMethod if (doc == null) return null; - IMember member = doc.GetMember (buffer.Caret.Line, buffer.Caret.Column); + var member = doc.GetMember (buffer.Caret.Location); if (member == null) return null; - ExtractMethodParameters param = new ExtractMethodParameters () { - DeclaringMember = member, + var param = new ExtractMethodParameters () { +// TODO: Type system conversion. +// DeclaringMember = member, Location = new TextLocation (buffer.Caret.Line, buffer.Caret.Column) }; Analyze (options, param, true); @@ -415,10 +416,10 @@ namespace MonoDevelop.CSharp.Refactoring.ExtractMethod return sb.ToString (); } - static IMethod GenerateMethodStub (RefactoringOptions options,ITypeDefinition callingType, ExtractMethodParameters param) + static IUnresolvedMethod GenerateMethodStub (RefactoringOptions options, IUnresolvedTypeDefinition callingType, ExtractMethodParameters param) { - var result = new DefaultMethod (callingType, param.Name); - result.ReturnType = param.ExpressionType ?? KnownTypeReference.Void; + var result = new DefaultUnresolvedMethod (callingType, param.Name); + result.ReturnType = param.ExpressionType.ToTypeReference (); result.Accessibility = param.Modifiers; // if (!param.ReferencesMember) // result.Modifiers |= MonoDevelop.Projects.Dom.Modifiers.Static; @@ -428,8 +429,7 @@ namespace MonoDevelop.CSharp.Refactoring.ExtractMethod foreach (var p in param.Parameters) { if (param.OneChangedVariable && p.UsedAfterCutRegion && !p.UsedInCutRegion) continue; - var newParameter = new DefaultParameter (p.ReturnType, p.Name); - + var newParameter = new DefaultUnresolvedParameter (p.ReturnType.ToTypeReference (), p.Name); if (!param.OneChangedVariable) { if (!p.IsDefinedInsideCutRegion && p.IsChangedInsideCutRegion) { if (p.UsedBeforeCutRegion) { @@ -469,16 +469,16 @@ namespace MonoDevelop.CSharp.Refactoring.ExtractMethod TabSize = options.Document.Editor.Options.TabSize }; var ctx = options.Document.TypeResolveContext; - ITypeDefinition callingType = null; + IUnresolvedTypeDefinition callingType = null; var cu = options.Document.ParsedDocument; if (cu != null) - callingType = cu.GetInnermostTypeDefinition (options.Document.Editor.Caret.Line, options.Document.Editor.Caret.Column); + callingType = cu.GetInnermostTypeDefinition (options.Document.Editor.Caret.Location); var newMethod = GenerateMethodStub (options, callingType, param); - var createdMethod = codeGenerator.CreateMemberImplementation (ctx, callingType, newMethod, false); + var createdMethod = codeGenerator.CreateMemberImplementation (callingType, newMethod, false); if (param.GenerateComment && DocGenerator.Instance != null) - methodText.AppendLine (DocGenerator.Instance.GenerateDocumentation (ctx, newMethod, indent + "/// ")); + methodText.AppendLine (DocGenerator.Instance.GenerateDocumentation (newMethod, indent + "/// ")); string code = createdMethod.Code; int idx1 = code.LastIndexOf ("throw"); int idx2 = code.LastIndexOf (";"); @@ -493,7 +493,7 @@ namespace MonoDevelop.CSharp.Refactoring.ExtractMethod if (param.OneChangedVariable) { var par = param.Variables.First (p => p.IsDefinedInsideCutRegion && p.UsedAfterCutRegion); if (!par.UsedInCutRegion) { - text.Append (codeGenerator.GetShortTypeString (options.Document, par.ReturnType.Resolve (ctx))); + text.Append (codeGenerator.GetShortTypeString (options.Document, par.ReturnType)); text.Append (" "); text.Append (par.Name); text.AppendLine (";"); @@ -553,7 +553,7 @@ namespace MonoDevelop.CSharp.Refactoring.ExtractMethod insertNewMethod.Description = string.Format (GettextCatalog.GetString ("Create new method {0} from selected statement(s)"), param.Name); var insertionPoint = param.InsertionPoint; if (insertionPoint == null) { - var points = CodeGenerationService.GetInsertionPoints (options.Document, param.DeclaringMember.DeclaringTypeDefinition); + var points = CodeGenerationService.GetInsertionPoints (options.Document, param.DeclaringMember.DeclaringTypeDefinition.Parts.First ()); insertionPoint = points.LastOrDefault (p => p.Location.Line < param.DeclaringMember.Region.BeginLine); if (insertionPoint == null) insertionPoint = points.FirstOrDefault (); diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/RefactorImports/RemoveUnusedImportsRefactoring.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/RefactorImports/RemoveUnusedImportsRefactoring.cs index db7bb3f5b2..e106762d6a 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/RefactorImports/RemoveUnusedImportsRefactoring.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/RefactorImports/RemoveUnusedImportsRefactoring.cs @@ -45,18 +45,19 @@ namespace MonoDevelop.CSharp.Refactoring.RefactorImports public override List<Change> PerformChanges (RefactoringOptions options, object properties) { - var doc = options.Document.UpdateParseDocument (); - var unit = doc.Annotation<CompilationUnit> (); - var resolver = new CSharpResolver (options.Dom, System.Threading.CancellationToken.None); - var nav = new VisitNamespaceNodesNavigator (); - new ResolveVisitor (resolver, doc.Annotation<CSharpParsedFile> (), nav).Scan (unit); var result = new List<Change> (); - var visitor = new ObservableAstVisitor<object, object> (); - visitor.UsingDeclarationVisited += delegate(UsingDeclaration u, object arg) { - if (!nav.GetsUsed (options.Dom, resolver, u.StartLocation, u.Namespace)) - result.Add (options.Document.Editor.GetRemoveNodeChange (u)); - }; - unit.AcceptVisitor (visitor); +// TODO: Type system conversion. +// var doc = options.Document.UpdateParseDocument (); +// var unit = doc.Annotation<CompilationUnit> (); +// var resolver = new CSharpResolver (options.Dom, System.Threading.CancellationToken.None); +// var nav = new VisitNamespaceNodesNavigator (); +// new ResolveVisitor (resolver, doc.Annotation<CSharpParsedFile> (), nav).Scan (unit); +// var visitor = new ObservableAstVisitor<object, object> (); +// visitor.UsingDeclarationVisited += delegate(UsingDeclaration u, object arg) { +// if (!nav.GetsUsed (options.Dom, resolver, u.StartLocation, u.Namespace)) +// result.Add (options.Document.Editor.GetRemoveNodeChange (u)); +// }; +// unit.AcceptVisitor (visitor); return result; } } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/VisitNamespaceNodesNavigator.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/VisitNamespaceNodesNavigator.cs index e3963ddd3b..e9f3434b85 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/VisitNamespaceNodesNavigator.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Refactoring/VisitNamespaceNodesNavigator.cs @@ -39,11 +39,12 @@ namespace MonoDevelop.CSharp.Refactoring {
HashSet<string> additionalNamespaces = new HashSet<string> ();
- public bool GetsUsed (ITypeResolveContext ctx, CSharpResolver cSharpResolver, TextLocation loc, string ns)
+ public bool GetsUsed (CSharpResolver cSharpResolver, TextLocation loc, string ns)
{
- return cSharpResolver.usedScopes
- .OfType<ITypeOrNamespaceReference> ()
- .Any (u => u.ResolveNamespace (ctx).NamespaceName == ns) || additionalNamespaces.Contains (ns);
+ return true;
+// return cSharpResolver.usedScopes
+// .OfType<ITypeOrNamespaceReference> ()
+// .Any (u => u.ResolveNamespace (ctx).NamespaceName == ns) || additionalNamespaces.Contains (ns);
}
#region IResolveVisitorNavigator implementation
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Resolver/HelperMethods.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Resolver/HelperMethods.cs index 8474572fff..7ed564488e 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Resolver/HelperMethods.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Resolver/HelperMethods.cs @@ -64,7 +64,7 @@ namespace MonoDevelop.CSharp public static ICSharpCode.NRefactory.CSharp.CompilationUnit Parse (this ICSharpCode.NRefactory.CSharp.CSharpParser parser, TextEditorData data) { using (var stream = data.OpenStream ()) { - return parser.Parse (stream); + return parser.Parse (stream, data.Document.FileName); } } @@ -83,7 +83,7 @@ namespace MonoDevelop.CSharp } parser.ErrorPrinter.Reset (); using (var stream = data.OpenStream ()) { - return parser.Parse (stream); + return parser.Parse (stream, data.Document.FileName); } } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Resolver/TextEditorResolverProvider.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Resolver/TextEditorResolverProvider.cs index 5b356b02f8..c8f46cee5b 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Resolver/TextEditorResolverProvider.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.Resolver/TextEditorResolverProvider.cs @@ -38,6 +38,8 @@ using System.Linq; using System.Collections.Generic; using ICSharpCode.NRefactory.Semantics; using ICSharpCode.NRefactory; +using ICSharpCode.NRefactory.CSharp.TypeSystem; +using System.Threading; namespace MonoDevelop.CSharp.Resolver { @@ -45,7 +47,7 @@ namespace MonoDevelop.CSharp.Resolver { #region ITextEditorResolverProvider implementation - public string GetExpression (ICSharpCode.NRefactory.TypeSystem.ITypeResolveContext dom, Mono.TextEditor.TextEditorData data, int offset) + public string GetExpression (Mono.TextEditor.TextEditorData data, int offset) { if (offset < 0) return ""; @@ -59,14 +61,9 @@ namespace MonoDevelop.CSharp.Resolver if (unit == null || parsedFile == null || node == null) return ""; - var csResolver = new CSharpResolver (doc.TypeResolveContext, System.Threading.CancellationToken.None); - var navigator = new NodeListResolveVisitorNavigator (new[] { node }); - var visitor = new ResolveVisitor (csResolver, parsedFile, navigator); - unit.AcceptVisitor (visitor, null); - return data.GetTextBetween (node.StartLocation.Line, node.StartLocation.Column, node.EndLocation.Line, node.EndLocation.Column); } - public ResolveResult GetLanguageItem (ITypeResolveContext dom, Mono.TextEditor.TextEditorData data, int offset, out DomRegion expressionRegion) + public ResolveResult GetLanguageItem (Mono.TextEditor.TextEditorData data, int offset, out DomRegion expressionRegion) { if (offset < 0) { expressionRegion = DomRegion.Empty; @@ -92,7 +89,7 @@ namespace MonoDevelop.CSharp.Resolver expressionRegion = DomRegion.Empty; return null; } - var node = ResolveAtLocation.Resolve (dom, parsedFile, unit, new TextLocation (loc.Line, loc.Column)); + var node = ResolveAtLocation.Resolve (doc.Compilation, parsedFile, unit, loc); if (node == null) { expressionRegion = DomRegion.Empty; return null; @@ -103,7 +100,7 @@ namespace MonoDevelop.CSharp.Resolver return node; } - public ResolveResult GetLanguageItem (ITypeResolveContext dom, Mono.TextEditor.TextEditorData data, int offset, string expression) + public ResolveResult GetLanguageItem (Mono.TextEditor.TextEditorData data, int offset, string expression) { if (offset < 0) { return null; @@ -128,11 +125,9 @@ namespace MonoDevelop.CSharp.Resolver return null; } - var csResolver = new CSharpResolver (doc.TypeResolveContext, System.Threading.CancellationToken.None); - var navigator = new NodeListResolveVisitorNavigator (new[] { node }); - var visitor = new ResolveVisitor (csResolver, parsedFile, navigator); - unit.AcceptVisitor (visitor, null); - var state = visitor.GetResolverStateBefore (node); + var resolver = new CSharpAstResolver (doc.Compilation, unit, parsedFile); + + var state = resolver.GetResolverStateBefore (node, CancellationToken.None); return state.LookupSimpleNameOrTypeName (expression, new List<IType> (), SimpleNameLookupMode.Expression); } @@ -169,9 +164,9 @@ namespace MonoDevelop.CSharp.Resolver return GettextCatalog.GetString ("Member"); } - public string CreateTooltip (ITypeResolveContext dom, IParsedFile unit, ResolveResult result, string errorInformations, Ambience ambience, Gdk.ModifierType modifierState) + public string CreateTooltip (IParsedFile unit, ResolveResult result, string errorInformations, Ambience ambience, Gdk.ModifierType modifierState) { - OutputSettings settings = new OutputSettings (OutputFlags.ClassBrowserEntries | OutputFlags.IncludeParameterName | OutputFlags.IncludeKeywords | OutputFlags.IncludeMarkup | OutputFlags.UseFullName) { Context = dom }; + OutputSettings settings = new OutputSettings (OutputFlags.ClassBrowserEntries | OutputFlags.IncludeParameterName | OutputFlags.IncludeKeywords | OutputFlags.IncludeMarkup | OutputFlags.UseFullName); // if ((Gdk.ModifierType.ShiftMask & modifierState) == Gdk.ModifierType.ShiftMask) { // settings.EmitNameCallback = delegate(object domVisitable, ref string outString) { // // crop used namespaces. diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpAmbience.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpAmbience.cs index 16d54f2dc7..c466bd9be3 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpAmbience.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpAmbience.cs @@ -343,12 +343,12 @@ namespace MonoDevelop.CSharp } } - protected override string GetTypeReferenceString (ITypeReference reference, OutputSettings settings) + protected override string GetTypeReferenceString (IType reference, OutputSettings settings) { if (reference == null) return "null"; - var type = reference.Resolve (settings.Context); - if (type == SharedTypes.UnknownType) + var type = reference; + if (type.Kind == TypeKind.Unknown) return reference.ToString (); var sb = new StringBuilder (); if (type is ITypeDefinition && ((ITypeDefinition)type).IsSynthetic&& ((ITypeDefinition)type).Name == "$Anonymous$") { @@ -473,9 +473,9 @@ namespace MonoDevelop.CSharp return result.ToString (); } - if (settings.IncludeBaseTypes && type.BaseTypes.Any ()) { + if (settings.IncludeBaseTypes && type.DirectBaseTypes.Any ()) { bool first = true; - foreach (var baseType in type.BaseTypes) { + foreach (var baseType in type.DirectBaseTypes) { // if (baseType.FullName == "System.Object" || baseType.FullName == "System.Enum") // continue; result.Append (settings.Markup (first ? " : " : ", ")); @@ -500,7 +500,7 @@ namespace MonoDevelop.CSharp } if (!settings.IncludeReturnType && settings.UseFullName) { - result.Append (GetTypeReferenceString (method.DeclaringType, new OutputSettings (OutputFlags.UseFullName) { Context = settings.Context})); + result.Append (GetTypeReferenceString (method.DeclaringType, new OutputSettings (OutputFlags.UseFullName))); result.Append (settings.Markup (".")); } AppendExplicitInterfaces (result, method, settings); @@ -564,7 +564,7 @@ namespace MonoDevelop.CSharp if (field == null) return ""; var result = new StringBuilder (); - bool isEnum = field.DeclaringType != null && field.DeclaringType.IsEnum (); + bool isEnum = field.DeclaringType != null && field.DeclaringType.Kind == TypeKind.Enum; AppendModifiers (result, settings, field); if (!settings.CompletionListFomat && settings.IncludeReturnType && !isEnum) { @@ -599,7 +599,7 @@ namespace MonoDevelop.CSharp } if (!settings.IncludeReturnType && settings.UseFullName) { - result.Append (GetTypeReferenceString (evt.DeclaringType, new OutputSettings (OutputFlags.UseFullName) { Context = settings.Context })); + result.Append (GetTypeReferenceString (evt.DeclaringType, new OutputSettings (OutputFlags.UseFullName))); result.Append (settings.Markup (".")); } @@ -625,7 +625,7 @@ namespace MonoDevelop.CSharp } if (!settings.IncludeReturnType && settings.UseFullName) { - result.Append (GetTypeReferenceString (property.DeclaringType, new OutputSettings (OutputFlags.UseFullName) { Context = settings.Context })); + result.Append (GetTypeReferenceString (property.DeclaringType, new OutputSettings (OutputFlags.UseFullName))); result.Append (settings.Markup (".")); } @@ -654,7 +654,7 @@ namespace MonoDevelop.CSharp } if (!settings.IncludeReturnType && settings.UseFullName) { - result.Append (GetTypeReferenceString (property.DeclaringType, new OutputSettings (OutputFlags.UseFullName) { Context = settings.Context })); + result.Append (GetTypeReferenceString (property.DeclaringType, new OutputSettings (OutputFlags.UseFullName))); result.Append (settings.Markup (".")); } @@ -707,7 +707,7 @@ namespace MonoDevelop.CSharp void AppendExplicitInterfaces (StringBuilder sb, IMember member, OutputSettings settings) { foreach (var explicitInterface in member.InterfaceImplementations) { - sb.Append (Format (explicitInterface.InterfaceType.Resolve (settings.Context).FullName)); + sb.Append (Format (explicitInterface.FullName)); sb.Append (settings.Markup (".")); } } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/PathedDocumentTextEditorExtension.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/PathedDocumentTextEditorExtension.cs index 4a28c69cd0..8ce2dbc524 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/PathedDocumentTextEditorExtension.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/PathedDocumentTextEditorExtension.cs @@ -34,6 +34,7 @@ using MonoDevelop.Core; using MonoDevelop.CSharp.Completion; using System.Linq; using MonoDevelop.Ide; +using ICSharpCode.NRefactory.CSharp.TypeSystem; namespace MonoDevelop.CSharp { @@ -60,8 +61,7 @@ namespace MonoDevelop.CSharp { object tag; Ambience amb; - List<IEntity> memberList = new List<IEntity> (); - ITypeResolveContext ctx; + List<IUnresolvedEntity> memberList = new List<IUnresolvedEntity> (); Document Document { get; set; @@ -70,7 +70,6 @@ namespace MonoDevelop.CSharp public DataProvider (Document doc, object tag, Ambience amb) { this.Document = doc; - this.ctx = doc.TypeResolveContext; this.tag = tag; this.amb = amb; Reset (); @@ -82,30 +81,36 @@ namespace MonoDevelop.CSharp stringCache.Clear (); memberList.Clear (); if (tag is IParsedFile) { - var types = new Stack<ITypeDefinition> (((IParsedFile)tag).TopLevelTypeDefinitions); + var types = new Stack<IUnresolvedTypeDefinition> (((IParsedFile)tag).TopLevelTypeDefinitions); while (types.Count > 0) { var type = types.Pop (); memberList.Add (type); foreach (var innerType in type.NestedTypes) types.Push (innerType); } - } else if (tag is ITypeDefinition) { - memberList.AddRange (((ITypeDefinition)tag).NestedTypes); - memberList.AddRange (((ITypeDefinition)tag).Members); + } else if (tag is IUnresolvedTypeDefinition) { + memberList.AddRange (((IUnresolvedTypeDefinition)tag).NestedTypes); + memberList.AddRange (((IUnresolvedTypeDefinition)tag).Members); } memberList.Sort ((x, y) => String.Compare (x.Name, y.Name, StringComparison.OrdinalIgnoreCase)); } - Dictionary<IEntity, string> stringCache = new Dictionary<IEntity, string> (); - string GetString (Ambience amb, IEntity x) + Dictionary<IUnresolvedEntity, string> stringCache = new Dictionary<IUnresolvedEntity, string> (); + string GetString (Ambience amb, IUnresolvedEntity x) { string result; if (stringCache.TryGetValue(x, out result)) return result; + var pf = Document.ParsedDocument.ParsedFile as CSharpParsedFile; + var ctx = pf.GetTypeResolveContext (Document.Compilation, x.Region.Begin); + IEntity rx = null; + if (x is IUnresolvedMember) + rx = ((IUnresolvedMember)x).CreateResolved (ctx); + if (tag is IParsedFile) { - result = amb.GetString (ctx, x, OutputFlags.IncludeGenerics | OutputFlags.IncludeParameters | OutputFlags.UseFullInnerTypeName | OutputFlags.ReformatDelegates); + result = amb.GetString (rx, OutputFlags.IncludeGenerics | OutputFlags.IncludeParameters | OutputFlags.UseFullInnerTypeName | OutputFlags.ReformatDelegates); } else { - result = amb.GetString (ctx, x, OutputFlags.IncludeGenerics | OutputFlags.IncludeParameters | OutputFlags.ReformatDelegates); + result = amb.GetString (rx, OutputFlags.IncludeGenerics | OutputFlags.IncludeParameters | OutputFlags.ReformatDelegates); } stringCache[x] = result; @@ -241,24 +246,24 @@ namespace MonoDevelop.CSharp return; var loc = Document.Editor.Caret.Location; - var ctx = Document.TypeResolveContext; var result = new List<PathEntry> (); var amb = GetAmbience (); + var ctx = (unit.ParsedFile as CSharpParsedFile).GetTypeResolveContext (document.Compilation, loc); - var type = unit.GetInnermostTypeDefinition (loc.Line, loc.Column); - var curType = type; + var type = unit.GetInnermostTypeDefinition (loc).Resolve (ctx); + var curType = type.GetDefinition (); while (curType != null) { var flags = OutputFlags.IncludeGenerics | OutputFlags.IncludeParameters | OutputFlags.ReformatDelegates | OutputFlags.IncludeMarkup; if (curType.DeclaringTypeDefinition == null) flags |= OutputFlags.UseFullInnerTypeName; - var markup = amb.GetString (ctx, (IEntity)curType, flags); + var markup = amb.GetString ((IEntity)curType, flags); result.Insert (0, new PathEntry (ImageService.GetPixbuf (type.GetStockIcon (), Gtk.IconSize.Menu), curType.IsObsolete () ? "<s>" + markup + "</s>" : markup) { Tag = (object)curType.DeclaringTypeDefinition ?? unit }); curType = curType.DeclaringTypeDefinition; } - var member = type != null && !type.IsDelegate () ? unit.GetMember (loc.Line, loc.Column) : null; + var member = type != null && type.Kind != TypeKind.Delegate ? unit.GetMember (loc.Line, loc.Column).CreateResolved (ctx) : null; if (member != null) { - var markup = amb.GetString (ctx, member, OutputFlags.IncludeGenerics | OutputFlags.IncludeParameters | OutputFlags.ReformatDelegates | OutputFlags.IncludeMarkup); + var markup = amb.GetString (member, OutputFlags.IncludeGenerics | OutputFlags.IncludeParameters | OutputFlags.ReformatDelegates | OutputFlags.IncludeMarkup); result.Add (new PathEntry (ImageService.GetPixbuf (member.GetStockIcon (), Gtk.IconSize.Menu), member.IsObsolete () ? "<s>" + markup + "</s>" : markup) { Tag = member.DeclaringTypeDefinition }); } @@ -269,7 +274,7 @@ namespace MonoDevelop.CSharp PathEntry noSelection = null; if (type == null) { noSelection = new PathEntry (GettextCatalog.GetString ("No selection")) { Tag = unit }; - } else if (member == null && !type.IsDelegate ()) + } else if (member == null && type.Kind != TypeKind.Delegate) noSelection = new PathEntry (GettextCatalog.GetString ("No selection")) { Tag = type }; if (noSelection != null) result.Add (noSelection); |