Exemplo n.º 1
0
        /// <inheritdoc />
        protected override bool HandleDynamic(CodeLambdaDeclarationExpression obj, Context ctx)
        {
            ctx.Writer.Write("Function"); //it is safe to declare it as a function, but will give a warning
            ctx.Writer.Write("(");
            GeneralUtils.HandleCollectionCommaSeparated(obj.Parameters, ctx.HandlerProvider.ExpressionHandler, ctx);
            ctx.Writer.Write(")");
            if (obj.Statements.Count == 1 && obj.Statements[0] is CodeExpressionStatement statement)
            {
                ctx.Writer.Write(" ");
                VisualBasicUtils.BeginBlock(BlockType.Function, ctx, false);
                ctx.HandlerProvider.ExpressionHandler.Handle(statement.Expression, ctx);
                VisualBasicUtils.EndBlock(ctx, false, false);
            }
            else
            {
                ctx.Writer.NewLine();
                ctx.Indent();
                VisualBasicUtils.BeginBlock(BlockType.Function, ctx, false);
                VisualBasicUtils.HandleStatementCollection(obj.Statements, ctx);
                ctx.Unindent();
                ctx.Writer.Indent(ctx);
                VisualBasicUtils.EndBlock(ctx, false);
            }

            return(true);
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        protected override void HandleConstructor(CodeConstructor obj, Context ctx)
        {
            //no return type, only access modifier
            ctx.HandlerProvider.MemberAttributesHandler.Handle(obj.Attributes, ctx);
            ctx.Writer.Write("Sub New");
            //no type parameters
            HandleMethodParameters(obj, ctx);
            VisualBasicUtils.BeginBlock(BlockType.Sub, ctx);
            if (obj.BaseConstructorArgs.Count > 0 || obj.ChainedConstructorArgs.Count > 0)
            {
                //TODO : this()

                if (obj.BaseConstructorArgs.Count > 0)
                {
                    ctx.Writer.IndentAndWrite("MyBase.New(", ctx);
                    GeneralUtils.HandleCollectionCommaSeparated(obj.BaseConstructorArgs.Cast <CodeExpression>(),
                                                                ctx.HandlerProvider.ExpressionHandler, ctx);
                }
                else
                {
                    ctx.Writer.IndentAndWrite("Me.New(", ctx);
                    GeneralUtils.HandleCollectionCommaSeparated(obj.ChainedConstructorArgs.Cast <CodeExpression>(),
                                                                ctx.HandlerProvider.ExpressionHandler, ctx);
                }

                ctx.Writer.WriteLine(")");
            }
            VisualBasicUtils.HandleStatementCollection(obj.Statements, ctx);
            VisualBasicUtils.EndBlock(ctx);
        }
Exemplo n.º 3
0
 /// <inheritdoc />
 protected override void HandleCondition(CodeConditionStatement obj, Context ctx)
 {
     VisualBasicUtils.BeginBlock(BlockType.If, ctx, false);
     HandleConditionNoBlock(obj, ctx);
     ctx.Writer.Indent(ctx);
     VisualBasicUtils.EndBlock(ctx, false);
 }
Exemplo n.º 4
0
 /// <inheritdoc />
 protected override void DoHandle(CodeNamespace obj, Context ctx)
 {
     ctx.CurrentNamespace = obj.Name;
     ctx.Writer.Write($"Namespace {VisualBasicUtils.GetValidNamespaceIdentifier(ctx.CurrentNamespace)}");
     VisualBasicUtils.BeginBlock(BlockType.Namespace, ctx);
     GeneralUtils.HandleCollection(obj.Types.Cast <CodeTypeDeclaration>(), ctx.HandlerProvider.TypeDeclarationHandler, ctx,
                                   preAction: (c) => c.Writer.Indent(c),
                                   postAction: (c) => c.Writer.NewLine(), doPostActionOnLast: false);
     VisualBasicUtils.EndBlock(ctx);
 }
Exemplo n.º 5
0
 /// <inheritdoc />
 protected override void HandleDoWhile(CodePostTestIterationStatement obj, Context ctx)
 {
     VisualBasicUtils.BeginBlock(BlockType.Do, ctx, false);
     ctx.Writer.WriteLine("Do");
     ctx.Indent();
     VisualBasicUtils.HandleStatementCollection(obj.Statements, ctx);
     ctx.Unindent();
     ctx.Writer.IndentAndWrite("Loop While ", ctx);
     ctx.HandlerProvider.ExpressionHandler.Handle(obj.TestExpression, ctx);
     VisualBasicUtils.EndBlock(ctx, false, false);
 }
Exemplo n.º 6
0
 /// <inheritdoc />
 protected override void HandleForEach(CodeForEachStatement obj, Context ctx)
 {
     VisualBasicUtils.BeginBlock(BlockType.For, ctx, false);
     ctx.Writer.Write($"For Each {obj.ItemName.AsVbId()}");
     if (!GeneralUtils.IsNullOrVoidType(obj.ItemType))
     {
         ctx.Writer.Write(" As ");
         ctx.HandlerProvider.TypeReferenceHandler.Handle(obj.ItemType, ctx);
     }
     ctx.Writer.Write(" In ");
     ctx.HandlerProvider.ExpressionHandler.Handle(obj.ObjectToIterate, ctx);
     ctx.Writer.NewLine();
     ctx.Indent();
     VisualBasicUtils.HandleStatementCollection(obj.Statements, ctx);
     ctx.Unindent();
     ctx.Writer.IndentAndWrite("Next", ctx);
     VisualBasicUtils.EndBlock(ctx, false, false);
 }
Exemplo n.º 7
0
 /// <inheritdoc />
 protected override void HandleTryCatchFinally(CodeTryCatchFinallyStatement obj, Context ctx)
 {
     VisualBasicUtils.BeginBlock(BlockType.Try, ctx, false);
     ctx.Writer.Write("Try");
     ctx.Indent();
     ctx.Writer.NewLine();
     VisualBasicUtils.HandleStatementCollection(obj.TryStatements, ctx);
     ctx.Unindent();
     GeneralUtils.HandleCollection(obj.CatchClauses.Cast <CodeCatchClause>(), _catchClauseHandler, ctx,
                                   preAction: (c) => c.Writer.Indent(c));
     if (obj.FinallyStatements.Count > 0)
     {
         ctx.Writer.Indent(ctx);
         ctx.Writer.WriteLine("Finally");
         ctx.Indent();
         VisualBasicUtils.HandleStatementCollection(obj.FinallyStatements, ctx);
         ctx.Unindent();
     }
     ctx.Writer.Indent(ctx);
     VisualBasicUtils.EndBlock(ctx, false);
 }
Exemplo n.º 8
0
        /// <inheritdoc />
        protected override void HandleProperty(CodeMemberProperty obj, Context ctx, bool isExt,
                                               CodeMemberPropertyExt objExt, bool doDefaultImplementation)
        {
            if (ctx.Options.DoConsistencyChecks)
            {
                if (!doDefaultImplementation && isExt && objExt.PropertyInitializer != null)
                {
                    throw new ConsistencyException($"Property {obj.Name} can't have initializer if it's not auto-property");
                }
            }

            if (GeneralUtils.IsNullOrVoidType(obj.PrivateImplementationType))
            {
                ctx.HandlerProvider.MemberAttributesHandler.Handle(obj.Attributes, ctx);
            }

            if (obj.HasGet && !obj.HasSet)
            {
                ctx.Writer.Write("ReadOnly ");
            }
            else if (obj.HasSet && !obj.HasGet)
            {
                ctx.Writer.Write("WriteOnly ");
            }

            ctx.Writer.Write($"Property ");
            if (GeneralUtils.IsNullOrVoidType(obj.PrivateImplementationType))
            {
                ctx.Writer.Write(obj.Name.AsVbId());
            }
            else
            {
                HandlePrivateImplementationTypeMemberName(obj.Name, obj.PrivateImplementationType, ctx);
            }
            ctx.Writer.Write(" As ");
            ctx.HandlerProvider.TypeReferenceHandler.Handle(obj.Type, ctx);
            if (doDefaultImplementation)
            {
                if (isExt && objExt.PropertyInitializer != null)
                {
                    ctx.Writer.Write(" = ");
                    ctx.HandlerProvider.ExpressionHandler.Handle(objExt.PropertyInitializer, ctx);
                }
                HandleImplementationTypes(obj.ImplementationTypes, obj.Name, ctx);
                HandlePrivateImplType(obj.PrivateImplementationType, obj.Name, ctx);
                ctx.Writer.NewLine();
            }
            else
            {
                HandleImplementationTypes(obj.ImplementationTypes, obj.Name, ctx);
                HandlePrivateImplType(obj.PrivateImplementationType, obj.Name, ctx);
                VisualBasicUtils.BeginBlock(BlockType.Property, ctx);

                if (obj.HasGet)
                {
                    ctx.Writer.Indent(ctx);
                    if (isExt && objExt.GetAccessibilityLevel != obj.Attributes.GetAccessibilityLevel())
                    {
                        ctx.Writer.Write($"{VisualBasicKeywordsUtils.AccessibilityLevelKeyword(objExt.GetAccessibilityLevel)} ");
                    }
                    ctx.Writer.Write("Get");
                    VisualBasicUtils.HandleStatementCollection(obj.GetStatements, ctx, BlockType.Get);
                }

                if (obj.HasSet)
                {
                    ctx.Writer.Indent(ctx);
                    if (isExt && objExt.SetAccessibilityLevel != obj.Attributes.GetAccessibilityLevel())
                    {
                        ctx.Writer.Write($"{VisualBasicKeywordsUtils.AccessibilityLevelKeyword(objExt.SetAccessibilityLevel)} ");
                    }
                    ctx.Writer.Write("Set");
                    VisualBasicUtils.HandleStatementCollection(obj.SetStatements, ctx, BlockType.Set);
                }

                VisualBasicUtils.EndBlock(ctx);
            }
        }