protected virtual List <IEvent> GetEventOverloads() { List <IEvent> list = new List <IEvent>(); var typeDef = this.TypeDefinition; while (typeDef != null) { var events = typeDef.Events.Where(e => { bool eq = false; if (e.IsStatic == this.Static) { if (e.AddAccessor != null && (Helpers.GetEventRef(e, this.Emitter, false, true, true) == this.JsName)) { eq = true; } else if (e.RemoveAccessor != null && (Helpers.GetEventRef(e, this.Emitter, true, true, true) == this.JsName)) { eq = true; } } if (eq) { if (e.IsOverride) { return(false); } return(true); } return(false); }); list.AddRange(events); if (this.Inherit) { var baseTypeDefinition = typeDef.DirectBaseTypes.FirstOrDefault(); if (baseTypeDefinition != null && baseTypeDefinition.Kind == typeDef.Kind) { typeDef = baseTypeDefinition.GetDefinition(); } else { typeDef = null; } } else { typeDef = null; } } return(list); }
private OverloadsCollection(IEmitter emitter, IMember member, bool isSetter = false, bool includeInline = false, bool isField = false) { if (member is IMethod) { var method = (IMethod)member; this.Inherit = !method.IsConstructor && !method.IsStatic; this.Static = method.IsStatic; this.Constructor = method.IsConstructor; } else if (member is IEntity) { var entity = (IEntity)member; this.Inherit = !entity.IsStatic; this.Static = entity.IsStatic; } this.Emitter = emitter; this.Name = member.Name; this.IsField = isField; if (member is IProperty) { this.CancelChangeCase = member.DeclaringTypeDefinition == null || !this.Emitter.Validator.IsObjectLiteral(member.DeclaringTypeDefinition); 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, true); } else if (member is IEvent) { this.CancelChangeCase = true; 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 { if (member is IField) { this.CancelChangeCase = false; } this.JsName = this.Emitter.GetEntityName(member, false, true); } this.IncludeInline = includeInline; this.Member = member; this.SetCaseFromNameAttr(); this.TypeDefinition = this.Member.DeclaringTypeDefinition; this.Type = this.Member.DeclaringType; this.IsSetter = isSetter; this.InitMembers(); this.Emitter.OverloadsCacheMembers[new Tuple <IMember, bool, bool>(member, isSetter, includeInline)] = this; }
private OverloadsCollection(IEmitter emitter, CustomEventDeclaration eventDeclaration, bool remove) { this.Emitter = emitter; this.Name = eventDeclaration.Name; this.JsName = Helpers.GetEventRef(eventDeclaration, emitter, remove, true); this.Inherit = !eventDeclaration.HasModifier(Modifiers.Static); this.CancelChangeCase = true; this.IsSetter = remove; this.Static = eventDeclaration.HasModifier(Modifiers.Static); this.Member = this.FindMember(eventDeclaration); this.TypeDefinition = this.Member.DeclaringTypeDefinition; this.Type = this.Member.DeclaringType; this.InitMembers(); this.Emitter.OverloadsCache[eventDeclaration.GetHashCode().ToString()] = this; }
private OverloadsCollection(IEmitter emitter, IMember member, bool isSetter = false, bool includeInline = false) { if (member is IMethod) { var method = (IMethod)member; this.Inherit = !method.IsConstructor && !method.IsStatic; this.Static = method.IsStatic; this.Constructor = method.IsConstructor; } else if (member is IEntity) { var entity = (IEntity)member; this.Inherit = !entity.IsStatic; this.Static = entity.IsStatic; } this.Emitter = emitter; this.Name = member.Name; if (member is IProperty) { this.CancelChangeCase = !Helpers.IsFieldProperty(member, emitter); this.JsName = Helpers.GetPropertyRef(member, emitter, isSetter, true, true); this.AltJsName = Helpers.GetPropertyRef(member, emitter, !isSetter, true, true); var p = (IProperty)member; this.FieldJsName = Helpers.IsAutoProperty(p) ? (Helpers.IsFieldProperty(p, this.Emitter) ? this.Emitter.GetEntityName(p) : Helpers.GetPropertyRef(p, this.Emitter, true, true, true, false, true)) : null; } else if (member is IEvent) { this.CancelChangeCase = true; 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, false, true); } this.IncludeInline = includeInline; this.Member = member; this.TypeDefinition = this.Member.DeclaringTypeDefinition; this.Type = this.Member.DeclaringType; this.IsSetter = isSetter; this.InitMembers(); this.Emitter.OverloadsCacheMembers[new Tuple <IMember, bool, bool>(member, isSetter, includeInline)] = this; }
private OverloadsCollection(IEmitter emitter, IMember member, bool isSetter = false, bool includeInline = false, bool isField = false) { if (member is IMethod) { var method = (IMethod)member; this.Inherit = !method.IsConstructor && !method.IsStatic; this.Static = method.IsStatic; this.Constructor = method.IsConstructor; } else if (member is IEntity) { var entity = (IEntity)member; 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); }
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) { if (member is IMethod) { var method = (IMethod)member; this.Inherit = !method.IsConstructor && !method.IsStatic; this.Static = method.IsStatic; this.Constructor = method.IsConstructor; } else if (member is IEntity) { var entity = (IEntity)member; this.Inherit = !entity.IsStatic; this.Static = entity.IsStatic; } this.Emitter = emitter; this.Name = member.Name; if (member is IProperty) { this.CancelChangeCase = !Helpers.IsFieldProperty(member, emitter); this.JsName = Helpers.GetPropertyRef(member, emitter, isSetter, true, true); this.AltJsName = Helpers.GetPropertyRef(member, emitter, !isSetter, true, true); } else if (member is IEvent) { this.CancelChangeCase = true; this.JsName = Helpers.GetEventRef(member, emitter, isSetter, true, true); this.AltJsName = Helpers.GetEventRef(member, emitter, !isSetter, true, true); } else { this.JsName = this.Emitter.GetEntityName(member, false, true); } this.IncludeInline = includeInline; this.Member = member; this.TypeDefinition = this.Member.DeclaringTypeDefinition; this.Type = this.Member.DeclaringType; this.IsSetter = isSetter; this.InitMembers(); string key = (member.MemberDefinition != null ? member.MemberDefinition.GetHashCode().ToString() : member.GetHashCode().ToString()) + isSetter.GetHashCode().ToString(); this.Emitter.OverloadsCache[key] = this; }
public static string GetEventRef(CustomEventDeclaration property, IEmitter emitter, bool remove = false, bool noOverload = false, bool ignoreInterface = false, bool withoutTypeParams = false) { MemberResolveResult resolveResult = emitter.Resolver.ResolveNode(property, emitter) as MemberResolveResult; if (resolveResult != null && resolveResult.Member != null) { return(Helpers.GetEventRef(resolveResult.Member, emitter, remove, noOverload, ignoreInterface, withoutTypeParams)); } if (!noOverload) { var overloads = OverloadsCollection.Create(emitter, property, remove); return(overloads.GetOverloadName(ignoreInterface, Helpers.GetAddOrRemove(!remove), withoutTypeParams)); } var name = emitter.GetEntityName(property); return(Helpers.GetAddOrRemove(!remove, name)); }
protected virtual List <IEvent> GetEventOverloads(List <IEvent> list = null, ITypeDefinition typeDef = null) { bool isTop = list == null; list = list ?? new List <IEvent>(); typeDef = typeDef ?? this.TypeDefinition; if (typeDef != null) { var events = typeDef.Events.Where(e => { 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; if (e.IsStatic == this.Static) { var addName = e.AddAccessor != null ? Helpers.GetEventRef(e, this.Emitter, false, true, true) : null; var removeName = e.RemoveAccessor != null ? Helpers.GetEventRef(e, this.Emitter, true, true, true) : null; if (addName != null && (addName == this.JsName || addName == this.AltJsName)) { eq = true; } else if (removeName != null && (removeName == this.JsName || removeName == this.AltJsName)) { eq = true; } } if (eq) { if (e.IsOverride && !this.IsTemplateOverride(e)) { return(false); } 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) { var result = this.GetEventOverloads(list, baseTypeDef.GetDefinition()); list.AddRange(result); } } } return(isTop ? list.Distinct().ToList() : list); }
public static void EmitComment(IAbstractEmitterBlock block, AstNode node, bool?getter = null, VariableInitializer varInitializer = null) { if (block.Emitter.AssemblyInfo.GenerateDocumentation == Bridge.Contract.DocumentationMode.None || node.Parent == null) { return; } var visitor = new DocumentationCommentVisitor(); node.AcceptChildren(visitor); if (block.Emitter.AssemblyInfo.GenerateDocumentation == Bridge.Contract.DocumentationMode.Basic && visitor.Comments.Count == 0) { return; } object value = null; var rr = block.Emitter.Resolver.ResolveNode(varInitializer ?? node, block.Emitter); string source = BuildCommentString(visitor.Comments); if (node is FieldDeclaration) { var initializer = varInitializer.Initializer as PrimitiveExpression; if (initializer != null) { value = initializer.Value; } } else if (node is EventDeclaration) { var eventDecl = (EventDeclaration)node; foreach (var evVar in eventDecl.Variables) { var ev_rr = block.Emitter.Resolver.ResolveNode(evVar, block.Emitter); 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; } var prop = node as PropertyDeclaration; if (prop != null) { 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; } var indexer = node as IndexerDeclaration; if (indexer != null) { 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(); }
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); }
protected virtual List <IEvent> GetEventOverloads() { List <IEvent> list = new List <IEvent>(); var typeDef = this.TypeDefinition; while (typeDef != null) { var events = typeDef.Events.Where(e => { 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; if (e.IsStatic == this.Static) { var addName = e.AddAccessor != null ? Helpers.GetEventRef(e, this.Emitter, false, true, true) : null; var removeName = e.RemoveAccessor != null ? Helpers.GetEventRef(e, this.Emitter, true, true, true) : null; if (addName != null && (addName == this.JsName || addName == this.AltJsName)) { eq = true; } else if (removeName != null && (removeName == this.JsName || removeName == this.AltJsName)) { eq = true; } } if (eq) { if (e.IsOverride) { return(false); } return(true); } return(false); }); list.AddRange(events); if (this.Inherit) { var baseTypeDefinition = typeDef.DirectBaseTypes.FirstOrDefault(); if (baseTypeDefinition != null && baseTypeDefinition.Kind == typeDef.Kind) { typeDef = baseTypeDefinition.GetDefinition(); } else { typeDef = null; } } else { typeDef = null; } } return(list); }