diff options
Diffstat (limited to 'main/src/addins/CSharpBinding/MonoDevelop.CSharp')
7 files changed, 1650 insertions, 1511 deletions
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/AstAmbience.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/AstAmbience.cs index b03f260a13..34a02f2a3a 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/AstAmbience.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/AstAmbience.cs @@ -24,82 +24,90 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; -using ICSharpCode.NRefactory.CSharp; using System.Text; using System.Collections.Generic; using System.Linq; using MonoDevelop.Core; +using Microsoft.CodeAnalysis.Options; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Formatting; namespace MonoDevelop.CSharp { class AstAmbience { - CSharpFormattingOptions options; +// OptionSet options; - public AstAmbience (ICSharpCode.NRefactory.CSharp.CSharpFormattingOptions options) + public AstAmbience (OptionSet options) { - this.options = options; +// this.options = options; } - static bool IsObsolete (EntityDeclaration entity) + static bool IsObsolete (MemberDeclarationSyntax entity) { if (entity == null) return false; - foreach (var section in entity.Attributes) { - foreach (var attr in section.Attributes) { - var attrText = attr.Type.ToString (); - if (attrText == "Obsolete" || attrText == "ObsoleteAttribute" || attrText == "System.Obsolete" || attrText == "System.ObsoleteAttribute" ) - return true; - } - } + // TODO! +// foreach (var section in entity.Attributes) { +// foreach (var attr in section.Attributes) { +// var attrText = attr.Type.ToString (); +// if (attrText == "Obsolete" || attrText == "ObsoleteAttribute" || attrText == "System.Obsolete" || attrText == "System.ObsoleteAttribute" ) +// return true; +// } +// } return false; } - void AppendTypeParameter (StringBuilder sb, IEnumerable<TypeParameterDeclaration> parameters) + void AppendTypeParameter (StringBuilder sb, TypeParameterListSyntax parameters) { - if (!parameters.Any ()) + if (parameters == null || parameters.Parameters.Count == 0) return; sb.Append ("<"); bool first = true; - foreach (var param in parameters) { + foreach (var param in parameters.Parameters) { if (!first) { sb.Append (", "); } else { first = false; } - AppendEscaped (sb, param.ToString (options)); + AppendEscaped (sb, param.ToString ()); } sb.Append (">"); } - void AppendParameter (StringBuilder sb, IEnumerable<ParameterDeclaration> parameters) + void AppendParameter (StringBuilder sb, ParameterListSyntax parameters) { - if (options.SpaceBeforeMethodDeclarationParentheses) - sb.Append (" "); + // Missing roslyn formatting option ? + // if (options.GetOption (CSharpFormattingOptions.Spacing ???)) + // sb.Append (" "); sb.Append ("("); - var hasParameters = parameters.Any (); - if (!hasParameters && options.SpaceBetweenEmptyMethodDeclarationParentheses) { - sb.Append (" )"); - return; - } - if (hasParameters && options.SpaceWithinMethodDeclarationParentheses) - sb.Append (" "); - + var hasParameters = parameters != null && parameters.Parameters.Count > 0; + + // Missing roslyn formatting option ? + //if (hasParameters && options.GetOption (SpaceWithinMethodDeclarationParentheses)) + // sb.Append (" "); + bool first = true; - foreach (var param in parameters) { - if (!first) { - if (options.SpaceBeforeMethodDeclarationParameterComma) - sb.Append (" "); - sb.Append (","); - if (options.SpaceAfterMethodDeclarationParameterComma) + if (hasParameters) { + foreach (var param in parameters.Parameters) { + if (!first) { + //if (options.SpaceBeforeMethodDeclarationParameterComma) + // sb.Append (" "); + sb.Append (","); + //if (options.SpaceAfterMethodDeclarationParameterComma) sb.Append (" "); - } else { - first = false; + } else { + first = false; + } + AppendEscaped (sb, param.ToString ()); } - AppendEscaped (sb, param.ToString (options)); } - if (hasParameters && options.SpaceWithinMethodDeclarationParentheses) - sb.Append (" "); + + // Missing roslyn formatting option ? + //if (hasParameters && options.SpaceWithinMethodDeclarationParentheses) + // sb.Append (" "); sb.Append (")"); } @@ -131,128 +139,121 @@ namespace MonoDevelop.CSharp } } - public string GetEntityMarkup (AstNode e) + public string GetEntityMarkup (SyntaxNode e) { var sb = new StringBuilder (); - if (e is TypeDeclaration) { - var type = e as TypeDeclaration; - sb.Append (type.Name); - AppendTypeParameter (sb, type.TypeParameters); - } else if (e is DelegateDeclaration) { - var del = e as DelegateDeclaration; - sb.Append (del.Name); - AppendTypeParameter (sb, del.TypeParameters); - AppendParameter (sb, del.Parameters); - } else if (e is Accessor) { - if (e.Role == PropertyDeclaration.GetterRole) { + if (e is NamespaceDeclarationSyntax) { + return ((NamespaceDeclarationSyntax)e).Name.ToString (); + } + if (e is TypeDeclarationSyntax) { + var type = e as TypeDeclarationSyntax; + sb.Append (type.Identifier); + AppendTypeParameter (sb, type.TypeParameterList); + } else if (e is DelegateDeclarationSyntax) { + var del = e as DelegateDeclarationSyntax; + sb.Append (del.Identifier); + AppendTypeParameter (sb, del.TypeParameterList); + AppendParameter (sb, del.ParameterList); + } else if (e is AccessorDeclarationSyntax) { + if (e.Kind () == SyntaxKind.GetAccessorDeclaration) { sb.Append ("get"); - } else if (e.Role == PropertyDeclaration.SetterRole) { + } else if (e.Kind () == SyntaxKind.SetAccessorDeclaration) { sb.Append ("set"); - } else if (e.Role == CustomEventDeclaration.AddAccessorRole) { + } else if (e.Kind () == SyntaxKind.AddAccessorDeclaration) { sb.Append ("add"); - } else if (e.Role == CustomEventDeclaration.RemoveAccessorRole) { + } else if (e.Kind () == SyntaxKind.RemoveAccessorDeclaration) { sb.Append ("remove"); } - } else if (e is OperatorDeclaration) { - var op = e as OperatorDeclaration; + } else if (e is OperatorDeclarationSyntax) { + var op = (OperatorDeclarationSyntax)e; sb.Append ("operator "); - if (!op.OperatorTypeToken.IsNull) - AppendEscaped (sb, op.OperatorTypeToken.ToString ()); - AppendParameter (sb, op.Parameters); - } else if (e is MethodDeclaration) { - var method = e as MethodDeclaration; - if (!method.PrivateImplementationType.IsNull) - AppendEscaped (sb, method.PrivateImplementationType.ToString () + "."); - sb.Append (method.Name); - AppendTypeParameter (sb, method.TypeParameters); - AppendParameter (sb, method.Parameters); - if (method.Body.IsNull) { + AppendEscaped (sb, op.OperatorToken.ToString ()); + AppendParameter (sb, op.ParameterList); + } else if (e is MethodDeclarationSyntax) { + var method = (MethodDeclarationSyntax)e; + if (method.ExplicitInterfaceSpecifier != null) + AppendEscaped (sb, method.ExplicitInterfaceSpecifier + "."); + sb.Append (method.Identifier); + AppendTypeParameter (sb, method.TypeParameterList); + AppendParameter (sb, method.ParameterList); + if (method.Body != null && !method.Body.IsMissing) { string tag = null; - if (method.HasModifier (Modifiers.Abstract)) + if (method.Modifiers.Any (m => m.Kind () == SyntaxKind.AbstractKeyword)) tag = GettextCatalog.GetString ("(abstract)"); - if (method.HasModifier (Modifiers.Partial)) + if (method.Modifiers.Any (m => m.Kind () == SyntaxKind.PartialKeyword)) tag = GettextCatalog.GetString ("(partial)"); if (tag != null) sb.Append (" <small>" + tag + "</small>"); } - } else if (e is ConstructorDeclaration) { - var constructor = e as ConstructorDeclaration; - sb.Append (constructor.Name); - AppendParameter (sb, constructor.Parameters); - } else if (e is DestructorDeclaration) { - var destructror = e as DestructorDeclaration; + } else if (e is ConstructorDeclarationSyntax) { + var constructor = e as ConstructorDeclarationSyntax; + sb.Append (constructor.Identifier); + AppendParameter (sb, constructor.ParameterList); + } else if (e is DestructorDeclarationSyntax) { + var destructror = e as DestructorDeclarationSyntax; sb.Append ("~"); - sb.Append (destructror.Name); - if (options.SpaceBeforeMethodDeclarationParentheses) - sb.Append (" "); + sb.Append (destructror.Identifier); + // if (options.SpaceBeforeMethodDeclarationParentheses) + // sb.Append (" "); sb.Append ("()"); - } else if (e is IndexerDeclaration) { - var indexer = e as IndexerDeclaration; + } else if (e is IndexerDeclarationSyntax) { + var indexer = e as IndexerDeclarationSyntax; sb.Append ("this"); - if (options.SpaceBeforeIndexerDeclarationBracket) - sb.Append (" "); + //if (options.SpaceBeforeIndexerDeclarationBracket) + // sb.Append (" "); sb.Append ("["); - if (options.SpaceWithinIndexerDeclarationBracket) - sb.Append (" "); + //if (options.SpaceWithinIndexerDeclarationBracket) + // sb.Append (" "); bool first = true; - foreach (var param in indexer.Parameters) { + foreach (var param in indexer.ParameterList.Parameters) { if (!first) { - if (options.SpaceBeforeIndexerDeclarationParameterComma) - sb.Append (" "); + //if (options.SpaceBeforeIndexerDeclarationParameterComma) + // sb.Append (" "); sb.Append (","); - if (options.SpaceAfterIndexerDeclarationParameterComma) - sb.Append (" "); + //if (options.SpaceAfterIndexerDeclarationParameterComma) + // sb.Append (" "); } else { first = false; } - sb.Append (param.ToString (options)); + sb.Append (param.ToString ()); } - if (options.SpaceWithinIndexerDeclarationBracket) - sb.Append (" "); + //if (options.SpaceWithinIndexerDeclarationBracket) + // sb.Append (" "); sb.Append ("]"); - } else if (e is VariableInitializer) { - var initializer = (VariableInitializer)e; - sb.Append (initializer.Name); - if (IsObsolete (initializer.Parent as EntityDeclaration)) - return "<s>" + sb.ToString () + "</s>"; - } else if (e is FixedVariableInitializer) { - var initializer = (FixedVariableInitializer)e; - sb.Append (initializer.Name); - if (IsObsolete (initializer.Parent as EntityDeclaration)) + } else if (e is VariableDeclaratorSyntax) { + var initializer = (VariableDeclaratorSyntax)e; + sb.Append (initializer.Identifier); + if (IsObsolete (initializer.Parent as MemberDeclarationSyntax)) return "<s>" + sb.ToString () + "</s>"; - } else if (e is FieldDeclaration) { - var field = (FieldDeclaration)e; - if (!field.Variables.Any ()) + } else if (e is FieldDeclarationSyntax) { + var field = (FieldDeclarationSyntax)e; + if (!field.Declaration.Variables.Any ()) return ""; - sb.Append (field.Variables.First ().Name); - } else if (e is FixedFieldDeclaration) { - var field = (FixedFieldDeclaration)e; - if (!field.Variables.Any ()) + sb.Append (field.Declaration.Variables.First ().Identifier); + } else if (e is EventFieldDeclarationSyntax) { + var evt = (EventFieldDeclarationSyntax)e; + if (!evt.Declaration.Variables.Any ()) return ""; - sb.Append (field.Variables.First ().Name); - } else if (e is EventDeclaration) { - var evt = (EventDeclaration)e; - if (!evt.Variables.Any ()) - return ""; - sb.Append (evt.Variables.First ().Name); - } else if (e is PropertyDeclaration) { - var property = (PropertyDeclaration)e; - if (!property.PrivateImplementationType.IsNull) - AppendEscaped (sb, property.PrivateImplementationType.ToString () + "."); - sb.Append (property.Name); - } else if (e is CustomEventDeclaration) { - var customEvent = (CustomEventDeclaration)e; - if (!customEvent.PrivateImplementationType.IsNull) - AppendEscaped (sb, customEvent.PrivateImplementationType.ToString () + "."); - sb.Append (customEvent.Name); - } else if (e is EntityDeclaration) { - var entity = (EntityDeclaration)e; - sb.Append (entity.Name); - } + sb.Append (evt.Declaration.Variables.First ().Identifier); + } else if (e is PropertyDeclarationSyntax) { + var property = (PropertyDeclarationSyntax)e; + if (property.ExplicitInterfaceSpecifier != null) + AppendEscaped (sb, property.ExplicitInterfaceSpecifier + "."); + sb.Append (property.Identifier); + } else if (e is EventDeclarationSyntax) { + var customEvent = (EventDeclarationSyntax)e; + if (customEvent.ExplicitInterfaceSpecifier != null) + AppendEscaped (sb, customEvent.ExplicitInterfaceSpecifier + "."); + sb.Append (customEvent.Identifier); + } /*else if (e is MemberDeclarationSyntax) { + LoggingService.LogWarning ("can't display : " + e); + // var entity = (MemberDeclarationSyntax)e; + // sb.Append (entity.Name); + }*/ string markup = sb.ToString (); - if (IsObsolete (e as EntityDeclaration)) + if (IsObsolete (e as MemberDeclarationSyntax)) return "<s>" + markup + "</s>"; return markup; } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/AstStockIcons.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/AstStockIcons.cs index aec03f9f17..d8b09e4689 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/AstStockIcons.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/AstStockIcons.cs @@ -25,10 +25,12 @@ // THE SOFTWARE. using System; -using ICSharpCode.NRefactory.TypeSystem; +using System.Linq; using MonoDevelop.Ide.TypeSystem; using MonoDevelop.Core; -using ICSharpCode.NRefactory.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; namespace MonoDevelop.CSharp { @@ -41,7 +43,6 @@ namespace MonoDevelop.CSharp static readonly IconId Field = "md-field"; static readonly IconId Interface = "md-interface"; static readonly IconId Method = "md-method"; - static readonly IconId ExtensionMethod = "md-extensionmethod"; static readonly IconId Property = "md-property"; static readonly IconId Struct = "md-struct"; static readonly IconId Delegate = "md-delegate"; @@ -54,7 +55,6 @@ namespace MonoDevelop.CSharp static readonly IconId InternalField = "md-internal-field"; static readonly IconId InternalInterface = "md-internal-interface"; static readonly IconId InternalMethod = "md-internal-method"; - static readonly IconId InternalExtensionMethod = "md-internal-extensionmethod"; static readonly IconId InternalProperty = "md-internal-property"; static readonly IconId InternalStruct = "md-internal-struct"; @@ -65,7 +65,6 @@ namespace MonoDevelop.CSharp static readonly IconId InternalAndProtectedField = "md-InternalAndProtected-field"; static readonly IconId InternalAndProtectedInterface = "md-InternalAndProtected-interface"; static readonly IconId InternalAndProtectedMethod = "md-InternalAndProtected-method"; - static readonly IconId InternalAndProtectedExtensionMethod = "md-InternalAndProtected-extensionmethod"; static readonly IconId InternalAndProtectedProperty = "md-InternalAndProtected-property"; static readonly IconId InternalAndProtectedStruct = "md-InternalAndProtected-struct"; @@ -76,7 +75,6 @@ namespace MonoDevelop.CSharp static readonly IconId PrivateField = "md-private-field"; static readonly IconId PrivateInterface = "md-private-interface"; static readonly IconId PrivateMethod = "md-private-method"; - static readonly IconId PrivateExtensionMethod = "md-private-extensionmethod"; static readonly IconId PrivateProperty = "md-private-property"; static readonly IconId PrivateStruct = "md-private-struct"; @@ -87,7 +85,6 @@ namespace MonoDevelop.CSharp static readonly IconId ProtectedField = "md-protected-field"; static readonly IconId ProtectedInterface = "md-protected-interface"; static readonly IconId ProtectedMethod = "md-protected-method"; - static readonly IconId ProtectedExtensionMethod = "md-protected-extensionmethod"; static readonly IconId ProtectedProperty = "md-protected-property"; static readonly IconId ProtectedStruct = "md-protected-struct"; @@ -98,7 +95,6 @@ namespace MonoDevelop.CSharp static readonly IconId ProtectedOrInternalField = "md-ProtectedOrInternal-field"; static readonly IconId ProtectedOrInternalInterface = "md-ProtectedOrInternal-interface"; static readonly IconId ProtectedOrInternalMethod = "md-ProtectedOrInternal-method"; - static readonly IconId ProtectedOrInternalExtensionMethod = "md-ProtectedOrInternal-extensionmethod"; static readonly IconId ProtectedOrInternalProperty = "md-ProtectedOrInternal-property"; static readonly IconId ProtectedOrInternalStruct = "md-ProtectedOrInternal-struct"; @@ -115,9 +111,6 @@ namespace MonoDevelop.CSharp static readonly IconId[] methodIconTable = { AstStockIcons.Method, AstStockIcons.PrivateMethod, AstStockIcons.Method, AstStockIcons.ProtectedMethod, AstStockIcons.InternalMethod, AstStockIcons.ProtectedOrInternalMethod, AstStockIcons.InternalAndProtectedMethod }; - static readonly IconId[] extensionMethodIconTable = { - AstStockIcons.ExtensionMethod, AstStockIcons.PrivateExtensionMethod, AstStockIcons.ExtensionMethod, AstStockIcons.ProtectedExtensionMethod, AstStockIcons.InternalExtensionMethod, AstStockIcons.ProtectedOrInternalExtensionMethod, AstStockIcons.InternalAndProtectedExtensionMethod - }; static readonly IconId[] propertyIconTable = { AstStockIcons.Property, AstStockIcons.PrivateProperty, AstStockIcons.Property, AstStockIcons.ProtectedProperty, AstStockIcons.InternalProperty, AstStockIcons.ProtectedOrInternalProperty, AstStockIcons.InternalAndProtectedProperty }; @@ -125,86 +118,111 @@ namespace MonoDevelop.CSharp AstStockIcons.Event, AstStockIcons.PrivateEvent, AstStockIcons.Event, AstStockIcons.ProtectedEvent, AstStockIcons.InternalEvent, AstStockIcons.ProtectedOrInternalEvent, AstStockIcons.InternalAndProtectedEvent }; - static bool GetAccessibility (EntityDeclaration element, out Accessibility acc) + static void AdjustAccessibility (SyntaxTokenList modifiers, ref Accessibility acc, ref bool result) + { + if (modifiers.Any (mod => mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.ProtectedKeyword) && + modifiers.Any (mod => mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.InternalKeyword)) { + acc = Accessibility.ProtectedOrInternal; + result = true; + return; + } + + foreach (var mod in modifiers) { + if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.PublicKeyword) { + acc = Accessibility.Public; + result = true; + return; + } + if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.PrivateKeyword) { + acc = Accessibility.Private; + result = true; + return; + } + if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.ProtectedKeyword) { + acc = Accessibility.Protected; + result = true; + return; + } + if (mod.Kind () == Microsoft.CodeAnalysis.CSharp.SyntaxKind.InternalKeyword) { + acc = Accessibility.Internal; + result = true; + return; + } + } + } + + static bool GetAccessibility (SyntaxNode element, out Accessibility acc) { - if (element.Parent is TypeDeclaration && ((TypeDeclaration)element.Parent).ClassType == ClassType.Interface) { + if (element.Parent is TypeDeclarationSyntax && element.Parent is InterfaceDeclarationSyntax) { acc = Accessibility.Public; return true; } bool result = false; acc = Accessibility.Private; - if (element is TypeDeclaration && !(element.Parent is TypeDeclaration)) - acc = Accessibility.Internal; - if (element.HasModifier (Modifiers.Public)) { - acc = Accessibility.Public; - result = true; - } else if (element.HasModifier (Modifiers.Private)) { - acc = Accessibility.Private; - result = true; - } else if (element.HasModifier (Modifiers.Protected | Modifiers.Internal)) { - acc = Accessibility.ProtectedOrInternal; - result = true; - } else if (element.HasModifier (Modifiers.Protected)) { - acc = Accessibility.Protected; - result = true; - } else if (element.HasModifier (Modifiers.Internal)) { + if (element is TypeDeclarationSyntax && !(element.Parent is TypeDeclarationSyntax)) acc = Accessibility.Internal; - result = true; - } + + if (element is TypeDeclarationSyntax) + AdjustAccessibility (((TypeDeclarationSyntax)element).Modifiers, ref acc, ref result); + if (element is BaseFieldDeclarationSyntax) + AdjustAccessibility (((BaseFieldDeclarationSyntax)element).Modifiers, ref acc, ref result); + if (element is BasePropertyDeclarationSyntax) + AdjustAccessibility (((BasePropertyDeclarationSyntax)element).Modifiers, ref acc, ref result); + if (element is BaseMethodDeclarationSyntax) + AdjustAccessibility (((BaseMethodDeclarationSyntax)element).Modifiers, ref acc, ref result); return result; } - - public static string GetStockIcon (this EntityDeclaration element) + public static string GetStockIcon (this SyntaxNode element) { Accessibility acc = Accessibility.Public; + if (element is NamespaceDeclarationSyntax) + return Namespace; - if (element is Accessor) { - if (!GetAccessibility (element, out acc)) - GetAccessibility (element.Parent as EntityDeclaration, out acc); + if (element is AccessorDeclarationSyntax) { + if (!GetAccessibility ((MemberDeclarationSyntax)element, out acc)) + GetAccessibility (element.Parent as MemberDeclarationSyntax, out acc); return methodIconTable [(int) (acc)]; } GetAccessibility (element, out acc); - if (element is TypeDeclaration) { - var type = element as TypeDeclaration; - - switch (type.ClassType) { - case ClassType.Class: + if (element is TypeDeclarationSyntax) { + var type = element as TypeDeclarationSyntax; + switch (type.Keyword.Kind ()) { + case SyntaxKind.ClassKeyword: return typeIconTable [0, (int) (acc)]; - case ClassType.Struct: + case SyntaxKind.StructKeyword: return typeIconTable [3, (int) (acc)]; - case ClassType.Interface: + case SyntaxKind.InterfaceKeyword: return typeIconTable [2, (int) (acc)]; - case ClassType.Enum: + case SyntaxKind.EnumKeyword: return typeIconTable [1, (int) (acc)]; default: throw new ArgumentOutOfRangeException (); } } - if (element is DelegateDeclaration) + if (element is DelegateDeclarationSyntax) return typeIconTable [4, (int) (acc)]; // member accessibility GetAccessibility (element, out acc); - if (element is MethodDeclaration) { - var method = element as MethodDeclaration; - if (method.IsExtensionMethod) - return extensionMethodIconTable [(int) (acc)]; + if (element is BaseMethodDeclarationSyntax) { + // TODO! + // var method = element as MethodDeclarationSyntax; + // if (method.ParameterList.Parameters.First ()) + // return extensionMethodIconTable [(int) (acc)]; return methodIconTable [(int) (acc)]; } - if (element is OperatorDeclaration || element is ConstructorDeclaration || element is DestructorDeclaration || element is Accessor) - return methodIconTable [(int) (acc)]; - if (element is PropertyDeclaration || element is IndexerDeclaration) + if (element is PropertyDeclarationSyntax || element is IndexerDeclarationSyntax) return propertyIconTable [(int) (acc)]; - if (element is EventDeclaration || element is CustomEventDeclaration) + if (element is EventDeclarationSyntax || element is EventFieldDeclarationSyntax) return eventIconTable [(int) (acc)]; - if (element.Parent is TypeDeclaration && ((TypeDeclaration)element.Parent).ClassType == ClassType.Enum) + if (element.Parent is EnumDeclarationSyntax) acc = Accessibility.Public; return fieldIconTable [(int) (acc)]; } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpAmbience.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpAmbience.cs index 3536c9a86c..db298762d5 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpAmbience.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpAmbience.cs @@ -32,16 +32,11 @@ using MonoDevelop.CSharp.Formatting; using MonoDevelop.Ide; using System.Collections.ObjectModel; using MonoDevelop.Ide.TypeSystem; -using ICSharpCode.NRefactory.TypeSystem; -using ICSharpCode.NRefactory.CSharp.Refactoring; using System.IO; -using ICSharpCode.NRefactory.CSharp.Resolver; -using ICSharpCode.NRefactory.CSharp; -using ICSharpCode.NRefactory.TypeSystem.Implementation; namespace MonoDevelop.CSharp { - class CSharpAmbience : Ambience + class CSharpAmbience : AmbienceTooltipProvider { static Dictionary<string, string> netToCSharpTypes = new Dictionary<string, string> (); static HashSet<string> keywords = new HashSet<string> (new [] { @@ -186,40 +181,33 @@ namespace MonoDevelop.CSharp netToCSharpTypes ["System.Decimal"] = "decimal"; netToCSharpTypes ["System.String"] = "string"; - classTypes [TypeKind.Class] = "class"; - classTypes [TypeKind.Enum] = "enum"; - classTypes [TypeKind.Interface] = "interface"; - classTypes [TypeKind.Struct] = "struct"; - classTypes [TypeKind.Delegate] = "delegate"; +// classTypes [TypeKind.Class] = "class"; +// classTypes [TypeKind.Enum] = "enum"; +// classTypes [TypeKind.Interface] = "interface"; +// classTypes [TypeKind.Struct] = "struct"; +// classTypes [TypeKind.Delegate] = "delegate"; } - - public CSharpAmbience () : base ("C#") - { - } - - static Dictionary<TypeKind, string> classTypes = new Dictionary<TypeKind, string> (); - - public override MonoDevelop.Ide.CodeCompletion.TooltipInformation GetTooltip (IEntity entity) +// +// public CSharpAmbience () : base ("C#") +// { +// } +// +// static Dictionary<TypeKind, string> classTypes = new Dictionary<TypeKind, string> (); +// + public override MonoDevelop.Ide.CodeCompletion.TooltipInformation GetTooltip (Microsoft.CodeAnalysis.ISymbol entity) { if (entity == null) throw new ArgumentNullException ("entity"); - return MonoDevelop.CSharp.Completion.MemberCompletionData.CreateTooltipInformation ( - entity.Compilation, - null, - null, - new CSharpFormattingPolicy (), - entity, - false, - true); + return MonoDevelop.CSharp.Completion.RoslynSymbolCompletionData.CreateTooltipInformation (null, null, entity, false, true); } - static string GetString (TypeKind classType) - { - string res; - if (classTypes.TryGetValue (classType, out res)) - return res; - return string.Empty; - } +// static string GetString (TypeKind classType) +// { +// string res; +// if (classTypes.TryGetValue (classType, out res)) +// return res; +// return string.Empty; +// } internal static string FilterName (string name) { @@ -235,334 +223,334 @@ namespace MonoDevelop.CSharp return netTypeName; } - #region implemented abstract members of MonoDevelop.Ide.TypeSystem.Ambience - public override string GetIntrinsicTypeName (string reflectionName) - { - return NetToCSharpTypeName (reflectionName); - } - - public override string SingleLineComment (string text) - { - return "// " + text; - } - - public override string GetString (string nameSpace, OutputSettings settings) - { - var result = new StringBuilder (); - if (settings.IncludeKeywords) - result.Append (settings.EmitKeyword ("namespace")); - result.Append (Format (nameSpace)); - return result.ToString (); - } - - public void AppendType (StringBuilder sb, IType type, OutputSettings settings) - { - if (type.Kind == TypeKind.Unknown) { - sb.Append (settings.IncludeMarkup ? settings.Markup (type.Name) : type.Name); - return; - } - if (type.Kind == TypeKind.TypeParameter) { - sb.Append (settings.IncludeMarkup ? settings.Markup (type.Name) : type.Name); - return; - } - if (type.DeclaringType != null) { - AppendType (sb, type.DeclaringType, settings); - sb.Append (settings.Markup (".")); - } - if (type.Namespace == "System" && type.TypeParameterCount == 0) { - switch (type.Name) { - case "Object": - sb.Append ("object"); - return; - case "Boolean": - sb.Append ("bool"); - return; - case "Char": - sb.Append ("char"); - return; - case "SByte": - sb.Append ("sbyte"); - return; - case "Byte": - sb.Append ("byte"); - return; - case "Int16": - sb.Append ("short"); - return; - case "UInt16": - sb.Append ("ushort"); - return; - case "Int32": - sb.Append ("int"); - return; - case "UInt32": - sb.Append ("uint"); - return; - case "Int64": - sb.Append ("long"); - return; - case "UInt64": - sb.Append ("ulong"); - return; - case "Single": - sb.Append ("float"); - return; - case "Double": - sb.Append ("double"); - return; - case "Decimal": - sb.Append ("decimal"); - return; - case "String": - sb.Append ("string"); - return; - case "Void": - sb.Append ("void"); - return; - } - } - - var typeWithElementType = type as TypeWithElementType; - if (typeWithElementType != null) { - AppendType (sb, typeWithElementType.ElementType, settings); - - if (typeWithElementType is PointerType) { - sb.Append (settings.Markup ("*")); - } - - if (typeWithElementType is ArrayType) { - sb.Append (settings.Markup ("[")); - sb.Append (settings.Markup (new string (',', ((ArrayType)type).Dimensions - 1))); - sb.Append (settings.Markup ("]")); - } - return; - } - - if (type.TypeArguments.Count > 0) { - if (type.Name == "Nullable" && type.Namespace == "System" && type.TypeParameterCount == 1) { - AppendType (sb, type.TypeArguments [0], settings); - sb.Append (settings.Markup ("?")); - return; - } - sb.Append (type.Name); - if (type.TypeParameterCount > 0) { - sb.Append (settings.Markup ("<")); - for (int i = 0; i < type.TypeParameterCount; i++) { - if (i > 0) - sb.Append (settings.Markup (", ")); - AppendType (sb, type.TypeArguments [i], settings); - } - sb.Append (settings.Markup (">")); - } - return; - } - - var typeDef = type as ITypeDefinition ?? type.GetDefinition (); - if (typeDef != null) { - if (settings.UseFullName) { - sb.Append (settings.IncludeMarkup ? settings.Markup (typeDef.FullName) : typeDef.FullName); - } else { - sb.Append (settings.IncludeMarkup ? settings.Markup (typeDef.Name) : typeDef.Name); - } - - if (typeDef.TypeParameterCount > 0) { - sb.Append (settings.Markup ("<")); - for (int i = 0; i < typeDef.TypeParameterCount; i++) { - if (i > 0) - sb.Append (settings.Markup (", ")); - AppendVariance (sb, typeDef.TypeParameters [i].Variance); - AppendType (sb, typeDef.TypeParameters [i], settings); - } - sb.Append (settings.Markup (">")); - } - } - } - - static void AppendVariance (StringBuilder sb, VarianceModifier variance) - { - if (variance == VarianceModifier.Contravariant) { - sb.Append ("in "); - } else if (variance == VarianceModifier.Covariant) { - sb.Append ("out "); - } - } - - protected override string GetTypeReferenceString (IType reference, OutputSettings settings) - { - if (reference == null) - return "null"; - var type = reference; - if (type.Kind == TypeKind.Unknown) { - return settings.IncludeMarkup ? settings.Markup (reference.Name) : reference.Name; - } - - if (reference.Kind == TypeKind.TypeParameter) - return settings.IncludeMarkup ? settings.Markup (reference.Name) : reference.FullName; - - var sb = new StringBuilder (); - if (type is ITypeDefinition && ((ITypeDefinition)type).IsSynthetic && ((ITypeDefinition)type).Name == "$Anonymous$") { - sb.Append ("new {"); - foreach (var property in ((ITypeDefinition)type).Properties) { - sb.AppendLine (); - sb.Append ("\t"); - sb.Append (GetTypeReferenceString (property.ReturnType, settings) ?? "?"); - sb.Append (" "); - sb.Append (settings.IncludeMarkup ? settings.Markup (property.Name) : property.Name); - sb.Append (";"); - } - sb.AppendLine (); - sb.Append ("}"); - return sb.ToString (); - } - - AppendType (sb, type, settings); - return sb.ToString (); - } - - protected override string GetTypeString (IType t, OutputSettings settings) - { - if (t.Kind == TypeKind.Unknown) { - return settings.IncludeMarkup ? settings.Markup (t.Name) : t.Name; - } - - if (t.Kind == TypeKind.TypeParameter) - return settings.IncludeMarkup ? settings.Markup (t.FullName) : t.FullName; - - var typeWithElementType = t as TypeWithElementType; - if (typeWithElementType != null) { - var sb = new StringBuilder (); - - if (typeWithElementType is PointerType) { - sb.Append (settings.Markup ("*")); - } - AppendType (sb, typeWithElementType.ElementType, settings); - - if (typeWithElementType is ArrayType) { - sb.Append (settings.Markup ("[")); - sb.Append (settings.Markup (new string (',', ((ArrayType)t).Dimensions - 1))); - sb.Append (settings.Markup ("]")); - } - return sb.ToString (); - } - - ITypeDefinition type = t.GetDefinition (); - if (type == null) - return ""; - - if (!settings.UseNETTypeNames && type.Namespace == "System" && type.TypeParameterCount == 0) { - switch (type.Name) { - case "Object": - return "object"; - case "Boolean": - return "bool"; - case "Char": - return "char"; - case "SByte": - return "sbyte"; - case "Byte": - return "byte"; - case "Int16": - return "short"; - case "UInt16": - return "ushort"; - case "Int32": - return "int"; - case "UInt32": - return "uint"; - case "Int64": - return "long"; - case "UInt64": - return "ulong"; - case "Single": - return "float"; - case "Double": - return "double"; - case "Decimal": - return "decimal"; - case "String": - return "string"; - case "Void": - return "void"; - } - } - - // output anonymous type - if (type.IsSynthetic && type.Name == "$Anonymous$") - return GetTypeReferenceString (type, settings); - - var result = new StringBuilder (); - - - var def = type; - AppendModifiers (result, settings, def); - if (settings.IncludeKeywords) - result.Append (GetString (def.Kind)); - if (result.Length > 0 && !result.ToString ().EndsWith (" ")) - result.Append (settings.Markup (" ")); - - - if (type.Kind == TypeKind.Delegate && settings.ReformatDelegates && settings.IncludeReturnType) { - var invoke = type.GetDelegateInvokeMethod (); - result.Append (GetTypeReferenceString (invoke.ReturnType, settings)); - result.Append (settings.Markup (" ")); - } - - if (settings.UseFullName && !string.IsNullOrEmpty (type.Namespace)) - result.Append ((settings.IncludeMarkup ? settings.Markup (t.Namespace) : type.Namespace) + "."); - - if (settings.UseFullInnerTypeName && type.DeclaringTypeDefinition != null) { - bool includeGenerics = settings.IncludeGenerics; - settings.OutputFlags |= OutputFlags.IncludeGenerics; - string typeString = GetTypeReferenceString (type.DeclaringTypeDefinition, settings); - if (!includeGenerics) - settings.OutputFlags &= ~OutputFlags.IncludeGenerics; - result.Append (typeString); - result.Append (settings.Markup (".")); - } - result.Append (settings.EmitName (type, settings.IncludeMarkup ? settings.Markup (t.Name) : type.Name)); - if (settings.IncludeGenerics && type.TypeParameterCount > 0) { - result.Append (settings.Markup ("<")); - for (int i = 0; i < type.TypeParameterCount; i++) { - if (i > 0) - result.Append (settings.Markup (settings.HideGenericParameterNames ? "," : ", ")); - if (!settings.HideGenericParameterNames) { - if (t.TypeArguments.Count > 0) { - result.Append (GetTypeReferenceString (t.TypeArguments [i], settings)); - } else { - AppendVariance (result, type.TypeParameters [i].Variance); - result.Append (NetToCSharpTypeName (type.TypeParameters [i].FullName)); - } - } - } - result.Append (settings.Markup (">")); - } - - if (t.Kind == TypeKind.Delegate && settings.ReformatDelegates) { -// var policy = GetPolicy (settings); -// if (policy.BeforeMethodCallParentheses) -// result.Append (settings.Markup (" ")); - result.Append (settings.Markup ("(")); - var invoke = type.GetDelegateInvokeMethod (); - if (invoke != null) - AppendParameterList (result, settings, invoke.Parameters); - result.Append (settings.Markup (")")); - return result.ToString (); - } - - if (settings.IncludeBaseTypes && type.DirectBaseTypes.Any ()) { - bool first = true; - foreach (var baseType in type.DirectBaseTypes) { -// if (baseType.FullName == "System.Object" || baseType.FullName == "System.Enum") -// continue; - result.Append (settings.Markup (first ? " : " : ", ")); - first = false; - result.Append (GetTypeReferenceString (baseType, settings)); - } - - } -// OutputConstraints (result, settings, type.TypeParameters); - return result.ToString (); - } +// #region implemented abstract members of MonoDevelop.Ide.TypeSystem.Ambience +// public override string GetIntrinsicTypeName (string reflectionName) +// { +// return NetToCSharpTypeName (reflectionName); +// } +// +// public override string SingleLineComment (string text) +// { +// return "// " + text; +// } +// +// public override string GetString (string nameSpace, OutputSettings settings) +// { +// var result = new StringBuilder (); +// if (settings.IncludeKeywords) +// result.Append (settings.EmitKeyword ("namespace")); +// result.Append (Format (nameSpace)); +// return result.ToString (); +// } +// +// public void AppendType (StringBuilder sb, IType type, OutputSettings settings) +// { +// if (type.Kind == TypeKind.Unknown) { +// sb.Append (settings.IncludeMarkup ? settings.Markup (type.Name) : type.Name); +// return; +// } +// if (type.Kind == TypeKind.TypeParameter) { +// sb.Append (settings.IncludeMarkup ? settings.Markup (type.Name) : type.Name); +// return; +// } +// if (type.DeclaringType != null) { +// AppendType (sb, type.DeclaringType, settings); +// sb.Append (settings.Markup (".")); +// } +// if (type.Namespace == "System" && type.TypeParameterCount == 0) { +// switch (type.Name) { +// case "Object": +// sb.Append ("object"); +// return; +// case "Boolean": +// sb.Append ("bool"); +// return; +// case "Char": +// sb.Append ("char"); +// return; +// case "SByte": +// sb.Append ("sbyte"); +// return; +// case "Byte": +// sb.Append ("byte"); +// return; +// case "Int16": +// sb.Append ("short"); +// return; +// case "UInt16": +// sb.Append ("ushort"); +// return; +// case "Int32": +// sb.Append ("int"); +// return; +// case "UInt32": +// sb.Append ("uint"); +// return; +// case "Int64": +// sb.Append ("long"); +// return; +// case "UInt64": +// sb.Append ("ulong"); +// return; +// case "Single": +// sb.Append ("float"); +// return; +// case "Double": +// sb.Append ("double"); +// return; +// case "Decimal": +// sb.Append ("decimal"); +// return; +// case "String": +// sb.Append ("string"); +// return; +// case "Void": +// sb.Append ("void"); +// return; +// } +// } +// +// var typeWithElementType = type as TypeWithElementType; +// if (typeWithElementType != null) { +// AppendType (sb, typeWithElementType.ElementType, settings); +// +// if (typeWithElementType is PointerType) { +// sb.Append (settings.Markup ("*")); +// } +// +// if (typeWithElementType is ArrayType) { +// sb.Append (settings.Markup ("[")); +// sb.Append (settings.Markup (new string (',', ((ArrayType)type).Dimensions - 1))); +// sb.Append (settings.Markup ("]")); +// } +// return; +// } +// +// if (type.TypeArguments.Count > 0) { +// if (type.Name == "Nullable" && type.Namespace == "System" && type.TypeParameterCount == 1) { +// AppendType (sb, type.TypeArguments [0], settings); +// sb.Append (settings.Markup ("?")); +// return; +// } +// sb.Append (type.Name); +// if (type.TypeParameterCount > 0) { +// sb.Append (settings.Markup ("<")); +// for (int i = 0; i < type.TypeParameterCount; i++) { +// if (i > 0) +// sb.Append (settings.Markup (", ")); +// AppendType (sb, type.TypeArguments [i], settings); +// } +// sb.Append (settings.Markup (">")); +// } +// return; +// } +// +// var typeDef = type as ITypeDefinition ?? type.GetDefinition (); +// if (typeDef != null) { +// if (settings.UseFullName) { +// sb.Append (settings.IncludeMarkup ? settings.Markup (typeDef.FullName) : typeDef.FullName); +// } else { +// sb.Append (settings.IncludeMarkup ? settings.Markup (typeDef.Name) : typeDef.Name); +// } +// +// if (typeDef.TypeParameterCount > 0) { +// sb.Append (settings.Markup ("<")); +// for (int i = 0; i < typeDef.TypeParameterCount; i++) { +// if (i > 0) +// sb.Append (settings.Markup (", ")); +// AppendVariance (sb, typeDef.TypeParameters [i].Variance); +// AppendType (sb, typeDef.TypeParameters [i], settings); +// } +// sb.Append (settings.Markup (">")); +// } +// } +// } +// +// static void AppendVariance (StringBuilder sb, VarianceModifier variance) +// { +// if (variance == VarianceModifier.Contravariant) { +// sb.Append ("in "); +// } else if (variance == VarianceModifier.Covariant) { +// sb.Append ("out "); +// } +// } +// +// protected override string GetTypeReferenceString (IType reference, OutputSettings settings) +// { +// if (reference == null) +// return "null"; +// var type = reference; +// if (type.Kind == TypeKind.Unknown) { +// return settings.IncludeMarkup ? settings.Markup (reference.Name) : reference.Name; +// } +// +// if (reference.Kind == TypeKind.TypeParameter) +// return settings.IncludeMarkup ? settings.Markup (reference.Name) : reference.FullName; +// +// var sb = new StringBuilder (); +// if (type is ITypeDefinition && ((ITypeDefinition)type).IsSynthetic && ((ITypeDefinition)type).Name == "$Anonymous$") { +// sb.Append ("new {"); +// foreach (var property in ((ITypeDefinition)type).Properties) { +// sb.AppendLine (); +// sb.Append ("\t"); +// sb.Append (GetTypeReferenceString (property.ReturnType, settings) ?? "?"); +// sb.Append (" "); +// sb.Append (settings.IncludeMarkup ? settings.Markup (property.Name) : property.Name); +// sb.Append (";"); +// } +// sb.AppendLine (); +// sb.Append ("}"); +// return sb.ToString (); +// } +// +// AppendType (sb, type, settings); +// return sb.ToString (); +// } +// +// protected override string GetTypeString (IType t, OutputSettings settings) +// { +// if (t.Kind == TypeKind.Unknown) { +// return settings.IncludeMarkup ? settings.Markup (t.Name) : t.Name; +// } +// +// if (t.Kind == TypeKind.TypeParameter) +// return settings.IncludeMarkup ? settings.Markup (t.FullName) : t.FullName; +// +// var typeWithElementType = t as TypeWithElementType; +// if (typeWithElementType != null) { +// var sb = new StringBuilder (); +// +// if (typeWithElementType is PointerType) { +// sb.Append (settings.Markup ("*")); +// } +// AppendType (sb, typeWithElementType.ElementType, settings); +// +// if (typeWithElementType is ArrayType) { +// sb.Append (settings.Markup ("[")); +// sb.Append (settings.Markup (new string (',', ((ArrayType)t).Dimensions - 1))); +// sb.Append (settings.Markup ("]")); +// } +// return sb.ToString (); +// } +// +// ITypeDefinition type = t.GetDefinition (); +// if (type == null) +// return ""; +// +// if (!settings.UseNETTypeNames && type.Namespace == "System" && type.TypeParameterCount == 0) { +// switch (type.Name) { +// case "Object": +// return "object"; +// case "Boolean": +// return "bool"; +// case "Char": +// return "char"; +// case "SByte": +// return "sbyte"; +// case "Byte": +// return "byte"; +// case "Int16": +// return "short"; +// case "UInt16": +// return "ushort"; +// case "Int32": +// return "int"; +// case "UInt32": +// return "uint"; +// case "Int64": +// return "long"; +// case "UInt64": +// return "ulong"; +// case "Single": +// return "float"; +// case "Double": +// return "double"; +// case "Decimal": +// return "decimal"; +// case "String": +// return "string"; +// case "Void": +// return "void"; +// } +// } +// +// // output anonymous type +// if (type.IsSynthetic && type.Name == "$Anonymous$") +// return GetTypeReferenceString (type, settings); +// +// var result = new StringBuilder (); +// +// +// var def = type; +// AppendModifiers (result, settings, def); +// if (settings.IncludeKeywords) +// result.Append (GetString (def.Kind)); +// if (result.Length > 0 && !result.ToString ().EndsWith (" ")) +// result.Append (settings.Markup (" ")); +// +// +// if (type.Kind == TypeKind.Delegate && settings.ReformatDelegates && settings.IncludeReturnType) { +// var invoke = type.GetDelegateInvokeMethod (); +// result.Append (GetTypeReferenceString (invoke.ReturnType, settings)); +// result.Append (settings.Markup (" ")); +// } +// +// if (settings.UseFullName && !string.IsNullOrEmpty (type.Namespace)) +// result.Append ((settings.IncludeMarkup ? settings.Markup (t.Namespace) : type.Namespace) + "."); +// +// if (settings.UseFullInnerTypeName && type.DeclaringTypeDefinition != null) { +// bool includeGenerics = settings.IncludeGenerics; +// settings.OutputFlags |= OutputFlags.IncludeGenerics; +// string typeString = GetTypeReferenceString (type.DeclaringTypeDefinition, settings); +// if (!includeGenerics) +// settings.OutputFlags &= ~OutputFlags.IncludeGenerics; +// result.Append (typeString); +// result.Append (settings.Markup (".")); +// } +// result.Append (settings.EmitName (type, settings.IncludeMarkup ? settings.Markup (t.Name) : type.Name)); +// if (settings.IncludeGenerics && type.TypeParameterCount > 0) { +// result.Append (settings.Markup ("<")); +// for (int i = 0; i < type.TypeParameterCount; i++) { +// if (i > 0) +// result.Append (settings.Markup (settings.HideGenericParameterNames ? "," : ", ")); +// if (!settings.HideGenericParameterNames) { +// if (t.TypeArguments.Count > 0) { +// result.Append (GetTypeReferenceString (t.TypeArguments [i], settings)); +// } else { +// AppendVariance (result, type.TypeParameters [i].Variance); +// result.Append (NetToCSharpTypeName (type.TypeParameters [i].FullName)); +// } +// } +// } +// result.Append (settings.Markup (">")); +// } +// +// if (t.Kind == TypeKind.Delegate && settings.ReformatDelegates) { +//// var policy = GetPolicy (settings); +//// if (policy.BeforeMethodCallParentheses) +//// result.Append (settings.Markup (" ")); +// result.Append (settings.Markup ("(")); +// var invoke = type.GetDelegateInvokeMethod (); +// if (invoke != null) +// AppendParameterList (result, settings, invoke.Parameters); +// result.Append (settings.Markup (")")); +// return result.ToString (); +// } +// +// if (settings.IncludeBaseTypes && type.DirectBaseTypes.Any ()) { +// bool first = true; +// foreach (var baseType in type.DirectBaseTypes) { +//// if (baseType.FullName == "System.Object" || baseType.FullName == "System.Enum") +//// continue; +// result.Append (settings.Markup (first ? " : " : ", ")); +// first = false; +// result.Append (GetTypeReferenceString (baseType, settings)); +// } +// +// } +//// OutputConstraints (result, settings, type.TypeParameters); +// return result.ToString (); +// } internal static string GetOperator (string methodName) { @@ -623,336 +611,336 @@ namespace MonoDevelop.CSharp } return methodName; } - - string InternalGetMethodString (IMethod method, OutputSettings settings, string methodName, bool getReturnType) - { - if (method == null) - return ""; - var result = new StringBuilder (); - AppendModifiers (result, settings, method); - if (!settings.CompletionListFomat && settings.IncludeReturnType && getReturnType) { - result.Append (GetTypeReferenceString (method.ReturnType, settings)); - result.Append (settings.Markup (" ")); - } - - if (!settings.IncludeReturnType && settings.UseFullName) { - result.Append (GetTypeReferenceString (method.DeclaringTypeDefinition, new OutputSettings (OutputFlags.UseFullName))); - result.Append (settings.Markup (".")); - } - AppendExplicitInterfaces (result, method, settings); - if (method.SymbolKind == SymbolKind.Operator) { - result.Append ("operator "); - result.Append (settings.Markup (GetOperator (methodName))); - } else { - result.Append (methodName); - } - - if (settings.IncludeGenerics) { - if (method.TypeParameters.Count > 0) { - result.Append (settings.Markup ("<")); - for (int i = 0; i < method.TypeParameters.Count; i++) { - if (i > 0) - result.Append (settings.Markup (settings.HideGenericParameterNames ? "," : ", ")); - if (!settings.HideGenericParameterNames) { - AppendVariance (result, method.TypeParameters [i].Variance); - result.Append (NetToCSharpTypeName (method.TypeParameters [i].Name)); - } - } - result.Append (settings.Markup (">")); - } - } - - if (settings.IncludeParameters) { -// CSharpFormattingPolicy policy = GetPolicy (settings); -// if (policy.BeforeMethodCallParentheses) +// +// string InternalGetMethodString (IMethod method, OutputSettings settings, string methodName, bool getReturnType) +// { +// if (method == null) +// return ""; +// var result = new StringBuilder (); +// AppendModifiers (result, settings, method); +// if (!settings.CompletionListFomat && settings.IncludeReturnType && getReturnType) { +// result.Append (GetTypeReferenceString (method.ReturnType, settings)); // result.Append (settings.Markup (" ")); - result.Append (settings.Markup ("(")); - AppendParameterList (result, settings, method.Parameters); - result.Append (settings.Markup (")")); - } - - if (settings.CompletionListFomat && settings.IncludeReturnType && getReturnType) { - result.Append (settings.Markup (" : ")); - result.Append (GetTypeReferenceString (method.ReturnType, settings)); - } - -// OutputConstraints (result, settings, method.TypeParameters); - - return result.ToString (); - } - - protected override string GetMethodString (IMethod method, OutputSettings settings) - { - return InternalGetMethodString (method, settings, settings.EmitName (method, Format (FilterName (method.SymbolKind == SymbolKind.Constructor || method.SymbolKind == SymbolKind.Destructor ? method.DeclaringTypeDefinition.Name : method.Name))), true); - } - - protected override string GetConstructorString (IMethod method, OutputSettings settings) - { - return InternalGetMethodString (method, settings, settings.EmitName (method, Format (FilterName (method.DeclaringTypeDefinition != null ? method.DeclaringTypeDefinition.Name : method.Name))), false); - } - - protected override string GetDestructorString (IMethod method, OutputSettings settings) - { - return InternalGetMethodString (method, settings, settings.EmitName (method, settings.Markup ("~") + Format (FilterName (method.DeclaringTypeDefinition != null ? method.DeclaringTypeDefinition.Name : method.Name))), false); - } - - protected override string GetOperatorString (IMethod method, OutputSettings settings) - { - return InternalGetMethodString (method, settings, settings.EmitName (method, Format (FilterName (method.Name))), true); - } - - protected override string GetFieldString (IField field, OutputSettings settings) - { - if (field == null) - return ""; - var result = new StringBuilder (); - bool isEnum = field.DeclaringTypeDefinition != null && field.DeclaringTypeDefinition.Kind == TypeKind.Enum; - AppendModifiers (result, settings, field); - - if (!settings.CompletionListFomat && settings.IncludeReturnType && !isEnum) { - result.Append (GetTypeReferenceString (field.ReturnType, settings)); - result.Append (settings.Markup (" ")); - } - - if (!settings.IncludeReturnType && settings.UseFullName) { - result.Append (GetTypeReferenceString (field.DeclaringTypeDefinition, settings)); - result.Append (settings.Markup (".")); - } - result.Append (settings.EmitName (field, FilterName (Format (field.Name)))); - - if (settings.CompletionListFomat && settings.IncludeReturnType && !isEnum) { - result.Append (settings.Markup (" : ")); - result.Append (GetTypeReferenceString (field.ReturnType, settings)); - } - return result.ToString (); - } - - protected override string GetEventString (IEvent evt, OutputSettings settings) - { - if (evt == null) - return ""; - var result = new StringBuilder (); - AppendModifiers (result, settings, evt); - if (settings.IncludeKeywords) - result.Append (settings.EmitKeyword ("event")); - if (!settings.CompletionListFomat && settings.IncludeReturnType) { - result.Append (GetTypeReferenceString (evt.ReturnType, settings)); - result.Append (settings.Markup (" ")); - } - - if (!settings.IncludeReturnType && settings.UseFullName) { - result.Append (GetTypeReferenceString (evt.DeclaringTypeDefinition, new OutputSettings (OutputFlags.UseFullName))); - result.Append (settings.Markup (".")); - } - - AppendExplicitInterfaces (result, evt, settings); - result.Append (settings.EmitName (evt, Format (FilterName (evt.Name)))); - - if (settings.CompletionListFomat && settings.IncludeReturnType) { - result.Append (settings.Markup (" : ")); - result.Append (GetTypeReferenceString (evt.ReturnType, settings)); - } - return result.ToString (); - } - - protected override string GetPropertyString (IProperty property, OutputSettings settings) - { - if (property == null) - return ""; - var result = new StringBuilder (); - AppendModifiers (result, settings, property); - if (!settings.CompletionListFomat && settings.IncludeReturnType) { - result.Append (GetTypeReferenceString (property.ReturnType, settings)); - result.Append (settings.Markup (" ")); - } - - if (!settings.IncludeReturnType && settings.UseFullName) { - result.Append (GetTypeReferenceString (property.DeclaringTypeDefinition, new OutputSettings (OutputFlags.UseFullName))); - result.Append (settings.Markup (".")); - } - - AppendExplicitInterfaces (result, property, settings); - - if (property.SymbolKind == SymbolKind.Indexer) { - result.Append (settings.EmitName (property, "this")); - } else { - result.Append (settings.EmitName (property, Format (FilterName (property.Name)))); - } - - if (settings.IncludeParameters && property.Parameters.Count > 0) { - result.Append (settings.Markup ("[")); - AppendParameterList (result, settings, property.Parameters); - result.Append (settings.Markup ("]")); - } - - if (settings.CompletionListFomat && settings.IncludeReturnType) { - result.Append (settings.Markup (" : ")); - result.Append (GetTypeReferenceString (property.ReturnType, settings)); - } - - if (settings.IncludeAccessor) { - result.Append (settings.Markup (" {")); - if (property.CanGet) - result.Append (settings.Markup (" get;")); - if (property.CanSet) - result.Append (settings.Markup (" set;")); - result.Append (settings.Markup (" }")); - } - - return result.ToString (); - } - - protected override string GetIndexerString (IProperty property, OutputSettings settings) - { - if (property == null) - return ""; - var result = new StringBuilder (); - - AppendModifiers (result, settings, property); - - if (settings.IncludeReturnType) { - result.Append (GetTypeReferenceString (property.ReturnType, settings)); - result.Append (settings.Markup (" ")); - } - - if (!settings.IncludeReturnType && settings.UseFullName) { - result.Append (GetTypeReferenceString (property.DeclaringTypeDefinition, new OutputSettings (OutputFlags.UseFullName))); - result.Append (settings.Markup (".")); - } - - AppendExplicitInterfaces (result, property, settings); - - result.Append (settings.EmitName (property, Format ("this"))); - - if (settings.IncludeParameters && property.Getter.Parameters.Count > 0) { - result.Append (settings.Markup ("[")); - AppendParameterList (result, settings, property.Getter.Parameters); - result.Append (settings.Markup ("]")); - } - if (settings.IncludeAccessor) { - result.Append (settings.Markup (" {")); - if (property.CanGet) - result.Append (settings.Markup (" get;")); - if (property.CanSet) - result.Append (settings.Markup (" set;")); - result.Append (settings.Markup (" }")); - } - return result.ToString (); - } - - protected override string GetParameterString (IParameterizedMember member, IParameter parameter, OutputSettings settings) - { - if (parameter == null) - return ""; - var result = new StringBuilder (); - if (settings.IncludeParameterName) { - if (settings.IncludeModifiers) { - if (parameter.IsOut) { - result.Append (settings.EmitKeyword ("out")); - } - if (parameter.IsRef) { - result.Append (settings.EmitKeyword ("ref")); - } - if (parameter.IsParams) { - result.Append (settings.EmitKeyword ("params")); - } - } - - result.Append (GetTypeReferenceString (parameter.Type, settings)); - result.Append (" "); - - if (settings.HighlightName) { - result.Append (settings.EmitName (parameter, settings.Highlight (Format (FilterName (parameter.Name))))); - } else { - result.Append (settings.EmitName (parameter, Format (FilterName (parameter.Name)))); - } - } else { - result.Append (GetTypeReferenceString (parameter.Type, settings)); - } - return result.ToString (); - } - - #endregion - - void AppendExplicitInterfaces (StringBuilder sb, IMember member, OutputSettings settings) - { - if (member == null || !member.IsExplicitInterfaceImplementation) - return; - foreach (var implementedInterfaceMember in member.ImplementedInterfaceMembers) { - if (settings.UseFullName) { - sb.Append (Format (implementedInterfaceMember.DeclaringTypeDefinition.FullName)); - } else { - sb.Append (Format (implementedInterfaceMember.DeclaringTypeDefinition.Name)); - } - sb.Append (settings.Markup (".")); - } - } - - void AppendParameterList (StringBuilder result, OutputSettings settings, IEnumerable<IParameter> parameterList) - { - if (parameterList == null) - return; - - bool first = true; - foreach (var parameter in parameterList) { - if (!first) - result.Append (settings.Markup (", ")); - AppendParameter (settings, result, parameter); - first = false; - } - } - - void AppendParameter (OutputSettings settings, StringBuilder result, IParameter parameter) - { - if (parameter == null) - return; - if (parameter.IsOut) { - result.Append (settings.Markup ("out")); - result.Append (settings.Markup (" ")); - } else if (parameter.IsRef) { - result.Append (settings.Markup ("ref")); - result.Append (settings.Markup (" ")); - } else if (parameter.IsParams) { - result.Append (settings.Markup ("params")); - result.Append (settings.Markup (" ")); - } - result.Append (GetParameterString (null, parameter, settings)); - } - - void AppendModifiers (StringBuilder result, OutputSettings settings, IEntity entity) - { - if (!settings.IncludeModifiers) - return; - if (entity.IsStatic) - result.Append (settings.EmitModifiers ("static")); - if (entity.IsSealed) - result.Append (settings.EmitModifiers ("sealed")); - if (entity.IsAbstract) - result.Append (settings.EmitModifiers ("abstract")); - if (entity.IsShadowing) - result.Append (settings.EmitModifiers ("new")); - - switch (entity.Accessibility) { - case Accessibility.Internal: - result.Append (settings.EmitModifiers ("internal")); - break; - case Accessibility.ProtectedAndInternal: - result.Append (settings.EmitModifiers ("protected internal")); - break; - case Accessibility.ProtectedOrInternal: - result.Append (settings.EmitModifiers ("internal protected")); - break; - case Accessibility.Protected: - result.Append (settings.EmitModifiers ("protected")); - break; - case Accessibility.Private: - result.Append (settings.EmitModifiers ("private")); - break; - case Accessibility.Public: - result.Append (settings.EmitModifiers ("public")); - break; - } - } +// } +// +// if (!settings.IncludeReturnType && settings.UseFullName) { +// result.Append (GetTypeReferenceString (method.DeclaringTypeDefinition, new OutputSettings (OutputFlags.UseFullName))); +// result.Append (settings.Markup (".")); +// } +// AppendExplicitInterfaces (result, method, settings); +// if (method.SymbolKind == SymbolKind.Operator) { +// result.Append ("operator "); +// result.Append (settings.Markup (GetOperator (methodName))); +// } else { +// result.Append (methodName); +// } +// +// if (settings.IncludeGenerics) { +// if (method.TypeParameters.Count > 0) { +// result.Append (settings.Markup ("<")); +// for (int i = 0; i < method.TypeParameters.Count; i++) { +// if (i > 0) +// result.Append (settings.Markup (settings.HideGenericParameterNames ? "," : ", ")); +// if (!settings.HideGenericParameterNames) { +// AppendVariance (result, method.TypeParameters [i].Variance); +// result.Append (NetToCSharpTypeName (method.TypeParameters [i].Name)); +// } +// } +// result.Append (settings.Markup (">")); +// } +// } +// +// if (settings.IncludeParameters) { +//// CSharpFormattingPolicy policy = GetPolicy (settings); +//// if (policy.BeforeMethodCallParentheses) +//// result.Append (settings.Markup (" ")); +// result.Append (settings.Markup ("(")); +// AppendParameterList (result, settings, method.Parameters); +// result.Append (settings.Markup (")")); +// } +// +// if (settings.CompletionListFomat && settings.IncludeReturnType && getReturnType) { +// result.Append (settings.Markup (" : ")); +// result.Append (GetTypeReferenceString (method.ReturnType, settings)); +// } +// +//// OutputConstraints (result, settings, method.TypeParameters); +// +// return result.ToString (); +// } +// +// protected override string GetMethodString (IMethod method, OutputSettings settings) +// { +// return InternalGetMethodString (method, settings, settings.EmitName (method, Format (FilterName (method.SymbolKind == SymbolKind.Constructor || method.SymbolKind == SymbolKind.Destructor ? method.DeclaringTypeDefinition.Name : method.Name))), true); +// } +// +// protected override string GetConstructorString (IMethod method, OutputSettings settings) +// { +// return InternalGetMethodString (method, settings, settings.EmitName (method, Format (FilterName (method.DeclaringTypeDefinition != null ? method.DeclaringTypeDefinition.Name : method.Name))), false); +// } +// +// protected override string GetDestructorString (IMethod method, OutputSettings settings) +// { +// return InternalGetMethodString (method, settings, settings.EmitName (method, settings.Markup ("~") + Format (FilterName (method.DeclaringTypeDefinition != null ? method.DeclaringTypeDefinition.Name : method.Name))), false); +// } +// +// protected override string GetOperatorString (IMethod method, OutputSettings settings) +// { +// return InternalGetMethodString (method, settings, settings.EmitName (method, Format (FilterName (method.Name))), true); +// } +// +// protected override string GetFieldString (IField field, OutputSettings settings) +// { +// if (field == null) +// return ""; +// var result = new StringBuilder (); +// bool isEnum = field.DeclaringTypeDefinition != null && field.DeclaringTypeDefinition.Kind == TypeKind.Enum; +// AppendModifiers (result, settings, field); +// +// if (!settings.CompletionListFomat && settings.IncludeReturnType && !isEnum) { +// result.Append (GetTypeReferenceString (field.ReturnType, settings)); +// result.Append (settings.Markup (" ")); +// } +// +// if (!settings.IncludeReturnType && settings.UseFullName) { +// result.Append (GetTypeReferenceString (field.DeclaringTypeDefinition, settings)); +// result.Append (settings.Markup (".")); +// } +// result.Append (settings.EmitName (field, FilterName (Format (field.Name)))); +// +// if (settings.CompletionListFomat && settings.IncludeReturnType && !isEnum) { +// result.Append (settings.Markup (" : ")); +// result.Append (GetTypeReferenceString (field.ReturnType, settings)); +// } +// return result.ToString (); +// } +// +// protected override string GetEventString (IEvent evt, OutputSettings settings) +// { +// if (evt == null) +// return ""; +// var result = new StringBuilder (); +// AppendModifiers (result, settings, evt); +// if (settings.IncludeKeywords) +// result.Append (settings.EmitKeyword ("event")); +// if (!settings.CompletionListFomat && settings.IncludeReturnType) { +// result.Append (GetTypeReferenceString (evt.ReturnType, settings)); +// result.Append (settings.Markup (" ")); +// } +// +// if (!settings.IncludeReturnType && settings.UseFullName) { +// result.Append (GetTypeReferenceString (evt.DeclaringTypeDefinition, new OutputSettings (OutputFlags.UseFullName))); +// result.Append (settings.Markup (".")); +// } +// +// AppendExplicitInterfaces (result, evt, settings); +// result.Append (settings.EmitName (evt, Format (FilterName (evt.Name)))); +// +// if (settings.CompletionListFomat && settings.IncludeReturnType) { +// result.Append (settings.Markup (" : ")); +// result.Append (GetTypeReferenceString (evt.ReturnType, settings)); +// } +// return result.ToString (); +// } +// +// protected override string GetPropertyString (IProperty property, OutputSettings settings) +// { +// if (property == null) +// return ""; +// var result = new StringBuilder (); +// AppendModifiers (result, settings, property); +// if (!settings.CompletionListFomat && settings.IncludeReturnType) { +// result.Append (GetTypeReferenceString (property.ReturnType, settings)); +// result.Append (settings.Markup (" ")); +// } +// +// if (!settings.IncludeReturnType && settings.UseFullName) { +// result.Append (GetTypeReferenceString (property.DeclaringTypeDefinition, new OutputSettings (OutputFlags.UseFullName))); +// result.Append (settings.Markup (".")); +// } +// +// AppendExplicitInterfaces (result, property, settings); +// +// if (property.SymbolKind == SymbolKind.Indexer) { +// result.Append (settings.EmitName (property, "this")); +// } else { +// result.Append (settings.EmitName (property, Format (FilterName (property.Name)))); +// } +// +// if (settings.IncludeParameters && property.Parameters.Count > 0) { +// result.Append (settings.Markup ("[")); +// AppendParameterList (result, settings, property.Parameters); +// result.Append (settings.Markup ("]")); +// } +// +// if (settings.CompletionListFomat && settings.IncludeReturnType) { +// result.Append (settings.Markup (" : ")); +// result.Append (GetTypeReferenceString (property.ReturnType, settings)); +// } +// +// if (settings.IncludeAccessor) { +// result.Append (settings.Markup (" {")); +// if (property.CanGet) +// result.Append (settings.Markup (" get;")); +// if (property.CanSet) +// result.Append (settings.Markup (" set;")); +// result.Append (settings.Markup (" }")); +// } +// +// return result.ToString (); +// } +// +// protected override string GetIndexerString (IProperty property, OutputSettings settings) +// { +// if (property == null) +// return ""; +// var result = new StringBuilder (); +// +// AppendModifiers (result, settings, property); +// +// if (settings.IncludeReturnType) { +// result.Append (GetTypeReferenceString (property.ReturnType, settings)); +// result.Append (settings.Markup (" ")); +// } +// +// if (!settings.IncludeReturnType && settings.UseFullName) { +// result.Append (GetTypeReferenceString (property.DeclaringTypeDefinition, new OutputSettings (OutputFlags.UseFullName))); +// result.Append (settings.Markup (".")); +// } +// +// AppendExplicitInterfaces (result, property, settings); +// +// result.Append (settings.EmitName (property, Format ("this"))); +// +// if (settings.IncludeParameters && property.Getter.Parameters.Count > 0) { +// result.Append (settings.Markup ("[")); +// AppendParameterList (result, settings, property.Getter.Parameters); +// result.Append (settings.Markup ("]")); +// } +// if (settings.IncludeAccessor) { +// result.Append (settings.Markup (" {")); +// if (property.CanGet) +// result.Append (settings.Markup (" get;")); +// if (property.CanSet) +// result.Append (settings.Markup (" set;")); +// result.Append (settings.Markup (" }")); +// } +// return result.ToString (); +// } +// +// protected override string GetParameterString (IParameterizedMember member, IParameter parameter, OutputSettings settings) +// { +// if (parameter == null) +// return ""; +// var result = new StringBuilder (); +// if (settings.IncludeParameterName) { +// if (settings.IncludeModifiers) { +// if (parameter.IsOut) { +// result.Append (settings.EmitKeyword ("out")); +// } +// if (parameter.IsRef) { +// result.Append (settings.EmitKeyword ("ref")); +// } +// if (parameter.IsParams) { +// result.Append (settings.EmitKeyword ("params")); +// } +// } +// +// result.Append (GetTypeReferenceString (parameter.Type, settings)); +// result.Append (" "); +// +// if (settings.HighlightName) { +// result.Append (settings.EmitName (parameter, settings.Highlight (Format (FilterName (parameter.Name))))); +// } else { +// result.Append (settings.EmitName (parameter, Format (FilterName (parameter.Name)))); +// } +// } else { +// result.Append (GetTypeReferenceString (parameter.Type, settings)); +// } +// return result.ToString (); +// } +// +// #endregion +// +// void AppendExplicitInterfaces (StringBuilder sb, IMember member, OutputSettings settings) +// { +// if (member == null || !member.IsExplicitInterfaceImplementation) +// return; +// foreach (var implementedInterfaceMember in member.ImplementedInterfaceMembers) { +// if (settings.UseFullName) { +// sb.Append (Format (implementedInterfaceMember.DeclaringTypeDefinition.FullName)); +// } else { +// sb.Append (Format (implementedInterfaceMember.DeclaringTypeDefinition.Name)); +// } +// sb.Append (settings.Markup (".")); +// } +// } +// +// void AppendParameterList (StringBuilder result, OutputSettings settings, IEnumerable<IParameter> parameterList) +// { +// if (parameterList == null) +// return; +// +// bool first = true; +// foreach (var parameter in parameterList) { +// if (!first) +// result.Append (settings.Markup (", ")); +// AppendParameter (settings, result, parameter); +// first = false; +// } +// } +// +// void AppendParameter (OutputSettings settings, StringBuilder result, IParameter parameter) +// { +// if (parameter == null) +// return; +// if (parameter.IsOut) { +// result.Append (settings.Markup ("out")); +// result.Append (settings.Markup (" ")); +// } else if (parameter.IsRef) { +// result.Append (settings.Markup ("ref")); +// result.Append (settings.Markup (" ")); +// } else if (parameter.IsParams) { +// result.Append (settings.Markup ("params")); +// result.Append (settings.Markup (" ")); +// } +// result.Append (GetParameterString (null, parameter, settings)); +// } +// +// void AppendModifiers (StringBuilder result, OutputSettings settings, IEntity entity) +// { +// if (!settings.IncludeModifiers) +// return; +// if (entity.IsStatic) +// result.Append (settings.EmitModifiers ("static")); +// if (entity.IsSealed) +// result.Append (settings.EmitModifiers ("sealed")); +// if (entity.IsAbstract) +// result.Append (settings.EmitModifiers ("abstract")); +// if (entity.IsShadowing) +// result.Append (settings.EmitModifiers ("new")); +// +// switch (entity.Accessibility) { +// case Accessibility.Internal: +// result.Append (settings.EmitModifiers ("internal")); +// break; +// case Accessibility.ProtectedAndInternal: +// result.Append (settings.EmitModifiers ("protected internal")); +// break; +// case Accessibility.ProtectedOrInternal: +// result.Append (settings.EmitModifiers ("internal protected")); +// break; +// case Accessibility.Protected: +// result.Append (settings.EmitModifiers ("protected")); +// break; +// case Accessibility.Private: +// result.Append (settings.EmitModifiers ("private")); +// break; +// case Accessibility.Public: +// result.Append (settings.EmitModifiers ("public")); +// break; +// } +// } } - + } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpLanguageBinding.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpLanguageBinding.cs index eab17d4f76..b6a3c101b3 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpLanguageBinding.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/CSharpLanguageBinding.cs @@ -41,7 +41,6 @@ using MonoDevelop.Core; using MonoDevelop.Core.Instrumentation; using MonoDevelop.CSharp.Parser; -using ICSharpCode.NRefactory.CSharp; using MonoDevelop.CSharp.Formatting; using MonoDevelop.CSharp.Project; diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/ExpandSelectionHandler.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/ExpandSelectionHandler.cs index a09c5ecf26..95595339d0 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/ExpandSelectionHandler.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/ExpandSelectionHandler.cs @@ -24,10 +24,10 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; -using ICSharpCode.NRefactory.CSharp; using MonoDevelop.Components.Commands; using MonoDevelop.Ide; using System.Collections.Generic; +using Microsoft.CodeAnalysis; namespace MonoDevelop.CSharp { @@ -39,68 +39,99 @@ namespace MonoDevelop.CSharp class ExpandSelectionHandler : CommandHandler { + internal class ExpandSelectionAnnotation + { + readonly MonoDevelop.Ide.Editor.TextEditor editor; + + public Stack<SyntaxNode> Stack = new Stack<SyntaxNode> (); + + public ExpandSelectionAnnotation (MonoDevelop.Ide.Editor.TextEditor editor) + { + this.editor = editor; + editor.CaretPositionChanged += Editor_CaretPositionChanged; + } + + void Editor_CaretPositionChanged (object sender, EventArgs e) + { + editor.CaretPositionChanged -= Editor_CaretPositionChanged; + Stack = null; + editor.RemoveAnnotations<ExpandSelectionAnnotation> (); + } + } + + internal static ExpandSelectionAnnotation GetSelectionAnnotation (MonoDevelop.Ide.Editor.TextEditor editor) + { + var result = editor.Annotation<ExpandSelectionAnnotation> (); + if (result == null) { + result = new ExpandSelectionAnnotation (editor); + editor.AddAnnotation (result); + } + return result; + } + protected override void Run () { var doc = IdeApp.Workbench.ActiveDocument; if (doc == null) return; + var selectionRange = doc.Editor.SelectionRange; var parsedDocument = doc.ParsedDocument; if (parsedDocument == null) return; - var unit = parsedDocument.GetAst<SyntaxTree> (); - if (unit == null) + var model = parsedDocument.GetAst<SemanticModel> (); + if (model == null) return; - var node = unit.GetNodeAt (doc.Editor.Caret.Location); + var unit = model.SyntaxTree.GetRoot (); + var node = unit.FindNode (Microsoft.CodeAnalysis.Text.TextSpan.FromBounds (selectionRange.Offset, selectionRange.EndOffset)); if (node == null) return; if (doc.Editor.IsSomethingSelected) { - while (node != null && doc.Editor.MainSelection.IsSelected (node.StartLocation, node.EndLocation)) { + while (node != null && ShrinkSelectionHandler.IsSelected (doc.Editor, node.Span)) { node = node.Parent; } } - - if (node != null) - doc.Editor.SetSelection (node.StartLocation, node.EndLocation); + + if (node != null) { + var selectionAnnotation = GetSelectionAnnotation (doc.Editor); + selectionAnnotation.Stack.Push (node); + doc.Editor.SetSelection (node.SpanStart, node.Span.End); + } } } class ShrinkSelectionHandler : CommandHandler { - protected override void Run () + internal static bool IsSelected (MonoDevelop.Ide.Editor.TextEditor editor, Microsoft.CodeAnalysis.Text.TextSpan span) + { + var selection = editor.SelectionRange; + return selection.Offset == span.Start && selection.Length == span.Length; + } + + protected async override void Run () { var doc = IdeApp.Workbench.ActiveDocument; - var parsedDocument = doc.ParsedDocument; + if (doc == null) + return; + var selectionRange = doc.Editor.CaretOffset; + var analysisDocument = doc.AnalysisDocument; + if (analysisDocument == null) + return; + var parsedDocument = await analysisDocument.GetSyntaxTreeAsync (); if (parsedDocument == null) return; - var unit = parsedDocument.GetAst<SyntaxTree> (); + var unit = parsedDocument.GetRoot (); if (unit == null) return; - var node = unit.GetNodeAt (doc.Editor.Caret.Line, doc.Editor.Caret.Column); - if (node == null) - return; - var nodeStack = new Stack<AstNode> (); - nodeStack.Push (node); - if (doc.Editor.IsSomethingSelected) { - while (node != null && doc.Editor.MainSelection.IsSelected (node.StartLocation, node.EndLocation)) { - node = node.Parent; - if (node != null) { - if (nodeStack.Count > 0 && nodeStack.Peek ().StartLocation == node.StartLocation && nodeStack.Peek ().EndLocation == node.EndLocation) - nodeStack.Pop (); - nodeStack.Push (node); - } - } - } - - if (nodeStack.Count > 2) { - nodeStack.Pop (); // parent - nodeStack.Pop (); // current node - node = nodeStack.Pop (); // next children in which the caret is - doc.Editor.SetSelection (node.StartLocation, node.EndLocation); + + var selectionAnnotation = ExpandSelectionHandler.GetSelectionAnnotation (doc.Editor); + selectionAnnotation.Stack.Pop (); + if (selectionAnnotation.Stack.Count > 0) { + var node = selectionAnnotation.Stack.Peek (); + doc.Editor.SetSelection (node.SpanStart, node.Span.End); } else { doc.Editor.ClearSelection (); } } } -} - +}
\ No newline at end of file diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/PathedDocumentTextEditorExtension.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/PathedDocumentTextEditorExtension.cs index 4484afcad9..fe409ae573 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/PathedDocumentTextEditorExtension.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/PathedDocumentTextEditorExtension.cs @@ -27,16 +27,20 @@ using System; using MonoDevelop.Ide.Gui.Content; using MonoDevelop.Components; using System.Collections.Generic; -using ICSharpCode.NRefactory.TypeSystem; using MonoDevelop.Ide.TypeSystem; using MonoDevelop.Ide.Gui; using MonoDevelop.Core; using MonoDevelop.CSharp.Completion; using System.Linq; using MonoDevelop.Ide; -using ICSharpCode.NRefactory.CSharp; using System.Text; +using MonoDevelop.Ide.Editor; +using MonoDevelop.Ide.Editor.Extension; using MonoDevelop.Projects; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Text; namespace MonoDevelop.CSharp { @@ -44,19 +48,19 @@ namespace MonoDevelop.CSharp { public override void Dispose () { + Editor.CaretPositionChanged -= UpdatePath; IdeApp.Workspace.FileAddedToProject -= HandleProjectChanged; IdeApp.Workspace.FileRemovedFromProject -= HandleProjectChanged; IdeApp.Workspace.WorkspaceItemUnloaded -= HandleWorkspaceItemUnloaded; - IdeApp.Workspace.WorkspaceItemLoaded -= HandleWorkspaceItemLoaded;; + IdeApp.Workspace.WorkspaceItemLoaded -= HandleWorkspaceItemLoaded; + IdeApp.Workspace.ItemAddedToSolution -= HandleProjectChanged; + - if (caret != null) { - caret.PositionChanged -= UpdatePath; - caret = null; - } if (ext != null) { ext.TypeSegmentTreeUpdated -= HandleTypeSegmentTreeUpdated; ext = null; } + currentPath = null; lastType = null; lastMember = null; @@ -64,12 +68,16 @@ namespace MonoDevelop.CSharp } bool isPathSet; - Mono.TextEditor.Caret caret; CSharpCompletionTextEditorExtension ext; List<DotNetProject> ownerProjects = new List<DotNetProject> (); - public override void Initialize () + public override bool IsValidInContext (DocumentContext context) + { + return context.GetContent<CSharpCompletionTextEditorExtension> () != null; + } + + protected override void Initialize () { CurrentPath = new PathEntry[] { new PathEntry (GettextCatalog.GetString ("No selection")) { Tag = null } }; isPathSet = false; @@ -79,14 +87,15 @@ namespace MonoDevelop.CSharp UpdateOwnerProjects (); UpdatePath (null, null); }); - caret = Document.Editor.Caret; - caret.PositionChanged += UpdatePath; - ext = Document.GetContent<CSharpCompletionTextEditorExtension> (); + Editor.CaretPositionChanged += UpdatePath; + ext = DocumentContext.GetContent<CSharpCompletionTextEditorExtension> (); ext.TypeSegmentTreeUpdated += HandleTypeSegmentTreeUpdated; + IdeApp.Workspace.FileAddedToProject += HandleProjectChanged; IdeApp.Workspace.FileRemovedFromProject += HandleProjectChanged; IdeApp.Workspace.WorkspaceItemUnloaded += HandleWorkspaceItemUnloaded; - IdeApp.Workspace.WorkspaceItemLoaded += HandleWorkspaceItemLoaded;; + IdeApp.Workspace.WorkspaceItemLoaded += HandleWorkspaceItemLoaded; + IdeApp.Workspace.ItemAddedToSolution += HandleProjectChanged; } void HandleWorkspaceItemLoaded (object sender, WorkspaceItemEventArgs e) @@ -105,11 +114,11 @@ namespace MonoDevelop.CSharp } if (ownerProjects.Count == 0) { ownerProjects = null; - Document.AttachToProject (null); + DocumentContext.AttachToProject (null); } } - void HandleProjectChanged (object sender, ProjectFileEventArgs e) + void HandleProjectChanged (object sender, EventArgs e) { UpdateOwnerProjects (); UpdatePath (null, null); @@ -122,16 +131,16 @@ namespace MonoDevelop.CSharp void UpdateOwnerProjects (IEnumerable<DotNetProject> allProjects) { - var projects = new HashSet<DotNetProject> (allProjects.Where (p => p.IsFileInProject (Document.FileName))); + var projects = new HashSet<DotNetProject> (allProjects.Where (p => p.IsFileInProject (DocumentContext.Name))); if (ownerProjects == null || !projects.SetEquals (ownerProjects)) { ownerProjects = projects.OrderBy (p => p.Name).ToList (); - var dnp = Document.Project as DotNetProject; + var dnp = DocumentContext.Project as DotNetProject; if (ownerProjects.Count > 0 && (dnp == null || !ownerProjects.Contains (dnp))) { // If the project for the document is not a DotNetProject but there is a project containing this file // in the current solution, then use that project - var pp = Document.Project != null ? ownerProjects.FirstOrDefault (p => p.ParentSolution == Document.Project.ParentSolution) : null; + var pp = DocumentContext.Project != null ? ownerProjects.FirstOrDefault (p => p.ParentSolution == DocumentContext.Project.ParentSolution) : null; if (pp != null) - Document.AttachToProject (pp); + DocumentContext.AttachToProject (pp); } } } @@ -139,8 +148,8 @@ namespace MonoDevelop.CSharp void UpdateOwnerProjects () { UpdateOwnerProjects (IdeApp.Workspace.GetAllItems<DotNetProject> ()); - if (Document.Project == null && ownerProjects.Count > 0) - Document.AttachToProject (ownerProjects[0]); + if (DocumentContext.Project == null && ownerProjects.Count > 0) + DocumentContext.AttachToProject (ownerProjects[0]); } #region IPathedDocument implementation @@ -158,7 +167,7 @@ namespace MonoDevelop.CSharp { readonly PathedDocumentTextEditorExtension ext; object tag; - List<AstNode> memberList = new List<AstNode> (); + List<SyntaxNode> memberList = new List<SyntaxNode> (); public DataProvider (PathedDocumentTextEditorExtension ext, object tag) { @@ -171,17 +180,14 @@ namespace MonoDevelop.CSharp #region IListDataProvider implementation - void AddTypeToMemberList (TypeDeclaration type) + void AddTypeToMemberList (TypeDeclarationSyntax type) { foreach (var member in type.Members) { - if (member is FieldDeclaration) { - foreach (var variable in ((FieldDeclaration)member).Variables) - memberList.Add (variable); - } else if (member is FixedFieldDeclaration) { - foreach (var variable in ((FixedFieldDeclaration)member).Variables) + if (member is FieldDeclarationSyntax) { + foreach (var variable in ((FieldDeclarationSyntax)member).Declaration.Variables) memberList.Add (variable); - } else if (member is EventDeclaration) { - foreach (var variable in ((EventDeclaration)member).Variables) + } else if (member is EventFieldDeclarationSyntax) { + foreach (var variable in ((EventFieldDeclarationSyntax)member).Declaration.Variables) memberList.Add (variable); } else { memberList.Add (member); @@ -194,16 +200,16 @@ namespace MonoDevelop.CSharp memberList.Clear (); if (tag is SyntaxTree) { var unit = tag as SyntaxTree; - memberList.AddRange (unit.GetTypes (true)); - } else if (tag is TypeDeclaration) { - AddTypeToMemberList ((TypeDeclaration)tag); - } else if (tag is Accessor) { - var acc = (Accessor)tag; - var parent = (EntityDeclaration)acc.Parent; - memberList.AddRange (parent.Children.OfType<Accessor> ()); - } else if (tag is EntityDeclaration) { - var entity = (EntityDeclaration)tag; - var type = entity.Parent as TypeDeclaration; + memberList.AddRange (unit.GetRoot ().DescendantNodes ().OfType<TypeDeclarationSyntax> ()); + } else if (tag is TypeDeclarationSyntax) { + AddTypeToMemberList ((TypeDeclarationSyntax)tag); + } else if (tag is AccessorDeclarationSyntax) { + var acc = (AccessorDeclarationSyntax)tag; + var parent = (MemberDeclarationSyntax)acc.Parent; + memberList.AddRange (parent.ChildNodes ().OfType<AccessorDeclarationSyntax> ()); + } else if (tag is MemberDeclarationSyntax) { + var entity = (MemberDeclarationSyntax)tag; + var type = entity.Parent as TypeDeclarationSyntax; if (type != null) { AddTypeToMemberList (type); } @@ -217,74 +223,77 @@ namespace MonoDevelop.CSharp result = GetParameters (x).CompareTo (GetParameters (y)); // partial methods without body should come last - if (result == 0 && x is MethodDeclaration && y is MethodDeclaration) { - var mx = x as MethodDeclaration; - var my = y as MethodDeclaration; - if (mx.Body.IsNull && !my.Body.IsNull) + if (result == 0 && x is MethodDeclarationSyntax && y is MethodDeclarationSyntax) { + var mx = x as MethodDeclarationSyntax; + var my = y as MethodDeclarationSyntax; + if (mx.Body == null && my.Body != null) return 1; - if (!mx.Body.IsNull && my.Body.IsNull) + if (mx.Body != null && my.Body == null) return -1; } return result; }); } - static int GetTypeParameters (AstNode x) + static int GetTypeParameters (SyntaxNode x) { - return x.GetChildrenByRole (Roles.TypeParameter).Count (); + return 0; //x.GetChildrenByRole (Roles.TypeParameter).Count (); } - static int GetParameters (AstNode x) + static int GetParameters (SyntaxNode x) { - return x.GetChildrenByRole (Roles.Parameter).Count (); + return 0; // x.GetChildrenByRole (Roles.Parameter).Count (); } - string GetName (AstNode node) + string GetName (SyntaxNode node) { if (tag is SyntaxTree) { - var type = node as TypeDeclaration; + var type = node as TypeDeclarationSyntax; if (type != null) { var sb = new StringBuilder (); - sb.Append (type.Name); - while (type.Parent is TypeDeclaration) { - type = type.Parent as TypeDeclaration; - sb.Insert (0, type.Name + "."); + sb.Append (type.Identifier.ToString ()); + while (type.Parent is TypeDeclarationSyntax) { + type = type.Parent as TypeDeclarationSyntax; + sb.Insert (0, type.Identifier + "."); } return sb.ToString (); } - var delegateDecl = node as DelegateDeclaration; + var delegateDecl = node as DelegateDeclarationSyntax; if (delegateDecl != null) { var sb = new StringBuilder (); - sb.Append (delegateDecl.Name); - var parentType = delegateDecl.Parent as TypeDeclaration; + sb.Append (delegateDecl.Identifier.ToString ()); + var parentType = delegateDecl.Parent as TypeDeclarationSyntax; while (parentType != null) { - sb.Insert (0, parentType.Name + "."); - parentType = parentType.Parent as TypeDeclaration; + sb.Insert (0, parentType.Identifier + "."); + parentType = parentType.Parent as TypeDeclarationSyntax; } return sb.ToString (); } } - if (node is Accessor) { - if (node.Role == PropertyDeclaration.GetterRole) + var accessor = node as AccessorDeclarationSyntax; + if (accessor != null) { + if (accessor.Kind () == SyntaxKind.GetAccessorDeclaration) return "get"; - if (node.Role == PropertyDeclaration.SetterRole) + if (accessor.Kind () == SyntaxKind.SetAccessorDeclaration) return "set"; - if (node.Role == CustomEventDeclaration.AddAccessorRole) + if (accessor.Kind () == SyntaxKind.AddAccessorDeclaration) return "add"; - if (node.Role == CustomEventDeclaration.RemoveAccessorRole) + if (accessor.Kind () == SyntaxKind.RemoveAccessorDeclaration) return "remove"; return node.ToString (); } - if (node is OperatorDeclaration) + if (node is OperatorDeclarationSyntax) return "operator"; - if (node is EntityDeclaration) - return ((EntityDeclaration)node).Name; - if (node is FixedVariableInitializer) { - return ((FixedVariableInitializer)node).Name; - } - return ((VariableInitializer)node).Name; + if (node is MemberDeclarationSyntax) + return ((MemberDeclarationSyntax)node).ToString (); +// if (node is fixeds) { +// return ((FixedVariableInitializer)node).Name; +// } + if (node is VariableDeclaratorSyntax) + return ((VariableDeclaratorSyntax)node).Identifier.ToString (); + return node.ToString (); } public string GetMarkup (int n) @@ -299,7 +308,7 @@ namespace MonoDevelop.CSharp if (type != null) { var sb = new StringBuilder (); sb.Append (ext.GetEntityMarkup (type)); - while (type.Parent is TypeDeclaration) { + while (type.Parent is TypeDeclarationSyntax) { sb.Insert (0, ext.GetEntityMarkup (type.Parent) + "."); type = type.Parent; } @@ -316,10 +325,10 @@ namespace MonoDevelop.CSharp icon = ext.ownerProjects [n].StockIcon; } else { var node = memberList [n]; - if (node is EntityDeclaration) { - icon = ((EntityDeclaration)node).GetStockIcon (); + if (node is MemberDeclarationSyntax) { + icon = ((MemberDeclarationSyntax)node).GetStockIcon (); } else { - icon = ((EntityDeclaration)node.Parent).GetStockIcon (); + icon = node.Parent.GetStockIcon (); } } return ImageService.GetIcon (icon, Gtk.IconSize.Menu); @@ -336,26 +345,20 @@ namespace MonoDevelop.CSharp public void ActivateItem (int n) { if (tag is DotNetProject) { - ext.Document.AttachToProject (ext.ownerProjects [n]); + ext.DocumentContext.AttachToProject (ext.ownerProjects [n]); } else { var node = memberList [n]; - var extEditor = ext.Document.GetContent<IExtensibleTextEditor> (); + var extEditor = ext.DocumentContext.GetContent<TextEditor> (); if (extEditor != null) { - int line, col; - if (node is OperatorDeclaration) { - line = Math.Max (1, ((OperatorDeclaration)node).OperatorToken.StartLocation.Line); - col = Math.Max (1, ((OperatorDeclaration)node).OperatorToken.StartLocation.Column); - } else if (node is IndexerDeclaration) { - line = Math.Max (1, ((IndexerDeclaration)node).ThisToken.StartLocation.Line); - col = Math.Max (1, ((IndexerDeclaration)node).ThisToken.StartLocation.Column); - } else if (node is EntityDeclaration && !(node is Accessor)) { - line = Math.Max (1, ((EntityDeclaration)node).NameToken.StartLocation.Line); - col = Math.Max (1, ((EntityDeclaration)node).NameToken.StartLocation.Column); + int offset; + if (node is OperatorDeclarationSyntax) { + offset = Math.Max (1, ((OperatorDeclarationSyntax)node).OperatorToken.SpanStart); + } else if (node is MemberDeclarationSyntax && !(node is AccessorDeclarationSyntax)) { + offset = Math.Max (1, ((MemberDeclarationSyntax)node).SpanStart); } else { - line = node.StartLocation.Line; - col = node.StartLocation.Column; + offset = node.SpanStart; } - extEditor.SetCaretTo (line, col); + extEditor.SetCaretLocation (extEditor.OffsetToLocation (offset), true); } } } @@ -375,14 +378,17 @@ namespace MonoDevelop.CSharp class CompilationUnitDataProvider : DropDownBoxListWindow.IListDataProvider { - Document Document { + TextEditor editor; + + DocumentContext DocumentContext { get; set; } - public CompilationUnitDataProvider (Document document) + public CompilationUnitDataProvider (TextEditor editor, DocumentContext documentContext) { - this.Document = document; + this.editor = editor; + this.DocumentContext = documentContext; } #region IListDataProvider implementation @@ -393,7 +399,7 @@ namespace MonoDevelop.CSharp public string GetMarkup (int n) { - return GLib.Markup.EscapeText (Document.ParsedDocument.UserRegions.ElementAt (n).Name); + return GLib.Markup.EscapeText (DocumentContext.ParsedDocument.GetUserRegionsAsync().Result.ElementAt (n).Name); } internal static Xwt.Drawing.Image Pixbuf { @@ -409,22 +415,23 @@ namespace MonoDevelop.CSharp public object GetTag (int n) { - return Document.ParsedDocument.UserRegions.ElementAt (n); + return DocumentContext.ParsedDocument.GetUserRegionsAsync().Result.ElementAt (n); } public void ActivateItem (int n) { - var reg = Document.ParsedDocument.UserRegions.ElementAt (n); - var extEditor = Document.GetContent<MonoDevelop.Ide.Gui.Content.IExtensibleTextEditor> (); - if (extEditor != null) - extEditor.SetCaretTo (Math.Max (1, reg.Region.BeginLine), reg.Region.BeginColumn); + var reg = DocumentContext.ParsedDocument.GetUserRegionsAsync().Result.ElementAt (n); + var extEditor = editor; + if (extEditor != null) { + extEditor.SetCaretLocation(Math.Max (1, reg.Region.BeginLine), reg.Region.BeginColumn, true); + } } public int IconCount { get { - if (Document.ParsedDocument == null) + if (DocumentContext.ParsedDocument == null) return 0; - return Document.ParsedDocument.UserRegions.Count (); + return DocumentContext.ParsedDocument.GetUserRegionsAsync().Result.Count (); } } @@ -438,7 +445,7 @@ namespace MonoDevelop.CSharp if (path == null || index < 0 || index >= path.Length) return null; var tag = path [index].Tag; - var window = new DropDownBoxListWindow (tag == null ? (DropDownBoxListWindow.IListDataProvider)new CompilationUnitDataProvider (Document) : new DataProvider (this, tag)); + var window = new DropDownBoxListWindow (tag == null ? (DropDownBoxListWindow.IListDataProvider)new CompilationUnitDataProvider (Editor, DocumentContext) : new DataProvider (this, tag)); window.FixedRowHeight = 22; window.MaxVisibleRows = 14; window.SelectItem (path [index].Tag); @@ -457,12 +464,19 @@ namespace MonoDevelop.CSharp } } - static PathEntry GetRegionEntry (ParsedDocument unit, Mono.TextEditor.DocumentLocation loc) + static PathEntry GetRegionEntry (ParsedDocument unit, DocumentLocation loc) { PathEntry entry; - if (!unit.UserRegions.Any ()) + FoldingRegion reg; + try { + if (unit == null || !unit.GetUserRegionsAsync ().Result.Any ()) + return null; + reg = unit.GetUserRegionsAsync ().Result.LastOrDefault (r => r.Region.Contains (loc)); + } catch (AggregateException) { return null; - var reg = unit.UserRegions.LastOrDefault (r => r.Region.IsInside (loc)); + } catch (OperationCanceledException) { + return null; + } if (reg == null) { entry = new PathEntry (GettextCatalog.GetString ("No region")); } else { @@ -480,59 +494,57 @@ namespace MonoDevelop.CSharp OnPathChanged (new DocumentPathChangedEventArgs (prev)); } - EntityDeclaration lastType; + SyntaxNode lastType; string lastTypeMarkup; - EntityDeclaration lastMember; + SyntaxNode lastMember; string lastMemberMarkup; MonoDevelop.Projects.Project lastProject; AstAmbience amb; - string GetEntityMarkup (AstNode node) + string GetEntityMarkup (SyntaxNode node) { - if (amb == null) + if (amb == null || node == null) return ""; return amb.GetEntityMarkup (node); } - void UpdatePath (object sender, Mono.TextEditor.DocumentLocationEventArgs e) + + void UpdatePath (object sender, EventArgs e) { - var parsedDocument = Document.ParsedDocument; - if (parsedDocument == null || parsedDocument.ParsedFile == null) + var parsedDocument = DocumentContext.ParsedDocument; + if (parsedDocument == null) return; - amb = new AstAmbience (document.GetFormattingOptions ()); + var caretOffset = Editor.CaretOffset; + var model = parsedDocument.GetAst<SemanticModel> (); + if (model == null) + return; + var unit = model.SyntaxTree; + amb = new AstAmbience (TypeSystemService.Workspace.Options); - var unit = parsedDocument.GetAst<SyntaxTree> (); - if (unit == null) + var loc = Editor.CaretLocation; +// var compExt = Editor.GetContent<CSharpCompletionTextEditorExtension> (); + + var root = unit.GetRoot (); + SyntaxNode token; + try { + token = root.FindNode (TextSpan.FromBounds (caretOffset, caretOffset)); + } catch (Exception) { return; - - var loc = Document.Editor.Caret.Location; - var compExt = Document.GetContent<CSharpCompletionTextEditorExtension> (); - var caretOffset = Document.Editor.Caret.Offset; - var segType = compExt.GetTypeAt (caretOffset); - if (segType != null) - loc = segType.Region.Begin; - - var curType = (EntityDeclaration)unit.GetNodeAt (loc, n => n is TypeDeclaration || n is DelegateDeclaration); - - var curProject = ownerProjects != null && ownerProjects.Count > 1 ? Document.Project : null; - - var segMember = compExt.GetMemberAt (caretOffset); - if (segMember != null) { - loc = segMember.Region.Begin; - } else { - loc = Document.Editor.Caret.Location; } + var curMember = token.AncestorsAndSelf ().FirstOrDefault (m => m is MemberDeclarationSyntax && !(m is NamespaceDeclarationSyntax)); + var curType = token.AncestorsAndSelf ().FirstOrDefault (m => m is TypeDeclarationSyntax || m is DelegateDeclarationSyntax); - var curMember = unit.GetNodeAt<EntityDeclaration> (loc); - if (curType == curMember || curType is DelegateDeclaration) + var curProject = ownerProjects != null && ownerProjects.Count > 1 ? DocumentContext.Project : null; + + if (curType == curMember || curType is DelegateDeclarationSyntax) curMember = null; if (isPathSet && curType == lastType && curMember == lastMember && curProject == lastProject) return; var curTypeMakeup = GetEntityMarkup (curType); var curMemberMarkup = GetEntityMarkup (curMember); - if (isPathSet && curType != null && lastType != null && curType.StartLocation == lastType.StartLocation && curTypeMakeup == lastTypeMarkup && - curMember != null && lastMember != null && curMember.StartLocation == lastMember.StartLocation && curMemberMarkup == lastMemberMarkup && curProject == lastProject) + if (isPathSet && curType != null && lastType != null && curTypeMakeup == lastTypeMarkup && + curMember != null && lastMember != null && curMemberMarkup == lastMemberMarkup && curProject == lastProject) return; lastType = curType; @@ -547,13 +559,13 @@ namespace MonoDevelop.CSharp if (ownerProjects != null && ownerProjects.Count > 1) { // Current project if there is more than one - result.Add (new PathEntry (ImageService.GetIcon (Document.Project.StockIcon, Gtk.IconSize.Menu), GLib.Markup.EscapeText (Document.Project.Name)) { Tag = Document.Project }); + result.Add (new PathEntry (ImageService.GetIcon (DocumentContext.Project.StockIcon, Gtk.IconSize.Menu), GLib.Markup.EscapeText (DocumentContext.Project.Name)) { Tag = DocumentContext.Project }); } if (curType == null) { - if (CurrentPath != null && CurrentPath.Length == 1 && CurrentPath [0].Tag is IUnresolvedFile) + if (CurrentPath != null && CurrentPath.Length == 1 && CurrentPath [0].Tag is CSharpSyntaxTree) return; - if (CurrentPath != null && CurrentPath.Length == 2 && CurrentPath [1].Tag is IUnresolvedFile) + if (CurrentPath != null && CurrentPath.Length == 2 && CurrentPath [1].Tag is CSharpSyntaxTree) return; var prevPath = CurrentPath; result.Add (new PathEntry (GettextCatalog.GetString ("No selection")) { Tag = unit }); @@ -566,29 +578,33 @@ namespace MonoDevelop.CSharp var type = curType; var pos = result.Count; while (type != null) { - var declaringType = type.Parent as TypeDeclaration; - result.Insert (pos, new PathEntry (ImageService.GetIcon (type.GetStockIcon (), Gtk.IconSize.Menu), GetEntityMarkup (type)) { Tag = (AstNode)declaringType ?? unit }); - type = declaringType; + if (!(type is TypeDeclarationSyntax)) + break; + result.Insert (pos, new PathEntry (ImageService.GetIcon (type.GetStockIcon (), Gtk.IconSize.Menu), GetEntityMarkup (type)) { Tag = (object)type ?? unit }); + type = type.Parent; } } if (curMember != null) { result.Add (new PathEntry (ImageService.GetIcon (curMember.GetStockIcon (), Gtk.IconSize.Menu), curMemberMarkup) { Tag = curMember }); - if (curMember is Accessor) { - var parent = curMember.Parent as EntityDeclaration; + if (curMember.Kind () == SyntaxKind.GetAccessorDeclaration || + curMember.Kind () == SyntaxKind.SetAccessorDeclaration || + curMember.Kind () == SyntaxKind.AddAccessorDeclaration || + curMember.Kind () == SyntaxKind.RemoveAccessorDeclaration) { + var parent = curMember.Parent; if (parent != null) result.Insert (result.Count - 1, new PathEntry (ImageService.GetIcon (parent.GetStockIcon (), Gtk.IconSize.Menu), GetEntityMarkup (parent)) { Tag = parent }); } } - var entry = GetRegionEntry (parsedDocument, loc); + var entry = GetRegionEntry (DocumentContext.ParsedDocument, loc); if (entry != null) result.Add (entry); PathEntry noSelection = null; if (curType == null) { noSelection = new PathEntry (GettextCatalog.GetString ("No selection")) { Tag = unit }; - } else if (curMember == null && !(curType is DelegateDeclaration)) { + } else if (curMember == null && !(curType is DelegateDeclarationSyntax)) { noSelection = new PathEntry (GettextCatalog.GetString ("No selection")) { Tag = curType }; } diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/SignatureMarkupCreator.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/SignatureMarkupCreator.cs index 4938335f00..c57f0e699d 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp/SignatureMarkupCreator.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp/SignatureMarkupCreator.cs @@ -26,31 +26,35 @@ using System; using MonoDevelop.Ide.TypeSystem; using System.Text; -using ICSharpCode.NRefactory.TypeSystem; -using ICSharpCode.NRefactory.CSharp.Refactoring; using System.IO; -using ICSharpCode.NRefactory.CSharp.Resolver; -using ICSharpCode.NRefactory.CSharp; -using ICSharpCode.NRefactory.TypeSystem.Implementation; using System.Collections.Generic; -using Mono.TextEditor.Highlighting; -using Mono.TextEditor; using System.Linq; using MonoDevelop.Core; using MonoDevelop.Ide.CodeCompletion; using MonoDevelop.Projects; -using ICSharpCode.NRefactory.Semantics; using System.ComponentModel; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Options; +using Microsoft.CodeAnalysis.Simplification; +using Microsoft.CodeAnalysis.CSharp.Formatting; +using System.Collections.Immutable; +using MonoDevelop.NUnit; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.CSharp; +using MonoDevelop.Ide.Editor; +using MonoDevelop.Components; +using MonoDevelop.Ide.Editor.Highlighting; +using ICSharpCode.NRefactory6.CSharp; namespace MonoDevelop.CSharp { class SignatureMarkupCreator { const double optionalAlpha = 0.7; - readonly CSharpResolver resolver; - readonly TypeSystemAstBuilder astBuilder; - readonly CSharpFormattingOptions formattingOptions; + readonly DocumentContext ctx; + readonly OptionSet options; readonly ColorScheme colorStyle; + readonly int offset; public bool BreakLineAfterReturnType { get; @@ -68,129 +72,148 @@ namespace MonoDevelop.CSharp } } - public SignatureMarkupCreator (CSharpResolver resolver, CSharpFormattingOptions formattingOptions) + public SignatureMarkupCreator (DocumentContext ctx, int offset) { + this.offset = offset; this.colorStyle = SyntaxModeService.GetColorStyle (MonoDevelop.Ide.IdeApp.Preferences.ColorScheme); - - this.resolver = resolver; - this.astBuilder = new TypeSystemAstBuilder (resolver) { - ConvertUnboundTypeArguments = true, - UseAliases = false - }; - this.formattingOptions = formattingOptions; + this.ctx = ctx; + if (ctx != null) { + if (ctx.ParsedDocument == null || ctx.AnalysisDocument == null) { + LoggingService.LogError ("Signature markup creator created with invalid context." + Environment.NewLine + Environment.StackTrace); + } + this.options = ctx.GetOptionSet (); + } else { + this.options = TypeSystemService.Workspace.Options; + } } - public string GetTypeReferenceString (IType type, bool highlight = true) + public string GetTypeReferenceString (ITypeSymbol type, bool highlight = true) { if (type == null) throw new ArgumentNullException ("type"); - if (type.Kind == TypeKind.Null) + if (type.TypeKind == TypeKind.Error) return "?"; - if (type.Kind == TypeKind.Array) { - var arrayType = (ArrayType)type; - return GetTypeReferenceString (arrayType.ElementType, highlight) + "[" + new string (',', arrayType.Dimensions - 1) + "]"; + if (type.TypeKind == TypeKind.Array) { + var arrayType = (IArrayTypeSymbol)type; + return GetTypeReferenceString (arrayType.ElementType, highlight) + "[" + new string (',', arrayType.Rank - 1) + "]"; } - if (type.Kind == TypeKind.Pointer) - return GetTypeReferenceString (((PointerType)type).ElementType, highlight) + "*"; - AstType astType; - try { - astType = astBuilder.ConvertType (type); - } catch (Exception e) { - var compilation = GetCompilation (type); - if (compilation == null) { - LoggingService.LogWarning ("type:" + type.GetType (), e); - return "?"; + if (type.TypeKind == TypeKind.Pointer) + return GetTypeReferenceString (((IPointerTypeSymbol)type).PointedAtType, highlight) + "*"; + string displayString; + + if (ctx != null) { + SemanticModel model = null; + var parsedDocument = ctx.ParsedDocument; + if (parsedDocument != null) { + model = parsedDocument.GetAst<SemanticModel> () ?? ctx.AnalysisDocument.GetSemanticModelAsync ().Result; } - astType = new TypeSystemAstBuilder (new CSharpResolver (compilation)).ConvertType (type); + //Math.Min (model.SyntaxTree.Length, offset)) is needed in case parsedDocument.GetAst<SemanticModel> () is outdated + //this is tradeoff between performance and consistency between editor text(offset) and model, since + //ToMinimalDisplayString can use little outdated model this is fine + //but in case of Sketches where user usually is at end of document when typing text this can throw exception + //because offset can be >= Length + displayString = model != null ? type.ToMinimalDisplayString (model, Math.Min (model.SyntaxTree.Length, offset)) : type.Name; + } else { + displayString = type.ToDisplayString (SymbolDisplayFormat.CSharpErrorMessageFormat); } - if (astType is PrimitiveType) { - return Highlight (astType.ToString (formattingOptions), colorStyle.KeywordTypes); - } - var text = AmbienceService.EscapeText (astType.ToString (formattingOptions)); + var text = Ambience.EscapeText (displayString); return highlight ? HighlightSemantically (text, colorStyle.UserTypes) : text; } - static ICompilation GetCompilation (IType type) - { - var def = type.GetDefinition (); - if (def == null) { - var t = type; - while (t is TypeWithElementType) { - t = ((TypeWithElementType)t).ElementType; - } - if (t != null) - def = t.GetDefinition (); - } - if (def != null) - return def.Compilation; - return null; - } - - public string GetMarkup (IType type) +// static ICompilation GetCompilation (IType type) +// { +// var def = type.GetDefinition (); +// if (def == null) { +// var t = type; +// while (t is TypeWithElementType) { +// t = ((TypeWithElementType)t).ElementType; +// } +// if (t != null) +// def = t.GetDefinition (); +// } +// if (def != null) +// return def.Compilation; +// return null; +// } + + public string GetMarkup (ITypeSymbol type) { if (type == null) throw new ArgumentNullException ("entity"); return GetTypeMarkup (type); } - public string GetMarkup (IEntity entity) + + public string GetMarkup (Microsoft.CodeAnalysis.ISymbol entity) { if (entity == null) throw new ArgumentNullException ("entity"); string result; - switch (entity.SymbolKind) { - case SymbolKind.TypeDefinition: - result = GetTypeMarkup ((ITypeDefinition)entity); + switch (entity.Kind) { + case Microsoft.CodeAnalysis.SymbolKind.NamedType: + result = GetTypeMarkup ((ITypeSymbol)entity); break; - case SymbolKind.Field: - result = GetFieldMarkup ((IField)entity); + case Microsoft.CodeAnalysis.SymbolKind.Field: + result = GetFieldMarkup ((IFieldSymbol)entity); break; - case SymbolKind.Property: - case SymbolKind.Indexer: - result = GetPropertyMarkup ((IProperty)entity); + case Microsoft.CodeAnalysis.SymbolKind.Property: + result = GetPropertyMarkup ((IPropertySymbol)entity); break; - case SymbolKind.Event: - result = GetEventMarkup ((IEvent)entity); + case Microsoft.CodeAnalysis.SymbolKind.Event: + result = GetEventMarkup ((IEventSymbol)entity); break; - case SymbolKind.Method: - case SymbolKind.Operator: - result = GetMethodMarkup ((IMethod)entity); + case Microsoft.CodeAnalysis.SymbolKind.Method: + var method = (IMethodSymbol)entity; + switch (method.MethodKind) { + case MethodKind.Constructor: + result = GetConstructorMarkup (method); + break; + case MethodKind.Destructor: + result = GetDestructorMarkup (method); + break; + default: + result = GetMethodMarkup (method); + break; + } break; - case SymbolKind.Constructor: - result = GetConstructorMarkup ((IMethod)entity); + case Microsoft.CodeAnalysis.SymbolKind.Namespace: + result = GetNamespaceMarkup ((INamespaceSymbol)entity); break; - case SymbolKind.Destructor: - result = GetDestructorMarkup ((IMethod)entity); + case Microsoft.CodeAnalysis.SymbolKind.Local: + result = GetLocalVariableMarkup ((ILocalSymbol)entity); + break; + case Microsoft.CodeAnalysis.SymbolKind.Parameter: + result = GetParameterVariableMarkup ((IParameterSymbol)entity); break; default: - throw new ArgumentOutOfRangeException (); - } - string reason; - if (entity.IsObsolete (out reason)) { - var attr = reason == null ? "[Obsolete]" : "[Obsolete(\"" + reason + "\")]"; - result = "<span size=\"smaller\">" + attr + "</span>" + Environment.NewLine + result; + Console.WriteLine (entity.Kind); + return null; } + // TODO +// if (entity.IsObsolete (out reason)) { +// var attr = reason == null ? "[Obsolete]" : "[Obsolete(\"" + reason + "\")]"; +// result = "<span size=\"smaller\">" + attr + "</span>" + Environment.NewLine + result; +// } return result; } - public string GetMarkup (INamespace ns) + string GetNamespaceMarkup (INamespaceSymbol ns) { var result = new StringBuilder (); result.Append (Highlight ("namespace ", colorStyle.KeywordNamespace)); - result.Append (ns.FullName); + result.Append (ns.Name); return result.ToString (); } - - void AppendModifiers (StringBuilder result, IEntity entity) + void AppendModifiers (StringBuilder result, ISymbol entity) { - if (entity.DeclaringType != null && entity.DeclaringType.Kind == TypeKind.Interface) + if (entity.ContainingType != null && entity.ContainingType.TypeKind == TypeKind.Interface) return; - switch (entity.Accessibility) { + switch (entity.DeclaredAccessibility) { case Accessibility.Internal: - if (entity.SymbolKind != SymbolKind.TypeDefinition) + if (entity.Kind != SymbolKind.NamedType) result.Append (Highlight ("internal ", colorStyle.KeywordModifiers)); break; case Accessibility.ProtectedAndInternal: @@ -210,35 +233,41 @@ namespace MonoDevelop.CSharp result.Append (Highlight ("public ", colorStyle.KeywordModifiers)); break; } - var field = entity as IField; - + var field = entity as IFieldSymbol; + if (field != null) { - if (field.IsFixed) { + // TODO!!!! + /*if (field.IsFixed) { result.Append (Highlight ("fixed ", colorStyle.KeywordModifiers)); - } else if (field.IsConst) { + } else*/ + if (field.IsConst) { result.Append (Highlight ("const ", colorStyle.KeywordModifiers)); } } else if (entity.IsStatic) { result.Append (Highlight ("static ", colorStyle.KeywordModifiers)); } else if (entity.IsSealed) { - if (!(entity is IType && ((IType)entity).Kind == TypeKind.Delegate)) + if (!(entity is ITypeSymbol && ((ITypeSymbol)entity).TypeKind == TypeKind.Delegate)) result.Append (Highlight ("sealed ", colorStyle.KeywordModifiers)); } else if (entity.IsAbstract) { - if (!(entity is IType && ((IType)entity).Kind == TypeKind.Interface)) + if (!(entity is ITypeSymbol && ((ITypeSymbol)entity).TypeKind == TypeKind.Interface)) result.Append (Highlight ("abstract ", colorStyle.KeywordModifiers)); } +// TODO!!!! +// if (entity.IsShadowing) +// result.Append (Highlight ("new ", colorStyle.KeywordModifiers)); - if (entity.IsShadowing) - result.Append (Highlight ("new ", colorStyle.KeywordModifiers)); - - var member = entity as IMember; - if (member != null) { - if (member.IsOverride) { + var method = entity as IMethodSymbol; + if (method != null) { + if (method.IsOverride) { result.Append (Highlight ("override ", colorStyle.KeywordModifiers)); - } else if (member.IsVirtual) { + } else if (method.IsVirtual) { result.Append (Highlight ("virtual ", colorStyle.KeywordModifiers)); } + if (method.IsAsync) + result.Append (Highlight ("async ", colorStyle.KeywordModifiers)); + if (method.PartialDefinitionPart != null || method.PartialImplementationPart != null) + result.Append (Highlight ("partial ", colorStyle.KeywordModifiers)); } if (field != null) { if (field.IsVolatile) @@ -247,18 +276,11 @@ namespace MonoDevelop.CSharp result.Append (Highlight ("readonly ", colorStyle.KeywordModifiers)); } - var method = entity as IMethod; - if (method != null) { - if (method.IsAsync) - result.Append (Highlight ("async ", colorStyle.KeywordModifiers)); - if (method.IsPartial) - result.Append (Highlight ("partial ", colorStyle.KeywordModifiers)); - } } - void AppendAccessibility (StringBuilder result, IMethod entity) + void AppendAccessibility (StringBuilder result, IMethodSymbol entity) { - switch (entity.Accessibility) { + switch (entity.DeclaredAccessibility) { case Accessibility.Internal: result.Append (Highlight ("internal", colorStyle.KeywordModifiers)); break; @@ -309,13 +331,12 @@ namespace MonoDevelop.CSharp return result; } - static bool IsObjectOrValueType (IType type) + static bool IsObjectOrValueType (ITypeSymbol type) { - var d = type.GetDefinition (); - return d != null && (d.KnownTypeCode == KnownTypeCode.Object || d.KnownTypeCode == KnownTypeCode.ValueType); + return type != null && (type.SpecialType == SpecialType.System_Object || type.IsValueType); } - string GetTypeParameterMarkup (IType t) + string GetTypeParameterMarkup (ITypeSymbol t) { if (t == null) throw new ArgumentNullException ("t"); @@ -324,12 +345,12 @@ namespace MonoDevelop.CSharp result.Append (highlightedTypeName); var color = AlphaBlend (colorStyle.PlainText.Foreground, colorStyle.PlainText.Background, optionalAlpha); - var colorString = Mono.TextEditor.HelperMethods.GetColorString (color); + var colorString = MonoDevelop.Components.HelperMethods.GetColorString (color); result.Append ("<span foreground=\"" + colorString + "\">" + " (type parameter)</span>"); - var tp = t as ITypeParameter; + var tp = t as ITypeParameterSymbol; if (tp != null) { - if (!tp.HasDefaultConstructorConstraint && !tp.HasReferenceTypeConstraint && !tp.HasValueTypeConstraint && tp.DirectBaseTypes.All (IsObjectOrValueType)) + if (!tp.HasConstructorConstraint && !tp.HasReferenceTypeConstraint && !tp.HasValueTypeConstraint && tp.ConstraintTypes.All (IsObjectOrValueType)) return result.ToString (); result.AppendLine (); result.Append (Highlight (" where ", colorStyle.KeywordContext)); @@ -344,7 +365,7 @@ namespace MonoDevelop.CSharp constraints++; result.Append (Highlight ("struct", colorStyle.KeywordDeclaration)); } - foreach (var bt in tp.DirectBaseTypes) { + foreach (var bt in tp.ConstraintTypes) { if (!IsObjectOrValueType (bt)) { if (constraints > 0) { result.Append (","); @@ -357,7 +378,7 @@ namespace MonoDevelop.CSharp result.Append (GetTypeReferenceString (bt)); } } - if (tp.HasDefaultConstructorConstraint) { + if (tp.HasConstructorConstraint) { if (constraints > 0) result.Append (","); result.Append (Highlight ("new", colorStyle.KeywordOperators)); @@ -367,62 +388,70 @@ namespace MonoDevelop.CSharp return result.ToString (); } - string GetNullableMarkup (IType t) + string GetNullableMarkup (ITypeSymbol t) { var result = new StringBuilder (); result.Append (GetTypeReferenceString (t)); return result.ToString (); } - void AppendTypeParameterList (StringBuilder result, ITypeDefinition def) + void AppendTypeParameterList (StringBuilder result, INamedTypeSymbol def) { - IEnumerable<ITypeParameter> parameters = def.TypeParameters; - if (def.DeclaringTypeDefinition != null) - parameters = parameters.Skip (def.DeclaringTypeDefinition.TypeParameterCount); + var parameters = def.TypeParameters; +// if (def.ContainingType != null) +// parameters = parameters.Skip (def.DeclaringTypeDefinition.TypeParameterCount); AppendTypeParameters (result, parameters); } - void AppendTypeArgumentList (StringBuilder result, IType def) + void AppendTypeArgumentList (StringBuilder result, INamedTypeSymbol def) { - IEnumerable<IType> parameters = def.TypeArguments; - if (def.DeclaringType != null) - parameters = parameters.Skip (def.DeclaringType.TypeParameterCount); + var parameters = def.TypeArguments; +// if (def.DeclaringType != null) +// parameters = parameters.Skip (def.DeclaringType.TypeParameterCount); AppendTypeParameters (result, parameters); } - string GetTypeNameWithParameters (IType t) + string GetTypeNameWithParameters (ITypeSymbol t) { StringBuilder result = new StringBuilder (); result.Append (Highlight (FilterEntityName (t.Name), colorStyle.UserTypesTypeParameters)); - if (t.TypeParameterCount > 0) { - if (t.TypeArguments.Count > 0) { - AppendTypeArgumentList (result, t); - } else { - AppendTypeParameterList (result, t.GetDefinition ()); + var namedTypeSymbol = t as INamedTypeSymbol; + if (namedTypeSymbol != null) { + if (namedTypeSymbol.IsGenericType) { + AppendTypeParameterList (result, namedTypeSymbol); + } else if (namedTypeSymbol.IsUnboundGenericType) { + AppendTypeArgumentList (result, namedTypeSymbol); } } return result.ToString (); } + + public static bool IsNullableType (ITypeSymbol type) + { + var original = type.OriginalDefinition; + return original.SpecialType == SpecialType.System_Nullable_T; + } + - string GetTypeMarkup (IType t, bool includeDeclaringTypes = false) + string GetTypeMarkup (ITypeSymbol t, bool includeDeclaringTypes = false) { if (t == null) throw new ArgumentNullException ("t"); - if (t.Kind == TypeKind.Null) + if (t.TypeKind == TypeKind.Error) return "Type can not be resolved."; - if (t.Kind == TypeKind.Delegate) - return GetDelegateMarkup (t); - if (t.Kind == TypeKind.TypeParameter) + if (t.TypeKind == TypeKind.Delegate) + return GetDelegateMarkup ((INamedTypeSymbol)t); + if (t.TypeKind == TypeKind.TypeParameter) return GetTypeParameterMarkup (t); - if (t.Kind == TypeKind.Array || t.Kind == TypeKind.Pointer) + if (t.TypeKind == TypeKind.Array || t.TypeKind == TypeKind.Pointer) return GetTypeReferenceString (t); - if (NullableType.IsNullable (t)) + if (t.SpecialType == SpecialType.System_Nullable_T) return GetNullableMarkup (t); var result = new StringBuilder (); - if (t.GetDefinition () != null) - AppendModifiers (result, t.GetDefinition ()); + if (IsNullableType (t)) + AppendModifiers (result, t); - switch (t.Kind) { + switch (t.TypeKind) { case TypeKind.Class: result.Append (Highlight ("class ", colorStyle.KeywordDeclaration)); break; @@ -442,7 +471,7 @@ namespace MonoDevelop.CSharp var curType = t; while (curType != null) { typeNames.Add (GetTypeNameWithParameters (curType)); - curType = curType.DeclaringType; + curType = curType.ContainingType; } typeNames.Reverse (); result.Append (string.Join (".", typeNames)); @@ -450,21 +479,26 @@ namespace MonoDevelop.CSharp result.Append (GetTypeNameWithParameters (t)); } - if (t.Kind == TypeKind.Array) + if (t.TypeKind == TypeKind.Array) return result.ToString (); bool first = true; int maxLength = GetMarkupLength (result.ToString ()); int length = maxLength; - var sortedTypes = new List<IType> (t.DirectBaseTypes.Where (x => x.FullName != "System.Object")); + var sortedTypes = new List<INamedTypeSymbol> (t.Interfaces); + sortedTypes.Sort ((x, y) => GetTypeReferenceString (y).Length.CompareTo (GetTypeReferenceString (x).Length)); - if (t.Kind != TypeKind.Enum) { + + if (t.BaseType != null && t.BaseType.SpecialType != SpecialType.System_Object) + sortedTypes.Insert (0, t.BaseType); + + if (t.TypeKind != TypeKind.Enum) { foreach (var directBaseType in sortedTypes) { if (first) { result.AppendLine (" :"); result.Append (" "); length = 2; - } else { + } else { // 5.5. um 10:45 result.Append (", "); length += 2; } @@ -481,8 +515,8 @@ namespace MonoDevelop.CSharp first = false; } } else { - var enumBase = t.GetDefinition ().EnumUnderlyingType; - if (enumBase.Name != "Int32") { + var enumBase = t.BaseType; + if (enumBase.SpecialType != SpecialType.System_Int32) { result.AppendLine (" :"); result.Append (" "); result.Append (GetTypeReferenceString (enumBase, false)); @@ -492,7 +526,7 @@ namespace MonoDevelop.CSharp return result.ToString (); } - void AppendTypeParameters (StringBuilder result, IEnumerable<ITypeParameter> typeParameters) + void AppendTypeParameters (StringBuilder result, ImmutableArray<ITypeParameterSymbol> typeParameters) { if (!typeParameters.Any ()) return; @@ -514,7 +548,7 @@ namespace MonoDevelop.CSharp result.Append (">"); } - void AppendTypeParameters (StringBuilder result, IEnumerable<IType> typeParameters) + void AppendTypeParameters (StringBuilder result, ImmutableArray<ITypeSymbol> typeParameters) { if (!typeParameters.Any ()) return; @@ -529,8 +563,8 @@ namespace MonoDevelop.CSharp result.Append (", "); } } - if (typeParameter is ITypeParameter) - AppendVariance (result, ((ITypeParameter)typeParameter).Variance); + if (typeParameter is ITypeParameterSymbol) + AppendVariance (result, ((ITypeParameterSymbol)typeParameter).Variance); result.Append (GetTypeReferenceString (typeParameter, false)); i++; } @@ -539,14 +573,14 @@ namespace MonoDevelop.CSharp static string FilterEntityName (string name) { - return AmbienceService.EscapeText (CSharpAmbience.FilterName (name)); + return Ambience.EscapeText (CSharpAmbience.FilterName (name)); } - public string GetDelegateInfo (IType type) + public string GetDelegateInfo (ITypeSymbol type) { if (type == null) - throw new ArgumentNullException ("returnType"); - var t = type.GetDefinition (); + throw new ArgumentNullException ("type"); + var t = type; var result = new StringBuilder (); @@ -563,25 +597,32 @@ namespace MonoDevelop.CSharp AppendTypeParameters (result, method.TypeParameters); - if (formattingOptions.SpaceBeforeDelegateDeclarationParentheses) - result.Append (" "); + // TODO: +// if (document.GetOptionSet ().GetOption (CSharpFormattingOptions.SpaceBeforeDelegateDeclarationParentheses)) +// result.Append (" "); result.Append ('('); - AppendParameterList (result, method.Parameters, formattingOptions.SpaceBeforeDelegateDeclarationParameterComma, formattingOptions.SpaceAfterDelegateDeclarationParameterComma, false); + AppendParameterList ( + result, + method.Parameters, + false /* formattingOptions.SpaceBeforeDelegateDeclarationParameterComma */, + true /* formattingOptions.SpaceAfterDelegateDeclarationParameterComma*/, + false + ); result.Append (')'); return result.ToString (); } - string GetDelegateMarkup (IType delegateType) + string GetDelegateMarkup (INamedTypeSymbol delegateType) { var result = new StringBuilder (); - - var method = delegateType.GetDelegateInvokeMethod (); + var type = delegateType.IsUnboundGenericType ? delegateType.OriginalDefinition : delegateType; + var method = type.GetDelegateInvokeMethod (); - if (delegateType.GetDefinition () != null) - AppendModifiers (result, delegateType.GetDefinition ()); + AppendModifiers (result, type); result.Append (Highlight ("delegate ", colorStyle.KeywordDeclaration)); - result.Append (GetTypeReferenceString (method.ReturnType)); + if (method != null) + result.Append (GetTypeReferenceString (method.ReturnType)); if (BreakLineAfterReturnType) { result.AppendLine (); } else { @@ -589,67 +630,91 @@ namespace MonoDevelop.CSharp } - result.Append (FilterEntityName (delegateType.Name)); - - if (delegateType.TypeArguments.Count > 0) { - AppendTypeArgumentList (result, delegateType); + result.Append (FilterEntityName (type.Name)); + + if (type.TypeArguments.Length > 0) { + AppendTypeArgumentList (result, type); } else { - AppendTypeParameterList (result, delegateType.GetDefinition ()); + AppendTypeParameterList (result, type); } - - if (formattingOptions.SpaceBeforeMethodDeclarationParameterComma) - result.Append (" "); +// TODO +// if (formattingOptions.SpaceBeforeMethodDeclarationParameterComma) +// result.Append (" "); result.Append ('('); - AppendParameterList (result, method.Parameters, formattingOptions.SpaceBeforeDelegateDeclarationParameterComma, formattingOptions.SpaceAfterDelegateDeclarationParameterComma); + AppendParameterList ( + result, + method.Parameters, + false /* formattingOptions.SpaceBeforeDelegateDeclarationParameterComma */, + false /* formattingOptions.SpaceAfterDelegateDeclarationParameterComma */); result.Append (')'); return result.ToString (); } - public string GetLocalVariableMarkup (IVariable variable) + string GetLocalVariableMarkup (ILocalSymbol local) { - if (variable == null) - throw new ArgumentNullException ("field"); + if (local == null) + throw new ArgumentNullException ("local"); var result = new StringBuilder (); - if (variable.IsConst) + if (local.IsConst) result.Append (Highlight ("const ", colorStyle.KeywordModifiers)); - result.Append (GetTypeReferenceString (variable.Type)); + result.Append (GetTypeReferenceString (local.Type)); if (BreakLineAfterReturnType) { result.AppendLine (); } else { result.Append (" "); } - result.Append (FilterEntityName (variable.Name)); + result.Append (FilterEntityName (local.Name)); + + if (local.IsConst) { + if (options.GetOption (CSharpFormattingOptions.SpacingAroundBinaryOperator) == BinaryOperatorSpacingOptions.Single) { + result.Append (" = "); + } else { + result.Append ("="); + } + AppendConstant (result, local.Type, local.ConstantValue); + } - if (variable.IsConst) { - if (formattingOptions.SpaceAroundAssignment) { + return result.ToString (); + } + + string GetParameterVariableMarkup (IParameterSymbol parameter) + { + if (parameter == null) + throw new ArgumentNullException ("parameter"); + + var result = new StringBuilder (); + AppendParameter (result, parameter); + + if (parameter.HasExplicitDefaultValue) { + if (options.GetOption (CSharpFormattingOptions.SpacingAroundBinaryOperator) == BinaryOperatorSpacingOptions.Single) { result.Append (" = "); } else { result.Append ("="); } - AppendConstant (result, variable.Type, variable.ConstantValue); + AppendConstant (result, parameter.Type, parameter.ExplicitDefaultValue); } return result.ToString (); } - string GetFieldMarkup (IField field) + string GetFieldMarkup (IFieldSymbol field) { if (field == null) throw new ArgumentNullException ("field"); var result = new StringBuilder (); - bool isEnum = field.DeclaringTypeDefinition != null && field.DeclaringTypeDefinition.Kind == TypeKind.Enum; + bool isEnum = field.ContainingType.TypeKind == TypeKind.Enum; if (!isEnum) { AppendModifiers (result, field); - result.Append (GetTypeReferenceString (field.ReturnType)); + result.Append (GetTypeReferenceString (field.Type)); } else { - result.Append (GetTypeReferenceString (field.DeclaringType)); + result.Append (GetTypeReferenceString (field.ContainingType)); } if (BreakLineAfterReturnType) { result.AppendLine (); @@ -659,34 +724,36 @@ namespace MonoDevelop.CSharp result.Append (HighlightSemantically (FilterEntityName (field.Name), colorStyle.UserFieldDeclaration)); - if (field.IsFixed) { - if (formattingOptions.SpaceBeforeArrayDeclarationBrackets) { - result.Append (" ["); - } else { - result.Append ("["); - } - if (formattingOptions.SpacesWithinBrackets) - result.Append (" "); - AppendConstant (result, field.Type, field.ConstantValue); - if (formattingOptions.SpacesWithinBrackets) - result.Append (" "); - result.Append ("]"); - } else if (field.IsConst) { - if (isEnum && !(field.DeclaringTypeDefinition.Attributes.Any (attr => attr.AttributeType.FullName == "System.FlagsAttribute"))) { +// if (field.IsFixed) { +// if (formattingOptions.SpaceBeforeArrayDeclarationBrackets) { +// result.Append (" ["); +// } else { +// result.Append ("["); +// } +// if (formattingOptions.SpacesWithinBrackets) +// result.Append (" "); +// AppendConstant (result, field.Type, field.ConstantValue); +// if (formattingOptions.SpacesWithinBrackets) +// result.Append (" "); +// result.Append ("]"); +// } else + + if (field.IsConst) { + if (isEnum && !(field.ContainingType.GetAttributes ().Any ((AttributeData attr) => attr.AttributeClass.Name == "FlagsAttribute" && attr.AttributeClass.ContainingNamespace.Name == "System"))) { return result.ToString (); } - if (formattingOptions.SpaceAroundAssignment) { + if (options.GetOption (CSharpFormattingOptions.SpacingAroundBinaryOperator) == BinaryOperatorSpacingOptions.Single) { result.Append (" = "); } else { result.Append ("="); } - AppendConstant (result, field.Type, field.ConstantValue, field.DeclaringType.Kind == TypeKind.Enum); + AppendConstant (result, field.Type, field.ConstantValue, isEnum); } return result.ToString (); } - string GetMethodMarkup (IMethod method) + string GetMethodMarkup (IMethodSymbol method) { if (method == null) throw new ArgumentNullException ("method"); @@ -700,17 +767,17 @@ namespace MonoDevelop.CSharp result.Append (" "); } - AppendExplicitInterfaces (result, method); + AppendExplicitInterfaces (result, method.ExplicitInterfaceImplementations.Cast<ISymbol> ()); - if (method.SymbolKind == SymbolKind.Operator) { + if (method.MethodKind == MethodKind.BuiltinOperator || method.MethodKind == MethodKind.UserDefinedOperator) { result.Append ("operator "); result.Append (CSharpAmbience.GetOperator (method.Name)); } else { result.Append (HighlightSemantically (FilterEntityName (method.Name), colorStyle.UserMethodDeclaration)); } - if (method.TypeArguments.Count > 0) { + if (method.TypeArguments.Length > 0) { result.Append ("<"); - for (int i = 0; i < method.TypeArguments.Count; i++) { + for (int i = 0; i < method.TypeArguments.Length; i++) { if (i > 0) result.Append (", "); result.Append (HighlightSemantically (GetTypeReferenceString (method.TypeArguments [i], false), colorStyle.UserTypes)); @@ -719,18 +786,20 @@ namespace MonoDevelop.CSharp } else { AppendTypeParameters (result, method.TypeParameters); } - - if (formattingOptions.SpaceBeforeMethodDeclarationParentheses) - result.Append (" "); +// TODO! +// if (formattingOptions.SpaceBeforeMethodDeclarationParentheses) +// result.Append (" "); result.Append ('('); - IList<IParameter> parameters = method.Parameters; - AppendParameterList (result, parameters, formattingOptions.SpaceBeforeMethodDeclarationParameterComma, formattingOptions.SpaceAfterMethodDeclarationParameterComma); + var parameters = method.Parameters; + AppendParameterList (result, parameters, + false /* formattingOptions.SpaceBeforeMethodDeclarationParameterComma*/, + false /* formattingOptions.SpaceAfterMethodDeclarationParameterComma*/); result.Append (')'); return result.ToString (); } - string GetConstructorMarkup (IMethod method) + string GetConstructorMarkup (IMethodSymbol method) { if (method == null) throw new ArgumentNullException ("method"); @@ -739,24 +808,28 @@ namespace MonoDevelop.CSharp var result = new StringBuilder (); AppendModifiers (result, method); - result.Append (FilterEntityName (method.DeclaringType.Name)); - - if (formattingOptions.SpaceBeforeConstructorDeclarationParentheses) - result.Append (" "); + result.Append (FilterEntityName (method.ContainingType.Name)); +// +// if (formattingOptions.SpaceBeforeConstructorDeclarationParentheses) +// result.Append (" "); result.Append ('('); - if (method.DeclaringType.Kind == TypeKind.Delegate) { + if (method.ContainingType.TypeKind == TypeKind.Delegate) { result.Append (Highlight ("delegate", colorStyle.KeywordDeclaration) + " ("); - AppendParameterList (result, method.DeclaringType.GetDelegateInvokeMethod ().Parameters, formattingOptions.SpaceBeforeConstructorDeclarationParameterComma, formattingOptions.SpaceAfterConstructorDeclarationParameterComma); + AppendParameterList (result, method.ContainingType.GetDelegateInvokeMethod ().Parameters, + false /* formattingOptions.SpaceBeforeConstructorDeclarationParameterComma */, + false /* formattingOptions.SpaceAfterConstructorDeclarationParameterComma */); result.Append (")"); } else { - AppendParameterList (result, method.Parameters, formattingOptions.SpaceBeforeConstructorDeclarationParameterComma, formattingOptions.SpaceAfterConstructorDeclarationParameterComma); + AppendParameterList (result, method.Parameters, + false /* formattingOptions.SpaceBeforeConstructorDeclarationParameterComma */, + false /* formattingOptions.SpaceAfterConstructorDeclarationParameterComma */); } result.Append (')'); return result.ToString (); } - string GetDestructorMarkup (IMethod method) + string GetDestructorMarkup (IMethodSymbol method) { if (method == null) throw new ArgumentNullException ("method"); @@ -770,68 +843,75 @@ namespace MonoDevelop.CSharp } result.Append ("~"); - result.Append (FilterEntityName (method.DeclaringType.Name)); + result.Append (FilterEntityName (method.ContainingType.Name)); - if (formattingOptions.SpaceBeforeConstructorDeclarationParentheses) - result.Append (" "); +// if (formattingOptions.SpaceBeforeConstructorDeclarationParentheses) +// result.Append (" "); result.Append ('('); - AppendParameterList (result, method.Parameters, formattingOptions.SpaceBeforeConstructorDeclarationParameterComma, formattingOptions.SpaceAfterConstructorDeclarationParameterComma); + AppendParameterList (result, method.Parameters, + false /* formattingOptions.SpaceBeforeConstructorDeclarationParameterComma */, + false /* formattingOptions.SpaceAfterConstructorDeclarationParameterComma */); result.Append (')'); return result.ToString (); } - bool IsAccessibleOrHasSourceCode (IEntity entity) + bool IsAccessibleOrHasSourceCode (ISymbol entity) { - if (!entity.Region.Begin.IsEmpty) - return true; - var lookup = new MemberLookup (resolver.CurrentTypeDefinition, resolver.Compilation.MainAssembly); - return lookup.IsAccessible (entity, false); + if (entity.DeclaredAccessibility == Accessibility.Public) + return true; + return entity.IsDefinedInSource (); +// if (!entity.Region.Begin.IsEmpty) +// return true; +// var lookup = new MemberLookup (resolver.CurrentTypeDefinition, resolver.Compilation.MainAssembly); +// return lookup.IsAccessible (entity, false); } - string GetPropertyMarkup (IProperty property) + string GetPropertyMarkup (IPropertySymbol property) { if (property == null) throw new ArgumentNullException ("property"); var result = new StringBuilder (); AppendModifiers (result, property); - result.Append (GetTypeReferenceString (property.ReturnType)); + result.Append (GetTypeReferenceString (property.Type)); if (BreakLineAfterReturnType) { result.AppendLine (); } else { result.Append (" "); } - AppendExplicitInterfaces (result, property); + AppendExplicitInterfaces (result, property.ExplicitInterfaceImplementations.Cast<ISymbol> ()); - if (property.SymbolKind == SymbolKind.Indexer) { + if (property.IsIndexer) { result.Append (Highlight ("this", colorStyle.KeywordAccessors)); } else { result.Append (HighlightSemantically (FilterEntityName (property.Name), colorStyle.UserPropertyDeclaration)); } - if (property.Parameters.Count > 0) { - if (formattingOptions.SpaceBeforeIndexerDeclarationBracket) - result.Append (" "); + if (property.Parameters.Length > 0) { +// if (formattingOptions.SpaceBeforeIndexerDeclarationBracket) +// result.Append (" "); result.Append ("["); - AppendParameterList (result, property.Parameters, formattingOptions.SpaceBeforeIndexerDeclarationParameterComma, formattingOptions.SpaceAfterIndexerDeclarationParameterComma); + AppendParameterList (result, property.Parameters, + false /*formattingOptions.SpaceBeforeIndexerDeclarationParameterComma*/, + false /*formattingOptions.SpaceAfterIndexerDeclarationParameterComma*/); result.Append ("]"); } result.Append (" {"); - if (property.CanGet && IsAccessibleOrHasSourceCode (property.Getter)) { - if (property.Getter.Accessibility != property.Accessibility) { + if (property.GetMethod != null&& IsAccessibleOrHasSourceCode (property.GetMethod)) { + if (property.GetMethod.DeclaredAccessibility != property.DeclaredAccessibility) { result.Append (" "); - AppendAccessibility (result, property.Getter); + AppendAccessibility (result, property.GetMethod); } result.Append (Highlight (" get", colorStyle.KeywordProperty) + ";"); } - if (property.CanSet && IsAccessibleOrHasSourceCode (property.Setter)) { - if (property.Setter.Accessibility != property.Accessibility) { + if (property.SetMethod != null && IsAccessibleOrHasSourceCode (property.SetMethod)) { + if (property.SetMethod.DeclaredAccessibility != property.DeclaredAccessibility) { result.Append (" "); - AppendAccessibility (result, property.Setter); + AppendAccessibility (result, property.SetMethod); } result.Append (Highlight (" set", colorStyle.KeywordProperty) + ";"); } @@ -841,17 +921,17 @@ namespace MonoDevelop.CSharp } - public TooltipInformation GetExternAliasTooltip (ExternAliasDeclaration externAliasDeclaration, DotNetProject project) + public TooltipInformation GetExternAliasTooltip (ExternAliasDirectiveSyntax externAliasDeclaration, DotNetProject project) { var result = new TooltipInformation (); - result.SignatureMarkup = Highlight ("extern ", colorStyle.KeywordModifiers) + Highlight ("alias ", colorStyle.KeywordNamespace) + externAliasDeclaration.Name; + result.SignatureMarkup = Highlight ("extern ", colorStyle.KeywordModifiers) + Highlight ("alias ", colorStyle.KeywordNamespace) + externAliasDeclaration.Identifier; if (project == null) return result; foreach (var r in project.References) { if (string.IsNullOrEmpty (r.Aliases)) continue; foreach (var alias in r.Aliases.Split (',', ';')) { - if (alias == externAliasDeclaration.Name) + if (alias == externAliasDeclaration.Identifier.ToFullString ()) result.AddCategory (GettextCatalog.GetString ("Reference"), r.StoredReference); } } @@ -859,66 +939,61 @@ namespace MonoDevelop.CSharp return result; } - public TooltipInformation GetKeywordTooltip (AstNode node) - { - return GetKeywordTooltip (node.ToString (), node); - } - - public TooltipInformation GetKeywordTooltip (string keyword, AstNode hintNode) + public TooltipInformation GetKeywordTooltip (SyntaxToken node) { var result = new TooltipInformation (); var color = AlphaBlend (colorStyle.PlainText.Foreground, colorStyle.PlainText.Background, optionalAlpha); - var colorString = Mono.TextEditor.HelperMethods.GetColorString (color); + var colorString = MonoDevelop.Components.HelperMethods.GetColorString (color); var keywordSign = "<span foreground=\"" + colorString + "\">" + " (keyword)</span>"; - switch (keyword) { - case "abstract": + switch (node.Kind ()) { + case SyntaxKind.AbstractKeyword: result.SignatureMarkup = Highlight ("abstract", colorStyle.KeywordModifiers) + keywordSign; result.SummaryMarkup = "The " + Highlight ("abstract", colorStyle.KeywordModifiers) + " modifier can be used with classes, methods, properties, indexers, and events."; break; - case "add": + case SyntaxKind.AddKeyword: result.SignatureMarkup = Highlight ("add", colorStyle.KeywordContext) + keywordSign; result.AddCategory ("Form", "[modifiers] " + Highlight ("add", colorStyle.KeywordContext) + " { accessor-body }"); result.SummaryMarkup = "The " + Highlight ("add", colorStyle.KeywordContext) + " keyword is used to define a custom accessor for when an event is subscribed to. If supplied, a remove accessor must also be supplied."; break; - case "ascending": + case SyntaxKind.AscendingKeyword: result.SignatureMarkup = Highlight ("ascending", colorStyle.KeywordContext) + keywordSign; result.AddCategory ("Query Form", Highlight ("orderby", colorStyle.KeywordContext) + " ordering-statement " + Highlight ("ascending", colorStyle.KeywordContext)); result.SummaryMarkup = "The " + Highlight ("ascending", colorStyle.KeywordContext) + " keyword is used to set the sorting order from smallest to largest in a query expression. This is the default behaviour."; break; - case "async": + case SyntaxKind.AsyncKeyword: result.SignatureMarkup = Highlight ("async", colorStyle.KeywordContext) + keywordSign; result.SummaryMarkup = "The " + Highlight ("async", colorStyle.KeywordContext) + " modifier is used to specify that a class method, anonymous method, or lambda expression is asynchronous."; break; - case "as": + case SyntaxKind.AsKeyword: result.SignatureMarkup = Highlight ("as", colorStyle.KeywordOperators) + keywordSign; result.AddCategory ("Form", "expression " + Highlight ("as", colorStyle.KeywordOperators) + " type"); result.SummaryMarkup = "The " + Highlight ("as", colorStyle.KeywordOperators) + " operator is used to perform conversions between compatible types. "; break; - case "await": + case SyntaxKind.AwaitKeyword: result.SignatureMarkup = Highlight ("await", colorStyle.KeywordContext) + keywordSign; result.SummaryMarkup = "The " + Highlight ("await", colorStyle.KeywordContext) + " operator is used to specify that an " + Highlight ("async", colorStyle.KeywordContext) + " method is to have its execution suspended until the " + Highlight ("await", colorStyle.KeywordContext) + " task has completed."; break; - case "base": + case SyntaxKind.BaseKeyword: result.SignatureMarkup = Highlight ("base", colorStyle.KeywordAccessors) + keywordSign; result.SummaryMarkup = "The " + Highlight ("base", colorStyle.KeywordAccessors) + " keyword is used to access members of the base class from within a derived class."; break; - case "break": + case SyntaxKind.BreakKeyword: result.SignatureMarkup = Highlight ("break", colorStyle.KeywordJump) + keywordSign; result.AddCategory ("Form", Highlight ("break", colorStyle.KeywordJump) + ";"); result.SummaryMarkup = "The " + Highlight ("break", colorStyle.KeywordJump) + " statement terminates the closest enclosing loop or switch statement in which it appears."; break; - case "case": + case SyntaxKind.CaseKeyword: result.SignatureMarkup = Highlight ("case", colorStyle.KeywordSelection) + keywordSign; result.AddCategory ("Form", Highlight ("case", colorStyle.KeywordSelection) + " constant-expression:" + Environment.NewLine + " statement" + Environment.NewLine + " jump-statement"); result.SummaryMarkup = ""; break; - case "catch": + case SyntaxKind.CatchKeyword: result.SignatureMarkup = Highlight ("catch", colorStyle.KeywordException) + keywordSign; result.AddCategory ("Form", Highlight ("try", colorStyle.KeywordException) + " try-block" + Environment.NewLine + " " + Highlight ("catch", colorStyle.KeywordException) + " (exception-declaration-1) catch-block-1" + Environment.NewLine + @@ -927,37 +1002,37 @@ namespace MonoDevelop.CSharp Highlight ("try", colorStyle.KeywordException) + " try-block " + Highlight ("catch", colorStyle.KeywordException) + " catch-block"); result.SummaryMarkup = ""; break; - case "checked": + case SyntaxKind.CheckedKeyword: result.SignatureMarkup = Highlight ("checked", colorStyle.KeywordOther) + keywordSign; result.AddCategory ("Form", Highlight ("checked", colorStyle.KeywordOther) + " block" + Environment.NewLine + "or" + Environment.NewLine + Highlight ("checked", colorStyle.KeywordOther) + " (expression)"); result.SummaryMarkup = "The " + Highlight ("checked", colorStyle.KeywordOther) + " keyword is used to control the overflow-checking context for integral-type arithmetic operations and conversions. It can be used as an operator or a statement."; break; - case "class": + case SyntaxKind.ClassKeyword: result.SignatureMarkup = Highlight ("class", colorStyle.KeywordDeclaration) + keywordSign; result.AddCategory ("Form", "[attributes] [modifiers] " + Highlight ("class", colorStyle.KeywordDeclaration) + " identifier [:base-list] { class-body }[;]"); result.SummaryMarkup = "Classes are declared using the keyword " + Highlight ("class", colorStyle.KeywordDeclaration) + "."; break; - case "const": + case SyntaxKind.ConstKeyword: result.SignatureMarkup = Highlight ("const", colorStyle.KeywordModifiers) + keywordSign; result.AddCategory ("Form", "[attributes] [modifiers] " + Highlight ("const", colorStyle.KeywordModifiers) + " type declarators;"); result.SummaryMarkup = "The " + Highlight ("const", colorStyle.KeywordModifiers) + " keyword is used to modify a declaration of a field or local variable. It specifies that the value of the field or the local variable cannot be modified. "; break; - case "continue": + case SyntaxKind.ContinueKeyword: result.SignatureMarkup = Highlight ("continue", colorStyle.KeywordJump) + keywordSign; result.AddCategory ("Form", Highlight ("continue", colorStyle.KeywordJump) + ";"); result.SummaryMarkup = "The " + Highlight ("continue", colorStyle.KeywordJump) + " statement passes control to the next iteration of the enclosing iteration statement in which it appears."; break; - case "default": + case SyntaxKind.DefaultKeyword: result.SignatureMarkup = Highlight ("default", colorStyle.KeywordSelection) + keywordSign; result.SummaryMarkup = ""; - if (hintNode != null) { - if (hintNode.Parent is DefaultValueExpression) { + if (node.Parent != null) { + if (node.Parent is DefaultExpressionSyntax) { result.AddCategory ("Form", Highlight ("default", colorStyle.KeywordSelection) + " (Type)"); break; - } else if (hintNode.Parent is CaseLabel) { + } else if (node.Parent is SwitchStatementSyntax) { result.AddCategory ("Form", Highlight ("switch", colorStyle.KeywordSelection) + " (expression) { " + Environment.NewLine + " " + Highlight ("case", colorStyle.KeywordSelection) + " constant-expression:" + Environment.NewLine + @@ -972,36 +1047,40 @@ namespace MonoDevelop.CSharp } result.AddCategory ("Form", Highlight ("default", colorStyle.KeywordSelection) + " (Type)" + Environment.NewLine + Environment.NewLine + - "or" + Environment.NewLine + Environment.NewLine + + "or" + Environment.NewLine + Environment.NewLine + Highlight ("switch", colorStyle.KeywordSelection) + " (expression) { " + Environment.NewLine + - " " + Highlight ("case", colorStyle.KeywordSelection) + " constant-expression:" + Environment.NewLine + - " statement" + Environment.NewLine + - " jump-statement" + Environment.NewLine + - " [" + Highlight ("default", colorStyle.KeywordSelection) + ":" + Environment.NewLine + - " statement" + Environment.NewLine + - " jump-statement]" + Environment.NewLine + - "}"); - break; - case "delegate": + " " + Highlight ("case", colorStyle.KeywordSelection) + " constant-expression:" + Environment.NewLine + + " statement" + Environment.NewLine + + " jump-statement" + Environment.NewLine + + " [" + Highlight ("default", colorStyle.KeywordSelection) + ":" + Environment.NewLine + + " statement" + Environment.NewLine + + " jump-statement]" + Environment.NewLine + + "}"); + break; + case SyntaxKind.DelegateKeyword: result.SignatureMarkup = Highlight ("delegate", colorStyle.KeywordDeclaration) + keywordSign; result.AddCategory ("Form", "[attributes] [modifiers] " + Highlight ("delegate", colorStyle.KeywordDeclaration) + " result-type identifier ([formal-parameters]);"); result.SummaryMarkup = "A " + Highlight ("delegate", colorStyle.KeywordDeclaration) + " declaration defines a reference type that can be used to encapsulate a method with a specific signature."; break; - case "dynamic": - result.SignatureMarkup = Highlight ("dynamic", colorStyle.KeywordContext) + keywordSign; - result.SummaryMarkup = "The " + Highlight ("dynamic", colorStyle.KeywordContext) + " type allows for an object to bypass compile-time type checking and resolve type checking during run-time."; + case SyntaxKind.IdentifierName: + if (node.ToFullString () == "dynamic") { + result.SignatureMarkup = Highlight ("dynamic", colorStyle.KeywordContext) + keywordSign; + result.SummaryMarkup = "The " + Highlight ("dynamic", colorStyle.KeywordContext) + " type allows for an object to bypass compile-time type checking and resolve type checking during run-time."; + } else { + return null; + } break; - case "descending": + case SyntaxKind.DescendingKeyword: result.SignatureMarkup = Highlight ("descending", colorStyle.KeywordContext) + keywordSign; result.AddCategory ("Query Form", Highlight ("orderby", colorStyle.KeywordContext) + " ordering-statement " + Highlight ("descending", colorStyle.KeywordContext)); result.SummaryMarkup = "The " + Highlight ("descending", colorStyle.KeywordContext) + " keyword is used to set the sorting order from largest to smallest in a query expression."; break; - case "do": + case SyntaxKind.DoKeyword: result.SignatureMarkup = Highlight ("do", colorStyle.KeywordIteration) + keywordSign; result.AddCategory ("Form", Highlight ("do", colorStyle.KeywordIteration) + " statement " + Highlight ("while", colorStyle.KeywordIteration) + " (expression);"); result.SummaryMarkup = "The " + Highlight ("do", colorStyle.KeywordIteration) + " statement executes a statement or a block of statements repeatedly until a specified expression evaluates to false."; break; - case "else": + case SyntaxKind.ElseKeyword: result.SignatureMarkup = Highlight ("else", colorStyle.KeywordSelection) + keywordSign; result.AddCategory ("Form", Highlight ("if", colorStyle.KeywordSelection) + " (expression)" + Environment.NewLine + " statement1" + Environment.NewLine + @@ -1009,69 +1088,69 @@ namespace MonoDevelop.CSharp " statement2]"); result.SummaryMarkup = ""; break; - case "enum": + case SyntaxKind.EnumKeyword: result.SignatureMarkup = Highlight ("enum", colorStyle.KeywordDeclaration) + keywordSign; result.AddCategory ("Form", "[attributes] [modifiers] " + Highlight ("enum", colorStyle.KeywordDeclaration) + " identifier [:base-type] {enumerator-list} [;]"); result.SummaryMarkup = "The " + Highlight ("enum", colorStyle.KeywordDeclaration) + " keyword is used to declare an enumeration, a distinct type consisting of a set of named constants called the enumerator list."; break; - case "event": + case SyntaxKind.EventKeyword: result.SignatureMarkup = Highlight ("event", colorStyle.KeywordModifiers) + keywordSign; result.AddCategory ("Form", "[attributes] [modifiers] " + Highlight ("event", colorStyle.KeywordModifiers) + " type declarator;" + Environment.NewLine + "[attributes] [modifiers] " + Highlight ("event", colorStyle.KeywordModifiers) + " type member-name {accessor-declarations};"); result.SummaryMarkup = "Specifies an event."; break; - case "explicit": + case SyntaxKind.ExplicitKeyword: result.SignatureMarkup = Highlight ("explicit", colorStyle.KeywordOperatorDeclaration) + keywordSign; result.SummaryMarkup = "The " + Highlight ("explicit", colorStyle.KeywordOperatorDeclaration) + " keyword is used to declare an explicit user-defined type conversion operator."; break; - case "extern": + case SyntaxKind.ExternKeyword: result.SignatureMarkup = Highlight ("extern", colorStyle.KeywordModifiers) + keywordSign; result.SummaryMarkup = "Use the " + Highlight ("extern", colorStyle.KeywordModifiers) + " modifier in a method declaration to indicate that the method is implemented externally. A common use of the extern modifier is with the DllImport attribute."; break; - case "finally": + case SyntaxKind.FinallyKeyword: result.SignatureMarkup = Highlight ("finally", colorStyle.KeywordException) + keywordSign; result.AddCategory ("Form", Highlight ("try", colorStyle.KeywordException) + " try-block " + Highlight ("finally", colorStyle.KeywordException) + " finally-block"); result.SummaryMarkup = "The " + Highlight ("finally", colorStyle.KeywordException) + " block is useful for cleaning up any resources allocated in the try block. Control is always passed to the finally block regardless of how the try block exits."; break; - case "fixed": + case SyntaxKind.FixedKeyword: result.SignatureMarkup = Highlight ("fixed", colorStyle.KeywordOther) + keywordSign; result.AddCategory ("Form", Highlight ("fixed", colorStyle.KeywordOther) + " ( type* ptr = expr ) statement"); result.SummaryMarkup = "Prevents relocation of a variable by the garbage collector."; break; - case "for": + case SyntaxKind.ForKeyword: result.SignatureMarkup = Highlight ("for", colorStyle.KeywordIteration) + keywordSign; result.AddCategory ("Form", Highlight ("for", colorStyle.KeywordIteration) + " ([initializers]; [expression]; [iterators]) statement"); result.SummaryMarkup = "The " + Highlight ("for", colorStyle.KeywordIteration) + " loop executes a statement or a block of statements repeatedly until a specified expression evaluates to false."; break; - case "foreach": + case SyntaxKind.ForEachKeyword: result.SignatureMarkup = Highlight ("foreach", colorStyle.KeywordIteration) + keywordSign; result.AddCategory ("Form", Highlight ("foreach", colorStyle.KeywordIteration) + " (type identifier " + Highlight ("in", colorStyle.KeywordIteration) + " expression) statement"); result.SummaryMarkup = "The " + Highlight ("foreach", colorStyle.KeywordIteration) + " statement repeats a group of embedded statements for each element in an array or an object collection. "; break; - case "from": + case SyntaxKind.FromKeyword: result.SignatureMarkup = Highlight ("from", colorStyle.KeywordContext) + keywordSign; result.AddCategory ("Form", Highlight ("from", colorStyle.KeywordContext) + " range-variable " + Highlight ("in", colorStyle.KeywordIteration) + " data-source [query clauses] " + Highlight ("select", colorStyle.KeywordContext) + " product-expression"); result.SummaryMarkup = "The " + Highlight ("from", colorStyle.KeywordContext) + " keyword marks the beginning of a query expression and defines the data source and local variable to represent the elements in the sequence."; break; - case "get": + case SyntaxKind.GetKeyword: result.SignatureMarkup = Highlight ("get", colorStyle.KeywordContext) + keywordSign; result.AddCategory ("Form", "[modifiers] " + Highlight ("get", colorStyle.KeywordContext) + " [ { accessor-body } ]"); result.SummaryMarkup = "The " + Highlight ("get", colorStyle.KeywordContext) + " keyword is used to define an accessor method to retrieve the value of the property or indexer element."; break; - case "global": + case SyntaxKind.GlobalKeyword: result.SignatureMarkup = Highlight ("global", colorStyle.KeywordContext) + keywordSign; result.AddCategory ("Form", Highlight ("global", colorStyle.KeywordContext) + " :: type"); result.SummaryMarkup = "The " + Highlight ("global", colorStyle.KeywordContext) + " keyword is used to specify a type is within the global namespace."; break; - case "goto": + case SyntaxKind.GotoKeyword: result.SignatureMarkup = Highlight ("goto", colorStyle.KeywordJump) + keywordSign; result.AddCategory ("Form", Highlight ("goto", colorStyle.KeywordJump) + " identifier;" + Environment.NewLine + Highlight ("goto", colorStyle.KeywordJump) + " " + Highlight ("case", colorStyle.KeywordSelection) + " constant-expression;" + Environment.NewLine + Highlight ("goto", colorStyle.KeywordJump) + " " + Highlight ("default", colorStyle.KeywordSelection) + ";"); result.SummaryMarkup = "The " + Highlight ("goto", colorStyle.KeywordJump) + " statement transfers the program control directly to a labeled statement. "; break; - case "group": + case SyntaxKind.GroupKeyword: result.SignatureMarkup = Highlight ("group", colorStyle.KeywordContext) + keywordSign; result.AddCategory ("Query Form", Highlight ("group", colorStyle.KeywordContext) + " range-variable " + Highlight ("by", colorStyle.KeywordContext) + "key-value" + Environment.NewLine + Environment.NewLine + "or" + Environment.NewLine + Environment.NewLine + @@ -1079,7 +1158,7 @@ namespace MonoDevelop.CSharp result.SummaryMarkup = "The " + Highlight ("group", colorStyle.KeywordContext) + " keyword groups elements together from a query which match the key value and stores the result in an " + Highlight ("IGrouping<TKey, TElement>", colorStyle.KeywordTypes) + ". It can also be stored in a group for further use in the query with 'into'."; break; - case "if": + case SyntaxKind.IfKeyword: result.SignatureMarkup = Highlight ("if", colorStyle.KeywordSelection) + keywordSign; result.AddCategory ("Form", Highlight ("if", colorStyle.KeywordSelection) + " (expression)" + Environment.NewLine + " statement1" + Environment.NewLine + @@ -1087,29 +1166,29 @@ namespace MonoDevelop.CSharp " statement2]"); result.SummaryMarkup = "The " + Highlight ("if", colorStyle.KeywordSelection) + " statement selects a statement for execution based on the value of a Boolean expression. "; break; - case "into": + case SyntaxKind.IntoKeyword: result.SignatureMarkup = Highlight ("into", colorStyle.KeywordContext) + keywordSign; result.AddCategory ("Query Form", Highlight ("group", colorStyle.KeywordContext) + " range-variable " + Highlight ("by", colorStyle.KeywordContext) + " key-value " + Highlight ("into", colorStyle.KeywordContext) + " group-name "); result.SummaryMarkup = "The " + Highlight ("into", colorStyle.KeywordContext) + " keyword stores the result of a group statement for further use in the query."; break; - case "implicit": + case SyntaxKind.ImplicitKeyword: result.SignatureMarkup = Highlight ("implicit", colorStyle.KeywordOperatorDeclaration) + keywordSign; result.SummaryMarkup = "The " + Highlight ("implicit", colorStyle.KeywordOperatorDeclaration) + " keyword is used to declare an implicit user-defined type conversion operator."; break; - case "in": + case SyntaxKind.InKeyword: result.SignatureMarkup = Highlight ("in", colorStyle.KeywordIteration) + keywordSign; - if (hintNode != null) { - if (hintNode.Parent is ForeachStatement) { + if (node.Parent != null) { + if (node.Parent is ForEachStatementSyntax) { result.AddCategory ("Form", Highlight ("foreach", colorStyle.KeywordIteration) + " (type identifier " + Highlight ("in", colorStyle.KeywordIteration) + " expression) statement"); break; } - if (hintNode.Parent is QueryFromClause) { + if (node.Parent is FromClauseSyntax) { result.AddCategory ("Form", Highlight ("from", colorStyle.KeywordContext) + " range-variable " + Highlight ("in", colorStyle.KeywordIteration) + " data-source [query clauses] " + Highlight ("select", colorStyle.KeywordContext) + " product-expression"); break; } - if (hintNode.Parent is TypeParameterDeclaration) { + if (node.Parent is TypeParameterConstraintClauseSyntax) { result.AddCategory ("Form", Highlight ("interface", colorStyle.KeywordDeclaration) + " IMyInterface<" + Highlight ("in", colorStyle.KeywordIteration) + " T> {}"); break; @@ -1122,52 +1201,52 @@ namespace MonoDevelop.CSharp Highlight ("interface", colorStyle.KeywordDeclaration) + " IMyInterface<" + Highlight ("in", colorStyle.KeywordIteration) + " T> {}" ); break; - case "interface": + case SyntaxKind.InterfaceKeyword: result.SignatureMarkup = Highlight ("interface", colorStyle.KeywordDeclaration) + keywordSign; result.AddCategory ("Form", "[attributes] [modifiers] " + Highlight ("interface", colorStyle.KeywordDeclaration) + " identifier [:base-list] {interface-body}[;]"); result.SummaryMarkup = "An interface defines a contract. A class or struct that implements an interface must adhere to its contract."; break; - case "internal": + case SyntaxKind.InternalKeyword: result.SignatureMarkup = Highlight ("internal", colorStyle.KeywordModifiers) + keywordSign; result.SummaryMarkup = "The " + Highlight ("internal", colorStyle.KeywordModifiers) + " keyword is an access modifier for types and type members. Internal members are accessible only within files in the same assembly."; break; - case "is": + case SyntaxKind.IsKeyword: result.SignatureMarkup = Highlight ("is", colorStyle.KeywordOperators) + keywordSign; result.AddCategory ("Form", "expression " + Highlight ("is", colorStyle.KeywordOperators) + " type"); result.SummaryMarkup = "The " + Highlight ("is", colorStyle.KeywordOperators) + " operator is used to check whether the run-time type of an object is compatible with a given type."; break; - case "join": + case SyntaxKind.JoinKeyword: result.SignatureMarkup = Highlight ("join", colorStyle.KeywordContext) + keywordSign; result.AddCategory ("Query Form", Highlight ("join", colorStyle.KeywordContext) + " range-variable2 " + Highlight ("in", colorStyle.KeywordContext) + " range2 " + Highlight ("on", colorStyle.KeywordContext) + " statement1 " + Highlight ("equals", colorStyle.KeywordContext) + " statement2 [ " + Highlight ("into", colorStyle.KeywordContext) + " group-name ]"); result.SummaryMarkup = "The " + Highlight ("join", colorStyle.KeywordContext) + " clause produces a new sequence of elements from two source sequences on a given equality condition."; break; - case "let": + case SyntaxKind.LetKeyword: result.SignatureMarkup = Highlight ("let", colorStyle.KeywordContext) + keywordSign; result.AddCategory ("Query Form", Highlight ("let", colorStyle.KeywordContext) + " range-variable = expression"); result.SummaryMarkup = "The " + Highlight ("let", colorStyle.KeywordContext) + " clause allows for a sub-expression to have its value stored in a new range variable for use later in the query."; break; - case "lock": + case SyntaxKind.LockKeyword: result.SignatureMarkup = Highlight ("lock", colorStyle.KeywordOther) + keywordSign; result.AddCategory ("Form", Highlight ("lock", colorStyle.KeywordOther) + " (expression) statement_block"); result.SummaryMarkup = "The " + Highlight ("lock", colorStyle.KeywordOther) + " keyword marks a statement block as a critical section by obtaining the mutual-exclusion lock for a given object, executing a statement, and then releasing the lock. "; break; - case "namespace": + case SyntaxKind.NamespaceKeyword: result.SignatureMarkup = Highlight ("namespace", colorStyle.KeywordNamespace) + keywordSign; result.AddCategory ("Form", Highlight ("namespace", colorStyle.KeywordNamespace) + " name[.name1] ...] {" + Environment.NewLine + "type-declarations" + Environment.NewLine + " }"); result.SummaryMarkup = "The " + Highlight ("namespace", colorStyle.KeywordNamespace) + " keyword is used to declare a scope. "; break; - case "new": + case SyntaxKind.NewKeyword: result.SignatureMarkup = Highlight ("new", colorStyle.KeywordOperators) + keywordSign; result.SummaryMarkup = "The " + Highlight ("new", colorStyle.KeywordOperators) + " keyword can be used as an operator or as a modifier. The operator is used to create objects on the heap and invoke constructors. The modifier is used to hide an inherited member from a base class member."; break; - case "null": + case SyntaxKind.NullKeyword: result.SignatureMarkup = Highlight ("null", colorStyle.KeywordConstants) + keywordSign; result.SummaryMarkup = "The " + Highlight ("null", colorStyle.KeywordConstants) + " keyword is a literal that represents a null reference, one that does not refer to any object. " + Highlight ("null", colorStyle.KeywordConstants) + " is the default value of reference-type variables."; break; - case "operator": + case SyntaxKind.OperatorKeyword: result.SignatureMarkup = Highlight ("operator", colorStyle.KeywordOperatorDeclaration) + keywordSign; result.AddCategory ("Form", Highlight ("public static ", colorStyle.KeywordModifiers) + "result-type " + Highlight ("operator", colorStyle.KeywordOperatorDeclaration) + " unary-operator ( op-type operand )" + Environment.NewLine + Highlight ("public static ", colorStyle.KeywordModifiers) + "result-type " + Highlight ("operator", colorStyle.KeywordOperatorDeclaration) + " binary-operator (" + Environment.NewLine + @@ -1179,20 +1258,20 @@ namespace MonoDevelop.CSharp ); result.SummaryMarkup = "The " + Highlight ("operator", colorStyle.KeywordOperatorDeclaration) + " keyword is used to declare an operator in a class or struct declaration."; break; - case "orderby": + case SyntaxKind.OrderByKeyword: result.SignatureMarkup = Highlight ("orderby", colorStyle.KeywordContext) + keywordSign; result.AddCategory ("Query Form", Highlight ("orderby", colorStyle.KeywordContext) + " order-key1 [ " + Highlight ("ascending", colorStyle.KeywordContext) + "|" + Highlight ("descending", colorStyle.KeywordContext) + " , [order-key2, ...]"); result.SummaryMarkup = "The " + Highlight ("orderby", colorStyle.KeywordContext) + " clause specifies for the returned sequence to be sorted on a given element in either ascending or descending order."; break; - case "out": + case SyntaxKind.OutKeyword: result.SignatureMarkup = Highlight ("out", colorStyle.KeywordParameter) + keywordSign; - if (hintNode != null) { - if (hintNode.Parent is TypeParameterDeclaration) { + if (node.Parent != null) { + if (node.Parent is TypeParameterSyntax) { result.AddCategory ("Form", Highlight ("interface", colorStyle.KeywordDeclaration) + " IMyInterface<" + Highlight ("out", colorStyle.KeywordParameter) + " T> {}"); break; } - if (hintNode.Parent is ParameterDeclaration) { + if (node.Parent is ParameterSyntax) { result.AddCategory ("Form", Highlight ("out", colorStyle.KeywordParameter) + " parameter-name"); result.SummaryMarkup = "The " + Highlight ("out", colorStyle.KeywordParameter) + " method parameter keyword on a method parameter causes a method to refer to the same variable that was passed into the method."; @@ -1206,22 +1285,22 @@ namespace MonoDevelop.CSharp Highlight ("interface", colorStyle.KeywordDeclaration) + " IMyInterface<" + Highlight ("out", colorStyle.KeywordParameter) + " T> {}" ); break; - case "override": + case SyntaxKind.OverrideKeyword: result.SignatureMarkup = Highlight ("override", colorStyle.KeywordModifiers) + keywordSign; result.SummaryMarkup = "The " + Highlight ("override", colorStyle.KeywordModifiers) + " modifier is used to override a method, a property, an indexer, or an event."; break; - case "params": + case SyntaxKind.ParamKeyword: result.SignatureMarkup = Highlight ("params", colorStyle.KeywordParameter) + keywordSign; result.SummaryMarkup = "The " + Highlight ("params", colorStyle.KeywordParameter) + " keyword lets you specify a method parameter that takes an argument where the number of arguments is variable."; break; - case "partial": + case SyntaxKind.PartialKeyword: result.SignatureMarkup = Highlight ("partial", colorStyle.KeywordContext) + keywordSign; - if (hintNode != null) { - if (hintNode.Parent is TypeDeclaration) { + if (node.Parent != null) { + if (node.Parent is TypeDeclarationSyntax) { result.AddCategory ("Form", "[modifiers] " + Highlight ("partial", colorStyle.KeywordContext) + " type-declaration"); result.SummaryMarkup = "The " + Highlight ("partial", colorStyle.KeywordContext) + " keyword on a type declaration allows for the definition to be split into multiple files."; break; - } else if (hintNode.Parent is MethodDeclaration) { + } else if (node.Parent is MethodDeclarationSyntax) { result.AddCategory ("Form", Highlight ("partial", colorStyle.KeywordContext) + " method-declaration"); result.SummaryMarkup = "The " + Highlight ("partial", colorStyle.KeywordContext) + " keyword on a method declaration allows for the implementation of a method to be defined in another part of the partial class."; } @@ -1229,70 +1308,70 @@ namespace MonoDevelop.CSharp result.AddCategory ("Form", "[modifiers] " + Highlight ("partial", colorStyle.KeywordContext) + " type-declaration" + Environment.NewLine + Environment.NewLine + "or" + Environment.NewLine + Environment.NewLine + Highlight ("partial", colorStyle.KeywordContext) + " method-declaration"); break; - case "private": + case SyntaxKind.PrivateKeyword: result.SignatureMarkup = Highlight ("private", colorStyle.KeywordModifiers) + keywordSign; result.SummaryMarkup = "The " + Highlight ("private", colorStyle.KeywordModifiers) + " keyword is a member access modifier. Private access is the least permissive access level. Private members are accessible only within the body of the class or the struct in which they are declared."; break; - case "protected": + case SyntaxKind.ProtectedKeyword: result.SignatureMarkup = Highlight ("protected", colorStyle.KeywordModifiers) + keywordSign; result.SummaryMarkup = "The " + Highlight ("protected", colorStyle.KeywordModifiers) + " keyword is a member access modifier. A protected member is accessible from within the class in which it is declared, and from within any class derived from the class that declared this member."; break; - case "public": + case SyntaxKind.PublicKeyword: result.SignatureMarkup = Highlight ("public", colorStyle.KeywordModifiers) + keywordSign; result.SummaryMarkup = "The " + Highlight ("public", colorStyle.KeywordModifiers) + " keyword is an access modifier for types and type members. Public access is the most permissive access level. There are no restrictions on accessing public members."; break; - case "readonly": + case SyntaxKind.ReadOnlyKeyword: result.SignatureMarkup = Highlight ("readonly", colorStyle.KeywordModifiers) + keywordSign; result.SummaryMarkup = "The " + Highlight ("readonly", colorStyle.KeywordModifiers) + " keyword is a modifier that you can use on fields. When a field declaration includes a " + Highlight ("readonly", colorStyle.KeywordModifiers) + " modifier, assignments to the fields introduced by the declaration can only occur as part of the declaration or in a constructor in the same class."; break; - case "ref": + case SyntaxKind.RefKeyword: result.SignatureMarkup = Highlight ("ref", colorStyle.KeywordParameter) + keywordSign; result.SummaryMarkup = "The " + Highlight ("ref", colorStyle.KeywordParameter) + " method parameter keyword on a method parameter causes a method to refer to the same variable that was passed into the method."; break; - case "remove": + case SyntaxKind.RemoveKeyword: result.SignatureMarkup = Highlight ("remove", colorStyle.KeywordContext) + keywordSign; result.AddCategory ("Form", "[modifiers] " + Highlight ("remove", colorStyle.KeywordContext) + " { accessor-body }"); result.SummaryMarkup = "The " + Highlight ("remove", colorStyle.KeywordContext) + " keyword is used to define a custom accessor for when an event is unsubscribed from. If supplied, an add accessor must also be supplied."; break; - case "return": + case SyntaxKind.ReturnKeyword: result.SignatureMarkup = Highlight ("return", colorStyle.KeywordJump) + keywordSign; result.AddCategory ("Form", Highlight ("return", colorStyle.KeywordJump) + " [expression];"); result.SummaryMarkup = "The " + Highlight ("return", colorStyle.KeywordJump) + " statement terminates execution of the method in which it appears and returns control to the calling method."; break; - case "select": + case SyntaxKind.SelectKeyword: result.SignatureMarkup = Highlight ("select", colorStyle.KeywordContext) + keywordSign; result.AddCategory ("Query Form", Highlight ("select", colorStyle.KeywordContext) + " return-type"); result.SummaryMarkup = "The " + Highlight ("select", colorStyle.KeywordContext) + " clause specifies the type of value to return from the query."; break; - case "sealed": + case SyntaxKind.SealedKeyword: result.SignatureMarkup = Highlight ("sealed", colorStyle.KeywordModifiers) + keywordSign; result.SummaryMarkup = "A sealed class cannot be inherited."; break; - case "set": + case SyntaxKind.SetKeyword: result.SignatureMarkup = Highlight ("set", colorStyle.KeywordContext) + keywordSign; result.AddCategory ("Form", "[modifiers] " + Highlight ("set", colorStyle.KeywordContext) + " [ { accessor-body } ]"); result.SummaryMarkup = "The " + Highlight ("set", colorStyle.KeywordContext) + " keyword is used to define an accessor method to assign to the value of the property or indexer element."; break; - case "sizeof": + case SyntaxKind.SizeOfKeyword: result.SignatureMarkup = Highlight ("sizeof", colorStyle.KeywordOperators) + keywordSign; result.AddCategory ("Form", Highlight ("sizeof", colorStyle.KeywordOperators) + " (type)"); result.SummaryMarkup = "The " + Highlight ("sizeof", colorStyle.KeywordOperators) + " operator is used to obtain the size in bytes for a value type."; break; - case "stackalloc": + case SyntaxKind.StackAllocKeyword: result.SignatureMarkup = Highlight ("stackalloc", colorStyle.KeywordOperators) + keywordSign; result.AddCategory ("Form", "type * ptr = " + Highlight ("stackalloc", colorStyle.KeywordOperators) + " type [ expr ];"); result.SummaryMarkup = "Allocates a block of memory on the stack."; break; - case "static": + case SyntaxKind.StaticKeyword: result.SignatureMarkup = Highlight ("static", colorStyle.KeywordModifiers) + keywordSign; result.SummaryMarkup = "Use the " + Highlight ("static", colorStyle.KeywordModifiers) + " modifier to declare a static member, which belongs to the type itself rather than to a specific object."; break; - case "struct": + case SyntaxKind.StructKeyword: result.SignatureMarkup = Highlight ("struct", colorStyle.KeywordDeclaration) + keywordSign; result.AddCategory ("Form", "[attributes] [modifiers] " + Highlight ("struct", colorStyle.KeywordDeclaration) + " identifier [:interfaces] body [;]"); result.SummaryMarkup = "A " + Highlight ("struct", colorStyle.KeywordDeclaration) + " type is a value type that can contain constructors, constants, fields, methods, properties, indexers, operators, events, and nested types. "; break; - case "switch": + case SyntaxKind.SwitchKeyword: result.SignatureMarkup = Highlight ("switch", colorStyle.KeywordSelection) + keywordSign; result.AddCategory ("Form", Highlight ("switch", colorStyle.KeywordSelection) + " (expression)" + Environment.NewLine + " {" + Environment.NewLine + @@ -1305,16 +1384,16 @@ namespace MonoDevelop.CSharp " }"); result.SummaryMarkup = "The " + Highlight ("switch", colorStyle.KeywordSelection) + " statement is a control statement that handles multiple selections by passing control to one of the " + Highlight ("case", colorStyle.KeywordSelection) + " statements within its body."; break; - case "this": + case SyntaxKind.ThisKeyword: result.SignatureMarkup = Highlight ("this", colorStyle.KeywordAccessors) + keywordSign; result.SummaryMarkup = "The " + Highlight ("this", colorStyle.KeywordAccessors) + " keyword refers to the current instance of the class."; break; - case "throw": + case SyntaxKind.ThrowKeyword: result.SignatureMarkup = Highlight ("throw", colorStyle.KeywordException) + keywordSign; result.AddCategory ("Form", Highlight ("throw", colorStyle.KeywordException) + " [expression];"); result.SummaryMarkup = "The " + Highlight ("throw", colorStyle.KeywordException) + " statement is used to signal the occurrence of an anomalous situation (exception) during the program execution."; break; - case "try": + case SyntaxKind.TryKeyword: result.SignatureMarkup = Highlight ("try", colorStyle.KeywordException) + keywordSign; result.AddCategory ("Form", Highlight ("try", colorStyle.KeywordException) + " try-block" + Environment.NewLine + " " + Highlight ("catch", colorStyle.KeywordException) + " (exception-declaration-1) catch-block-1 " + Environment.NewLine + @@ -1323,48 +1402,48 @@ namespace MonoDevelop.CSharp Highlight ("try", colorStyle.KeywordException) + " try-block " + Highlight ("catch", colorStyle.KeywordException) + " catch-block"); result.SummaryMarkup = "The try-catch statement consists of a " + Highlight ("try", colorStyle.KeywordException) + " block followed by one or more " + Highlight ("catch", colorStyle.KeywordException) + " clauses, which specify handlers for different exceptions."; break; - case "typeof": + case SyntaxKind.TypeOfKeyword: result.SignatureMarkup = Highlight ("typeof", colorStyle.KeywordOperators) + keywordSign; result.AddCategory ("Form", Highlight ("typeof", colorStyle.KeywordOperators) + "(type)"); result.SummaryMarkup = "The " + Highlight ("typeof", colorStyle.KeywordOperators) + " operator is used to obtain the System.Type object for a type."; break; - case "unchecked": + case SyntaxKind.UncheckedKeyword: result.SignatureMarkup = Highlight ("unchecked", colorStyle.KeywordOther) + keywordSign; result.AddCategory ("Form", Highlight ("unchecked", colorStyle.KeywordOther) + " block" + Environment.NewLine + Highlight ("unchecked", colorStyle.KeywordOther) + " (expression)"); result.SummaryMarkup = "The " + Highlight ("unchecked", colorStyle.KeywordOther) + " keyword is used to control the overflow-checking context for integral-type arithmetic operations and conversions."; break; - case "unsafe": + case SyntaxKind.UnsafeKeyword: result.SignatureMarkup = Highlight ("unsafe", colorStyle.KeywordOther) + keywordSign; result.SummaryMarkup = "The " + Highlight ("unsafe", colorStyle.KeywordOther) + " keyword denotes an unsafe context, which is required for any operation involving pointers."; break; - case "using": + case SyntaxKind.UsingKeyword: result.SignatureMarkup = Highlight ("using", colorStyle.KeywordNamespace) + keywordSign; result.AddCategory ("Form", Highlight ("using", colorStyle.KeywordNamespace) + " (expression | type identifier = initializer) statement" + Environment.NewLine + Highlight ("using", colorStyle.KeywordNamespace) + " [alias = ]class_or_namespace;"); result.SummaryMarkup = "The " + Highlight ("using", colorStyle.KeywordNamespace) + " directive creates an alias for a namespace or imports types defined in other namespaces. The " + Highlight ("using", colorStyle.KeywordNamespace) + " statement defines a scope at the end of which an object will be disposed."; break; - case "virtual": + case SyntaxKind.VirtualKeyword: result.SignatureMarkup = Highlight ("virtual", colorStyle.KeywordModifiers) + keywordSign; result.SummaryMarkup = "The " + Highlight ("virtual", colorStyle.KeywordModifiers) + " keyword is used to modify a method, property, indexer, or event declaration and allow for it to be overridden in a derived class."; break; - case "volatile": + case SyntaxKind.VolatileKeyword: result.SignatureMarkup = Highlight ("volatile", colorStyle.KeywordModifiers) + keywordSign; result.AddCategory ("Form", Highlight ("volatile", colorStyle.KeywordModifiers) + " declaration"); result.SummaryMarkup = "The " + Highlight ("volatile", colorStyle.KeywordModifiers) + " keyword indicates that a field can be modified in the program by something such as the operating system, the hardware, or a concurrently executing thread."; break; - case "void": + case SyntaxKind.VoidKeyword: result.SignatureMarkup = Highlight ("void", colorStyle.KeywordTypes) + keywordSign; break; - case "where": + case SyntaxKind.WhereKeyword: result.SignatureMarkup = Highlight ("where", colorStyle.KeywordContext) + keywordSign; - if (hintNode != null) { - if (hintNode.Parent is QueryWhereClause) { + if (node.Parent != null) { + if (node.Parent is WhereClauseSyntax) { result.AddCategory ("Query Form", Highlight ("where", colorStyle.KeywordContext) + " condition"); result.SummaryMarkup = "The " + Highlight ("where", colorStyle.KeywordContext) + " clause specifies which elements from the data source to be returned according to a given condition."; break; } - if (hintNode.Parent is Constraint) { + if (node.Parent is TypeConstraintSyntax) { result.AddCategory ("Form", "generic-class-declaration " + Highlight ("where", colorStyle.KeywordContext) + " type-parameter : type-constraint"); result.SummaryMarkup = "The " + Highlight ("where", colorStyle.KeywordContext) + " clause constrains which types can be used as the type parameter in a generic declaration."; break; @@ -1375,41 +1454,43 @@ namespace MonoDevelop.CSharp " condition" + " [query-clauses]"); } break; - case "yield": + case SyntaxKind.YieldKeyword: result.SignatureMarkup = Highlight ("yield", colorStyle.KeywordContext) + keywordSign; result.AddCategory ("Form", Highlight ("yield", colorStyle.KeywordContext) + Highlight ("break", colorStyle.KeywordJump) + Environment.NewLine + Environment.NewLine + "or" + Environment.NewLine + Environment.NewLine + Highlight ("yield", colorStyle.KeywordContext) + Highlight ("return", colorStyle.KeywordJump) + " expression"); result.SummaryMarkup = "The " + Highlight ("yield", colorStyle.KeywordContext) + " keyword is used to indicate that a method, get accessor, or operator is an iterator."; break; - case "while": + case SyntaxKind.WhileKeyword: result.SignatureMarkup = Highlight ("while", colorStyle.KeywordIteration) + keywordSign; result.AddCategory ("Form", Highlight ("while", colorStyle.KeywordIteration) + " (expression) statement"); result.SummaryMarkup = "The " + Highlight ("while", colorStyle.KeywordIteration) + " statement executes a statement or a block of statements until a specified expression evaluates to false. "; break; + default: + return null; } return result; } - public TooltipInformation GetConstraintTooltip (string keyword) + public TooltipInformation GetConstraintTooltip (SyntaxToken keyword) { var result = new TooltipInformation (); var color = AlphaBlend (colorStyle.PlainText.Foreground, colorStyle.PlainText.Background, optionalAlpha); - var colorString = Mono.TextEditor.HelperMethods.GetColorString (color); + var colorString = MonoDevelop.Components.HelperMethods.GetColorString (color); var keywordSign = "<span foreground=\"" + colorString + "\">" + " (keyword)</span>"; - result.SignatureMarkup = Highlight (keyword, colorStyle.KeywordTypes) + keywordSign; + result.SignatureMarkup = Highlight (keyword.ToFullString (), colorStyle.KeywordTypes) + keywordSign; - switch (keyword) { - case "class": + switch (keyword.Parent.Kind ()) { + case SyntaxKind.ClassConstraint: result.AddCategory ("Constraint", "The type argument must be a reference type; this applies also to any class, interface, delegate, or array type."); break; - case "new": + case SyntaxKind.ConstructorConstraint: result.AddCategory ("Constraint", "The type argument must have a public parameterless constructor. When used together with other constraints, the new() constraint must be specified last."); break; - case "struct": + case SyntaxKind.StructConstraint: result.AddCategory ("Constraint", "The type argument must be a value type. Any value type except Nullable can be specified. See Using Nullable Types (C# Programming Guide) for more information."); break; } @@ -1417,48 +1498,48 @@ namespace MonoDevelop.CSharp return result; } - public TooltipInformation GetTypeOfTooltip (TypeOfExpression typeOfExpression, TypeOfResolveResult resolveResult) + public TooltipInformation GetTypeOfTooltip (TypeOfExpressionSyntax typeOfExpression, ITypeSymbol resolveResult) { var result = new TooltipInformation (); if (resolveResult == null) { - result.SignatureMarkup = AmbienceService.EscapeText (typeOfExpression.Type.ToString ()); + result.SignatureMarkup = Ambience.EscapeText (typeOfExpression.Type.ToString ()); } else { - result.SignatureMarkup = GetTypeMarkup (resolveResult.ReferencedType, true); + result.SignatureMarkup = GetTypeMarkup (resolveResult, true); } return result; } - public TooltipInformation GetAliasedNamespaceTooltip (AliasNamespaceResolveResult resolveResult) - { - var result = new TooltipInformation (); - result.SignatureMarkup = GetMarkup (resolveResult.Namespace); - result.AddCategory (GettextCatalog.GetString ("Alias information"), GettextCatalog.GetString ("Resolved using alias '{0}'", resolveResult.Alias)); - return result; - } - - public TooltipInformation GetAliasedTypeTooltip (AliasTypeResolveResult resolveResult) - { - var result = new TooltipInformation (); - result.SignatureMarkup = GetTypeMarkup (resolveResult.Type, true); - result.AddCategory (GettextCatalog.GetString ("Alias information"), GettextCatalog.GetString ("Resolved using alias '{0}'", resolveResult.Alias)); - return result; - } - - string GetEventMarkup (IEvent evt) +// public TooltipInformation GetAliasedNamespaceTooltip (AliasNamespaceResolveResult resolveResult) +// { +// var result = new TooltipInformation (); +// result.SignatureMarkup = GetMarkup (resolveResult.Namespace); +// result.AddCategory (GettextCatalog.GetString ("Alias information"), GettextCatalog.GetString ("Resolved using alias '{0}'", resolveResult.Alias)); +// return result; +// } +// +// public TooltipInformation GetAliasedTypeTooltip (AliasTypeResolveResult resolveResult) +// { +// var result = new TooltipInformation (); +// result.SignatureMarkup = GetTypeMarkup (resolveResult.Type, true); +// result.AddCategory (GettextCatalog.GetString ("Alias information"), GettextCatalog.GetString ("Resolved using alias '{0}'", resolveResult.Alias)); +// return result; +// } + + string GetEventMarkup (IEventSymbol evt) { if (evt == null) throw new ArgumentNullException ("evt"); var result = new StringBuilder (); AppendModifiers (result, evt); result.Append (Highlight ("event ", colorStyle.KeywordModifiers)); - result.Append (GetTypeReferenceString (evt.ReturnType)); + result.Append (GetTypeReferenceString (evt.Type)); if (BreakLineAfterReturnType) { result.AppendLine (); } else { result.Append (" "); } - - AppendExplicitInterfaces (result, evt); + + AppendExplicitInterfaces (result, evt.ExplicitInterfaceImplementations.Cast<ISymbol>()); result.Append (HighlightSemantically (FilterEntityName (evt.Name), colorStyle.UserEventDeclaration)); return result.ToString (); } @@ -1474,17 +1555,17 @@ namespace MonoDevelop.CSharp } } - void AppendParameterList (StringBuilder result, IList<IParameter> parameterList, bool spaceBefore, bool spaceAfter, bool newLine = true) + void AppendParameterList (StringBuilder result, ImmutableArray<IParameterSymbol> parameterList, bool spaceBefore, bool spaceAfter, bool newLine = true) { - if (parameterList == null || parameterList.Count == 0) + if (parameterList == null || parameterList.Length == 0) return; if (newLine) result.AppendLine (); - for (int i = 0; i < parameterList.Count; i++) { + for (int i = 0; i < parameterList.Length; i++) { var parameter = parameterList [i]; if (newLine) result.Append (new string (' ', 2)); - var doHighightParameter = i == HighlightParameter || HighlightParameter >= i && i == parameterList.Count - 1 && parameter.IsParams; + var doHighightParameter = i == HighlightParameter || HighlightParameter >= i && i == parameterList.Length - 1 && parameter.IsParams; if (doHighightParameter) result.Append ("<u>"); /* if (parameter.IsOptional) { @@ -1495,18 +1576,18 @@ namespace MonoDevelop.CSharp }*/ AppendParameter (result, parameter); if (parameter.IsOptional) { - if (formattingOptions.SpaceAroundAssignment) { + if (options.GetOption (CSharpFormattingOptions.SpacingAroundBinaryOperator) == BinaryOperatorSpacingOptions.Single) { result.Append (" = "); } else { result.Append ("="); } - AppendConstant (result, parameter.Type, parameter.ConstantValue); + AppendConstant (result, parameter.Type, parameter.ExplicitDefaultValue); // GrayOut = false; // result.Append ("</span>"); } if (doHighightParameter) result.Append ("</u>"); - if (i + 1 < parameterList.Count) { + if (i + 1 < parameterList.Length) { if (spaceBefore) result.Append (' '); result.Append (','); @@ -1522,13 +1603,13 @@ namespace MonoDevelop.CSharp result.AppendLine (); } - void AppendParameter (StringBuilder result, IParameter parameter) + void AppendParameter (StringBuilder result, IParameterSymbol parameter) { if (parameter == null) return; - if (parameter.IsOut) { + if (parameter.RefKind == RefKind.Out) { result.Append (Highlight ("out ", colorStyle.KeywordParameter)); - } else if (parameter.IsRef) { + } else if (parameter.RefKind == RefKind.Ref) { result.Append (Highlight ("ref ", colorStyle.KeywordParameter)); } else if (parameter.IsParams) { result.Append (Highlight ("params ", colorStyle.KeywordParameter)); @@ -1538,12 +1619,10 @@ namespace MonoDevelop.CSharp result.Append (FilterEntityName (parameter.Name)); } - void AppendExplicitInterfaces (StringBuilder sb, IMember member) + void AppendExplicitInterfaces (StringBuilder sb, IEnumerable<Microsoft.CodeAnalysis.ISymbol> member) { - if (member == null || !member.IsExplicitInterfaceImplementation) - return; - foreach (var implementedInterfaceMember in member.ImplementedInterfaceMembers) { - sb.Append (GetTypeReferenceString (implementedInterfaceMember.DeclaringTypeDefinition)); + foreach (var implementedInterfaceMember in member) { + sb.Append (GetTypeReferenceString (implementedInterfaceMember.ContainingType)); sb.Append ("."); } } @@ -1560,7 +1639,7 @@ namespace MonoDevelop.CSharp } } - void AppendConstant (StringBuilder sb, IType constantType, object constantValue, bool useNumericalEnumValue = false) + void AppendConstant (StringBuilder sb, ITypeSymbol constantType, object constantValue, bool useNumericalEnumValue = false) { if (constantValue is string) { sb.Append (Highlight ("\"" + constantValue + "\"", colorStyle.String)); @@ -1576,7 +1655,7 @@ namespace MonoDevelop.CSharp } if (constantValue == null) { - if (constantType.Kind == TypeKind.Struct) { + if (constantType.TypeKind == TypeKind.Struct) { // structs can never be == null, therefore it's the default value. sb.Append (Highlight ("default", colorStyle.KeywordSelection) + "(" + GetTypeReferenceString (constantType) + ")"); } else { @@ -1584,11 +1663,11 @@ namespace MonoDevelop.CSharp } return; } - - while (NullableType.IsNullable (constantType)) - constantType = NullableType.GetUnderlyingType (constantType); - if (constantType.Kind == TypeKind.Enum) { - foreach (var field in constantType.GetFields ()) { +// TODOδ +// while (IsNullableType (constantType)) +// constantType = NullableType.GetUnderlyingType (constantType); + if (constantType.TypeKind == TypeKind.Enum) { + foreach (var field in constantType.GetMembers ().OfType<IFieldSymbol> ()) { if (field.ConstantValue == constantValue) { if (useNumericalEnumValue) { sb.Append (Highlight (string.Format ("0x{0:X}", field.ConstantValue), colorStyle.Number)); @@ -1599,11 +1678,11 @@ namespace MonoDevelop.CSharp } } // try to decompose flags - if (constantType.GetDefinition ().Attributes.Any (attr => attr.AttributeType.Name == "FlagsAttribute" && attr.AttributeType.Namespace == "System")) { + if (constantType.GetAttributes ().Any (attr => attr.AttributeClass.Name == "FlagsAttribute" && attr.AttributeClass.ContainingNamespace.Name == "System")) { var val = GetUlong (constantValue.ToString ()); var outVal = 0UL; - var fields = new List<IField> (); - foreach (var field in constantType.GetFields ()) { + var fields = new List<IFieldSymbol> (); + foreach (var field in constantType.GetMembers ().OfType<IFieldSymbol> ()) { if (field.ConstantValue == null) continue; var val2 = GetUlong (field.ConstantValue.ToString ()); @@ -1631,11 +1710,11 @@ namespace MonoDevelop.CSharp sb.Append (Highlight (constantValue.ToString (), colorStyle.Number)); } - void AppendVariance (StringBuilder sb, VarianceModifier variance) + void AppendVariance (StringBuilder sb, VarianceKind variance) { - if (variance == VarianceModifier.Contravariant) { + if (variance == VarianceKind.In) { sb.Append (Highlight ("in ", colorStyle.KeywordParameter)); - } else if (variance == VarianceModifier.Covariant) { + } else if (variance == VarianceKind.Out) { sb.Append (Highlight ("out ", colorStyle.KeywordParameter)); } } @@ -1654,7 +1733,12 @@ namespace MonoDevelop.CSharp return AlphaBlend ((Gdk.Color)((HslColor)color), (Gdk.Color)((HslColor)color2), alpha); } - public string GetArrayIndexerMarkup (ArrayType arrayType) + HslColor AlphaBlend (HslColor color, HslColor color2, double alpha) + { + return (HslColor)AlphaBlend ((Gdk.Color )color, (Gdk.Color)color2, alpha); + } + + public string GetArrayIndexerMarkup (IArrayTypeSymbol arrayType) { if (arrayType == null) throw new ArgumentNullException ("arrayType"); @@ -1667,7 +1751,7 @@ namespace MonoDevelop.CSharp } result.Append (Highlight ("this", colorStyle.KeywordAccessors)); result.Append ("["); - for (int i = 0; i < arrayType.Dimensions; i++) { + for (int i = 0; i < arrayType.Rank; i++) { if (i > 0) result.Append (", "); var doHighightParameter = i == HighlightParameter; @@ -1675,7 +1759,7 @@ namespace MonoDevelop.CSharp result.Append ("<u>"); result.Append (Highlight ("int ", colorStyle.KeywordTypes)); - result.Append (arrayType.Dimensions == 1 ? "index" : "i" + (i + 1)); + result.Append (arrayType.Rank == 1 ? "index" : "i" + (i + 1)); if (doHighightParameter) result.Append ("</u>"); } @@ -1698,51 +1782,53 @@ namespace MonoDevelop.CSharp color = AlphaBlend (color, (Gdk.Color)((HslColor)colorStyle.PlainText.Background), optionalAlpha); } - var colorString = Mono.TextEditor.HelperMethods.GetColorString (color); + var colorString = MonoDevelop.Components.HelperMethods.GetColorString (color); return "<span foreground=\"" + colorString + "\">" + str + "</span>"; } string HighlightSemantically (string str, ChunkStyle style) { - if (!MonoDevelop.SourceEditor.DefaultSourceEditorOptions.Instance.EnableSemanticHighlighting) + if (!DefaultSourceEditorOptions.Instance.EnableSemanticHighlighting) return str; return Highlight (str, style); } - public string CreateFooter (IEntity entity) + public string CreateFooter (ISymbol entity) { - var type = entity as IType; + var type = entity as ITypeSymbol; if (type != null) { - var def = type.GetDefinition (); - if (def != null) { - if (!def.Region.IsEmpty) { - MonoDevelop.Projects.Project project; - - if (def.TryGetSourceProject (out project)) { - var relPath = FileService.AbsoluteToRelativePath (project.BaseDirectory, def.Region.FileName); - return (string.IsNullOrEmpty (def.Namespace) ? "" : "<small>" + GettextCatalog.GetString ("Namespace:\t{0}", AmbienceService.EscapeText (def.Namespace)) + "</small>" + Environment.NewLine) + - "<small>" + GettextCatalog.GetString ("Project:\t{0}", AmbienceService.EscapeText (def.ParentAssembly.AssemblyName)) + "</small>" + Environment.NewLine + - "<small>" + GettextCatalog.GetString ("File:\t\t{0} (line {1})", AmbienceService.EscapeText (relPath), def.Region.Begin.Line) + "</small>"; - } - } - return (string.IsNullOrEmpty (def.Namespace) ? "" : "<small>" + GettextCatalog.GetString ("Namespace:\t{0}", AmbienceService.EscapeText (def.Namespace)) + "</small>" + Environment.NewLine) + - "<small>" + GettextCatalog.GetString ("Assembly:\t{0}", AmbienceService.EscapeText (def.ParentAssembly.AssemblyName)) + "</small>"; + var loc = type.Locations.First (); + if (loc.IsInSource) {// TODO: +// MonoDevelop.Projects.Project project; +// +// if (type.TryGetSourceProject (out project)) { +// var relPath = FileService.AbsoluteToRelativePath (project.BaseDirectory, loc.SourceTree.FilePath); +// var line = loc.SourceTree.GetLineSpan (loc.SourceSpan, true).StartLinePosition.Line; +// +// return (type.ContainingNamespace.IsGlobalNamespace ? "" : "<small>" + GettextCatalog.GetString ("Namespace:\t{0}", AmbienceService.EscapeText (type.ContainingNamespace.Name)) + "</small>" + Environment.NewLine) + +// "<small>" + GettextCatalog.GetString ("Project:\t{0}", AmbienceService.EscapeText (type.ContainingAssembly.Name)) + "</small>" + Environment.NewLine + +// "<small>" + GettextCatalog.GetString ("File:\t\t{0} (line {1})", AmbienceService.EscapeText (relPath), line) + "</small>"; +// } } - return null; + return (type.ContainingNamespace.IsGlobalNamespace ? "" : "<small>" + GettextCatalog.GetString ("Namespace:\t{0}", Ambience.EscapeText (type.ContainingNamespace.Name)) + "</small>" + Environment.NewLine) + + "<small>" + GettextCatalog.GetString ("Assembly:\t{0}", Ambience.EscapeText (type.ContainingAssembly.Name)) + "</small>"; } - if (entity.DeclaringTypeDefinition != null) { - if (!entity.Region.IsEmpty) { - MonoDevelop.Projects.Project project; - if (entity.DeclaringTypeDefinition.TryGetSourceProject (out project)) { - var relPath = FileService.AbsoluteToRelativePath (project.BaseDirectory, entity.Region.FileName); - return "<small>" + GettextCatalog.GetString ("Project:\t{0}", AmbienceService.EscapeText (project.Name)) + "</small>" + Environment.NewLine + - "<small>" + GettextCatalog.GetString ("From type:\t{0}", AmbienceService.EscapeText (entity.DeclaringTypeDefinition.FullName)) + "</small>" + Environment.NewLine + - "<small>" + GettextCatalog.GetString ("File:\t\t{0} (line {1})", AmbienceService.EscapeText (relPath), entity.Region.Begin.Line) + "</small>"; - } + if (entity.ContainingType != null) { + var loc = entity.Locations.First (); + if (!loc.IsInSource) { + // TODO: +// MonoDevelop.Projects.Project project; +// if (entity.ContainingType.TryGetSourceProject (out project)) { +// var relPath = FileService.AbsoluteToRelativePath (project.BaseDirectory, loc.SourceTree.FilePath); +// var line = loc.SourceTree.GetLineSpan (loc.SourceSpan, true).StartLinePosition.Line; +// return "<small>" + GettextCatalog.GetString ("Project:\t{0}", AmbienceService.EscapeText (project.Name)) + "</small>" + Environment.NewLine + +// "<small>" + GettextCatalog.GetString ("From type:\t{0}", AmbienceService.EscapeText (entity.ContainingType.Name)) + "</small>" + Environment.NewLine + +// "<small>" + GettextCatalog.GetString ("File:\t\t{0} (line {1})", AmbienceService.EscapeText (relPath), line) + "</small>"; +// } } - return "<small>" + GettextCatalog.GetString ("From type:\t{0}", AmbienceService.EscapeText (entity.DeclaringTypeDefinition.FullName)) + "</small>" + Environment.NewLine + - "<small>" + GettextCatalog.GetString ("Assembly:\t{0}", AmbienceService.EscapeText (entity.DeclaringTypeDefinition.ParentAssembly.AssemblyName)) + "</small>"; + return "<small>" + GettextCatalog.GetString ("From type:\t{0}", Ambience.EscapeText (entity.ContainingType.Name)) + "</small>" + Environment.NewLine + + "<small>" + GettextCatalog.GetString ("Assembly:\t{0}", Ambience.EscapeText (entity.ContainingAssembly.Name)) + "</small>"; } return null; } |