private OverloadsCollection(IEmitter emitter, EventDeclaration eventDeclaration) { this.Emitter = emitter; this.Name = emitter.GetEventName(eventDeclaration); this.JsName = this.Emitter.GetEntityName(eventDeclaration); this.Inherit = !eventDeclaration.HasModifier(Modifiers.Static); 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.Cache.AddNode(eventDeclaration, false, this); }
private OverloadsCollection(IEmitter emitter, EventDeclaration eventDeclaration) { this.Emitter = emitter; this.Name = emitter.GetEventName(eventDeclaration); this.JsName = this.Emitter.GetEntityName(eventDeclaration, false, true); this.Inherit = !eventDeclaration.HasModifier(Modifiers.Static); 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; }
public static MethodDeclaration CreateEventInvocator (RefactoringContext context, TypeDeclaration declaringType, EventDeclaration eventDeclaration, VariableInitializer initializer, IMethod invokeMethod, bool useExplictType) { bool hasSenderParam = false; IEnumerable<IParameter> pars = invokeMethod.Parameters; if (invokeMethod.Parameters.Any()) { var first = invokeMethod.Parameters [0]; if (first.Name == "sender" /*&& first.Type == "System.Object"*/) { hasSenderParam = true; pars = invokeMethod.Parameters.Skip(1); } } const string handlerName = "handler"; var arguments = new List<Expression>(); if (hasSenderParam) arguments.Add(eventDeclaration.HasModifier (Modifiers.Static) ? (Expression)new PrimitiveExpression (null) : new ThisReferenceExpression()); bool useThisMemberReference = false; foreach (var par in pars) { arguments.Add(new IdentifierExpression(par.Name)); useThisMemberReference |= par.Name == initializer.Name; } var proposedHandlerName = GetNameProposal(initializer); var modifiers = eventDeclaration.HasModifier(Modifiers.Static) ? Modifiers.Static : Modifiers.Protected | Modifiers.Virtual; if (declaringType.HasModifier (Modifiers.Sealed)) { modifiers = Modifiers.None; } var methodDeclaration = new MethodDeclaration { Name = proposedHandlerName, ReturnType = new PrimitiveType ("void"), Modifiers = modifiers, Body = new BlockStatement { new VariableDeclarationStatement ( useExplictType ? eventDeclaration.ReturnType.Clone () : new PrimitiveType ("var"), handlerName, useThisMemberReference ? (Expression)new MemberReferenceExpression (new ThisReferenceExpression (), initializer.Name) : new IdentifierExpression (initializer.Name) ), new IfElseStatement { Condition = new BinaryOperatorExpression (new IdentifierExpression (handlerName), BinaryOperatorType.InEquality, new PrimitiveExpression (null)), TrueStatement = new InvocationExpression (new IdentifierExpression (handlerName), arguments) } } }; foreach (var par in pars) { var typeName = context.CreateShortType(par.Type); var decl = new ParameterDeclaration(typeName, par.Name); methodDeclaration.Parameters.Add(decl); } return methodDeclaration; }
private OverloadsCollection(IEmitter emitter, EventDeclaration eventDeclaration) { this.Emitter = emitter; this.Name = emitter.GetEventName(eventDeclaration); this.JsName = this.Emitter.GetEntityName(eventDeclaration, false, true); this.Inherit = !eventDeclaration.HasModifier(Modifiers.Static); this.Static = eventDeclaration.HasModifier(Modifiers.Static); this.CancelChangeCase = true; this.Member = this.FindMember(eventDeclaration); this.TypeDefinition = this.Member.DeclaringTypeDefinition; this.Type = this.Member.DeclaringType; this.InitMembers(); this.Emitter.OverloadsCacheNodes[new Tuple <AstNode, bool>(eventDeclaration, false)] = this; }
private OverloadsCollection(IEmitter emitter, EventDeclaration eventDeclaration) { this.Emitter = emitter; this.Name = emitter.GetEventName(eventDeclaration); this.JsName = this.Emitter.GetEntityName(eventDeclaration, false, true); this.Inherit = !eventDeclaration.HasModifier(Modifiers.Static); this.Static = eventDeclaration.HasModifier(Modifiers.Static); this.CancelChangeCase = true; this.Member = this.FindMember(eventDeclaration); this.TypeDefinition = this.Member.DeclaringTypeDefinition; this.Type = this.Member.DeclaringType; this.InitMembers(); this.Emitter.OverloadsCache[eventDeclaration.GetHashCode().ToString()] = this; }
public override void VisitEventDeclaration(EventDeclaration eventDeclaration) { bool isStatic = eventDeclaration.HasModifier(Modifiers.Static); foreach (var item in eventDeclaration.Variables) { Expression initializer = item.Initializer; this.CurrentType.EventsDeclarations.Add(item.Name, eventDeclaration); if (isStatic) { this.CurrentType.StaticConfig.Events.Add(new TypeConfigItem { Name = item.Name, Entity = eventDeclaration, Initializer = initializer, VarInitializer = item }); } else { this.CurrentType.InstanceConfig.Events.Add(new TypeConfigItem { Name = item.Name, Entity = eventDeclaration, Initializer = initializer, VarInitializer = item }); } } }
public override void VisitEventDeclaration(EventDeclaration eventDeclaration) { bool isStatic = eventDeclaration.HasModifier(Modifiers.Static); foreach (var item in eventDeclaration.Variables) { Expression initializer = item.Initializer; this.CurrentType.EventsDeclarations.Add(item.Name, eventDeclaration); if (isStatic) { this.CurrentType.StaticConfig.Events.Add(new TypeConfigItem { Name = item.Name, Entity = eventDeclaration, Initializer = initializer, VarInitializer = item }); } else { this.CurrentType.InstanceConfig.Events.Add(new TypeConfigItem { Name = item.Name, Entity = eventDeclaration, Initializer = initializer, VarInitializer = item }); } var rr = this.Resolver.ResolveNode(item, null) as MemberResolveResult; if (OverloadsCollection.NeedCreateAlias(rr)) { var config = rr.Member.IsStatic ? CurrentType.StaticConfig : CurrentType.InstanceConfig; config.Alias.Add(new TypeConfigItem { Entity = eventDeclaration, VarInitializer = item }); } } }
public static MethodDeclaration CreateEventInvocator(RefactoringContext context, TypeDeclaration declaringType, EventDeclaration eventDeclaration, VariableInitializer initializer, IMethod invokeMethod, bool useExplictType) { bool hasSenderParam = false; IEnumerable <IParameter> pars = invokeMethod.Parameters; if (invokeMethod.Parameters.Any()) { var first = invokeMethod.Parameters [0]; if (first.Name == "sender" /*&& first.Type == "System.Object"*/) { hasSenderParam = true; pars = invokeMethod.Parameters.Skip(1); } } const string handlerName = "handler"; var arguments = new List <Expression>(); if (hasSenderParam) { arguments.Add(eventDeclaration.HasModifier(Modifiers.Static) ? (Expression) new PrimitiveExpression(null) : new ThisReferenceExpression()); } bool useThisMemberReference = false; foreach (var par in pars) { arguments.Add(new IdentifierExpression(par.Name)); useThisMemberReference |= par.Name == initializer.Name; } var proposedHandlerName = GetNameProposal(initializer); var modifiers = eventDeclaration.HasModifier(Modifiers.Static) ? Modifiers.Static : Modifiers.Protected | Modifiers.Virtual; if (declaringType.HasModifier(Modifiers.Sealed)) { modifiers = Modifiers.None; } var methodDeclaration = new MethodDeclaration { Name = proposedHandlerName, ReturnType = new PrimitiveType("void"), Modifiers = modifiers, Body = new BlockStatement { new VariableDeclarationStatement( useExplictType ? eventDeclaration.ReturnType.Clone() : new PrimitiveType("var"), handlerName, useThisMemberReference ? (Expression) new MemberReferenceExpression(new ThisReferenceExpression(), initializer.Name) : new IdentifierExpression(initializer.Name) ), new IfElseStatement { Condition = new BinaryOperatorExpression(new IdentifierExpression(handlerName), BinaryOperatorType.InEquality, new PrimitiveExpression(null)), TrueStatement = new ExpressionStatement(new InvocationExpression(new IdentifierExpression(handlerName), arguments)) } } }; foreach (var par in pars) { var typeName = context.CreateShortType(par.Type); var decl = new ParameterDeclaration(typeName, par.Name); methodDeclaration.Parameters.Add(decl); } return(methodDeclaration); }
public override void VisitEventDeclaration(EventDeclaration eventDeclaration) { bool isStatic = eventDeclaration.HasModifier(Modifiers.Static); foreach (var item in eventDeclaration.Variables) { Expression initializer = item.Initializer; this.CurrentType.EventsDeclarations.Add(item.Name, eventDeclaration); if (isStatic) { this.CurrentType.StaticConfig.Events.Add(new TypeConfigItem { Name = item.Name, Entity = eventDeclaration, Initializer = initializer, VarInitializer = item }); } else { this.CurrentType.InstanceConfig.Events.Add(new TypeConfigItem { Name = item.Name, Entity = eventDeclaration, Initializer = initializer, VarInitializer = item }); } } }