public static void Main(string[] args) { OverrideMethod om = new OverrideMethod(); om.Print(100); om.Print(3.14); GenericMethod gm = new GenericMethod(); gm.Print <int>(100); gm.Print <double>(3.14); gm.Print <string>("ABC"); }
static void Main(string[] args) { OverrideMethod om = new OverrideMethod(); om.Print(1); om.Print(3.14); om.Print("Hello World"); GenericMethod gm = new GenericMethod(); gm.Print <int>(1); gm.Print <double>(3.14); gm.Print <string>("Hello World"); }
public IEnumerable <SnippetCompletion> EnumSnippets( SymbolDefinition context, FGGrammar.TokenSet expectedTokens, SyntaxToken tokenLeft, Scope scope) { OverrideMethod.context = scope; if (tokenLeft == null || tokenLeft.parent == null || tokenLeft.parent.parent == null) { yield break; } if (tokenLeft.tokenKind != SyntaxToken.Kind.Keyword) { yield break; } if (tokenLeft.text != "override") { yield break; } var bodyScope = scope as BodyScope; if (bodyScope == null) { yield break; } var contextType = bodyScope.definition as TypeDefinitionBase; if (contextType == null || contextType.kind != SymbolKind.Class && contextType.kind != SymbolKind.Struct) { yield break; } var baseType = contextType.BaseType(); if (baseType == null || baseType.kind != SymbolKind.Class && baseType.kind != SymbolKind.Struct) { yield break; } var overrideMethodCandidates = new List <MethodDefinition>(); baseType.ListOverrideCandidates(overrideMethodCandidates, contextType.Assembly); if (overrideMethodCandidates.Count == 0) { yield break; } var textBuffer = FGTextBuffer.activeEditor.TextBuffer; var firstToken = tokenLeft.parent.parent.GetFirstLeaf().token; if (firstToken.formatedLine != tokenLeft.formatedLine) { firstToken = tokenLeft.formatedLine.tokens[0]; while (firstToken.tokenKind <= SyntaxToken.Kind.LastWSToken) { firstToken = firstToken.formatedLine.tokens[firstToken.TokenIndex + 1]; } } var tokenSpan = textBuffer.GetTokenSpan(firstToken.parent); OverrideMethod.overrideTextLength = FGTextBuffer.activeEditor.caretPosition.characterIndex - tokenSpan.StartPosition.index; foreach (var method in overrideMethodCandidates) { var methodGroup = contextType.FindName(method.name, -1, false) as MethodGroupDefinition; if (methodGroup != null) { bool skipThis = false; var signature = method.PrintParameters(method.GetParameters(), true); foreach (var m in methodGroup.methods) { if (method.NumTypeParameters == m.NumTypeParameters && signature == m.PrintParameters(m.GetParameters())) { skipThis = true; break; } } if (skipThis) { continue; } } var overrideCompletion = new OverrideMethod(method); yield return(overrideCompletion); } }
public IEnumerable<SnippetCompletion> EnumSnippets( SymbolDefinition context, FGGrammar.TokenSet expectedTokens, SyntaxToken tokenLeft, Scope scope) { OverrideMethod.context = scope; if (tokenLeft == null || tokenLeft.parent == null || tokenLeft.parent.parent == null) yield break; if (tokenLeft.tokenKind != SyntaxToken.Kind.Keyword) yield break; if (tokenLeft.text != "override") yield break; var bodyScope = scope as BodyScope; if (bodyScope == null) yield break; var contextType = bodyScope.definition as TypeDefinitionBase; if (contextType == null || contextType.kind != SymbolKind.Class && contextType.kind != SymbolKind.Struct) yield break; var baseType = contextType.BaseType(); if (baseType == null || baseType.kind != SymbolKind.Class && baseType.kind != SymbolKind.Struct) yield break; var overrideMethodCandidates = new List<MethodDefinition>(); baseType.ListOverrideCandidates(overrideMethodCandidates, contextType.Assembly); if (overrideMethodCandidates.Count == 0) yield break; var textBuffer = FGTextBuffer.activeEditor.TextBuffer; var firstToken = tokenLeft.parent.parent.GetFirstLeaf().token; if (firstToken.formatedLine != tokenLeft.formatedLine) { firstToken = tokenLeft.formatedLine.tokens[0]; while (firstToken.tokenKind <= SyntaxToken.Kind.LastWSToken) firstToken = firstToken.formatedLine.tokens[firstToken.TokenIndex + 1]; } var tokenSpan = textBuffer.GetTokenSpan(firstToken.parent); OverrideMethod.overrideTextLength = FGTextBuffer.activeEditor.caretPosition.characterIndex - tokenSpan.StartPosition.index; foreach (var method in overrideMethodCandidates) { var methodGroup = contextType.FindName(method.name, -1, false) as MethodGroupDefinition; if (methodGroup != null) { bool skipThis = false; var signature = method.PrintParameters(method.GetParameters(), true); foreach (var m in methodGroup.methods) { if (method.NumTypeParameters == m.NumTypeParameters && signature == m.PrintParameters(m.GetParameters())) { skipThis = true; break; } } if (skipThis) continue; } var overrideCompletion = new OverrideMethod(method); yield return overrideCompletion; } }