public void EnterTryBlock(ITryStatement tryStatement) { if (IsValid() == false) { return; } if (tryStatement == null) { return; } Logger.Assert(BlockModelsStack.Count > 0, "[Exceptional] There is no block for try statement."); var model = new TryStatementModel(AnalyzeUnit, tryStatement); var blockModel = BlockModelsStack.Peek(); blockModel.TryStatements.Add(model); model.ParentBlock = blockModel; _tryStatementModelsStack.Push(model); BlockModelsStack.Push(model); }
private IEnumerable <CatchClauseSyntax> BuildCatchSyntaxList(ITryStatement itemAsT) { var ret = new List <CatchClauseSyntax>(); foreach (var ctch in itemAsT.Catches) { var syntax = SyntaxFactory.CatchClause(); if (ctch.ExceptionType != null) { TypeSyntax typeSyntax = (TypeSyntax)(RDom.CSharp.GetSyntaxNode(ctch.ExceptionType)); var declaration = SyntaxFactory.CatchDeclaration(typeSyntax); if (ctch.Variable != null) { declaration = declaration.WithIdentifier(SyntaxFactory.Identifier(ctch.Variable.Name)); } declaration = BuildSyntaxHelpers.AttachWhitespace(declaration, ctch.Whitespace2Set, WhitespaceLookup); syntax = syntax.WithDeclaration(declaration); } // TODO: Add catch filter for 6.0 // TODO: Empty statement would return empty brackets here? var block = BuildSyntaxWorker.GetStatementBlock(ctch.Statements); block = BuildSyntaxHelpers.AttachWhitespace(block, ctch.Whitespace2Set, WhitespaceLookup); syntax = syntax.WithBlock(block); syntax = BuildSyntaxHelpers.AttachWhitespace(syntax, ctch.Whitespace2Set, WhitespaceLookup); ret.Add(syntax); } return(ret); }
public override void VisitTryStatement(ITryStatement operation) { LogString(nameof(ITryStatement)); LogCommonPropertiesAndNewLine(operation); base.VisitTryStatement(operation); }
public TypeNamedCatchExceptionBlockStatement(ITryStatement parent, TypedName nameAndExceptionType) : base(parent.Parent) { this.parent = parent; this.CaughtException = nameAndExceptionType.TypeReference; this._typedLocal = this.Locals.Add(nameAndExceptionType); this._typedLocal.AutoDeclare = false; }
public virtual void VisitTryStatement <TStatement, TCatchStatement, TFinallyStatement>( ITryStatement <TStatement, TCatchStatement, TFinallyStatement> tryStatement) where TStatement : IStatement where TCatchStatement : ICatchStatement where TFinallyStatement : IFinallyStatement { Visit(tryStatement); }
public TypedCatchExceptionBlockStatement(ITryStatement parent, IType exceptionType) : base(parent.Parent) { this.parent = parent; this.CaughtException = exceptionType; this._typedLocal = this.Locals.Add(new TypedName("_exception_", exceptionType)); this._typedLocal.AutoDeclare = false; }
private void FixSpacingAroundKeywordTry(ITryStatement item) { List<string> keywordSearch = new List<string> { "catch" }; foreach (var key in keywordSearch) { item.Text = this.whiteSpaceHelper.RemoveWhiteSpaceAroundKeyword(item.Text, key); } }
public override void VisitTryStatement(ITryStatement operation) { LogString(nameof(ITryStatement)); LogCommonPropertiesAndNewLine(operation); Visit(operation.Body, "Body"); VisitArray(operation.Catches, "Catch clauses", logElementCount: true); Visit(operation.FinallyHandler, "Finally"); }
public static void VisitTryStatementChildren <TStatement, TCatchStatement, TFinallyStatement>( ITryStatement <TStatement, TCatchStatement, TFinallyStatement> tryStatement, IGenericStatementVisitor visitor) where TStatement : IStatement where TCatchStatement : ICatchStatement where TFinallyStatement : IFinallyStatement { VisitCollection(tryStatement.TryStatements, visitor); VisitCollection(tryStatement.CatchStatements, visitor); VisitIfNotNull(tryStatement.FinallyStatement, visitor); }
private void FixSpacingAroundKeywordTry(ITryStatement item) { List <string> keywordSearch = new List <string> { "catch" }; foreach (var key in keywordSearch) { item.Text = this.whiteSpaceHelper.RemoveWhiteSpaceAroundKeyword(item.Text, key); } }
public override void VisitTryStatement(ITryStatement operation) { Visit(operation.Body); foreach (var catchClause in operation.Catches) { Visit(catchClause); } _finallyBlockNestingDepth++; Visit(operation.FinallyHandler); _finallyBlockNestingDepth--; }
public override void VisitTryStatement <TStatement, TCatchStatement, TFinallyStatement>( ITryStatement <TStatement, TCatchStatement, TFinallyStatement> tryStatement) { Steps.Add(new WriteTryKeyword()); Steps.AddBlockSteps(tryStatement.TryStatements); Steps.AddStatementStepsOnNewLines(tryStatement.CatchStatements); if (tryStatement.FinallyStatement != null) { Steps.Add(new WriteIndentedNewLine()); Steps.Add(new WriteStatement <TFinallyStatement>(tryStatement.FinallyStatement)); } }
private FinallyClauseSyntax BuildFinallySyntax(ITryStatement itemAsT) { var fnally = itemAsT.Finally; // TODO: Empty statement would return empty brackets here? var block = BuildSyntaxWorker.GetStatementBlock(fnally.Statements); block = BuildSyntaxHelpers.AttachWhitespace(block, fnally.Whitespace2Set, WhitespaceLookup); var syntax = SyntaxFactory.FinallyClause(block); syntax = BuildSyntaxHelpers.AttachWhitespace(syntax, fnally.Whitespace2Set, WhitespaceLookup); return(syntax); }
public override bool Visit(ITryStatement statement, IStatement context) { _stack.Push(statement); try { return(base.Visit(statement, context)); } finally { _stack.Pop(); } }
public override void VisitTryStatement(ITryStatement block, IList <IStatement> body) { AddIf(block, CompletionCase.EmptyCompletionBefore, body); var tryBlock = new TryBlock(); body.Add(tryBlock); AddIf(block, CompletionCase.InBody, tryBlock.Body); AddIf(block, CompletionCase.InFinally, tryBlock.Finally); VisitBlock(block.Try, tryBlock.Body); VisitBlock(block.FinallyBlock, tryBlock.Finally); foreach (var clause in block.Catches) { var catchBlock = new CatchBlock(); tryBlock.CatchBlocks.Add(catchBlock); AddIf(clause, CompletionCase.InBody, catchBlock.Body); VisitBlock(clause.Body, catchBlock.Body); var generalClause = clause as IGeneralCatchClause; if (generalClause != null) { catchBlock.Kind = CatchBlockKind.General; continue; } var specificClause = clause as ISpecificCatchClause; if (specificClause != null) { var varDecl = specificClause.ExceptionDeclaration; var isUnnamed = varDecl == null; var typeName = specificClause.ExceptionType.GetName(); var varName = isUnnamed ? "?" : varDecl.DeclaredName; catchBlock.Parameter = Names.Parameter("[{0}] {1}", typeName, varName); catchBlock.Kind = isUnnamed ? CatchBlockKind.Unnamed : CatchBlockKind.Default; } } AddIf(block, CompletionCase.EmptyCompletionAfter, body); }
/// <inheritdoc /> public override Expression VisitTryStatement(ITryStatement operation, LocalBinder argument) { CatchBlock MakeCatch(ICatchClause catchClause) { ParameterExpression variable = VisitLocal(catchClause.ExceptionLocal); LocalBinder binder = argument.Child(catchClause.ExceptionLocal, variable); return(Expression.MakeCatchBlock( catchClause.CaughtType.GetCorrespondingType(), variable, catchClause.Handler.Accept(this, binder), catchClause.Filter?.Accept(this, binder) )); } return(Expression.MakeTry(typeof(void), body: operation.Body.Accept(this, argument), @finally: operation.FinallyHandler?.Accept(this, argument), fault: null, handlers: operation.Catches.Select(MakeCatch) )); }
public override void VisitTryStatement(ITryStatement operation) { base.VisitTryStatement(operation); }
public override void VisitTryStatement <TStatement, TCatchStatement, TFinallyStatement>(ITryStatement <TStatement, TCatchStatement, TFinallyStatement> tryStatement) { Value = new Statement() { TryStatement = new TryStatementFactory(tryStatement).Value }; }
public override void VisitTryStatement(ITryStatement operation) { Visit(operation.Body); VisitArray(operation.Catches); Visit(operation.FinallyHandler); }
public static ITryStatement Update(this ITryStatement self, IBlockStatement @tryBlock, ImmutableArray <IOperation> @catchBlocks, IBlockStatement @finallyBlockOpt, Boolean @preferFaultHandler) => self;
void IStatementVisitor.Visit(ITryStatement statement) { this.Translate(statement); }
internal TryCatchBlockAnalyzer(ITryStatement statement) { _statement = statement; }
/// <summary> /// Determines whether [is catch statement] [the specified throw statement]. /// </summary> /// <param name="throwStatement"> /// The throw statement. /// </param> /// <param name="tryStatement"> /// The try statement. /// </param> /// <returns> /// <c>true</c> if [is catch statement] [the specified throw statement]; otherwise, <c>false</c>. /// </returns> private static bool IsCatchStatement(IThrowStatement throwStatement, ITryStatement tryStatement) { var catchClauses = tryStatement.Catches; foreach (var catchClause in catchClauses) { if (throwStatement.Exception == catchClause.ExceptionType) { return true; } } return false; }
public override void VisitTryStatement([NotNull] ITryStatement operation) { IncrementStatementCount(operation); base.VisitTryStatement(operation); }
TransformationImpact IStatementVisitor <TransformationImpact> .Visit(ITryStatement statement) { return(CalculateRefactorImpact(statement)); }
public abstract TransformationImpact CalculateRefactorImpact(ITryStatement statement);
public TestLinkerResult Visit(ITryStatement statement, ICompilationContext context) { throw new NotImplementedException(); }
public virtual void VisitTryStatement(ITryStatement operation) { DefaultVisit(operation); }
public bool Visit(ITryStatement statement, TContext context) { return(IsBrokeFull(statement, context) && statement.Values.All(clause => clause.Accept(this, context)) && (statement.HasCatchAll && statement.CatchAll.Accept(this, context) || !statement.HasCatchAll) && (statement.HasFinally && statement.Finally.Accept(this, context) || !statement.HasFinally)); }
/// <summary> /// Examines the catches. /// </summary> /// <param name="tryStatement"> /// The try statement. /// </param> /// <param name="exceptions"> /// The exceptions. /// </param> private static void ExamineCatches(ITryStatement tryStatement, IList<string[]> exceptions) { var list = tryStatement.Catches; var catches = new List<string>(); foreach (var clause in list) { var declaredType = clause.ExceptionType; if (declaredType == null) { break; } var clrName = declaredType.GetCLRName(); if (!string.IsNullOrEmpty(clrName)) { catches.Add(clrName); } } for (var n = exceptions.Count - 1; n >= 0; n--) { var typeName = exceptions[n][0]; if (catches.Contains(typeName)) { exceptions.RemoveAt(n); } } }
/// <summary>Determines whether [is catch statement] [the specified throw statement].</summary> /// <param name="throwStatement">The throw statement.</param> /// <param name="tryStatement">The try statement.</param> /// <returns><c>true</c> if [is catch statement] [the specified throw statement]; otherwise, <c>false</c>.</returns> private static bool IsCatchStatement(IThrowStatement throwStatement, ITryStatement tryStatement) { var catchClauses = tryStatement.Catches; return catchClauses.Any(catchClause => Equals(throwStatement.Exception, catchClause.ExceptionType)); }
private void UpdateExistingTryCatchBlock(CSharpElementFactory elementFactory, ITryStatement block, string exceptionTypeName) { // There is no way to create a catch clause so we need to create a fake try statement with our // catch clause and copy it to the currently selected clause. var statement = elementFactory.CreateStatement("try{}catch($0 ex){}", exceptionTypeName); ITryStatement tempTryStatement = statement as ITryStatement; if (null == tempTryStatement) return; block.AddCatchClause(tempTryStatement.Catches[0]); }
public abstract IStatement Transform(ITryStatement statement);
/// <inheritdoc /> public override IOperation VisitTryStatement(ITryStatement operation, object argument) { return(base.VisitTryStatement(operation, argument)); }
internal override void VisitTryStatement(ITryStatement operation) { base.VisitTryStatement(operation); }
public override IOperation VisitTryStatement(ITryStatement operation, object argument) { return(new TryStatement(Visit(operation.Body), VisitArray(operation.Catches), Visit(operation.Finally), ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit)); }