public override async Task WalkAsync(PythonWalkerAsync walker, CancellationToken cancellationToken = default)
        {
            if (await walker.WalkAsync(this, cancellationToken))
            {
                if (NameExpression != null)
                {
                    await NameExpression.WalkAsync(walker, cancellationToken);
                }

                foreach (var p in Parameters)
                {
                    await p.WalkAsync(walker, cancellationToken);
                }

                if (Decorators != null)
                {
                    await Decorators.WalkAsync(walker, cancellationToken);
                }
                if (_body != null)
                {
                    await _body.WalkAsync(walker, cancellationToken);
                }
                if (ReturnAnnotation != null)
                {
                    await ReturnAnnotation.WalkAsync(walker, cancellationToken);
                }
            }
            await walker.PostWalkAsync(this, cancellationToken);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Copies the visual appearance to the specified cell. This includes foreground, background, glyph, and mirror effect.
 /// </summary>
 /// <param name="cell">The target cell to copy to.</param>
 public void CopyAppearanceTo(Cell cell)
 {
     cell.Foreground = this.Foreground;
     cell.Background = this.Background;
     cell.Glyph      = this.Glyph;
     cell.Mirror     = this.Mirror;
     cell.Decorators = Decorators.Length != 0 ? Decorators.ToArray() : new CellDecorator[0];
 }
Exemplo n.º 3
0
 public override string GetLeadingWhiteSpace(PythonAst ast)
 {
     if (Decorators != null)
     {
         return(Decorators.GetLeadingWhiteSpace(ast));
     }
     return(base.GetLeadingWhiteSpace(ast));
 }
Exemplo n.º 4
0
        // Chain: LOG then AUTO-VALIDATE then run with AUTO-DISPOSE
        private static IDomainResponse Default <T>(T request, Expression <Func <T, IDomainResponse> > handler) where T : class, IDomainRequest
        {
            // create chain (last to first)
            Expression <Func <T, IDomainResponse> > autoDispose = p => Decorators.AutoDispose(handler);
            Expression <Func <T, IDomainResponse> > logTimings  = p => Decorators.Log(request, autoDispose);

            return(logTimings.Compile().Invoke(request));
        }
Exemplo n.º 5
0
 /// <summary>
 /// Copies the visual appearance to the specified cell. This includes foreground, background, glyph, and mirror effect.
 /// </summary>
 /// <param name="cell">The target cell to copy to.</param>
 public void CopyAppearanceTo(Cell cell)
 {
     cell.Foreground = Foreground;
     cell.Background = Background;
     cell.Glyph      = Glyph;
     cell.Mirror     = Mirror;
     cell.Decorators = Decorators.Length != 0 ? Decorators.ToArray() : Array.Empty <CellDecorator>();
 }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            Action operation  = Component.Operation;
            Action operation1 = Decorators.Operation1(operation);
            Action operation2 = Decorators.Operation2(operation1);

            operation2();
        }
Exemplo n.º 7
0
 public void AddDecorator(Type dependencyType, Expression expression)
 {
     if (!Decorators.TryGetValue(dependencyType, out ArrayList <Expression> list))
     {
         list = new ArrayList <Expression>();
         Decorators.Add(dependencyType, list);
     }
     list.Add(expression);
 }
Exemplo n.º 8
0
 public override void SetLeadingWhiteSpace(PythonAst ast, string whiteSpace)
 {
     if (Decorators != null)
     {
         Decorators.SetLeadingWhiteSpace(ast, whiteSpace);
         return;
     }
     base.SetLeadingWhiteSpace(ast, whiteSpace);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Restores this state to the specified cell.
 /// </summary>
 public void RestoreState(ref ColoredGlyph cell)
 {
     cell.Foreground = Foreground;
     cell.Background = Background;
     cell.Mirror     = Mirror;
     cell.Glyph      = Glyph;
     cell.IsVisible  = IsVisible;
     cell.Decorators = Decorators.Length != 0 ? Decorators.ToArray() : Array.Empty <CellDecorator>();
 }
        private ReflectionAttachedRtField(RtField actual)
        {
            this.Identifier = actual.Identifier;
            this.Type       = actual.Type;
            this.InitializationExpression = actual.InitializationExpression;
            foreach (var decorator in actual.Decorators)
            {
                Decorators.Add(decorator);
            }

            this.CopyActualProperties(actual);
        }
Exemplo n.º 11
0
 /// <summary>
 /// AddCustomAttributes
 /// </summary>
 /// <param name="writer"></param>
 private void AddCustomAttributes(StreamWriter writer, TsGeneratorOptions options, int depth)
 {
     //check if there are custom attributes
     if (Decorators.Any())
     {
         //add indent
         var customAttributeString = options.GetPreLineIndentString(depth);
         //get source
         var attributeList = Decorators.Select(el => el.GetSource());
         customAttributeString += string.Join(TsDomConstants.ATTRIBUTE_SEPEARATOR, attributeList);
         //write custom attribute string
         writer.WriteLine(customAttributeString);
     }
 }
Exemplo n.º 12
0
        public void AddDecorator(Decorators deco)
        {
            switch (deco)
            {
            case Decorators.ControlArrow:
                Logic = new ControlArrow(Logic);
                break;

            case Decorators.ControlJoy:
                Logic = new ControlJoy(Logic);
                break;

            case Decorators.ControlSimpleKi:
                Logic = new ControlSimpleKI(Logic);
                break;

            case Decorators.ControlWasd:
                Logic = new ControlWasd(Logic);
                break;

            case Decorators.GetDamage:
                Logic = new GetDamage(Logic);
                break;

            case Decorators.SpeedUp:
                Logic = new SpeedUp(Logic);
                break;

            case Decorators.WallCollider:
                Logic = new WallCollider(Logic);
                break;

            case Decorators.ControlNetwork:
                Logic = new ControlNetwork(Logic);
                break;

            case Decorators.UsePowerUps:
                Logic = new UsePowerUps(Logic);
                break;

            case Decorators.ControlNetworkHook:
                NetworkHook = new ControlNetworkHook(Logic);
                Logic       = NetworkHook;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(deco), deco, null);
            }
        }
 public override void Walk(PythonWalker walker)
 {
     if (walker.Walk(this))
     {
         NameExpression?.Walk(walker);
         foreach (var p in Parameters)
         {
             p.Walk(walker);
         }
         Decorators?.Walk(walker);
         _body?.Walk(walker);
         ReturnAnnotation?.Walk(walker);
     }
     walker.PostWalk(this);
 }
Exemplo n.º 14
0
        public void PaintWorld(WorldLayer layer)
        {
            if ((Hud.Game.SpecialArea != SpecialArea.Rift) && (Hud.Game.SpecialArea != SpecialArea.GreaterRift) && (Hud.Game.SpecialArea != SpecialArea.ChallengeRift))
            {
                return;
            }

            foreach (var monster in Hud.Game.AliveMonsters)
            {
                if (!monster.IsOnScreen || monster.Invisible)
                {
                    continue;
                }
                //~ var rp = (monster.SnoMonster.RiftProgression / Hud.Game.MaxQuestProgress * 100d).ToString("0.000");
                Decorators.Paint(layer, monster);
            }
        }
Exemplo n.º 15
0
        public ReflectionAttachedRtFunction(RtFunction actual, MethodInfo methodInfo)
        {
            MethodInfo = methodInfo;

            this.IsAsync    = actual.IsAsync;
            this.Identifier = actual.Identifier;
            this.ReturnType = actual.ReturnType;
            foreach (var argument in actual.Arguments)
            {
                Arguments.Add(argument);
            }
            foreach (var decorator in actual.Decorators)
            {
                Decorators.Add(decorator);
            }
            this.Body = actual.Body;

            this.CopyActualProperties(actual);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Write Source
        /// attribute methodname() : returntype
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="options"></param>
        /// <param name="info"></param>
        internal override void WriteSource(System.IO.StreamWriter writer, TsGeneratorOptions options, TsWriteInformation info)
        {
            //write base stuff
            base.WriteSource(writer, options, info);
            //check
            if (Decorators.Any())
            {
                throw new NotImplementedException("CodeMemberMethod, CustomAttributes not implemented yet!");
            }
            //set attribute
            var methodTypeSource = GetSource();

            if (Attributes != TsMemberAttributes.None)
            {
                methodTypeSource = TsMemberAttributeMappings.TypeMappings[Attributes] + TsDomConstants.ATTRIBUTE_SEPEARATOR + methodTypeSource;
            }
            //add method source
            var methodSource = options.GetPreLineIndentString(info.Depth) + string.Format(TsDomConstants.TS_MEMBERMETHOD_FORMAT, methodTypeSource, GetParameterSource(options, info));

            //return type (empty string if not available)
            if (ReturnType != null)
            {
                methodSource = string.Format(TsDomConstants.TS_ELEMENT_TYPE_FORMAT, methodSource, ReturnType.TsTypeName);
            }
            // we only write method info for interfaces
            if (info.ForType != TsElementTypes.Interface)
            {
                //add statement begin
                methodSource += TsDomConstants.ATTRIBUTE_SEPEARATOR + TsDomConstants.STATEMENT_BRACKET_BEGIN;
                //write begin line
                writer.WriteLine(methodSource);
                //write statemetns
                Statements.ToList().ForEach(el => el.WriteSource(writer, options, info.Clone(info.Depth + 1)));
                //write end source
                writer.WriteLine(GetStatementEnd(options, info.Depth));
            }
            else
            {
                methodSource += TsDomConstants.EXPRESSION_END;
                writer.WriteLine(methodSource);
            }
        }
        /// <summary>
        /// Gets the random decorator.
        /// </summary>
        /// <param name="theShape">The shape.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public ShapeSprite GetRandomDecorator(Shape theShape, int width, int height)
        {
            Decorators randomDecorator = this.determineRandomDecorator();

            ShapeSprite decorator = null;

            switch (randomDecorator)
            {
            case Decorators.HorizontalBar:
                decorator = new HorizontalBarDecorator(theShape, width, height);
                break;

            case Decorators.VerticalBar:
                decorator = new VerticalBarDecorator(theShape, width, height);
                break;

            case Decorators.Spot:
                decorator = new SpotDecorator(theShape, width, height);
                break;
            }
            return(decorator);
        }
Exemplo n.º 18
0
 public void AddDecorator(Decorators deco)
 {
     switch (deco)
     {
         case Decorators.ControlArrow:
             Logic = new ControlArrow(Logic);
             break;
         case Decorators.ControlJoy:
             Logic = new ControlJoy(Logic);
             break;
         case Decorators.ControlSimpleKi:
             Logic = new ControlSimpleKI(Logic);
             break;
         case Decorators.ControlWasd:
             Logic = new ControlWasd(Logic);
             break;
         case Decorators.GetDamage:
             Logic = new GetDamage(Logic);
             break;
         case Decorators.SpeedUp:
             Logic = new SpeedUp(Logic);
             break;
         case Decorators.WallCollider:
             Logic = new WallCollider(Logic);
             break;
         case Decorators.ControlNetwork:
             Logic = new ControlNetwork(Logic);
             break;
         case Decorators.UsePowerUps:
             Logic = new UsePowerUps(Logic);
             break;
         case Decorators.ControlNetworkHook:
             NetworkHook = new ControlNetworkHook(Logic);
             Logic = NetworkHook;
             break;
         default:
             throw new ArgumentOutOfRangeException(nameof(deco), deco, null);
     }
 }
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            if (Decorators != null)
            {
                Decorators.AppendCodeString(res, ast, format);
            }

            format.ReflowComment(res, this.GetProceedingWhiteSpace(ast));
            res.Append("class");
            res.Append(this.GetSecondWhiteSpace(ast));
            res.Append(this.GetVerbatimImage(ast) ?? Name);

            if (!this.IsAltForm(ast))
            {
                format.Append(
                    res,
                    format.SpaceBeforeClassDeclarationParen,
                    " ",
                    "",
                    this.GetThirdWhiteSpace(ast)
                    );

                res.Append('(');
            }

            if (Bases.Count != 0)
            {
                ListExpression.AppendItems(
                    res,
                    ast,
                    format,
                    "",
                    "",
                    this,
                    this.Bases.Count,
                    (i, sb) => {
                    if (format.SpaceWithinClassDeclarationParens != null && i == 0)
                    {
                        // need to remove any leading whitespace which was preserved for
                        // the 1st param, and then force the correct whitespace.
                        Bases[i].AppendCodeString(sb, ast, format, format.SpaceWithinClassDeclarationParens.Value ? " " : "");
                    }
                    else
                    {
                        Bases[i].AppendCodeString(sb, ast, format);
                    }
                }
                    );
            }
            else if (!this.IsAltForm(ast))
            {
                if (format.SpaceWithinEmptyBaseClassList != null && format.SpaceWithinEmptyBaseClassList.Value)
                {
                    res.Append(' ');
                }
            }

            if (!this.IsAltForm(ast) && !this.IsMissingCloseGrouping(ast))
            {
                if (Bases.Count != 0 ||
                    format.SpaceWithinEmptyBaseClassList == null ||
                    !String.IsNullOrWhiteSpace(this.GetFourthWhiteSpace(ast)))
                {
                    format.Append(
                        res,
                        format.SpaceWithinClassDeclarationParens,
                        " ",
                        "",
                        this.GetFourthWhiteSpace(ast)
                        );
                }

                res.Append(')');
            }

            _body.AppendCodeString(res, ast, format);
        }
Exemplo n.º 20
0
 public void PushDecorator(Func <IDiscordMessage, Task> fn)
 {
     Decorators.Add(fn);
 }
Exemplo n.º 21
0
 /// <summary>
 /// Returns a new cell with the same properties as this one.
 /// </summary>
 /// <returns>The new cell.</returns>
 public Cell Clone() => new Cell(Foreground, Background, Glyph, Mirror)
 {
     IsVisible = IsVisible, Decorators = Decorators.Length != 0 ? Decorators.ToArray() : Array.Empty <CellDecorator>()
 };
Exemplo n.º 22
0
        public override TypescriptBuilder Build(TypescriptBuilder builder, IElement parent)
        {
            if (Decorators.Any())
            {
                builder.NewLine();
            }
            builder.Join(Decorators, b => b.NewLine());
            if (Decorators.Any())
            {
                builder.NewLine();
            }

            if (parent == null)
            {
                builder.Append("var ").Append(Name);

                if (HasType)
                {
                    builder.Append(": ").Append(Type);
                }
                if (HasValue)
                {
                    builder.Append(" = ").Append(Value);
                }

                builder.Append(";");
            }

            if (HasGetter && parent is Class)
            {
                builder.Append(Get, this);
            }

            if (HasGetter && HasSetter)
            {
                builder.NewLine();
            }

            if (HasSetter && parent is Class)
            {
                builder.Append(Set, this);
            }

            if (!HasSetter && !HasGetter && parent != null || parent is Interface)
            {
                var modifiers = Modifiers.Distinct().OrderBy(m => !(m is IAccessor)).Select(m => m.ToString());
                builder.Join(modifiers, " ");

                if (Modifiers.Any())
                {
                    builder.Append(' ');
                }

                builder.Append(Name);

                if (HasType)
                {
                    builder.Append(": ").Append(Type);
                }
                if (HasValue)
                {
                    builder.Append(" = ").Append(Value);
                }

                builder.Append(";");
            }

            return(builder);
        }
Exemplo n.º 23
0
 /// <summary>
 /// Check if a set of decorators are present.
 /// </summary>
 /// <param name="decorators">The decorator(s) of interest.</param>
 /// <returns>
 /// Returns a value indicating whether the decorator(s) of interest are
 /// present.
 /// </returns>
 public bool HasDecorators(params object[] decorators)
 {
     return(Decorators.HasDecorators(decorators));
 }
Exemplo n.º 24
0
        internal override void AppendCodeStringStmt(StringBuilder res, PythonAst ast, CodeFormattingOptions format)
        {
            var decorateWhiteSpace = this.GetNamesWhiteSpace(ast);

            if (Decorators != null)
            {
                Decorators.AppendCodeString(res, ast, format);
            }
            format.ReflowComment(res, this.GetProceedingWhiteSpaceDefaultNull(ast));
            if (IsCoroutine)
            {
                res.Append("async");
                res.Append(NodeAttributes.GetWhiteSpace(this, ast, WhitespaceAfterAsync));
            }
            res.Append("def");
            var name = this.GetVerbatimImage(ast) ?? Name;

            if (!String.IsNullOrEmpty(name))
            {
                res.Append(this.GetSecondWhiteSpace(ast));
                res.Append(name);
                if (!this.IsIncompleteNode(ast))
                {
                    format.Append(
                        res,
                        format.SpaceBeforeFunctionDeclarationParen,
                        " ",
                        "",
                        this.GetThirdWhiteSpaceDefaultNull(ast)
                        );

                    res.Append('(');
                    if (Parameters.Count != 0)
                    {
                        var commaWhiteSpace = this.GetListWhiteSpace(ast);
                        ParamsToString(res,
                                       ast,
                                       commaWhiteSpace,
                                       format,
                                       format.SpaceWithinFunctionDeclarationParens != null ?
                                       format.SpaceWithinFunctionDeclarationParens.Value ? " " : "" :
                                       null
                                       );
                    }

                    string namedOnly = this.GetExtraVerbatimText(ast);
                    if (namedOnly != null)
                    {
                        res.Append(namedOnly);
                    }

                    if (!this.IsMissingCloseGrouping(ast))
                    {
                        format.Append(
                            res,
                            Parameters.Count != 0 ?
                            format.SpaceWithinFunctionDeclarationParens :
                            format.SpaceWithinEmptyParameterList,
                            " ",
                            "",
                            this.GetFourthWhiteSpaceDefaultNull(ast)
                            );

                        res.Append(')');
                    }
                    if (ReturnAnnotation != null)
                    {
                        format.Append(
                            res,
                            format.SpaceAroundAnnotationArrow,
                            " ",
                            "",
                            this.GetFifthWhiteSpace(ast)
                            );
                        res.Append("->");
                        _returnAnnotation.AppendCodeString(
                            res,
                            ast,
                            format,
                            format.SpaceAroundAnnotationArrow != null ?
                            format.SpaceAroundAnnotationArrow.Value ? " " : "" :
                            null
                            );
                    }
                    if (Body != null)
                    {
                        Body.AppendCodeString(res, ast, format);
                    }
                }
            }
        }
Exemplo n.º 25
0
 /// <summary>
 /// Returns a new cell with the same properties as this one.
 /// </summary>
 /// <returns>The new cell.</returns>
 public Cell Clone() => new Cell(Foreground, Background, Glyph, Mirror)
 {
     IsVisible = this.IsVisible, Decorators = Decorators.ToArray()
 };