/// Adds a field to the class public async Task BindToField(Stetic.Component obj) { if (targetObject == null) { return; } string name = GetMemberName(obj); var cls = GetClass(); if (FindField(cls, name) != null) { return; } var location = GetSourceLocation(cls); var doc = await IdeApp.Workbench.OpenDocument(location.SourceTree.FilePath, project, true); var editor = doc.Editor; if (editor != null) { await CodeGenerationService.AddNewMember(project, cls, cls.Locations.First(), GetFieldCode (cls, obj, name)); } }
/// Adds a signal handler to the class public void BindSignal(Stetic.Signal signal) { if (targetObject == null) { return; } var cls = GetClass(); if (cls == null) { return; } if (FindSignalHandler(cls, signal) != null) { return; } var met = SyntaxFactory.MethodDeclaration(SyntaxFactory.ParseTypeName(signal.SignalDescriptor.HandlerReturnTypeName), signal.Handler) .WithBody(SyntaxFactory.Block()) .AddModifiers(SyntaxFactory.Token(SyntaxKind.ProtectedKeyword)); var parameters = new List <ParameterSyntax> (); foreach (Stetic.ParameterDescriptor pinfo in signal.SignalDescriptor.HandlerParameters) { parameters.Add(SyntaxFactory.Parameter(new SyntaxList <AttributeListSyntax> (), new SyntaxTokenList(), SyntaxFactory.ParseTypeName(pinfo.TypeName), SyntaxFactory.Identifier(pinfo.Name), null)); } met = met.AddParameterListParameters(parameters.ToArray()); CodeGenerationService.AddNewMember(project, cls, GetSourceLocation(cls), met); }
/// Adds a field to the class public void BindToField(Stetic.Component obj) { if (targetObject == null) { return; } string name = GetMemberName(obj); var cls = GetClass(); if (FindField(cls.Resolve(project), name) != null) { return; } Document doc = IdeApp.Workbench.OpenDocument(cls.Region.FileName, true); IEditableTextFile editor = doc.GetContent <IEditableTextFile> (); if (editor != null) { var resolvedCls = cls.Resolve(cls.ParsedFile.GetTypeResolveContext(TypeSystemService.GetCompilation(project), cls.Region.Begin)).GetDefinition(); CodeGenerationService.AddNewMember(resolvedCls, cls, GetFieldCode(cls, obj, name)); } }
/// Adds a signal handler to the class public void BindSignal(Stetic.Signal signal) { if (targetObject == null) { return; } var cls = GetClass(); if (cls == null) { return; } if (FindSignalHandler(cls.Resolve(project), signal) != null) { return; } var met = new DefaultUnresolvedMethod(cls, signal.Handler) { Accessibility = Accessibility.Protected, ReturnType = ReflectionHelper.ParseReflectionName(signal.SignalDescriptor.HandlerReturnTypeName) }; foreach (Stetic.ParameterDescriptor pinfo in signal.SignalDescriptor.HandlerParameters) { met.Parameters.Add(new DefaultUnresolvedParameter(ReflectionHelper.ParseReflectionName(pinfo.TypeName), pinfo.Name)); } var resolvedCls = cls.Resolve(cls.ParsedFile.GetTypeResolveContext(TypeSystemService.GetCompilation(project), cls.Region.Begin)).GetDefinition(); CodeGenerationService.AddNewMember(resolvedCls, cls, met); }
/// Adds a field to the class public void BindToField(Stetic.Component obj) { if (targetObject == null) { return; } string name = GetMemberName(obj); IType cls = GetClass(); if (FindField(cls, name) != null) { return; } Document doc = IdeApp.Workbench.OpenDocument(cls.CompilationUnit.FileName, true); IEditableTextFile editor = doc.GetContent <IEditableTextFile> (); if (editor != null) { CodeGenerationService.AddNewMember(cls, GetFieldCode(obj, name)); } }
/// Adds a signal handler to the class public void BindSignal(Stetic.Signal signal) { if (targetObject == null) { return; } IType cls = GetClass(); if (cls == null) { return; } if (FindSignalHandler(cls, signal) != null) { return; } var met = new DomMethod() { Name = signal.Handler, Modifiers = Modifiers.Protected, ReturnType = new DomReturnType(signal.SignalDescriptor.HandlerReturnTypeName) }; foreach (Stetic.ParameterDescriptor pinfo in signal.SignalDescriptor.HandlerParameters) { met.Add(new DomParameter() { Name = pinfo.Name, ReturnType = new DomReturnType(pinfo.TypeName) }); } CodeGenerationService.AddNewMember(cls, met); }