Class for creating change scripts. 'Original document' = document without the change script applied. 'Current document' = document with the change script (as far as it is already created) applies.
상속: IDisposable
		void ApplyAction(Script script, WhileStatement statement) {
			var doWhile = new DoWhileStatement {
				Condition = statement.Condition.Clone(),
				EmbeddedStatement = statement.EmbeddedStatement.Clone()
			};

			script.Replace(statement, doWhile);
		}
		void GenerateNewScript(Script script, IfElseStatement ifStatement)
		{
			var mergedIfStatement = new IfElseStatement {
				Condition = CSharpUtil.InvertCondition(ifStatement.Condition),
				TrueStatement = new ContinueStatement()
			};
			mergedIfStatement.Condition.AcceptVisitor(_insertParenthesesVisitor);
			
			script.Replace(ifStatement, mergedIfStatement);
			
			SimplifyIfFlowAction.InsertBody(script, ifStatement);
		}
예제 #3
0
        internal static void InsertBody(Script script, IfElseStatement ifStatement)
        {
            var ifBody = ifStatement.TrueStatement.Clone();

            if (ifBody is BlockStatement) {
                AstNode last = ifStatement;
                foreach (var stmt in ((BlockStatement)ifBody).Children) {
                    if (stmt.Role == Roles.LBrace || stmt.Role == Roles.RBrace || stmt.Role == Roles.NewLine)
                        continue;
                    script.InsertAfter(last, stmt);
                    last = stmt;
                }
            } else {
                script.InsertAfter(ifStatement, ifBody);
            }
            script.FormatText(ifStatement.Parent);
        }
예제 #4
0
			void RemoveText (Script script, TextLocation start, TextLocation end)
			{
				var startOffset = script.GetCurrentOffset (start);
				var endOffset = script.GetCurrentOffset (end);
				if (startOffset < endOffset)
					script.RemoveText (startOffset, endOffset - startOffset);
			}
예제 #5
0
            void Fix(Script script, MethodDeclaration methodDeclaration, TypeDeclaration typeDeclaration)
            {
                var newTypeDeclaration = (TypeDeclaration)typeDeclaration.Clone();

                var resolver = ctx.GetResolverStateAfter(typeDeclaration.LBraceToken);

                var  typeResolve           = resolver.ResolveSimpleName("IDisposable", new List <IType>()) as TypeResolveResult;
                bool canShortenIDisposable = typeResolve != null && typeResolve.Type.FullName == "System.IDisposable";

                string interfaceName = (canShortenIDisposable ? string.Empty : "System.") + "IDisposable";

                newTypeDeclaration.BaseTypes.Add(new SimpleType(interfaceName));

                foreach (var method in DisposeMethods(newTypeDeclaration).ToList())
                {
                    if (typeDeclaration.ClassType == ClassType.Interface)
                    {
                        method.Remove();
                    }
                    else
                    {
                        method.Modifiers &= ~Modifiers.Private;
                        method.Modifiers &= ~Modifiers.Protected;
                        method.Modifiers &= ~Modifiers.Internal;
                        method.Modifiers |= Modifiers.Public;
                    }
                }

                if (typeDeclaration.ClassType == ClassType.Interface)
                {
                    var disposeMember = ((MemberResolveResult)ctx.Resolve(methodDeclaration)).Member;
                    script.DoGlobalOperationOn(new List <IEntity>()
                    {
                        disposeMember
                    }, (nCtx, nScript, nodes) => {
                        List <Tuple <AstType, AstType> > pendingChanges = new List <Tuple <AstType, AstType> >();
                        foreach (var node in nodes)
                        {
                            var method = node as MethodDeclaration;
                            if (method != null && !method.PrivateImplementationType.IsNull)
                            {
                                var nResolver = ctx.GetResolverStateAfter(typeDeclaration.LBraceToken);

                                var nTypeResolve            = nResolver.ResolveSimpleName("IDisposable", new List <IType>()) as TypeResolveResult;
                                bool nCanShortenIDisposable = nTypeResolve != null && nTypeResolve.Type.FullName == "System.IDisposable";

                                string nInterfaceName = (nCanShortenIDisposable ? string.Empty : "System.") + "IDisposable";

                                pendingChanges.Add(Tuple.Create(method.PrivateImplementationType, AstType.Create(nInterfaceName)));
                            }
                        }

                        foreach (var change in pendingChanges)
                        {
                            nScript.Replace(change.Item1, change.Item2);
                        }
                    }, "Fix explicitly implemented members");
                }

                script.Replace(typeDeclaration, newTypeDeclaration);
            }