Ejemplo n.º 1
0
        protected internal Block(NRefactory.BlockStatement blockStatement, IScope scope, INRefcatoryExpressionVisitor visitor, IEnumerable<ParameterExpression> parameters = null)
            : base(scope, visitor) {

            _blockStatement = blockStatement;
            InternalType = ResolveType(blockStatement);
            Parameters = parameters;
            BuildExpressions();
        }
Ejemplo n.º 2
0
 protected internal Block(NRefactory.BlockStatement blockStatement, IScope scope, INRefcatoryExpressionVisitor visitor, IEnumerable <ParameterExpression> parameters = null)
     : base(scope, visitor)
 {
     _blockStatement = blockStatement;
     InternalType    = ResolveType(blockStatement);
     Parameters      = parameters;
     BuildExpressions();
 }
Ejemplo n.º 3
0
 public static ConstructorBlock ConstructorBlock(NRefactory.BlockStatement blockStatement,
                                                 ParameterExpression contextParameter,
                                                 IScope scope,
                                                 INRefcatoryExpressionVisitor visitor,
                                                 IEnumerable <ParameterExpression> parameters = null,
                                                 IEnumerable <ParameterExpression> baseConstructorParameters = null)
 {
     return(new ConstructorBlock(blockStatement, contextParameter, parameters: parameters, scope: scope, visitor: visitor, baseConstructorParameters: baseConstructorParameters));
 }
Ejemplo n.º 4
0
        public MethodBlock(NRefactory.BlockStatement blockStatement, IScope scope, INRefcatoryExpressionVisitor visitor, IEnumerable <ParameterExpression> parameters = null)
            : base(blockStatement, parameters: parameters, scope: scope, visitor: visitor)
        {
            var registry = RootScope.BranchingRegistry;

            if (registry.HasReturnLabel)
            {
                AddReturnLabelExpression();
            }
        }
Ejemplo n.º 5
0
        public override Type ResolveType(NRefactory.BlockStatement blockStatement)
        {
            var methodDeclaration = blockStatement.Parent as NRefactory.MethodDeclaration;

            if (methodDeclaration != null)
            {
                return(methodDeclaration.GetReturnType());
            }

            return(null);
        }
Ejemplo n.º 6
0
        protected override Expression CreateBody(NRefactory.BlockStatement blockStatement, IEnumerable <ParameterExpression> parameters, IScope scope, INRefcatoryExpressionVisitor visitor)
        {
            IEnumerable <ParameterExpression> baseExpressionsParameters = null;

            if (!BaseConstructorParameters.IsNullOrEmpty())
            {
                baseExpressionsParameters = BaseConstructorParameters.Select(p => Expression.Parameter(p.Type, p.Name));
            }

            return(AstExpression.ConstructorBlock(blockStatement, ContextParameter, parameters: parameters, scope: scope, visitor: visitor, baseConstructorParameters: baseExpressionsParameters));
        }
 public ConstructorBlock(NRefactory.BlockStatement blockStatement,
                         ParameterExpression contextParameter,
                         IScope scope,
                         INRefcatoryExpressionVisitor visitor,
                         IEnumerable <ParameterExpression> parameters,
                         IEnumerable <ParameterExpression> baseConstructorParameters)
     : base(blockStatement, parameters: parameters, scope: scope, visitor: visitor)
 {
     _baseConstructorParameters = baseConstructorParameters;
     AddNewContextCreationExpression(contextParameter);
     InternalType = contextParameter.Type;
     AddReturnLabelExpression();
 }
Ejemplo n.º 8
0
        private static NRefactory.ConstructorDeclaration FiltertConstructorStatements(NRefactory.ConstructorDeclaration constructorDeclaration, Type baseType)
        {
            var block = new NRefactory.BlockStatement();

            foreach (var statement in constructorDeclaration.Body.Statements)
            {
                var expression = statement as NRefactory.ExpressionStatement;

                if (expression != null)
                {
                    if (expression.Expression is NRefactory.AssignmentExpression)
                    {
                        continue;
                    }

                    var invocation = expression.Expression as NRefactory.InvocationExpression;

                    block.Add(statement.Clone());

                    if (invocation != null && invocation.HasAnnotationOf <Cecil.MethodReference>())
                    {
                        var methodReference = invocation.Annotation <Cecil.MethodReference>();

                        if (methodReference.Name.Equals(".ctor") && methodReference.DeclaringType.GetActualType().Equals(baseType))
                        {
                            block.AddReturnStatement(new NRefactory.ThisReferenceExpression());
                            constructorDeclaration.Body = block;
                            break;
                        }
                    }
                }
                else
                {
                    block.Add(statement.Clone());
                }
            }

            return(constructorDeclaration);
        }
 protected virtual Expression CreateBody(NRefactory.BlockStatement blockStatement, IEnumerable <ParameterExpression> parameters, IScope scope, INRefcatoryExpressionVisitor visitor)
 {
     return(AstExpression.MethodBlock(blockStatement, parameters: parameters, scope: this, visitor: visitor));
 }
Ejemplo n.º 10
0
 public virtual S VisitBlockStatement(BlockStatement blockStatement, T data)
 {
     return(VisitChildren(blockStatement, data));
 }
Ejemplo n.º 11
0
 public AnonymousMethodExpression(BlockStatement body, params ParameterDeclaration[] parameters) : this(body, (IEnumerable <ParameterDeclaration>)parameters)
 {
 }
Ejemplo n.º 12
0
 private void BuildTryBlock(NRefactory.BlockStatement tryBlock)
 {
     Body = tryBlock.AcceptVisitor(Visitor, this);
 }
Ejemplo n.º 13
0
 private void BuildFinallyBlock(NRefactory.BlockStatement finallyBlack)
 {
     Finally = finallyBlack.AcceptVisitor(Visitor, this);
 }
        private static NRefactory.ConstructorDeclaration FiltertConstructorStatements(NRefactory.ConstructorDeclaration constructorDeclaration, Type baseType) {
            var block = new NRefactory.BlockStatement();

            foreach (var statement in constructorDeclaration.Body.Statements) {
                var expression = statement as NRefactory.ExpressionStatement;

                if (expression != null) {
                    if (expression.Expression is NRefactory.AssignmentExpression) {
                        continue;
                    }

                    var invocation = expression.Expression as NRefactory.InvocationExpression;

                    block.Add(statement.Clone());

                    if (invocation != null && invocation.HasAnnotationOf<Cecil.MethodReference>()) {
                        var methodReference = invocation.Annotation<Cecil.MethodReference>();

                        if (methodReference.Name.Equals(".ctor") && methodReference.DeclaringType.GetActualType().Equals(baseType)) {
                            block.AddReturnStatement(new NRefactory.ThisReferenceExpression());
                            constructorDeclaration.Body = block;
                            break;
                        }
                    }
                }
                else {
                    block.Add(statement.Clone());
                }
            }

            return constructorDeclaration;
        }
Ejemplo n.º 15
0
 public virtual Type ResolveType(NRefactory.BlockStatement blockStatement)
 {
     return(TypeSystem.Void);
 }
 public virtual S VisitBlockStatement(BlockStatement blockStatement, T data)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 17
0
 void IAstVisitor.VisitBlockStatement(BlockStatement blockStatement)
 {
     Visit(EnterBlockStatement, LeaveBlockStatement, blockStatement);
 }
 public override void VisitBlockStatement(BlockStatement blockStatement)
 {
     FixIndentation(blockStatement);
     VisitBlockWithoutFixingBraces(blockStatement, policy.IndentBlocks);
     FixIndentation(blockStatement.RBraceToken);
 }
        void FixEmbeddedStatment(BraceStyle braceStyle, CSharpTokenNode token, bool allowInLine, AstNode node, bool statementAlreadyIndented = false)
        {
            if (node == null)
            {
                return;
            }
            bool isBlock = node is BlockStatement;

            FormattingChanges.TextReplaceAction beginBraceAction = null;
            FormattingChanges.TextReplaceAction endBraceAction   = null;
            BlockStatement closeBlockToBeFixed = null;

            if (isBlock)
            {
                BlockStatement block = node as BlockStatement;
                if (allowInLine && block.StartLocation.Line == block.EndLocation.Line && block.Statements.Count() <= 1)
                {
                    if (block.Statements.Count() == 1)
                    {
                        nextStatementIndent = " ";
                    }
                }
                else
                {
                    if (!statementAlreadyIndented)
                    {
                        FixOpenBrace(braceStyle, block.LBraceToken);
                    }
                    closeBlockToBeFixed = block;
                }

                if (braceStyle == BraceStyle.NextLineShifted2)
                {
                    curIndent.Push(IndentType.Block);
                }
            }
            else
            {
                if (allowInLine && token.StartLocation.Line == node.EndLocation.Line)
                {
                    nextStatementIndent = " ";
                }
            }
            bool pushed = false;

            if (policy.IndentBlocks && !(policy.AlignEmbeddedIfStatements && node is IfElseStatement && node.Parent is IfElseStatement || policy.AlignEmbeddedUsingStatements && node is UsingStatement && node.Parent is UsingStatement))
            {
                curIndent.Push(IndentType.Block);
                pushed = true;
            }
            if (isBlock)
            {
                VisitBlockWithoutFixingBraces((BlockStatement)node, false);
            }
            else
            {
                if (!statementAlreadyIndented)
                {
                    PlaceOnNewLine(policy.EmbeddedStatementPlacement, node);
                    nextStatementIndent = null;
                }
                node.AcceptVisitor(this);
            }
            if (pushed)
            {
                curIndent.Pop();
            }
            if (beginBraceAction != null && endBraceAction != null)
            {
                beginBraceAction.DependsOn = endBraceAction;
                endBraceAction.DependsOn   = beginBraceAction;
            }

            if (isBlock && braceStyle == BraceStyle.NextLineShifted2)
            {
                curIndent.Pop();
            }
            if (closeBlockToBeFixed != null)
            {
                FixClosingBrace(braceStyle, closeBlockToBeFixed.RBraceToken);
            }
        }
Ejemplo n.º 20
0
        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
        {
            BlockStatement o = other as BlockStatement;

            return(o != null && !o.IsNull && this.Statements.DoMatch(o.Statements, match));
        }
Ejemplo n.º 21
0
 public static MethodBlock MethodBlock(NRefactory.BlockStatement blockStatement, IScope scope, INRefcatoryExpressionVisitor visitor, IEnumerable <ParameterExpression> parameters = null)
 {
     return(new MethodBlock(blockStatement, parameters: parameters, scope: scope, visitor: visitor));
 }
Ejemplo n.º 22
0
 public override AstExpression VisitBlockStatement(NRefactory.BlockStatement blockStatement, IScope scope)
 {
     return(AstExpression.Block(blockStatement, scope, this));
 }