public override void VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration)
			{
				var addAccessor = eventDeclaration.AddAccessor;
				FindIssuesInNode(addAccessor, addAccessor.Body, "add accessor");
				var removeAccessor = eventDeclaration.RemoveAccessor;
				FindIssuesInNode(removeAccessor, removeAccessor.Body, "remove accessor");
			}
 public override void VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration)
 {
     if (eventDeclaration.Modifiers.HasFlag (Modifiers.Override))
         return;
     base.VisitCustomEventDeclaration(eventDeclaration);
     CheckName(eventDeclaration, AffectedEntity.Event, eventDeclaration.NameToken, GetAccessibiltiy(eventDeclaration, Modifiers.Private));
 }
 public override void VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration)
 {
     var addAccessor = eventDeclaration.AddAccessor;
     var removeAccessor = eventDeclaration.RemoveAccessor;
     // don't warn on empty custom events
     if (addAccessor.Body.Statements.Count == 0 && removeAccessor.Body.Statements.Count == 0)
         return;
     FindIssuesInAccessor(addAccessor, "add accessor");
     FindIssuesInAccessor(removeAccessor, "remove accessor");
 }
Ejemplo n.º 4
0
        public static OverloadsCollection Create(IEmitter emitter, CustomEventDeclaration eventDeclaration, bool remove)
        {
            string key = eventDeclaration.GetHashCode().ToString() + remove.GetHashCode().ToString();
            if (emitter.OverloadsCache.ContainsKey(key))
            {
                return emitter.OverloadsCache[key];
            }

            return new OverloadsCollection(emitter, eventDeclaration, remove);
        }
Ejemplo n.º 5
0
        protected virtual void EmitPropertyMethod(CustomEventDeclaration customEventDeclaration, Accessor accessor, bool remover)
        {
            if (!accessor.IsNull && this.Emitter.GetInline(accessor) == null)
            {
                this.EnsureComma();

                this.ResetLocals();

                var prevMap      = this.BuildLocalsMap();
                var prevNamesMap = this.BuildLocalsNamesMap();

                this.AddLocals(new ParameterDeclaration[] { new ParameterDeclaration {
                                                                Name = "value"
                                                            } }, accessor.Body);

                var overloads = OverloadsCollection.Create(this.Emitter, customEventDeclaration, remover);

                this.Write((remover ? "remove" : "add") + overloads.GetOverloadName());
                this.WriteColon();
                this.WriteFunction();
                this.WriteOpenParentheses();
                this.Write("value");
                this.WriteCloseParentheses();
                this.WriteSpace();

                var script = this.Emitter.GetScript(accessor);

                if (script == null)
                {
                    accessor.Body.AcceptVisitor(this.Emitter);
                }
                else
                {
                    this.BeginBlock();

                    foreach (var line in script)
                    {
                        this.Write(line);
                        this.WriteNewLine();
                    }

                    this.EndBlock();
                }

                this.ClearLocalsMap(prevMap);
                this.ClearLocalsNamesMap(prevNamesMap);
                this.Emitter.Comma = true;
            }
        }
Ejemplo n.º 6
0
        public override AstNode VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration)
        {
            var rr = this.Resolver.ResolveNode(eventDeclaration, null) as MemberResolveResult;

            if (rr != null)
            {
                this.Rules = Contract.Rules.Get(this.Emitter, rr.Member);
            }
            else
            {
                this.Rules = Contract.Rules.Default;
            }

            return(base.VisitCustomEventDeclaration(eventDeclaration));
        }
 bool CheckAutomaticEventV2(CustomEventDeclaration ev, out Match addMatch, out Match removeMatch)
 {
     addMatch = removeMatch = default(Match);
     addMatch = automaticEventPatternV2.Match(ev.AddAccessor);
     if (!CheckAutomaticEventMatch(addMatch, ev, true))
     {
         return(false);
     }
     removeMatch = automaticEventPatternV2.Match(ev.RemoveAccessor);
     if (!CheckAutomaticEventMatch(removeMatch, ev, false))
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 8
0
 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;
 }
        public override IUnresolvedEntity VisitCustomEventDeclaration(CustomEventDeclaration node)
        {
            var ev = (IUnresolvedEvent)base.VisitCustomEventDeclaration(node);

            if (ev.AddAccessor != null)
            {
                ev.AddAccessor.Declaration = node.AddAccessor;
            }
            if (ev.RemoveAccessor != null)
            {
                ev.RemoveAccessor.Declaration = node.RemoveAccessor;
            }

            return(SetDecl(ev, node));
        }
Ejemplo n.º 10
0
        public override void VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration)
        {
            var nameToken = eventDeclaration.NameToken;

            VisitChildrenUntil(eventDeclaration, nameToken);
            if (!eventDeclaration.PrivateImplementationType.IsNull)
            {
                if (!CheckInterfaceImplementation(eventDeclaration))
                {
                    VisitChildrenAfter(eventDeclaration, nameToken);
                    return;
                }
            }
            Colorize(nameToken, eventDeclarationColor);
            VisitChildrenAfter(eventDeclaration, nameToken);
        }
Ejemplo n.º 11
0
        bool CheckAutomaticEventV4MCS(CustomEventDeclaration ev)
        {
            Match addMatch = automaticEventPatternV4MCS.Match(ev.AddAccessor);

            if (!CheckAutomaticEventMatch(addMatch, ev, true))
            {
                return(false);
            }
            Match removeMatch = automaticEventPatternV4MCS.Match(ev.RemoveAccessor);

            if (!CheckAutomaticEventMatch(removeMatch, ev, false))
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 12
0
 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.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() + remove.GetHashCode().ToString()] = this;
 }
        EventDeclaration TransformAutomaticEvents(CustomEventDeclaration ev)
        {
            Match m1, m2;

            if (!CheckAutomaticEventV4(ev, out m1, out m2) && !CheckAutomaticEventV2(ev, out m1, out m2))
            {
                return(null);
            }
            RemoveCompilerGeneratedAttribute(ev.AddAccessor.Attributes, attributeTypesToRemoveFromAutoEvents);
            EventDeclaration ed = new EventDeclaration();

            ev.Attributes.MoveTo(ed.Attributes);
            foreach (var attr in ev.AddAccessor.Attributes)
            {
                attr.AttributeTarget = "method";
                ed.Attributes.Add(attr.Detach());
            }
            ed.ReturnType = ev.ReturnType.Detach();
            ed.Modifiers  = ev.Modifiers;
            ed.Variables.Add(new VariableInitializer(ev.Name));
            ed.CopyAnnotationsFrom(ev);

            IEvent eventDef = ev.GetSymbol() as IEvent;

            if (eventDef != null)
            {
                IField field = eventDef.DeclaringType.GetFields(f => f.Name == ev.Name, GetMemberOptions.IgnoreInheritedMembers).SingleOrDefault();
                if (field != null)
                {
                    ed.AddAnnotation(field);
                    var attributes = field.Attributes
                                     .Where(a => !attributeTypesToRemoveFromAutoEvents.Any(t => t == a.AttributeType.FullName))
                                     .Select(context.TypeSystemAstBuilder.ConvertAttribute).ToArray();
                    if (attributes.Length > 0)
                    {
                        var section = new AttributeSection {
                            AttributeTarget = "field"
                        };
                        section.Attributes.AddRange(attributes);
                        ed.Attributes.Add(section);
                    }
                }
            }

            ev.ReplaceWith(ed);
            return(ed);
        }
Ejemplo n.º 14
0
        protected virtual void EmitPropertyMethod(CustomEventDeclaration customEventDeclaration, Accessor accessor, bool remover)
        {
            if (!accessor.IsNull && this.Emitter.GetInline(accessor) == null)
            {
                this.EnsureComma();

                this.ResetLocals();

                var prevMap = this.BuildLocalsMap();
                var prevNamesMap = this.BuildLocalsNamesMap();

                this.AddLocals(new ParameterDeclaration[] { new ParameterDeclaration { Name = "value" } }, accessor.Body);
                XmlToJsDoc.EmitComment(this, this.CustomEventDeclaration);
                var overloads = OverloadsCollection.Create(this.Emitter, customEventDeclaration, remover);

                this.Write((remover ? "remove" : "add") + overloads.GetOverloadName());
                this.WriteColon();
                this.WriteFunction();
                this.WriteOpenParentheses();
                this.Write("value");
                this.WriteCloseParentheses();
                this.WriteSpace();

                var script = this.Emitter.GetScript(accessor);

                if (script == null)
                {
                    accessor.Body.AcceptVisitor(this.Emitter);
                }
                else
                {
                    this.BeginBlock();

                    foreach (var line in script)
                    {
                        this.Write(line);
                        this.WriteNewLine();
                    }

                    this.EndBlock();
                }

                this.ClearLocalsMap(prevMap);
                this.ClearLocalsNamesMap(prevNamesMap);
                this.Emitter.Comma = true;
            }
        }
Ejemplo n.º 15
0
        public static string GetEventRef(CustomEventDeclaration property, IEmitter emitter, bool remove = false, bool noOverload = false, bool ignoreInterface = false, bool withoutTypeParams = false)
        {
            if (emitter.Resolver.ResolveNode(property) is MemberResolveResult resolveResult && resolveResult.Member != null)
            {
                return(GetEventRef(resolveResult.Member, emitter, remove, noOverload, ignoreInterface, withoutTypeParams));
            }

            if (!noOverload)
            {
                var overloads = OverloadsCollection.Create(emitter, property, remove);
                return(overloads.GetOverloadName(ignoreInterface, GetAddOrRemove(!remove), withoutTypeParams));
            }

            var name = emitter.GetEntityName(property);

            return(GetAddOrRemove(!remove, name));
        }
Ejemplo n.º 16
0
        protected virtual void EmitPropertyMethod(CustomEventDeclaration customEventDeclaration, Accessor accessor, bool remover)
        {
            if (!accessor.IsNull && Emitter.GetInline(accessor) == null)
            {
                EnsureComma();

                ResetLocals();

                var prevMap      = BuildLocalsMap();
                var prevNamesMap = BuildLocalsNamesMap();

                AddLocals(new ParameterDeclaration[] { new ParameterDeclaration {
                                                           Name = "value"
                                                       } }, accessor.Body);
                XmlToJsDoc.EmitComment(this, CustomEventDeclaration);
                var member_rr = (MemberResolveResult)Emitter.Resolver.ResolveNode(customEventDeclaration);

                Write(Helpers.GetEventRef(customEventDeclaration, Emitter, remover, false, false, OverloadsCollection.ExcludeTypeParameterForDefinition(member_rr)));
                WriteColon();
                WriteFunction();
                var m_rr = (MemberResolveResult)Emitter.Resolver.ResolveNode(customEventDeclaration);
                WriteOpenParentheses();
                Write("value");
                WriteCloseParentheses();
                WriteSpace();

                var script = Emitter.GetScript(accessor);

                if (script == null)
                {
                    accessor.Body.AcceptVisitor(Emitter);
                }
                else
                {
                    BeginBlock();

                    WriteLines(script);

                    EndBlock();
                }

                ClearLocalsMap(prevMap);
                ClearLocalsNamesMap(prevNamesMap);
                Emitter.Comma = true;
            }
        }
Ejemplo n.º 17
0
 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);
 }
Ejemplo n.º 18
0
        public override void VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration)
        {
            if (Found)
            {
                return;
            }

            if (Resolver.ResolveNode(eventDeclaration) is MemberResolveResult rr)
            {
                Rules = Contract.Rules.Get(Emitter, rr.Member);
            }
            else
            {
                Rules = Contract.Rules.Default;
            }

            base.VisitCustomEventDeclaration(eventDeclaration);
        }
Ejemplo n.º 19
0
        protected virtual void EmitPropertyMethod(CustomEventDeclaration customEventDeclaration, Accessor accessor, bool remover)
        {
            if (!accessor.IsNull && this.Emitter.GetInline(accessor) == null)
            {
                this.EnsureComma();

                this.ResetLocals();

                var prevMap      = this.BuildLocalsMap();
                var prevNamesMap = this.BuildLocalsNamesMap();

                this.AddLocals(new ParameterDeclaration[] { new ParameterDeclaration {
                                                                Name = "value"
                                                            } }, accessor.Body);
                XmlToJsDoc.EmitComment(this, this.CustomEventDeclaration);

                this.Write(Helpers.GetEventRef(customEventDeclaration, this.Emitter, remover, false, false, true));
                this.WriteColon();
                this.WriteFunction();
                this.WriteOpenParentheses();
                this.Write("value");
                this.WriteCloseParentheses();
                this.WriteSpace();

                var script = this.Emitter.GetScript(accessor);

                if (script == null)
                {
                    accessor.Body.AcceptVisitor(this.Emitter);
                }
                else
                {
                    this.BeginBlock();

                    this.WriteLines(script);

                    this.EndBlock();
                }

                this.ClearLocalsMap(prevMap);
                this.ClearLocalsNamesMap(prevNamesMap);
                this.Emitter.Comma = true;
            }
        }
Ejemplo n.º 20
0
            public override void VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration)
            {
                if (eventDeclaration.HasModifier(Modifiers.Static) ||
                    eventDeclaration.HasModifier(Modifiers.Virtual) ||
                    eventDeclaration.HasModifier(Modifiers.Override) ||
                    eventDeclaration.HasModifier(Modifiers.New) ||
                    eventDeclaration.Attributes.Any())
                {
                    return;
                }

                if (IsEmpty(eventDeclaration.RemoveAccessor) && IsEmpty(eventDeclaration.AddAccessor))
                {
                    return;
                }


                var resolved = ctx.Resolve(eventDeclaration) as MemberResolveResult;

                if (resolved == null || SkipMember(resolved.Member))
                {
                    return;
                }
                var isImplementingInterface = resolved.Member.ImplementedInterfaceMembers.Any();

                if (isImplementingInterface)
                {
                    return;
                }

                if (!eventDeclaration.AddAccessor.IsNull && StaticVisitor.UsesNotStaticMember(ctx, eventDeclaration.AddAccessor.Body) ||
                    !eventDeclaration.RemoveAccessor.IsNull && StaticVisitor.UsesNotStaticMember(ctx, eventDeclaration.RemoveAccessor.Body))
                {
                    return;
                }

                AddIssue(new CodeIssue(eventDeclaration.NameToken.StartLocation, eventDeclaration.NameToken.EndLocation,
                                       string.Format(ctx.TranslateString("Event '{0}' can be made static."), eventDeclaration.Name),
                                       string.Format(ctx.TranslateString("Make '{0}' static"), eventDeclaration.Name),
                                       script => script.ChangeModifier(eventDeclaration, eventDeclaration.Modifiers | Modifiers.Static))
                {
                    IssueMarker = IssueMarker.DottedLine
                });
            }
Ejemplo n.º 21
0
        protected virtual void EmitPropertyMethod(CustomEventDeclaration customEventDeclaration, Accessor accessor, bool remover)
        {
            if (!accessor.IsNull && this.Emitter.GetInline(accessor) == null)
            {
                XmlToJsDoc.EmitComment(this, customEventDeclaration);
                this.Write(Helpers.GetEventRef(customEventDeclaration, this.Emitter, remover, false, false));
                this.WriteOpenParentheses();
                this.Write("value");
                this.WriteColon();
                var retType = BridgeTypes.ToTypeScriptName(customEventDeclaration.ReturnType, this.Emitter);
                this.Write(retType);
                this.WriteCloseParentheses();
                this.WriteColon();
                this.Write("void");

                this.WriteSemiColon();
                this.WriteNewLine();
            }
        }
Ejemplo n.º 22
0
        public static string GetEventRef(CustomEventDeclaration property, IEmitter emitter, bool remove = false, bool noOverload = false, bool ignoreInterface = false)
        {
            ResolveResult resolveResult = emitter.Resolver.ResolveNode(property, emitter) as MemberResolveResult;
            if (resolveResult != null && ((MemberResolveResult)resolveResult).Member != null)
            {
                return GetEventRef(((MemberResolveResult)resolveResult).Member, emitter, remove, noOverload, ignoreInterface);
            }

            var name = emitter.GetEntityName(property, true, ignoreInterface);

            if (!noOverload)
            {
                var overloads = OverloadsCollection.Create(emitter, property, remove);
                name = overloads.HasOverloads ? overloads.GetOverloadName() : name;
                noOverload = !overloads.HasOverloads;
            }

            return (remove ? "remove" : "add") + name;
        }
        public override void VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration)
        {
            FixAttributesAndDocComment(eventDeclaration);

            FixOpenBrace(policy.EventBraceStyle, eventDeclaration.LBraceToken);
            if (policy.IndentEventBody)
                curIndent.Push(IndentType.Block);

            if (!eventDeclaration.AddAccessor.IsNull) {
                FixIndentation(eventDeclaration.AddAccessor);
                if (!eventDeclaration.AddAccessor.Body.IsNull) {
                    if (!policy.AllowEventAddBlockInline || eventDeclaration.AddAccessor.Body.LBraceToken.StartLocation.Line != eventDeclaration.AddAccessor.Body.RBraceToken.StartLocation.Line) {
                        FixOpenBrace(policy.EventAddBraceStyle, eventDeclaration.AddAccessor.Body.LBraceToken);
                        VisitBlockWithoutFixingBraces(eventDeclaration.AddAccessor.Body, policy.IndentBlocks);
                        FixClosingBrace(policy.EventAddBraceStyle, eventDeclaration.AddAccessor.Body.RBraceToken);
                    } else {
                        nextStatementIndent = " ";
                        VisitBlockWithoutFixingBraces(eventDeclaration.AddAccessor.Body, policy.IndentBlocks);
                    }
                }
            }

            if (!eventDeclaration.RemoveAccessor.IsNull) {
                FixIndentation(eventDeclaration.RemoveAccessor);
                if (!eventDeclaration.RemoveAccessor.Body.IsNull) {
                    if (!policy.AllowEventRemoveBlockInline || eventDeclaration.RemoveAccessor.Body.LBraceToken.StartLocation.Line != eventDeclaration.RemoveAccessor.Body.RBraceToken.StartLocation.Line) {
                        FixOpenBrace(policy.EventRemoveBraceStyle, eventDeclaration.RemoveAccessor.Body.LBraceToken);
                        VisitBlockWithoutFixingBraces(eventDeclaration.RemoveAccessor.Body, policy.IndentBlocks);
                        FixClosingBrace(policy.EventRemoveBraceStyle, eventDeclaration.RemoveAccessor.Body.RBraceToken);
                    } else {
                        nextStatementIndent = " ";
                        VisitBlockWithoutFixingBraces(eventDeclaration.RemoveAccessor.Body, policy.IndentBlocks);
                    }
                }
            }

            if (policy.IndentEventBody)
                curIndent.Pop();

            FixClosingBrace(policy.EventBraceStyle, eventDeclaration.RBraceToken);
        }
Ejemplo n.º 24
0
            public override void VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration)
            {
                var m = customEventPattern.Match(eventDeclaration);

                if (!m.Success)
                {
                    return;
                }
                var baseRef = m.Get <MemberReferenceExpression>("baseRef").First();

                if (baseRef == null || baseRef.MemberName != eventDeclaration.Name)
                {
                    return;
                }

                var title = ctx.TranslateString("Redundant event override");

                AddIssue(eventDeclaration, title, ctx.TranslateString("Remove event override"), script => {
                    script.Remove(eventDeclaration);
                });
            }
 EntityDeclaration ConvertEvent(IEvent ev)
 {
     if (this.UseCustomEvents)
     {
         CustomEventDeclaration decl = new CustomEventDeclaration();
         decl.Modifiers      = GetMemberModifiers(ev);
         decl.ReturnType     = ConvertType(ev.ReturnType);
         decl.Name           = ev.Name;
         decl.AddAccessor    = ConvertAccessor(ev.AddAccessor, ev.Accessibility);
         decl.RemoveAccessor = ConvertAccessor(ev.RemoveAccessor, ev.Accessibility);
         return(decl);
     }
     else
     {
         EventDeclaration decl = new EventDeclaration();
         decl.Modifiers  = GetMemberModifiers(ev);
         decl.ReturnType = ConvertType(ev.ReturnType);
         decl.Variables.Add(new VariableInitializer(ev.Name));
         return(decl);
     }
 }
Ejemplo n.º 26
0
        protected virtual void EmitPropertyMethod(CustomEventDeclaration customEventDeclaration, Accessor accessor, bool remover)
        {
            if (!accessor.IsNull && this.Emitter.GetInline(accessor) == null)
            {
                var overloads = OverloadsCollection.Create(this.Emitter, customEventDeclaration, remover);

                this.Write((remover ? "remove" : "add") + overloads.GetOverloadName());
                this.WriteOpenParentheses();
                this.Write("value");
                this.WriteColon();
                var retType = BridgeTypes.ToJsName(customEventDeclaration.ReturnType, this.Emitter);
                retType = EmitBlock.HandleType(retType);
                this.Write(retType);
                this.WriteCloseParentheses();
                this.WriteColon();
                this.Write("void");

                this.WriteSemiColon();
                this.WriteNewLine();
            }
        }
Ejemplo n.º 27
0
        protected virtual void EmitPropertyMethod(CustomEventDeclaration customEventDeclaration, Accessor accessor, bool remover)
        {
            if (!accessor.IsNull && this.Emitter.GetInline(accessor) == null)
            {
                XmlToJsDoc.EmitComment(this, customEventDeclaration);
                var overloads = OverloadsCollection.Create(this.Emitter, customEventDeclaration, remover);

                this.Write((remover ? "remove" : "add") + overloads.GetOverloadName());
                this.WriteOpenParentheses();
                this.Write("value");
                this.WriteColon();
                var retType = BridgeTypes.ToTypeScriptName(customEventDeclaration.ReturnType, this.Emitter);
                this.Write(retType);
                this.WriteCloseParentheses();
                this.WriteColon();
                this.Write("void");

                this.WriteSemiColon();
                this.WriteNewLine();
            }
        }
Ejemplo n.º 28
0
        bool CheckAutomaticEventMatch(Match m, CustomEventDeclaration ev, bool isAddAccessor)
        {
            if (!m.Success)
            {
                return(false);
            }
            Expression fieldExpression = m.Get <Expression>("field").Single();

            // field name must match event name
            switch (fieldExpression)
            {
            case IdentifierExpression identifier:
                if (identifier.Identifier != ev.Name)
                {
                    return(false);
                }
                break;

            case MemberReferenceExpression memberRef:
                if (memberRef.MemberName != ev.Name)
                {
                    return(false);
                }
                break;

            default:
                return(false);
            }
            if (!ev.ReturnType.IsMatch(m.Get("type").Single()))
            {
                return(false);                // variable types must match event type
            }
            var combineMethod = m.Get <AstNode>("delegateCombine").Single().Parent.GetSymbol() as IMethod;

            if (combineMethod == null || combineMethod.Name != (isAddAccessor ? "Combine" : "Remove"))
            {
                return(false);
            }
            return(combineMethod.DeclaringType.FullName == "System.Delegate");
        }
Ejemplo n.º 29
0
        bool CheckAutomaticEventV4Match(Match m, CustomEventDeclaration ev, bool isAddAccessor)
        {
            if (m == null)
            {
                return(false);
            }
            if (m.Get <MemberReferenceExpression>("field").Single().MemberName != ev.Name)
            {
                return(false);                // field name must match event name
            }
            if (ev.ReturnType.Match(m.Get("type").Single()) == null)
            {
                return(false);                // variable types must match event type
            }
            var combineMethod = m.Get("delegateCombine").Single().Parent.Annotation <MethodReference>();

            if (combineMethod == null || combineMethod.Name != (isAddAccessor ? "Combine" : "Remove"))
            {
                return(false);
            }
            return(combineMethod.DeclaringType.FullName == "System.Delegate");
        }
Ejemplo n.º 30
0
        protected virtual void EmitPropertyMethod(CustomEventDeclaration customEventDeclaration, Accessor accessor, bool remover)
        {
            if (!accessor.IsNull && Emitter.GetInline(accessor) == null)
            {
                XmlToJsDoc.EmitComment(this, customEventDeclaration);
                var memberResult    = Emitter.Resolver.ResolveNode(customEventDeclaration) as MemberResolveResult;
                var ignoreInterface = memberResult.Member.DeclaringType.Kind == TypeKind.Interface &&
                                      memberResult.Member.DeclaringType.TypeParameterCount > 0;
                Write(Helpers.GetEventRef(customEventDeclaration, Emitter, remover, false, ignoreInterface));
                WriteOpenParentheses();
                Write("value");
                WriteColon();
                var retType = H5Types.ToTypeScriptName(customEventDeclaration.ReturnType, Emitter);
                Write(retType);
                WriteCloseParentheses();
                WriteColon();
                Write("void");

                WriteSemiColon();
                WriteNewLine();
            }
        }
Ejemplo n.º 31
0
        EventDeclaration TransformAutomaticEvents(CustomEventDeclaration ev)
        {
            Match m1 = automaticEventPatternV4.Match(ev.AddAccessor);

            if (!CheckAutomaticEventV4Match(m1, ev, true))
            {
                return(null);
            }
            Match m2 = automaticEventPatternV4.Match(ev.RemoveAccessor);

            if (!CheckAutomaticEventV4Match(m2, ev, false))
            {
                return(null);
            }
            EventDeclaration ed = new EventDeclaration();

            ev.Attributes.MoveTo(ed.Attributes);
            ed.ReturnType = ev.ReturnType.Detach();
            ed.Modifiers  = ev.Modifiers;
            ed.Variables.Add(new VariableInitializer(ev.Name));
            ed.CopyAnnotationsFrom(ev);

            EventDefinition eventDef = ev.Annotation <EventDefinition>();

            if (eventDef != null)
            {
                FieldDefinition field = eventDef.DeclaringType.Fields.FirstOrDefault(f => f.Name == ev.Name);
                if (field != null)
                {
                    ed.AddAnnotation(field);
                    AstBuilder.ConvertAttributes(ed, field, AttributeTarget.Field);
                }
            }

            ev.ReplaceWith(ed);
            return(ed);
        }
Ejemplo n.º 32
0
        protected override CodeAction GetAction(RefactoringContext context, VariableInitializer node)
        {
            var eventDecl = node.Parent as EventDeclaration;

            if (eventDecl == null)
            {
                return(null);
            }
            return(new CodeAction(context.TranslateString("Create custom event implementation"),
                                  script =>
            {
                var accessor = new Accessor
                {
                    Body = new BlockStatement
                    {
                        new ThrowStatement(
                            new ObjectCreateExpression(context.CreateShortType("System", "NotImplementedException")))
                    }
                };
                var e = new CustomEventDeclaration
                {
                    Name = node.Name,
                    Modifiers = eventDecl.Modifiers,
                    ReturnType = eventDecl.ReturnType.Clone(),
                    AddAccessor = accessor,
                    RemoveAccessor = (Accessor)accessor.Clone(),
                };
                if (eventDecl.Variables.Count > 1)
                {
                    var newEventDecl = (EventDeclaration)eventDecl.Clone();
                    newEventDecl.Variables.Remove(
                        newEventDecl.Variables.FirstOrNullObject(v => v.Name == node.Name));
                    script.InsertBefore(eventDecl, newEventDecl);
                }
                script.Replace(eventDecl, e);
            }));
        }
Ejemplo n.º 33
0
        public override void VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration)
        {
            if (customEventDeclaration.HasModifier(Modifiers.Abstract))
            {
                return;
            }

            bool isStatic = customEventDeclaration.HasModifier(Modifiers.Static);

            IDictionary <string, List <EntityDeclaration> > dict = isStatic
                ? CurrentType.StaticProperties
                : CurrentType.InstanceProperties;

            var key = customEventDeclaration.Name;

            if (dict.ContainsKey(key))
            {
                dict[key].Add(customEventDeclaration);
            }
            else
            {
                dict.Add(key, new List <EntityDeclaration>(new[] { customEventDeclaration }));
            }
        }
Ejemplo n.º 34
0
        public override void VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration)
        {
            if (customEventDeclaration.HasModifier(Modifiers.Abstract))
            {
                return;
            }

            bool isStatic = customEventDeclaration.HasModifier(Modifiers.Static);

            IDictionary<string, List<EntityDeclaration>> dict = isStatic
                ? CurrentType.StaticProperties
                : CurrentType.InstanceProperties;

            var key = customEventDeclaration.Name;

            if (dict.ContainsKey(key))
                {
                dict[key].Add(customEventDeclaration);
                }
                else
                {
                dict.Add(key, new List<EntityDeclaration>(new[] { customEventDeclaration }));
            }
        }
Ejemplo n.º 35
0
        public override void VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration)
        {
            if (customEventDeclaration.HasModifier(Modifiers.Abstract))
            {
                return;
            }

            bool isStatic = customEventDeclaration.HasModifier(Modifiers.Static);

            IDictionary <string, List <EntityDeclaration> > dict = isStatic
                ? CurrentType.StaticProperties
                : CurrentType.InstanceProperties;

            var key = customEventDeclaration.Name;

            if (dict.ContainsKey(key))
            {
                dict[key].Add(customEventDeclaration);
            }
            else
            {
                dict.Add(key, new List <EntityDeclaration>(new[] { customEventDeclaration }));
            }

            var rr = this.Resolver.ResolveNode(customEventDeclaration, null) as MemberResolveResult;

            if (OverloadsCollection.NeedCreateAlias(rr))
            {
                var config = rr.Member.IsStatic
                ? CurrentType.StaticConfig
                : CurrentType.InstanceConfig;
                config.Alias.Add(new TypeConfigItem {
                    Entity = customEventDeclaration
                });
            }
        }
Ejemplo n.º 36
0
			public override void Visit (EventProperty ep)
			{
				CustomEventDeclaration newEvent = new CustomEventDeclaration ();
				AddAttributeSection (newEvent, ep);
				var location = LocationsBag.GetMemberLocation (ep);
				AddModifiers (newEvent, location);
				
				if (location != null)
					newEvent.AddChild (new CSharpTokenNode (Convert (location[0]), "event".Length), CustomEventDeclaration.Roles.Keyword);
				newEvent.AddChild (ConvertToType (ep.TypeName), CustomEventDeclaration.Roles.Type);
				if (ep.MemberName.Left != null) {
					newEvent.AddChild (ConvertToType (ep.MemberName.Left), CustomEventDeclaration.PrivateImplementationTypeRole);
					var privateImplTypeLoc = LocationsBag.GetLocations (ep.MemberName.Left);
					if (privateImplTypeLoc != null)
						newEvent.AddChild (new CSharpTokenNode (Convert (privateImplTypeLoc[0]), 1), MethodDeclaration.Roles.Dot);
				}
				
				newEvent.AddChild (Identifier.Create (ep.MemberName.Name, Convert (ep.Location)), CustomEventDeclaration.Roles.Identifier);

				if (location != null && location.Count >= 2)
					newEvent.AddChild (new CSharpTokenNode (Convert (location[1]), 1), CustomEventDeclaration.Roles.LBrace);
				
				if (ep.Add != null) {
					Accessor addAccessor = new Accessor ();
					AddAttributeSection (addAccessor, ep.Add);
					var addLocation = LocationsBag.GetMemberLocation (ep.Add);
					AddModifiers (addAccessor, addLocation);
					addAccessor.AddChild (new CSharpTokenNode (Convert (ep.Add.Location), "add".Length), CustomEventDeclaration.Roles.Keyword);
					if (ep.Add.Block != null)
						addAccessor.AddChild ((BlockStatement)ep.Add.Block.Accept (this), CustomEventDeclaration.Roles.Body);
					newEvent.AddChild (addAccessor, CustomEventDeclaration.AddAccessorRole);
				}
				
				if (ep.Remove != null) {
					Accessor removeAccessor = new Accessor ();
					AddAttributeSection (removeAccessor, ep.Remove);
					var removeLocation = LocationsBag.GetMemberLocation (ep.Remove);
					AddModifiers (removeAccessor, removeLocation);
					removeAccessor.AddChild (new CSharpTokenNode (Convert (ep.Remove.Location), "remove".Length), CustomEventDeclaration.Roles.Keyword);
					
					if (ep.Remove.Block != null)
						removeAccessor.AddChild ((BlockStatement)ep.Remove.Block.Accept (this), CustomEventDeclaration.Roles.Body);
					newEvent.AddChild (removeAccessor, CustomEventDeclaration.RemoveAccessorRole);
				}
				if (location != null && location.Count >= 3) {
					newEvent.AddChild (new CSharpTokenNode (Convert (location[2]), 1), CustomEventDeclaration.Roles.RBrace);
				} else {
					// parser error, set end node to max value.
					newEvent.AddChild (new ErrorNode (), AstNode.Roles.Error);
				}
				
				typeStack.Peek ().AddChild (newEvent, TypeDeclaration.MemberRole);
			}
			public override void VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration)
			{
			}
Ejemplo n.º 38
0
			public override void VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration)
			{
				base.VisitCustomEventDeclaration(eventDeclaration);
				CheckNode(eventDeclaration);
			}
Ejemplo n.º 39
0
 EntityDeclaration ConvertEvent(IEvent ev)
 {
     if (this.UseCustomEvents) {
         CustomEventDeclaration decl = new CustomEventDeclaration();
         decl.Modifiers = GetMemberModifiers(ev);
         decl.ReturnType = ConvertType(ev.ReturnType);
         decl.Name = ev.Name;
         decl.AddAccessor    = ConvertAccessor(ev.AddAccessor, ev.Accessibility);
         decl.RemoveAccessor = ConvertAccessor(ev.RemoveAccessor, ev.Accessibility);
         return decl;
     } else {
         EventDeclaration decl = new EventDeclaration();
         decl.Modifiers = GetMemberModifiers(ev);
         decl.ReturnType = ConvertType(ev.ReturnType);
         decl.Variables.Add(new VariableInitializer(ev.Name));
         return decl;
     }
 }
Ejemplo n.º 40
0
			public override void Visit (EventProperty ep)
			{
				CustomEventDeclaration newEvent = new CustomEventDeclaration ();
				
				var location = LocationsBag.GetMemberLocation (ep);
				AddModifiers (newEvent, location);
				
				if (location != null)
					newEvent.AddChild (new CSharpTokenNode (Convert (location[0]), "event".Length), CustomEventDeclaration.Roles.Keyword);
				newEvent.AddChild (ConvertToType (ep.TypeName), CustomEventDeclaration.Roles.Type);
				newEvent.AddChild (new Identifier (ep.MemberName.Name, Convert (ep.MemberName.Location)), CustomEventDeclaration.Roles.Identifier);
				if (location != null && location.Count >= 2)
					newEvent.AddChild (new CSharpTokenNode (Convert (location[1]), 1), CustomEventDeclaration.Roles.LBrace);
				
				if (ep.Add != null) {
					Accessor addAccessor = new Accessor ();
					var addLocation = LocationsBag.GetMemberLocation (ep.Add);
					AddModifiers (addAccessor, addLocation);
					addAccessor.AddChild (new CSharpTokenNode (Convert (ep.Add.Location), "add".Length), CustomEventDeclaration.Roles.Keyword);
					if (ep.Add.Block != null)
						addAccessor.AddChild ((BlockStatement)ep.Add.Block.Accept (this), CustomEventDeclaration.Roles.Body);
					newEvent.AddChild (addAccessor, CustomEventDeclaration.AddAccessorRole);
				}
				
				if (ep.Remove != null) {
					Accessor removeAccessor = new Accessor ();
					var removeLocation = LocationsBag.GetMemberLocation (ep.Remove);
					AddModifiers (removeAccessor, removeLocation);
					removeAccessor.AddChild (new CSharpTokenNode (Convert (ep.Remove.Location), "remove".Length), CustomEventDeclaration.Roles.Keyword);
					
					if (ep.Remove.Block != null)
						removeAccessor.AddChild ((BlockStatement)ep.Remove.Block.Accept (this), CustomEventDeclaration.Roles.Body);
					newEvent.AddChild (removeAccessor, CustomEventDeclaration.RemoveAccessorRole);
				}
				if (location != null && location.Count >= 3)
					newEvent.AddChild (new CSharpTokenNode (Convert (location[2]), 1), CustomEventDeclaration.Roles.RBrace);
				
				typeStack.Peek ().AddChild (newEvent, TypeDeclaration.MemberRole);
			}
Ejemplo n.º 41
0
		CustomEventDeclaration CreateEvent(EventDefinition eventDef)
		{
			CustomEventDeclaration astEvent = new CustomEventDeclaration();
			astEvent.AddAnnotation(eventDef);
			astEvent.Name = CleanName(eventDef.Name);
			astEvent.ReturnType = ConvertType(eventDef.EventType, eventDef);
			if (eventDef.AddMethod == null || !eventDef.AddMethod.HasOverrides)
				astEvent.Modifiers = ConvertModifiers(eventDef.AddMethod);
			else
				astEvent.PrivateImplementationType = ConvertType(eventDef.AddMethod.Overrides.First().DeclaringType);
			if (eventDef.AddMethod != null) {
				astEvent.AddAccessor = new Accessor {
					Body = AstMethodBodyBuilder.CreateMethodBody(eventDef.AddMethod, context)
				}.WithAnnotation(eventDef.AddMethod);
				ConvertAttributes(astEvent.AddAccessor, eventDef.AddMethod);
			}
			if (eventDef.RemoveMethod != null) {
				astEvent.RemoveAccessor = new Accessor {
					Body = AstMethodBodyBuilder.CreateMethodBody(eventDef.RemoveMethod, context)
				}.WithAnnotation(eventDef.RemoveMethod);
				ConvertAttributes(astEvent.RemoveAccessor, eventDef.RemoveMethod);
			}
			return astEvent;
		}
		public override void VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration)
		{
			VisitNewDeclarationSpace(eventDeclaration);
		}
Ejemplo n.º 43
0
		public virtual void VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration)
		{
			StartNode(customEventDeclaration);
			WriteAttributes(customEventDeclaration.Attributes);
			WriteModifiers(customEventDeclaration.ModifierTokens);
			WriteKeyword(CustomEventDeclaration.EventKeywordRole);
			customEventDeclaration.ReturnType.AcceptVisitor(this);
			Space();
			WritePrivateImplementationType(customEventDeclaration.PrivateImplementationType);
			WriteIdentifier(customEventDeclaration.NameToken);
			var braceHelper = OpenBrace(policy.EventBraceStyle, CodeBracesRangeFlags.EventBraces);
			// output add/remove in their original order
			int count = 0;
			foreach (AstNode node in customEventDeclaration.Children) {
				if (count-- <= 0) {
					cancellationToken.ThrowIfCancellationRequested();
					count = CANCEL_CHECK_LOOP_COUNT;
				}
				if (node.Role == CustomEventDeclaration.AddAccessorRole || node.Role == CustomEventDeclaration.RemoveAccessorRole) {
					node.AcceptVisitor(this);
				}
			}
			CloseBrace(policy.EventBraceStyle, braceHelper, true);
			NewLine();
			EndNode(customEventDeclaration);
		}
Ejemplo n.º 44
0
 EntityDeclaration ConvertEvent(IEvent ev)
 {
     if (this.UseCustomEvents) {
         CustomEventDeclaration decl = new CustomEventDeclaration();
         decl.Modifiers = GetMemberModifiers(ev);
         if (ShowAttributes) {
             decl.Attributes.AddRange (ev.Attributes.Select ((a) => new AttributeSection (ConvertAttribute (a))));
         }
         if (AddResolveResultAnnotations) {
             decl.AddAnnotation(new MemberResolveResult(null, ev));
         }
         decl.ReturnType = ConvertType(ev.ReturnType);
         decl.Name = ev.Name;
         decl.AddAccessor    = ConvertAccessor(ev.AddAccessor, ev.Accessibility, true);
         decl.RemoveAccessor = ConvertAccessor(ev.RemoveAccessor, ev.Accessibility, true);
         return decl;
     } else {
         EventDeclaration decl = new EventDeclaration();
         decl.Modifiers = GetMemberModifiers(ev);
         if (ShowAttributes) {
             decl.Attributes.AddRange (ev.Attributes.Select ((a) => new AttributeSection (ConvertAttribute (a))));
         }
         if (AddResolveResultAnnotations) {
             decl.AddAnnotation(new MemberResolveResult(null, ev));
         }
         decl.ReturnType = ConvertType(ev.ReturnType);
         decl.Variables.Add(new VariableInitializer(ev.Name));
         return decl;
     }
 }
Ejemplo n.º 45
0
		void HandleVisitorCustomEventDeclarationVisited (CustomEventDeclaration node, InspectionData data)
		{
			foreach (var rule in policy.Rules) {
				if (rule.CheckEvent (node, data))
					return;
			}
		}
Ejemplo n.º 46
0
		public override void VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration)
		{
			FormatAttributedNode(eventDeclaration);
			EnforceBraceStyle(policy.EventBraceStyle, eventDeclaration.LBraceToken, eventDeclaration.RBraceToken);
			if (policy.IndentEventBody) {
				curIndent.Push(IndentType.Block);
			}
			
			if (!eventDeclaration.AddAccessor.IsNull) {
				FixIndentation(eventDeclaration.AddAccessor.StartLocation);
				if (!eventDeclaration.AddAccessor.Body.IsNull) {
					if (!policy.AllowEventAddBlockInline || eventDeclaration.AddAccessor.Body.LBraceToken.StartLocation.Line != eventDeclaration.AddAccessor.Body.RBraceToken.StartLocation.Line) {
						EnforceBraceStyle(policy.EventAddBraceStyle, eventDeclaration.AddAccessor.Body.LBraceToken, eventDeclaration.AddAccessor.Body.RBraceToken);
					} else {
						nextStatementIndent = " ";
					}
					
					VisitBlockWithoutFixingBraces(eventDeclaration.AddAccessor.Body, policy.IndentBlocks);
				}
			}
			
			if (!eventDeclaration.RemoveAccessor.IsNull) {
				FixIndentation(eventDeclaration.RemoveAccessor.StartLocation);
				if (!eventDeclaration.RemoveAccessor.Body.IsNull) {
					if (!policy.AllowEventRemoveBlockInline || eventDeclaration.RemoveAccessor.Body.LBraceToken.StartLocation.Line != eventDeclaration.RemoveAccessor.Body.RBraceToken.StartLocation.Line) {
						EnforceBraceStyle(policy.EventRemoveBraceStyle, eventDeclaration.RemoveAccessor.Body.LBraceToken, eventDeclaration.RemoveAccessor.Body.RBraceToken);
					} else {
						nextStatementIndent = " ";
					}
					VisitBlockWithoutFixingBraces(eventDeclaration.RemoveAccessor.Body, policy.IndentBlocks);
				}
			}
			
			if (policy.IndentEventBody) {
				curIndent.Pop ();
			}
			
			if (eventDeclaration.NextSibling is EventDeclaration && IsSimpleEvent(eventDeclaration) && IsSimpleEvent(eventDeclaration.NextSibling)) {
				EnsureBlankLinesAfter(eventDeclaration, policy.BlankLinesBetweenEventFields);
			} else if (IsMember(eventDeclaration.NextSibling)) {
				EnsureBlankLinesAfter(eventDeclaration, policy.BlankLinesBetweenMembers);
			}
		}
Ejemplo n.º 47
0
 public override void VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration)
 {
     new VisitorCustomEventBlock(this, customEventDeclaration).Emit();
 }
Ejemplo n.º 48
0
 public override void VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration)
 {
     new VisitorCustomEventBlock(this, customEventDeclaration).Emit();
 }
 public override void VisitCustomEventDeclaration(CustomEventDeclaration syntax)
 {
     _underlyingVisitor.VisitCustomEventDeclaration(syntax);
 }
Ejemplo n.º 50
0
 public VisitorCustomEventBlock(IEmitter emitter, CustomEventDeclaration customEventDeclaration)
     : base(emitter, customEventDeclaration)
 {
     this.Emitter = emitter;
     this.CustomEventDeclaration = customEventDeclaration;
 }
Ejemplo n.º 51
0
		public override void VisitCustomEventDeclaration (CustomEventDeclaration eventDeclaration)
		{
			if (!eventDeclaration.LBraceToken.IsNull)
				AddFolding (GetEndOfPrev(eventDeclaration.LBraceToken),
				            eventDeclaration.RBraceToken.EndLocation, true);
			base.VisitCustomEventDeclaration (eventDeclaration);
		}
Ejemplo n.º 52
0
 CustomEventDeclaration CreateEvent(EventDefinition eventDef)
 {
     CustomEventDeclaration astEvent = new CustomEventDeclaration();
     astEvent.Name = eventDef.Name;
     astEvent.ReturnType = ConvertType(eventDef.EventType, eventDef);
     astEvent.Modifiers = ConvertModifiers(eventDef.AddMethod);
     if (eventDef.AddMethod != null) {
         astEvent.AddAccessor = new Accessor {
             Body = AstMethodBodyBuilder.CreateMethodBody(eventDef.AddMethod)
         };
     }
     if (eventDef.RemoveMethod != null) {
         astEvent.RemoveAccessor = new Accessor {
             Body = AstMethodBodyBuilder.CreateMethodBody(eventDef.RemoveMethod)
         };
     }
     return astEvent;
 }
Ejemplo n.º 53
0
			public override void Visit(EventProperty ep)
			{
				var newEvent = new CustomEventDeclaration();
				AddAttributeSection(newEvent, ep);
				var location = LocationsBag.GetMemberLocation(ep);
				AddModifiers(newEvent, location);
				
				if (location != null && location.Count > 0)
					newEvent.AddChild(new CSharpTokenNode(Convert(location [0]), CustomEventDeclaration.EventKeywordRole), CustomEventDeclaration.EventKeywordRole);
				newEvent.AddChild(ConvertToType(ep.TypeExpression), Roles.Type);
				
				AddExplicitInterface(newEvent, ep.MemberName);
				
				newEvent.AddChild(Identifier.Create(ep.MemberName.Name, Convert(ep.Location)), Roles.Identifier);

				if (location != null && location.Count >= 2)
					newEvent.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.LBrace), Roles.LBrace);
				
				if (ep.Add != null) {
					var addAccessor = new Accessor();
					AddAttributeSection(addAccessor, ep.Add);
					var addLocation = LocationsBag.GetMemberLocation(ep.Add);
					AddModifiers(addAccessor, addLocation);
					addAccessor.AddChild(new CSharpTokenNode(Convert(ep.Add.Location), CustomEventDeclaration.AddKeywordRole), CustomEventDeclaration.AddKeywordRole);
					if (ep.Add.Block != null)
						addAccessor.AddChild((BlockStatement)ep.Add.Block.Accept(this), Roles.Body);
					newEvent.AddChild(addAccessor, CustomEventDeclaration.AddAccessorRole);
				}
				
				if (ep.Remove != null) {
					var removeAccessor = new Accessor();
					AddAttributeSection(removeAccessor, ep.Remove);
					var removeLocation = LocationsBag.GetMemberLocation(ep.Remove);
					AddModifiers(removeAccessor, removeLocation);
					removeAccessor.AddChild(new CSharpTokenNode(Convert(ep.Remove.Location), CustomEventDeclaration.RemoveKeywordRole), CustomEventDeclaration.RemoveKeywordRole);
					
					if (ep.Remove.Block != null)
						removeAccessor.AddChild((BlockStatement)ep.Remove.Block.Accept(this), Roles.Body);
					newEvent.AddChild(removeAccessor, CustomEventDeclaration.RemoveAccessorRole);
				}
				if (location != null && location.Count >= 3) {
					newEvent.AddChild(new CSharpTokenNode(Convert(location [2]), Roles.RBrace), Roles.RBrace);
				} else {
					// parser error, set end node to max value.
					newEvent.AddChild(new ErrorNode(), Roles.Error);
				}
				
				typeStack.Peek().AddChild(newEvent, Roles.TypeMemberRole);
			}
Ejemplo n.º 54
0
 public override void VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration)
 {
     VisitXmlChildren(eventDeclaration);
 }
		public virtual void VisitCustomEventDeclaration (CustomEventDeclaration eventDeclaration)
		{
			VisitChildren (eventDeclaration);
		}
 public virtual void VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration)
 {
     if (this.ThrowException)
     {
         throw (Exception)this.CreateException(customEventDeclaration);
     }
 }
Ejemplo n.º 57
0
		public void VisitCustomEventDeclaration(CustomEventDeclaration customEventDeclaration)
		{
			StartNode(customEventDeclaration);
			WriteAttributes(customEventDeclaration.Attributes);
			WriteModifiers(customEventDeclaration.ModifierTokens);
			WriteKeyword(CustomEventDeclaration.EventKeywordRole);
			customEventDeclaration.ReturnType.AcceptVisitor(this);
			Space();
			WritePrivateImplementationType(customEventDeclaration.PrivateImplementationType);
			customEventDeclaration.NameToken.AcceptVisitor(this);
			OpenBrace(policy.EventBraceStyle);
			// output add/remove in their original order
			foreach (AstNode node in customEventDeclaration.Children) {
				if (node.Role == CustomEventDeclaration.AddAccessorRole || node.Role == CustomEventDeclaration.RemoveAccessorRole) {
					node.AcceptVisitor(this);
				}
			}
			CloseBrace(policy.EventBraceStyle);
			NewLine();
			EndNode(customEventDeclaration);
		}
Ejemplo n.º 58
0
        public override void VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration)
        {
            var resolveResult = _resolver.Resolve(eventDeclaration);
            if (!(resolveResult is MemberResolveResult)) {
                _errorReporter.Region = eventDeclaration.GetRegion();
                _errorReporter.InternalError("Event declaration " + eventDeclaration.Name + " does not resolve to a member.");
                return;
            }

            var evt = ((MemberResolveResult)resolveResult).Member as IEvent;
            if (evt == null) {
                _errorReporter.Region = eventDeclaration.GetRegion();
                _errorReporter.InternalError("Event declaration " + eventDeclaration.Name + " does not resolve to an event (resolves to " + resolveResult.ToString() + ")");
                return;
            }

            var jsClass = GetJsClass(evt.DeclaringTypeDefinition);
            if (jsClass == null)
                return;

            var impl = _metadataImporter.GetEventSemantics(evt);

            switch (impl.Type) {
                case EventScriptSemantics.ImplType.AddAndRemoveMethods: {
                    if (!eventDeclaration.AddAccessor.IsNull) {
                        MaybeCompileAndAddMethodToType(jsClass, eventDeclaration.AddAccessor, eventDeclaration.AddAccessor.Body, evt.AddAccessor, impl.AddMethod);
                    }

                    if (!eventDeclaration.RemoveAccessor.IsNull) {
                        MaybeCompileAndAddMethodToType(jsClass, eventDeclaration.RemoveAccessor, eventDeclaration.RemoveAccessor.Body, evt.RemoveAccessor, impl.RemoveMethod);
                    }
                    break;
                }
                case EventScriptSemantics.ImplType.NotUsableFromScript: {
                    break;
                }
                default: {
                    throw new InvalidOperationException("Invalid event implementation type");
                }
            }
        }
Ejemplo n.º 59
0
 public override void VisitCustomEventDeclaration(CustomEventDeclaration eventDeclaration)
 {
 }
Ejemplo n.º 60
0
        public static string GetEventRef(CustomEventDeclaration property, IEmitter emitter, bool remove = false, bool noOverload = false, bool ignoreInterface = false)
        {
            var name = emitter.GetEntityName(property, true, ignoreInterface);

            if (!noOverload)
            {
                var overloads = OverloadsCollection.Create(emitter, property, remove);
                name = overloads.HasOverloads ? overloads.GetOverloadName() : name;
                noOverload = !overloads.HasOverloads;
            }

            return (remove ? "remove" : "add") + name;
        }