private OverloadsCollection(IEmitter emitter, CustomEventDeclaration eventDeclaration, bool remove) { this.Emitter = emitter; this.Name = eventDeclaration.Name; this.JsName = Helpers.GetEventRef(eventDeclaration, emitter, remove, true); this.AltJsName = Helpers.GetEventRef(eventDeclaration, emitter, !remove, true); this.FieldJsName = emitter.GetEntityName(eventDeclaration); this.Inherit = !eventDeclaration.HasModifier(Modifiers.Static); this.IsSetter = remove; this.Static = eventDeclaration.HasModifier(Modifiers.Static); this.Member = this.FindMember(eventDeclaration); this.FieldJsName = Helpers.GetEventRef(this.Member, emitter, true, true, true, false, true);; this.TypeDefinition = this.Member.DeclaringTypeDefinition; this.Type = this.Member.DeclaringType; this.InitMembers(); this.Emitter.Cache.AddNode(eventDeclaration, remove, this); }
private OverloadsCollection(IEmitter emitter, IMember member, bool isSetter = false, bool includeInline = false, bool isField = false) { if (member is IMethod method) { this.Inherit = !method.IsConstructor && !method.IsStatic; this.Static = method.IsStatic; this.Constructor = method.IsConstructor; } else if (member is IEntity entity) { this.Inherit = !entity.IsStatic; this.Static = entity.IsStatic; } this.Emitter = emitter; this.Name = member.Name; this.IsField = isField; if (member is IProperty) { this.JsName = Helpers.GetPropertyRef(member, emitter, isSetter, true, true); this.AltJsName = Helpers.GetPropertyRef(member, emitter, !isSetter, true, true); var p = (IProperty)member; this.FieldJsName = this.Emitter.GetEntityName(p); } else if (member is IEvent) { this.JsName = Helpers.GetEventRef(member, emitter, isSetter, true, true); this.AltJsName = Helpers.GetEventRef(member, emitter, !isSetter, true, true); this.FieldJsName = Helpers.GetEventRef(member, emitter, true, true, true, false, true); } else { this.JsName = this.Emitter.GetEntityName(member); } this.IncludeInline = includeInline; this.Member = member; this.TypeDefinition = this.Member.DeclaringTypeDefinition; this.Type = this.Member.DeclaringType; this.IsSetter = isSetter; this.InitMembers(); this.Emitter.Cache.AddMember(member, isSetter, includeInline, this); }
protected virtual List <IEvent> GetEventOverloads(List <IEvent> list = null, ITypeDefinition typeDef = null) { typeDef = typeDef ?? this.TypeDefinition; bool isTop = list == null; list = list ?? new List <IEvent>(); if (typeDef != null) { var events = typeDef.Events.Where(e => { if (e.IsExplicitInterfaceImplementation) { return(false); } var inline = e.AddAccessor != null ? this.Emitter.GetInline(e.AddAccessor) : null; if (!string.IsNullOrWhiteSpace(inline)) { return(false); } inline = e.RemoveAccessor != null ? this.Emitter.GetInline(e.RemoveAccessor) : null; if (!string.IsNullOrWhiteSpace(inline)) { return(false); } bool eq = false; bool?equalsByAdd = null; if (e.IsStatic == this.Static) { var addName = e.AddAccessor != null && e.CanAdd ? Helpers.GetEventRef(e, this.Emitter, false, true, true) : null; var removeName = e.RemoveAccessor != null && e.CanRemove ? Helpers.GetEventRef(e, this.Emitter, true, true, true) : null; var fieldName = Helpers.GetEventRef(e, this.Emitter, true, true, true, false, true); if (addName != null && (addName == this.JsName || addName == this.AltJsName || addName == this.FieldJsName)) { eq = true; equalsByAdd = true; } else if (removeName != null && (removeName == this.JsName || removeName == this.AltJsName || removeName == this.FieldJsName)) { eq = true; equalsByAdd = false; } else if (fieldName != null && (fieldName == this.JsName || fieldName == this.AltJsName || fieldName == this.FieldJsName)) { eq = true; } } if (eq) { if (e.IsOverride && !this.IsTemplateOverride(e)) { return(false); } if (equalsByAdd.HasValue && this.Member is IMethod && this.AltJsName == null) { this.AltJsName = Helpers.GetEventRef(e, this.Emitter, equalsByAdd.Value, true, true); } return(true); } return(false); }); list.AddRange(events); if (this.Inherit) { var baseTypeDefinitions = typeDef.DirectBaseTypes.Where(t => t.Kind == typeDef.Kind || (typeDef.Kind == TypeKind.Struct && t.Kind == TypeKind.Class)); foreach (var baseTypeDef in baseTypeDefinitions) { list = this.GetEventOverloads(list, baseTypeDef.GetDefinition()); } } } var returnEvents = isTop ? list.Distinct().ToList() : list; return(returnEvents); }
public static void EmitComment(IAbstractEmitterBlock block, AstNode node, bool?getter = null, VariableInitializer varInitializer = null) { if (block.Emitter.AssemblyInfo.GenerateDocumentation == H5.Contract.DocumentationMode.None || node.Parent == null) { return; } var visitor = new DocumentationCommentVisitor(); node.AcceptChildren(visitor); if (block.Emitter.AssemblyInfo.GenerateDocumentation == H5.Contract.DocumentationMode.Basic && visitor.Comments.Count == 0) { return; } object value = null; var rr = block.Emitter.Resolver.ResolveNode(varInitializer ?? node); string source = BuildCommentString(visitor.Comments); if (node is FieldDeclaration) { if (varInitializer.Initializer is PrimitiveExpression initializer) { value = initializer.Value; } } else if (node is EventDeclaration eventDecl) { foreach (var evVar in eventDecl.Variables) { var ev_rr = block.Emitter.Resolver.ResolveNode(evVar); var memberResolveResult = ev_rr as MemberResolveResult; var ev = memberResolveResult.Member as IEvent; if (!getter.HasValue || getter.Value) { var comment = new JsDocComment(); InitMember(comment, ev.AddAccessor, block.Emitter, null); comment.Function = Helpers.GetEventRef(ev, block.Emitter, false); block.Write( block.WriteIndentToString(XmlToJsDoc.ReadComment(source, ev_rr, block.Emitter, comment))); block.WriteNewLine(); } if (!getter.HasValue || !getter.Value) { var comment = new JsDocComment(); InitMember(comment, ev.RemoveAccessor, block.Emitter, null); comment.Function = Helpers.GetEventRef(ev, block.Emitter, true); block.Write( block.WriteIndentToString(XmlToJsDoc.ReadComment(source, ev_rr, block.Emitter, comment))); block.WriteNewLine(); } } return; } if (node is PropertyDeclaration prop) { var memberResolveResult = rr as MemberResolveResult; var rProp = memberResolveResult.Member as IProperty; var comment = new JsDocComment(); InitMember(comment, rProp, block.Emitter, null); comment.Function = Helpers.GetPropertyRef(rProp, block.Emitter); block.Write(block.WriteIndentToString(XmlToJsDoc.ReadComment(source, rr, block.Emitter, comment))); block.WriteNewLine(); return; } if (node is IndexerDeclaration indexer) { var memberResolveResult = rr as MemberResolveResult; var rProp = memberResolveResult.Member as IProperty; var comment = new JsDocComment(); InitMember(comment, getter.HasValue && getter.Value ? rProp.Getter : rProp.Setter, block.Emitter, null); block.Write(block.WriteIndentToString(XmlToJsDoc.ReadComment(source, rr, block.Emitter, comment))); block.WriteNewLine(); return; } block.Write(block.WriteIndentToString(XmlToJsDoc.Convert(source, rr, block.Emitter, value))); block.WriteNewLine(); }