private async Task<Document> MakeIDataServiceAsync(Document document, InterfaceDeclarationSyntax interfaceDeclaration, CancellationToken cancellationToken) { var newImplementation = @" void Add(object dataSource); void Delete(object dataSource); void Save(object dataSource); System.Linq.IQueryable<object> GetAllItems(); "; var newInterfaceTree = SyntaxFactory.ParseSyntaxTree(newImplementation). GetRoot().DescendantNodes(). Where(n=> n.IsKind(SyntaxKind.MethodDeclaration)).Cast<MethodDeclarationSyntax>().Select(m=> m.WithAdditionalAnnotations(Formatter.Annotation, Simplifier.Annotation)).ToArray(); var newInterfaceBlock = SyntaxFactory.InterfaceDeclaration("IDataService"). AddModifiers(SyntaxFactory.ParseToken("public")).WithOpenBraceToken(SyntaxFactory.ParseToken("{")). WithCloseBraceToken(SyntaxFactory.ParseToken("}").WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed)); var newInterfaceNode = newInterfaceBlock.AddMembers(newInterfaceTree).NormalizeWhitespace(); var root = await document.GetSyntaxRootAsync(); SyntaxNode newRoot = root.ReplaceNode(interfaceDeclaration, newInterfaceNode); var newDocument = document.WithSyntaxRoot(newRoot); return newDocument; }
private InterfaceDeclarationSyntax addType(PropertyWithName pwn, InterfaceDeclarationSyntax @interface) { var method = MethodDeclaration(ParseTypeName($"I{pwn.Type.Name}"), $"Create{pwn.Type.Name}") .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)); return @interface.AddMembers(method); }
public InterfaceDeclarationTranslation(InterfaceDeclarationSyntax syntax, SyntaxTranslation parent) : base(syntax, parent) { if (syntax.BaseList != null) { BaseList = syntax.BaseList.Get<BaseListTranslation>(this); BaseList.IsForInterface = true; } }
public override SyntaxNode VisitInterfaceDeclaration(InterfaceDeclarationSyntax node) { var name = node.Identifier.ValueText; if (name.StartsWith("I")) { return base.VisitInterfaceDeclaration(node); } return node.ReplaceToken(node.Identifier, SyntaxFactory.ParseToken("I" + name)); }
public override void VisitInterfaceDeclaration(InterfaceDeclarationSyntax node) { if (compilation != null) { var type = compilation.GetSemanticModel(node.SyntaxTree).GetDeclaredSymbol(node); types.Add(type); } typeDeclarations.Add(node); base.VisitInterfaceDeclaration(node); }
/// <summary> /// Takes a synchronous ServiceContract interface and returns an asynchronous version /// </summary> /// <param name="originalInterface"></param> /// <returns></returns> private static InterfaceDeclarationSyntax ComputeNewServiceContractInterfaceNode(InterfaceDeclarationSyntax originalInterface) { var newMembers = new List<MemberDeclarationSyntax>( originalInterface.Members.OfType<MethodDeclarationSyntax>() .Where(m => m.GetAttribute<OperationContractAttribute>() != null) .SelectMany(ComputeNewOperationContractNodes)); return originalInterface .WithIdentifier(Syntax.Identifier(originalInterface.Identifier.ValueText + "Async")) .WithMembers(Syntax.List<MemberDeclarationSyntax>(newMembers)); }
public MissingRefitAttributeWarning(InterfaceDeclarationSyntax @interface, MethodDeclarationSyntax method) : base("RF001") { setLocation(method.GetLocation()); InterfaceName = @interface.Identifier.Text; MethodName = method.Identifier.Text; Message = string.Format( "Method {0}.{1} either has no Refit HTTP method attribute or you've used something other than a string literal for the 'path' argument.", InterfaceName, MethodName); }
/// <summary> /// Normalizes the <paramref name="interfaceDeclaration" />. /// </summary> public override SyntaxNode VisitInterfaceDeclaration(InterfaceDeclarationSyntax interfaceDeclaration) { interfaceDeclaration = (InterfaceDeclarationSyntax)base.VisitInterfaceDeclaration(interfaceDeclaration); if (!interfaceDeclaration.Modifiers.Any(SyntaxKind.PartialKeyword)) { var partialKeyword = SyntaxFactory.Token(SyntaxKind.PartialKeyword).WithTrailingSpace(); interfaceDeclaration = interfaceDeclaration.WithModifiers(interfaceDeclaration.Modifiers.Add(partialKeyword)); } return interfaceDeclaration; }
public override void VisitInterfaceDeclaration(InterfaceDeclarationSyntax node) { if (node.ShouldBeHidden()) return; if (node.ChildNodes().All(childNode => childNode is PropertyDeclarationSyntax || childNode is AttributeListSyntax)) { // simple nested interface var line = node.SyntaxTree.GetLineSpan(node.Span).StartLinePosition.Line; var walker = new CodeWithDocumentationWalker(0, line); walker.Visit(node); this.Blocks.AddRange(walker.Blocks); } }
Document PerformAction(Document document, SemanticModel model, SyntaxNode root, InterfaceDeclarationSyntax interfaceDeclaration, string interfaceName) { // Applying a refactoring means replacing parts of syntax tree with our new elements. // Note: Every call to any .With...() method creates a completely new syntax tree object, // which is not part of current document anymore! Finally we create a completely new document // based on a new syntax tree containing the result of our refactoring. string newInterfaceName = "I" + interfaceName; var newRoot = root.ReplaceNode( interfaceDeclaration, interfaceDeclaration.WithIdentifier(SyntaxFactory.Identifier(newInterfaceName).WithAdditionalAnnotations(Formatter.Annotation))); return document.WithSyntaxRoot(newRoot); }
public void GenerateCode(InterfaceDeclarationSyntax idecl, ICodeGenWriter writer) { var iname = idecl.Identifier.ToString(); Console.WriteLine("GenerateCode: " + iname); writer.PushRegion(iname); writer.PushNamespace(idecl.GetNamespaceScope()); GenerateTrackableContainerCode(idecl, writer); GenerateTrackableContainerTrackerCode(idecl, writer); writer.PopNamespace(); writer.PopRegion(); }
private async Task<Document> AddPublicAccessModifierAsync(Document document, InterfaceDeclarationSyntax interfaceDeclaration, CancellationToken cancellationToken) { SyntaxTokenList newModifiers = new SyntaxTokenList(); newModifiers = newModifiers.Add(SyntaxFactory.Token(SyntaxKind.PublicKeyword)); newModifiers = newModifiers.AddRange(interfaceDeclaration.Modifiers.Where(x => !x.IsKind(SyntaxKind.ProtectedKeyword) && !x.IsKind(SyntaxKind.InternalKeyword) && !x.IsKind(SyntaxKind.PrivateKeyword)) ); InterfaceDeclarationSyntax newInterfaceDeclaration = interfaceDeclaration.WithModifiers(newModifiers); SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken); SyntaxNode newRoot = root.ReplaceNode(interfaceDeclaration, newInterfaceDeclaration); return document.WithSyntaxRoot(newRoot); }
public void GenerateCode(InterfaceDeclarationSyntax idecl, ICodeGenWriter writer) { var iname = idecl.Identifier.ToString(); Console.WriteLine("GenerateCode: " + iname); writer.PushRegion(iname); writer.PushNamespace(idecl.GetNamespaceScope()); var useProtoContract = idecl.AttributeLists.GetAttribute("ProtoContractAttribute") != null; GenerateTrackablePocoCode(idecl, writer, useProtoContract); if (useProtoContract) GenerateTrackablePocoSurrogateCode(idecl, writer); writer.PopNamespace(); writer.PopRegion(); }
private static void CheckInterfaceVariance(InterfaceDeclarationSyntax declaration, SyntaxNodeAnalysisContext context) { var interfaceType = context.SemanticModel.GetDeclaredSymbol(declaration); if (interfaceType == null) { return; } foreach (var typeParameter in interfaceType.TypeParameters .Where(typeParameter => typeParameter.Variance == VarianceKind.None)) { var canBeIn = CheckTypeParameter(typeParameter, VarianceKind.In, interfaceType); var canBeOut = CheckTypeParameter(typeParameter, VarianceKind.Out, interfaceType); if (canBeIn ^ canBeOut) { ReportIssue(typeParameter, canBeIn ? VarianceKind.In : VarianceKind.Out, context); } } }
/// <summary> /// Generates the produce function for initial state. /// </summary> /// <param name="interfaceDeclaration">The interface declaration.</param> /// <returns>The method declaration.</returns> private MemberDeclarationSyntax GenerateInitialProduce(InterfaceDeclarationSyntax interfaceDeclaration) { var interfaceName = interfaceDeclaration.Identifier.Text; var className = this.mutableType.Name; var method = $@" /// <summary> /// Produces the next <see cref = ""{interfaceName}""/> based on the /// intial state. /// </summary> /// <param name = ""initialState"">The initial State.</param> /// <param name = ""producerOptions"">The producer options to use. If you leave them null, the default options will be used.</param> /// <returns>The next immutable state.</returns> [ExcludeFromCodeCoverage] public static {interfaceName} Produce({className} initialState, IProducerOptions producerOptions = null) => Produce(initialState, p => {{ }}, producerOptions); "; return(ParseMemberDeclaration(method) .NormalizeWhitespace()); }
public void GenerateCode(InterfaceDeclarationSyntax idecl, CodeWriter.CodeWriter w) { var iname = idecl.Identifier.ToString(); Console.WriteLine("GenerateCode: " + iname); w._($"#region {iname}"); w._(); var namespaceScope = idecl.GetNamespaceScope(); var namespaceHandle = (string.IsNullOrEmpty(namespaceScope) == false) ? w.B($"namespace {idecl.GetNamespaceScope()}") : null; GenerateTrackableContainerCode(idecl, w); GenerateTrackableContainerTrackerCode(idecl, w); namespaceHandle?.Dispose(); w._(); w._($"#endregion"); }
public ClassTemplateInfo GenerateClassInfoForInterface(InterfaceDeclarationSyntax interfaceTree) { var ret = new ClassTemplateInfo(); var parent = interfaceTree.Parent; while (parent != null && !(parent is NamespaceDeclarationSyntax)) { parent = parent.Parent; } var ns = parent as NamespaceDeclarationSyntax; ret.Namespace = ns.Name.ToString(); ret.InterfaceName = interfaceTree.Identifier.ValueText; if (interfaceTree.TypeParameterList != null) { var typeParameters = interfaceTree.TypeParameterList.Parameters; if (typeParameters.Any()) { ret.TypeParameters = string.Join(", ", typeParameters.Select(p => p.Identifier.ValueText)); } ret.ConstraintClauses = interfaceTree.ConstraintClauses.ToFullString().Trim(); } ret.MethodList = interfaceTree.Members .OfType <MethodDeclarationSyntax>() .Select(x => new MethodTemplateInfo() { Name = x.Identifier.ValueText, ReturnType = x.ReturnType.ToString(), ArgumentList = String.Join(",", x.ParameterList.Parameters .Select(y => y.Identifier.ValueText)), ArgumentListWithTypes = String.Join(",", x.ParameterList.Parameters .Select(y => String.Format("{0} {1}", y.Type.ToString(), y.Identifier.ValueText))), IsRefitMethod = HasRefitHttpMethodAttribute(x) }) .ToList(); return(ret); }
/// <summary> /// Gets the declaration location. /// </summary> /// <param name="syntax">The node from which the declaration should be found.</param> /// <returns>The location for declaration, or the whole node location.</returns> private static Location GetDeclarationLocation( SyntaxNode syntax ) { // Go over all the types one by one. We get the identifier most reliably for them that way. Location declarationLocation = null; // Is class? ClassDeclarationSyntax declSyntax = syntax as ClassDeclarationSyntax; if (declSyntax != null) { declarationLocation = declSyntax.Identifier.GetLocation(); } // Is interface? InterfaceDeclarationSyntax interfaceSyntax = syntax as InterfaceDeclarationSyntax; if (interfaceSyntax != null) { declarationLocation = interfaceSyntax.Identifier.GetLocation(); } // Is enum? EnumDeclarationSyntax enumSyntax = syntax as EnumDeclarationSyntax; if (enumSyntax != null) { declarationLocation = enumSyntax.Identifier.GetLocation(); } // Is something else? if (declarationLocation == null) { declarationLocation = syntax.GetLocation(); } // Return the resolved location. return(declarationLocation); }
/// <summary> /// 接口解析入口 /// </summary> /// <param name="interfaceDeclarationSyntax"></param> private void AnalyzerInterfaceDeclaration(InterfaceDeclarationSyntax interfaceDeclarationSyntax) { main.AppendLine( $"{TYPE} {interfaceDeclarationSyntax.Identifier.ToString()} {interfaceDeclarationSyntax.Keyword} {BracesS}"); foreach (var member in interfaceDeclarationSyntax.Members) { if (member is MethodDeclarationSyntax) { MethodDeclarationSyntax methodDeclarationSyntax = member as MethodDeclarationSyntax; var returnType = methodDeclarationSyntax.ReturnType.ToString(); if (returnType == VOID) { returnType = String.Empty; } main.AppendLine( $"{methodDeclarationSyntax.Identifier.Text} ({AnalyzerParameterList(methodDeclarationSyntax.ParameterList)}) {returnType}"); } } main.AppendLine(BracesE); }
public void Compile() { using (var workspace = new AdhocWorkspace()) { var document = workspace.CurrentSolution.AddProject("foo", "foo.dll", LanguageNames.CSharp) .AddMetadataReference(MetadataReference.CreateFromFile(typeof(object).Assembly.Location)) .AddMetadataReference(MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location)) .AddDocument("test", TestInput); var compilation = document.Project.GetCompilationAsync().Result; tree = compilation.SyntaxTrees.First(); semanticModel = compilation.GetSemanticModel(tree); baseClassDeclaration = tree.GetRoot().DescendantNodes().OfType <ClassDeclarationSyntax>() .First(m => m.Identifier.ValueText == "Base"); derivedClassDeclaration1 = tree.GetRoot().DescendantNodes().OfType <ClassDeclarationSyntax>() .First(m => m.Identifier.ValueText == "Derived1"); derivedClassDeclaration2 = tree.GetRoot().DescendantNodes().OfType <ClassDeclarationSyntax>() .First(m => m.Identifier.ValueText == "Derived2"); interfaceDeclaration = tree.GetRoot().DescendantNodes().OfType <InterfaceDeclarationSyntax>() .First(m => m.Identifier.ValueText == "IInterface"); } }
public DuplicateMembersService(InterfaceDeclarationSyntax interfaceDeclaration, SemanticModel semanticModel) { var membersPerInterfaceToImplement = Utilities.GetMembersGroupedByDeclaringType(interfaceDeclaration, semanticModel); _duplicateIndexers = membersPerInterfaceToImplement.SelectMany(memberToImplement => { return(memberToImplement.Value.OfType <IPropertySymbol>().Where(x => x.IsIndexer)); }).GroupBy(x => GetIndexerKey(x)) .ToImmutableDictionary(x => x.Key, x => x.ToImmutableHashSet()); _duplicateProperties = membersPerInterfaceToImplement.SelectMany(memberToImplement => { return(memberToImplement.Value.OfType <IPropertySymbol>().Where(x => !x.IsIndexer)); }).GroupBy(x => GetPropertyKey(x)) .ToImmutableDictionary(x => x.Key, x => x.ToImmutableHashSet()); _duplicateMethods = membersPerInterfaceToImplement.SelectMany(memberToImplement => { return(memberToImplement.Value.OfType <IMethodSymbol>()); }).GroupBy(x => GetMethodKey(x)) .ToImmutableDictionary(x => x.Key, x => x.ToImmutableHashSet()); }
private static async Task <ImmutableList <MemberDeclarationSyntax> > GenerateProxyInterfaces(Document sourceDocument, ClientProxyGenerator generator, CancellationToken cancellationToken) { CompilationUnitSyntax compilationUnit = await sourceDocument.GetCompilationUnitRootAsync(cancellationToken); IEnumerable <InterfaceDeclarationSyntax> sourceInterfaces = compilationUnit.DescendantNodes().OfType <InterfaceDeclarationSyntax>(); ImmutableList <MemberDeclarationSyntax> members = ImmutableList <MemberDeclarationSyntax> .Empty; SemanticModel semanticModel = await sourceDocument.GetSemanticModelAsync(cancellationToken); SyntaxGenerator syntaxGenerator = SyntaxGenerator.GetGenerator(sourceDocument); foreach (var sourceInterface in sourceInterfaces) { ITypeSymbol sourceInterfaceSymbol = semanticModel.GetDeclaredSymbol(sourceInterface); var options = GetGenerationOptionsFromAttribute <ProxyGenerationOptions>(sourceInterfaceSymbol, ProxyGenerationOptions.GenerateProxyAttributeName); if (options != null) { INamedTypeSymbol serviceInterfaceSymbol; serviceInterfaceSymbol = ResolveServiceInterface(semanticModel.Compilation, sourceInterfaceSymbol, options); if (!sourceInterface.IsPartial()) { throw new CodeGeneratorException(sourceInterface, $"The interface {sourceInterfaceSymbol.Name} must be partial to participate in generation."); } bool implementsSourceInterface = sourceInterfaceSymbol.AllInterfaces.Any(i => i.Equals(serviceInterfaceSymbol)); InterfaceDeclarationSyntax targetInterface = generator.GenerateProxyInterface(semanticModel, syntaxGenerator, serviceInterfaceSymbol, sourceInterfaceSymbol.Name, sourceInterfaceSymbol.DeclaredAccessibility, implementsSourceInterface, options.SuppressAsyncMethods, options.SuppressWarningComments); targetInterface = syntaxGenerator.AddModifiers(targetInterface, DeclarationModifiers.Partial); members = members.Add(CreateEnclosingMembers(semanticModel, syntaxGenerator, sourceInterface, targetInterface)); } } return(members); }
public void TestGetSyntaxNodesFromClassInterface() { string code1 = "public class ClassA:IClassB{}" + "public interface IClassB{}"; SyntaxTree tree1 = CSharpSyntaxTree.ParseText(code1); ClassDeclarationSyntax node1 = tree1.GetRootAsync().Result.DescendantNodesAndSelf().OfType <ClassDeclarationSyntax>().First(); InterfaceDeclarationSyntax node2 = tree1.GetRootAsync().Result.DescendantNodesAndSelf().OfType <InterfaceDeclarationSyntax>().First(); List <SyntaxTree> trees1 = new List <SyntaxTree> { tree1 }; Compilation comp1 = CSharpCompilation.Create("TestCompilation1", trees1); ScriptAnalyzerSymbolHelper sHelper = new ScriptAnalyzerSymbolHelper(new Compilation[] { comp1 }); ScriptAnalyzerResourceHelper rHelper = new ScriptAnalyzerResourceHelper(sHelper); List <SyntaxNode> result = rHelper.GetSyntaxNodes(node1); Assert.IsNotNull(result, "Returns a list"); Assert.AreEqual(1, result.Count(), "List has one node"); CollectionAssert.Contains(result, node2, "Node is expected node"); }
public override Evaluation VisitInterfaceDeclaration(InterfaceDeclarationSyntax node) { foreach (AttributeListSyntax attributeList in node.AttributeLists) { attributeList.Accept <Evaluation>(this); } node.BaseList?.Accept <Evaluation>(this); foreach (TypeParameterConstraintClauseSyntax clause in node.ConstraintClauses) { clause.Accept <Evaluation>(this); } foreach (MemberDeclarationSyntax member in node.Members) { member.Accept <Evaluation>(this); } node.TypeParameterList?.Accept <Evaluation>(this); return(base.VisitInterfaceDeclaration(node)); }
private static void GenerateClasses(Workspace workspace, Project project) { var compilation = project.GetCompilationAsync().Result; foreach (var tree in compilation.SyntaxTrees) { var interfaces = tree.GetRoot().DescendantNodesAndSelf().Where(x => x.IsKind(SyntaxKind.InterfaceDeclaration)); foreach (SyntaxNode node in interfaces) { InterfaceDeclarationSyntax interfaceDeclaration = (InterfaceDeclarationSyntax)node; if (!HasModelObjectAttribute(interfaceDeclaration)) { continue; } string rootDirectory = "c:\\myhome\\Dropbox\\faml\\XGraphics\\src"; try { Console.WriteLine($"Processing {interfaceDeclaration.Identifier.Text}"); new CompilationUnitGenerator(workspace, interfaceDeclaration, rootDirectory, WpfXamlOutputType.Instance).Generate(); new CompilationUnitGenerator(workspace, interfaceDeclaration, rootDirectory, XamarinFormsXamlOutputType.Instance).Generate(); //new CompilationUnitGenerator(workspace, interfaceDeclaration, rootDirectory, DefaultModelOutputType.Instance).Generate(); } catch (UserViewableException e) { Console.WriteLine($"Error: {e.Message}"); Environment.Exit(1); } catch (Exception e) { Console.WriteLine($"Error: {e.ToString()}"); Environment.Exit(2); } } } }
private string GenerateSyntaxInterface(string schemaName, string enumName, string syntaxInterfaceName) { PropertyDeclarationSyntax syntaxKindPropertyDeclaration = SyntaxFactory.PropertyDeclaration( SyntaxFactory.ParseTypeName(enumName), enumName) .AddAccessorListAccessors(SyntaxHelper.MakeGetAccessor()) .WithLeadingTrivia( SyntaxHelper.MakeDocComment( string.Format(CultureInfo.CurrentCulture, Resources.SyntaxInterfaceKindDescription, syntaxInterfaceName))); MethodDeclarationSyntax deepCloneMethodDeclaration = SyntaxFactory.MethodDeclaration( SyntaxFactory.ParseTypeName(_nodeInterfaceName), "DeepClone") .WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken)) .WithLeadingTrivia( SyntaxHelper.MakeDocComment(Resources.SyntaxInterfaceDeepCloneDescription)); InterfaceDeclarationSyntax interfaceDeclaration = SyntaxFactory.InterfaceDeclaration(_nodeInterfaceName) .AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword)) .AddMembers( syntaxKindPropertyDeclaration, deepCloneMethodDeclaration); string summaryComment = string.Format( CultureInfo.CurrentCulture, Resources.SyntaxInterfaceDescription, schemaName); return(interfaceDeclaration.Format( _settings.CopyrightNotice, null, // usings _settings.SuffixedNamespaceName, summaryComment)); }
private CSharpSyntaxGeneratorResult GenerateDataInterface( DataTypeDescriptor descriptor) { InterfaceDeclarationSyntax interfaceDeclaration = InterfaceDeclaration(descriptor.RuntimeType.Name) .AddModifiers( Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.PartialKeyword)) .AddGeneratedAttribute() .AddSummary(descriptor.Documentation) .AddImplements(descriptor.Implements); interfaceDeclaration = interfaceDeclaration.AddTypeProperty(); ForEachProperty( descriptor, p => interfaceDeclaration = interfaceDeclaration.AddStateProperty(p)); return(new( descriptor.RuntimeType.Name, State, descriptor.RuntimeType.NamespaceWithoutGlobal, interfaceDeclaration)); }
public override void VisitInterfaceDeclaration(InterfaceDeclarationSyntax node) { //允许在C#里定义与使用接口,lua里隐式支持任何接口 INamedTypeSymbol sym = m_Model.GetDeclaredSymbol(node); if (SymbolTable.Instance.IsCs2LuaSymbol(sym)) { var fullName = ClassInfo.GetFullName(sym); Dictionary <string, List <string> > intfs; if (m_ClassInfoStack.Count <= 0) { intfs = SymbolTable.Instance.Cs2LuaInterfaces; } else { intfs = m_ClassInfoStack.Peek().InnerInterfaces; } lock (intfs) { List <string> list; if (!intfs.TryGetValue(fullName, out list)) { list = new List <string>(); intfs.Add(fullName, list); } foreach (var intf in sym.AllInterfaces) { var fn = ClassInfo.GetFullName(intf); if (!list.Contains(fn)) { list.Add(fn); } } } } }
private void ParseInterface(string namespace_, InterfaceDeclarationSyntax interfaceSyntax, SemanticModel semanticModel) { var interfaceDef = new InterfaceDef(); interfaceDef.Namespace = namespace_; interfaceDef.Name = interfaceSyntax.Identifier.ValueText; var fullName = interfaceDef.Namespace + "." + interfaceDef.Name; if (TypesNotParsed.Contains(fullName)) { return; } // Summary var declaredSymbol = semanticModel.GetDeclaredSymbol(interfaceSyntax); var xml = declaredSymbol?.GetDocumentationCommentXml(); interfaceDef.Summary = SummaryComment.Parse(xml); ParseTypeDeclaration(interfaceDef, interfaceSyntax, semanticModel); definitions.Interfaces.Add(interfaceDef); }
public static void Write(this InterfaceDeclarationSyntax syntax, IIndentedTextWriterWrapper textWriter, IContext context) { WrappingException.TryActionAndWrapException(() => { switch ((InterfaceState)(context.PartialElementState.CurrentState ?? 0)) { default: WriteOpen(syntax, textWriter, context); context.PartialElementState.NextState = (int)InterfaceState.Members; break; case InterfaceState.Members: WriteMembers(syntax, textWriter, context); context.PartialElementState.NextState = (int)InterfaceState.Close; break; case InterfaceState.Close: WriteClose(textWriter, context); context.PartialElementState.NextState = null; break; } }, $"In visiting of interface {syntax.Identifier.Text}. State: {((InterfaceState) (context.PartialElementState.CurrentState ?? 0))}"); }
private static void WriteOpen(InterfaceDeclarationSyntax syntax, IIndentedTextWriterWrapper textWriter, IContext context) { if (!context.PartialElementState.IsFirst) { return; } var symbol = context.SemanticModel.GetDeclaredSymbol(syntax); var adaptor = context.SemanticAdaptor; textWriter.WriteLine("[{0}] = function(interactionElement, generics, staticValues)", adaptor.GetGenerics(symbol).Length); textWriter.Indent++; WriteGenericsMapping(syntax, textWriter, context); textWriter.Write( "local typeObject = System.Type('{0}','{1}', nil, {2}, generics, nil, interactionElement, 'Interface',", adaptor.GetName(symbol), adaptor.GetFullNamespace(symbol), adaptor.GetGenerics(symbol).Length); context.SignatureWriter.WriteSignature(symbol, textWriter); textWriter.WriteLine(");"); WriteImplements(syntax, textWriter, context, symbol); WriteAttributes(syntax, textWriter, context); }
static MemberDeclarationSyntax ToClass(InterfaceDeclarationSyntax @interface) { var @class = s.ClassDeclaration(@interface.Identifier.Text.Substring(1)).AddModifiers(s.Token(SyntaxKind.PublicKeyword), s.Token(SyntaxKind.PartialKeyword)); @class = @class.AddBaseListTypes(s.SimpleBaseType(s.IdentifierName(@interface.Identifier))); foreach (var property in @interface.Members.OfType<PropertyDeclarationSyntax>()) { @class = @class.AddMembers(s.PropertyDeclaration(property.Type, property.Identifier) .AddModifiers(s.Token(SyntaxKind.PublicKeyword)) .AddAccessorListAccessors( s.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration).WithSemicolonToken(s.Token(SyntaxKind.SemicolonToken)), s.AccessorDeclaration(SyntaxKind.SetAccessorDeclaration).AddModifiers(s.Token(SyntaxKind.PrivateKeyword)).WithSemicolonToken(s.Token(SyntaxKind.SemicolonToken)) )); } var members = @interface.Members.OfType<PropertyDeclarationSyntax>() .Select(property => ImmutableGenerator.ToMember(property.Identifier, property.Type, null, null)) .ToArray(); //var members = Array<ImmutableGenerator.Member>.Empty; @class = @class.AddMembers(ImmutableGenerator.GenerateConstructorAndWithMethod(@class.Identifier.Text, members).Members.ToArray()); return @class; }
private async Task <Solution> ChangeInterfaceNameAsync(Document document, InterfaceDeclarationSyntax interfaceStatement, CancellationToken cancellationToken) { var semanticModel = await document.GetSemanticModelAsync(cancellationToken); var newName = "I" + interfaceStatement.Identifier.ToString(); var solution = document.Project.Solution; if (solution == null) { return(null); } var symbol = semanticModel.GetDeclaredSymbol(interfaceStatement, cancellationToken); if (symbol == null) { return(null); } var options = solution.Workspace.Options; var newSolution = await Renamer.RenameSymbolAsync(solution, symbol, newName, options, cancellationToken).ConfigureAwait(false); return(newSolution); }
public void GenerateCode(InterfaceDeclarationSyntax idecl, CodeWriter.CodeWriter w) { var iname = idecl.Identifier.ToString(); Console.WriteLine("GenerateCode: " + iname); w._($"#region {iname}"); w._(); var namespaceScope = idecl.GetNamespaceScope(); var namespaceHandle = (string.IsNullOrEmpty(namespaceScope) == false) ? w.B($"namespace {idecl.GetNamespaceScope()}") : null; var useProtoContract = idecl.AttributeLists.GetAttribute("ProtoContractAttribute") != null; GenerateTrackablePocoCode(idecl, w, useProtoContract); if (useProtoContract) GenerateTrackablePocoSurrogateCode(idecl, w); namespaceHandle?.Dispose(); w._(); w._($"#endregion"); }
private static void CheckIfInterfaceIsRedundantForInterface(SyntaxNodeAnalysisContext c, InterfaceDeclarationSyntax interfaceDeclaration) { CheckIfInterfaceIsRedundant(c, interfaceDeclaration.BaseList, (interfaceType) => false); }
public override void VisitInterfaceDeclaration(InterfaceDeclarationSyntax node) { sb.AppendLine(node.Keyword.ValueText + " " + node.Identifier.ValueText); base.VisitInterfaceDeclaration(node); }
public override void VisitInterfaceDeclaration(InterfaceDeclarationSyntax node) { base.VisitInterfaceDeclaration(node); _types.Add(node); }
public override SyntaxNode VisitInterfaceDeclaration(InterfaceDeclarationSyntax node) { if (!_template.SupportInterface) { this.AppendCompileIssue(node, IssueType.Error, IssueId.InterfaceNotSupport, _template.Name); return node; } else { var interfaceInfo = this._semanticModel.GetDeclaredSymbol(node); string strInterface = interfaceInfo.GetTypeSymbolName(); var interfaceTemplate = _template.CreateInterfaceTemplate(); interfaceTemplate.Assign("interface", strInterface); _output.Write(node, interfaceTemplate.GetBeginString()); if (_indentType) _output.IncreaseIndent(); var count = 0; foreach (var member in node.Members) { Visit(member); count++; if (count != node.Members.Count) _output.TrivialWriteLine(','); } if (_indentType) _output.DecreaseIndent(); _output.TrivialWrite(interfaceTemplate.GetEndString()); if (node.BaseList != null) { this.AppendCompileIssue(node, IssueType.Error, IssueId.InterfaceInheritNotSupport); } } return node; }
private static SyntaxNode HandleInterfaceDeclaration(InterfaceDeclarationSyntax node) { SyntaxToken triviaToken = node.Keyword; if (triviaToken.IsMissing) { return null; } SyntaxKind defaultVisibility = IsNestedType(node) ? SyntaxKind.PrivateKeyword : SyntaxKind.InternalKeyword; SyntaxTokenList modifiers = DeclarationModifiersHelper.AddModifier(node.Modifiers, ref triviaToken, defaultVisibility); return node .WithKeyword(triviaToken) .WithModifiers(modifiers) .WithoutFormatting(); }
public override void VisitInterfaceDeclaration(InterfaceDeclarationSyntax node) { CheckXmlDocForErrors(node, semanticModel.GetDeclaredSymbol(node)); base.VisitInterfaceDeclaration(node); }
private void GenerateTrackableContainerCode(InterfaceDeclarationSyntax idecl, CodeWriter.CodeWriter w) { var typeName = idecl.GetTypeName(); var className = "Trackable" + typeName.Substring(1); var useProtoContract = idecl.AttributeLists.GetAttribute("ProtoContractAttribute") != null; if (useProtoContract) w._($"[ProtoContract]"); using (w.B($"public partial class {className} : {typeName}")) { var properties = idecl.GetProperties(); // Tracker w._($"[IgnoreDataMember]", $"private {className}Tracker _tracker;"); w._(); w._($"[IgnoreDataMember]"); using (w.B($"public {className}Tracker Tracker")) { using (w.b($"get")) { w._($"return _tracker;"); } using (w.b($"set")) { w._($"_tracker = value;"); foreach (var p in properties) { var propertyName = p.Identifier.ToString(); w._($"{propertyName}.Tracker = value?.{propertyName}Tracker;"); } } } // Clone using (w.B($"public {className} Clone()")) { w._($"var o = new {className}();"); foreach (var p in properties) { w._($"o._{p.Identifier} = _{p.Identifier}?.Clone();"); } w._($"return o;"); } // ITrackable.Changed w._("public bool Changed { get { return Tracker != null && Tracker.HasChange; } }"); w._(); // ITrackable.Tracker using (w.B($"ITracker ITrackable.Tracker")) { using (w.b($"get")) { w._($"return Tracker;"); } using (w.b($"set")) { w._($"var t = ({className}Tracker)value;"); w._($"Tracker = t;"); } } // ITrackable<T>.Tracker using (w.B($"ITracker<{typeName}> ITrackable<{typeName}>.Tracker")) { using (w.b($"get")) { w._($"return Tracker;"); } using (w.b($"set")) { w._($"var t = ({className}Tracker)value;"); w._($"Tracker = t;"); } } // IContainerTracker<T>.Tracker using (w.B($"IContainerTracker<{typeName}> ITrackableContainer<{typeName}>.Tracker")) { using (w.b($"get")) { w._($"return Tracker;"); } using (w.b($"set")) { w._($"var t = ({className}Tracker)value;"); w._($"Tracker = t;"); } } // ITrackable.Clone using (w.B($"ITrackable ITrackable.Clone()")) { w._($"return Clone();"); } // ITrackable.GetChildTrackable using (w.B($"public ITrackable GetChildTrackable(object name)")) { using (w.b($"switch ((string)name)")) { foreach (var p in properties) { var propertyName = p.Identifier.ToString(); w._($"case \"{propertyName}\":", $" return {propertyName} as ITrackable;"); } w._($"default:", $" return null;"); } } // ITrackable.GetChildTrackables using (w.B($"public IEnumerable<KeyValuePair<object, ITrackable>> " + $"GetChildTrackables(bool changedOnly = false)")) { if (properties.Any()) { foreach (var p in properties) { var propertyType = p.Type.ToString(); var propertyName = p.Identifier.ToString(); w._($"var trackable{propertyName} = {propertyName} as ITrackable;", $"if (trackable{propertyName} != null && (changedOnly == false || trackable{propertyName}.Changed))", $" yield return new KeyValuePair<object, ITrackable>(\"{propertyName}\", trackable{propertyName});"); } } else { w._($"yield break;"); } } // Property Accessors foreach (var p in properties) { var propertyType = p.Type.ToString(); var propertyName = p.Identifier.ToString(); w._(); w._($"private {propertyType} _{propertyName} = new {propertyType}();"); w._(); var protoMemberAttr = p.AttributeLists.GetAttribute("ProtoMemberAttribute"); if (protoMemberAttr != null) w._($"[ProtoMember{protoMemberAttr.ArgumentList}] "); using (w.B($"public {propertyType} {propertyName}")) { using (w.b($"get")) { w._($"return _{propertyName};"); } using (w.b($"set")) { w._($"if (_{propertyName} != null)", $" _{propertyName}.Tracker = null;", $"if (value != null)", $" value.Tracker = Tracker?.{propertyName}Tracker;", $"_{propertyName} = value;"); } } using (w.B($"{propertyType} {typeName}.{propertyName}")) { w._($"get {{ return _{propertyName}; }}", $"set {{ _{propertyName} = ({propertyType})value; }}"); } } } }
private void GenerateTrackableContainerTrackerCode(InterfaceDeclarationSyntax idecl, CodeWriter.CodeWriter w) { var typeName = idecl.GetTypeName(); var className = "Trackable" + typeName.Substring(1) + "Tracker"; var useProtoContract = idecl.AttributeLists.GetAttribute("ProtoContractAttribute") != null; if (useProtoContract) w._($"[ProtoContract]"); using (w.B($"public class {className} : IContainerTracker<{typeName}>")) { // Property Trackers var properties = idecl.GetProperties(); foreach (var p in properties) { var protoMemberAttr = p.AttributeLists.GetAttribute("ProtoMemberAttribute"); if (protoMemberAttr != null) w._($"[ProtoMember{protoMemberAttr.ArgumentList}] "); var propertyName = p.Identifier.ToString(); var trackerName = Utility.GetTrackerClassName(p.Type); w._($"public {trackerName} {propertyName}Tracker {{ get; set; }} = new {trackerName}();"); } w._(); // ToString() using (w.B($"public override string ToString()")) { w._("var sb = new StringBuilder();", "sb.Append(\"{ \");", "var first = true;"); foreach (var p in properties) { var propertyName = p.Identifier.ToString(); using (w.B($"if ({propertyName}Tracker != null && {propertyName}Tracker.HasChange)")) { w._($"if (first)", $" first = false;", $"else", $" sb.Append(\", \");", $"sb.Append(`{propertyName}:`);", $"sb.Append({propertyName}Tracker);"); } } w._("sb.Append(\" }\");", "return sb.ToString();"); } // ITracker.HasChange using (w.B($"public bool HasChange")) { using (w.b($"get")) { w._($"return"); foreach (var p in properties) { var propertyName = p.Identifier.ToString(); w._($" ({propertyName}Tracker != null && {propertyName}Tracker.HasChange) ||"); } w._($" false;"); } } // ITracker.HasChange using (w.B($"public event TrackerHasChangeSet HasChangeSet")) { w._("add { throw new NotImplementedException(); }", "remove { throw new NotImplementedException(); }"); } // ITracker.Clear using (w.B($"public void Clear()")) { foreach (var p in properties) { var propertyName = p.Identifier.ToString(); w._($"if ({propertyName}Tracker != null)", $" {propertyName}Tracker.Clear();"); } } // ITracker.ApplyTo(Trackable) using (w.B($"public void ApplyTo(object trackable)")) { w._($"ApplyTo(({typeName})trackable);"); } using (w.B($"public void ApplyTo({typeName} trackable)")) { foreach (var p in properties) { var propertyName = p.Identifier.ToString(); w._($"if ({propertyName}Tracker != null)", $" {propertyName}Tracker.ApplyTo(trackable.{propertyName});"); } } // ITracker.ApplyTo(Tracker) using (w.B($"public void ApplyTo(ITracker tracker)")) { w._($"ApplyTo(({className})tracker);"); } using (w.B($"public void ApplyTo(ITracker<{typeName}> tracker)")) { w._($"ApplyTo(({className})tracker);"); } using (w.B($"public void ApplyTo({className} tracker)")) { foreach (var p in properties) { var propertyName = p.Identifier.ToString(); w._($"if ({propertyName}Tracker != null)", $" {propertyName}Tracker.ApplyTo(tracker.{propertyName}Tracker);"); } } // ITracker.RollbackTo(Trackable) using (w.B($"public void RollbackTo(object trackable)")) { w._($"RollbackTo(({typeName})trackable);"); } using (w.B($"public void RollbackTo({typeName} trackable)")) { foreach (var p in properties) { var propertyName = p.Identifier.ToString(); w._($"if ({propertyName}Tracker != null)", $" {propertyName}Tracker.RollbackTo(trackable.{propertyName});"); } } // ITracker.RollbackTo(Tracker) using (w.B($"public void RollbackTo(ITracker tracker)")) { w._($"RollbackTo(({className})tracker);"); } using (w.B($"public void RollbackTo(ITracker<{typeName}> tracker)")) { w._($"RollbackTo(({className})tracker);"); } using (w.B($"public void RollbackTo({className} tracker)")) { foreach (var p in properties) { var propertyName = p.Identifier.ToString(); w._($"if ({propertyName}Tracker != null)", $" {propertyName}Tracker.RollbackTo(tracker.{propertyName}Tracker);"); } } } }
private InterfaceNode GetInterfaceNode(InterfaceDeclarationSyntax EachInterface) { InterfaceNode interfacenode = new InterfaceNode(); interfacenode.InterfaceName = EachInterface.Identifier.ToString(); foreach (var member in EachInterface.Members) { MethodDeclarationSyntax method = member as MethodDeclarationSyntax; interfacenode.Methods.Add(GetMethodNode(method)); } if (EachInterface.BaseList != null) { foreach (var baseType in EachInterface.BaseList.Types) { interfacenode.Links.Add(baseType.ToString()); } } return interfacenode; }
public void Compile() { using (var workspace = new AdhocWorkspace()) { var document = workspace.CurrentSolution.AddProject("foo", "foo.dll", LanguageNames.CSharp) .AddMetadataReference(MetadataReference.CreateFromFile(typeof(object).Assembly.Location)) .AddMetadataReference(MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location)) .AddDocument("test", input); compilation = document.Project.GetCompilationAsync().Result; tree = compilation.SyntaxTrees.First(); semanticModel = compilation.GetSemanticModel(tree); baseClassDeclaration = tree.GetRoot().DescendantNodes().OfType<ClassDeclarationSyntax>() .First(m => m.Identifier.ValueText == "Base"); derivedClassDeclaration1 = tree.GetRoot().DescendantNodes().OfType<ClassDeclarationSyntax>() .First(m => m.Identifier.ValueText == "Derived1"); derivedClassDeclaration2 = tree.GetRoot().DescendantNodes().OfType<ClassDeclarationSyntax>() .First(m => m.Identifier.ValueText == "Derived2"); interfaceDeclaration = tree.GetRoot().DescendantNodes().OfType<InterfaceDeclarationSyntax>() .First(m => m.Identifier.ValueText == "IInterface"); } }
public override void VisitInterfaceDeclaration(InterfaceDeclarationSyntax node) { Types.Add(node); base.VisitInterfaceDeclaration(node); }
public override void VisitInterfaceDeclaration(InterfaceDeclarationSyntax node) { AddEntry(node.Identifier.Text, node.GetLocation()); base.VisitInterfaceDeclaration(node); }
public ClassTemplateInfo GenerateClassInfoForInterface(InterfaceDeclarationSyntax interfaceTree) { var ret = new ClassTemplateInfo(); var parent = interfaceTree.Parent; while (parent != null && !(parent is NamespaceDeclarationSyntax)) parent = parent.Parent; var ns = parent as NamespaceDeclarationSyntax; ret.Namespace = ns.Name.ToString(); ret.InterfaceName = interfaceTree.Identifier.ValueText; ret.Modifiers = interfaceTree.Modifiers.Select(t => t.ValueText).FirstOrDefault(m => m == "public" || m == "internal"); if (interfaceTree.TypeParameterList != null) { var typeParameters = interfaceTree.TypeParameterList.Parameters; if (typeParameters.Any()) { ret.TypeParameters = string.Join(", ", typeParameters.Select(p => p.Identifier.ValueText)); } ret.ConstraintClauses = interfaceTree.ConstraintClauses.ToFullString().Trim(); } ret.MethodList = interfaceTree.Members .OfType<MethodDeclarationSyntax>() .Select(x => new MethodTemplateInfo() { Name = x.Identifier.ValueText, ReturnType = x.ReturnType.ToString(), ArgumentList = String.Join(",", x.ParameterList.Parameters .Select(y => y.Identifier.ValueText)), ArgumentListWithTypes = String.Join(",", x.ParameterList.Parameters .Select(y => String.Format("{0} {1}", y.Type.ToString(), y.Identifier.ValueText))), IsRefitMethod = HasRefitHttpMethodAttribute(x) }) .ToList(); return ret; }
public static IEnumerable <UsingDirectiveSyntax> GetRequiredUsings(this InterfaceDeclarationSyntax self) { return(self.AncestorsAndSelf() .SelectMany(x => x.GetUsings()) .Union(self.GetAllTransientDeclaringNamespace())); }
/// <summary> /// Initializes a new instance of the <see cref="ClassDeclarationSyntax"/> class. /// </summary> /// <param name="classDeclarationNode"></param> public InterfaceDeclaration(InterfaceDeclarationSyntax interfaceDeclarationNode) : base(interfaceDeclarationNode) { this.interfaces = null; }
public static UsingDirectiveSyntax GetDeclaringNamespace(this InterfaceDeclarationSyntax self, string suffix = null) { return(UsingDirective(ParseName(self.Ancestors().OfType <NamespaceDeclarationSyntax>().Select(x => x.Name.ToString()).Concatenate(".", suffix)))); }
public static IEnumerable <UsingDirectiveSyntax> GetAllTransientDeclaringNamespace(this InterfaceDeclarationSyntax self) { var namespaces = self.Ancestors() .OfType <NamespaceDeclarationSyntax>() .SelectMany(x => x.Name.ToString().Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries)) .ToList(); for (int i = 1; i < namespaces.Count; i++) { namespaces[i] = namespaces[i - 1] + "." + namespaces[i]; } return(namespaces.Select(x => UsingDirective(ParseName(x))) .ToList()); }
public static void ComputeRefactorings(RefactoringContext context, InterfaceDeclarationSyntax interfaceDeclaration) { SyntaxToken identifier = interfaceDeclaration.Identifier; ComputeRefactorings(context, interfaceDeclaration, identifier); }
public static InterfaceDeclarationSyntax BuildAsyncInterfaceDeclFromSyncInterfaceDecl(string serviceContractName, string serviceContractAsyncName, InterfaceDeclarationSyntax existingInterfaceDecl, bool useExistingAsBase) { var newInterfaceIdentifier = SyntaxFactory.Identifier(serviceContractAsyncName).WithoutTrivia(); var newInterfaceDecl = existingInterfaceDecl.WithIdentifier(newInterfaceIdentifier) .WithMembers(new SyntaxList <MemberDeclarationSyntax>()); //Why not convert the members too? if (useExistingAsBase) { newInterfaceDecl = newInterfaceDecl.WithBaseList(SyntaxFactory.BaseList(SyntaxFactory.Token(SyntaxKind.ColonToken), SyntaxFactory.SeparatedList <BaseTypeSyntax>() .Add(SyntaxFactory.SimpleBaseType(SyntaxFactory.ParseTypeName(serviceContractName))))); } return(newInterfaceDecl.WithoutTrivia() .WithOpenBraceToken(SyntaxFactory.Token(SyntaxKind.OpenBraceToken)) .WithCloseBraceToken(SyntaxFactory.Token(SyntaxKind.CloseBraceToken))); }
public override SingleNamespaceOrTypeDeclaration VisitInterfaceDeclaration(InterfaceDeclarationSyntax node) { return(VisitTypeDeclaration(node, DeclarationKind.Interface)); }
/// <summary> /// Creates a new <see cref="Syntax.ModifierListInfo"/> from the specified interface declaration. /// </summary> /// <param name="interfaceDeclaration"></param> /// <returns></returns> public static ModifierListInfo ModifierListInfo(InterfaceDeclarationSyntax interfaceDeclaration) { return(Syntax.ModifierListInfo.Create(interfaceDeclaration)); }
/// <summary> /// Creates a new <see cref="Syntax.MemberDeclarationListInfo"/> from the specified declaration. /// </summary> /// <param name="declaration"></param> /// <returns></returns> public static MemberDeclarationListInfo MemberDeclarationListInfo(InterfaceDeclarationSyntax declaration) { return(Syntax.MemberDeclarationListInfo.Create(declaration)); }
IEnumerable <MemberDeclarationSyntax> HandleRequests( InterfaceDeclarationSyntax handlerInterface, INamedTypeSymbol interfaceType, INamedTypeSymbol requestType, INamedTypeSymbol responseType, NameSyntax registryType, HashSet <string> additionalUsings) { var methodName = GetSendMethodName(interfaceType, _attributeData); var parameterList = ParameterList(SeparatedList(new[] { Parameter(Identifier("mediator")) .WithType(registryType) .WithModifiers(TokenList(Token(SyntaxKind.ThisKeyword))), Parameter(Identifier("@params")) .WithType(IdentifierName(requestType.Name)), Parameter(Identifier("cancellationToken")) .WithType(IdentifierName("CancellationToken")) .WithDefault(EqualsValueClause( LiteralExpression(SyntaxKind.DefaultLiteralExpression, Token(SyntaxKind.DefaultKeyword))) ) })); var partialItem = GetPartialItem(requestType); if (partialItem != null) { additionalUsings.Add("OmniSharp.Extensions.LanguageServer.Protocol.Progress"); var partialTypeSyntax = ResolveTypeName(partialItem); yield return(MethodDeclaration( GenericName( Identifier("IRequestProgressObservable")) .WithTypeArgumentList( TypeArgumentList( SeparatedList( new TypeSyntax[] { partialTypeSyntax, ResolveTypeName(responseType) }))), Identifier(methodName) ) .WithModifiers(TokenList( Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword)) ) .WithParameterList(parameterList) .WithExpressionBody(GetPartialInvokeExpression(ResolveTypeName(responseType))) .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)) .NormalizeWhitespace()); yield break; } var partialItems = GetPartialItems(requestType); if (partialItems != null) { additionalUsings.Add("OmniSharp.Extensions.LanguageServer.Protocol.Progress"); var partialTypeSyntax = ResolveTypeName(partialItems); var partialItemsSyntax = GenericName("IEnumerable").WithTypeArgumentList(TypeArgumentList(SeparatedList <TypeSyntax>(new[] { partialTypeSyntax }))); yield return(MethodDeclaration( GenericName( Identifier("IRequestProgressObservable")) .WithTypeArgumentList( TypeArgumentList( SeparatedList( new TypeSyntax[] { partialItemsSyntax, ResolveTypeName(responseType) }))), Identifier(methodName) ) .WithModifiers(TokenList( Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword)) ) .WithParameterList(parameterList) .WithExpressionBody(GetPartialInvokeExpression(ResolveTypeName(responseType))) .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)) .NormalizeWhitespace()); ; yield break; } var responseSyntax = responseType.Name == "Unit" ? IdentifierName("Task") as NameSyntax : GenericName("Task").WithTypeArgumentList(TypeArgumentList(SeparatedList <TypeSyntax>(new[] { ResolveTypeName(responseType) }))); yield return(MethodDeclaration(responseSyntax, methodName) .WithModifiers(TokenList( Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.StaticKeyword)) ) .WithParameterList(parameterList) .WithExpressionBody(GetRequestInvokeExpression()) .WithSemicolonToken(Token(SyntaxKind.SemicolonToken)) .NormalizeWhitespace()); }
public override SyntaxNode VisitInterfaceDeclaration(InterfaceDeclarationSyntax node) { node = (InterfaceDeclarationSyntax)base.VisitInterfaceDeclaration(node); interfaces.Add(node); return node; }