public DocumentScript(IDocument document, CSharpFormattingOptions formattingOptions, TextEditorOptions options) : base(formattingOptions, options)
		{
			this.originalDocument = document.CreateDocumentSnapshot();
			this.currentDocument = document;
			Debug.Assert(currentDocument.Version.CompareAge(originalDocument.Version) == 0);
			this.undoGroup = document.OpenUndoGroup();
		}
예제 #2
0
파일: Script.cs 프로젝트: 0xd4d/NRefactory
		protected Script(CSharpFormattingOptions formattingOptions, TextEditorOptions options)
		{
			if (formattingOptions == null)
				throw new ArgumentNullException("formattingOptions");
			if (options == null)
				throw new ArgumentNullException("options");
			this.formattingOptions = formattingOptions;
			this.options = options;
		}
 protected CSharpFormattingPolicy(CSharpFormattingOptions options)
 {
     this.options = options;
 }
 public CSharpFormattingPolicy()
 {
     this.options = FormattingOptionsFactory.CreateMono();
 }
예제 #5
0
 public AstAmbience(ICSharpCode.NRefactory.CSharp.CSharpFormattingOptions options)
 {
     this.options = options;
 }
예제 #6
0
        public void TestUsingAliasDeclarations()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();

            Test(policy, @"		using Foo = Bar;", @"using Foo = Bar;");
        }
예제 #7
0
            void WriteMemberDeclarationName(IMember member, TextWriterTokenWriter formatter, CSharpFormattingOptions formattingPolicy)
            {
                TypeSystemAstBuilder astBuilder = CreateAstBuilder();

                if ((ConversionFlags & ConversionFlags.ShowDeclaringType) == ConversionFlags.ShowDeclaringType)
                {
                    ConvertType(member.DeclaringType, formatter, formattingPolicy);
                    formatter.WriteToken(Roles.Dot, ".");
                }
                switch (member.SymbolKind)
                {
                case SymbolKind.Indexer:
                    formatter.WriteKeyword(IndexerDeclaration.ThisKeywordRole, "this");
                    break;

                case SymbolKind.Constructor:
                    formatter.WriteIdentifier(Identifier.Create(member.DeclaringType.Name));
                    break;

                case SymbolKind.Destructor:
                    formatter.WriteToken(DestructorDeclaration.TildeRole, "~");
                    formatter.WriteIdentifier(Identifier.Create(member.DeclaringType.Name));
                    break;

                case SymbolKind.Operator:
                    switch (member.Name)
                    {
                    case "op_Implicit":
                        formatter.WriteKeyword(OperatorDeclaration.ImplicitRole, "implicit");
                        formatter.Space();
                        formatter.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator");
                        formatter.Space();
                        ConvertType(member.ReturnType, formatter, formattingPolicy);
                        break;

                    case "op_Explicit":
                        formatter.WriteKeyword(OperatorDeclaration.ExplicitRole, "explicit");
                        formatter.Space();
                        formatter.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator");
                        formatter.Space();
                        ConvertType(member.ReturnType, formatter, formattingPolicy);
                        break;

                    default:
                        formatter.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator");
                        formatter.Space();
                        var operatorType = OperatorDeclaration.GetOperatorType(member.Name);
                        if (operatorType.HasValue)
                        {
                            formatter.WriteToken(OperatorDeclaration.GetRole(operatorType.Value), OperatorDeclaration.GetToken(operatorType.Value));
                        }
                        else
                        {
                            formatter.WriteIdentifier(Identifier.Create(member.Name));
                        }
                        break;
                    }
                    break;

                default:
                    formatter.WriteIdentifier(Identifier.Create(member.Name));
                    break;
                }
                if ((ConversionFlags & ConversionFlags.ShowTypeParameterList) == ConversionFlags.ShowTypeParameterList && member.SymbolKind == SymbolKind.Method)
                {
                    var outputVisitor = new CSharpOutputVisitor(formatter, formattingPolicy);
                    outputVisitor.WriteTypeParameters(astBuilder.ConvertEntity(member).GetChildrenByRole(Roles.TypeParameter));
                }
            }
예제 #8
0
 public override string ToString(CSharpFormattingOptions formattingOptions)
 {
     return("[ErrorNode]");
 }
예제 #9
0
 public sealed override string ToString(CSharpFormattingOptions formattingOptions)
 {
     return(NewLine.GetString(NewLineType));
 }
예제 #10
0
 public override string ToString(CSharpFormattingOptions formattingOptions)
 {
     return(Keyword);
 }
예제 #11
0
 public void TestParseLabelPositioning(string rawValue, LabelPositionOptions parsedValue)
 {
     Assert.Equal(parsedValue, CSharpFormattingOptions.ParseEditorConfigLabelPositioning(rawValue));
 }
예제 #12
0
 public void TestParseSpacingAroundBinaryOperator(string rawValue, BinaryOperatorSpacingOptions parsedValue)
 {
     Assert.Equal(parsedValue, CSharpFormattingOptions.ParseEditorConfigSpacingAroundBinaryOperator(rawValue));
 }
예제 #13
0
        public void TestAllowIfBlockInline()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();

            policy.StatementBraceStyle = BraceStyle.EndOfLine;
            policy.AllowIfBlockInline  = true;

            Test(policy, @"class Test
{
	Test TestMethod ()
	{
		if (true) {}
	}
}", @"class Test
{
	Test TestMethod ()
	{
		if (true) {}
	}
}");


            Test(policy, @"class Test
{
	Test TestMethod ()
	{
		if (true) { Foo (); }
	}
}", @"class Test
{
	Test TestMethod ()
	{
		if (true) { Foo (); }
	}
}");


            Test(policy, @"class Test
{
	Test TestMethod ()
	{
		if (true) Foo ();
	}
}", @"class Test
{
	Test TestMethod ()
	{
		if (true) Foo ();
	}
}");


            Test(policy, @"class Test
{
	Test TestMethod ()
	{
		if (true)
			Foo ();
	}
}",
                 @"class Test
{
	Test TestMethod ()
	{
		if (true)
			Foo ();
	}
}");
        }
예제 #14
0
        public void TestSwitchIndentBreak()
        {
            CSharpFormattingOptions policy = FormattingOptionsFactory.CreateMono();

            policy.IndentSwitchBody      = true;
            policy.IndentBreakStatements = true;

            Test(policy, @"class Test
{
	Test TestMethod ()
	{
		switch (a) {
			case 1:
			case 2:
			DoSomething ();
			break;
			default:
			Foo ();
			break;
		}
	}
}",
                 @"class Test
{
	Test TestMethod ()
	{
		switch (a) {
			case 1:
			case 2:
				DoSomething ();
				break;
			default:
				Foo ();
				break;
		}
	}
}");
            policy.IndentSwitchBody      = true;
            policy.IndentBreakStatements = false;

            Test(policy, @"class Test
{
	Test TestMethod ()
	{
		switch (a) {
			case 1:
			case 2:
			DoSomething ();
			break;
			default:
			Foo ();
			break;
		}
	}
}",
                 @"class Test
{
	Test TestMethod ()
	{
		switch (a) {
			case 1:
			case 2:
				DoSomething ();
			break;
			default:
				Foo ();
			break;
		}
	}
}");
        }
예제 #15
0
 public virtual void SetUp()
 {
     formattingOptions = FormattingOptionsFactory.CreateMono();
 }
예제 #16
0
 public MDRefactoringScript(MDRefactoringContext context, CSharpFormattingOptions formattingOptions) : base(context.TextEditor.Document, formattingOptions, context.TextEditor.CreateNRefactoryTextEditorOptions())
 {
     this.context      = context;
     undoGroup         = this.context.TextEditor.OpenUndoGroup();
     this.startVersion = this.context.TextEditor.Version;
 }
예제 #17
0
            public void ConvertEntity(IEntity entity, TextWriterTokenWriter formatter, CSharpFormattingOptions formattingPolicy)
            {
                if (entity == null)
                {
                    throw new ArgumentNullException("entity");
                }
                if (formatter == null)
                {
                    throw new ArgumentNullException("formatter");
                }
                if (formattingPolicy == null)
                {
                    throw new ArgumentNullException("options");
                }

                TypeSystemAstBuilder astBuilder = CreateAstBuilder();
                EntityDeclaration    node       = astBuilder.ConvertEntity(entity);

                PrintModifiers(node.Modifiers, formatter);

                if ((ConversionFlags & ConversionFlags.ShowDefinitionKeyword) == ConversionFlags.ShowDefinitionKeyword)
                {
                    if (node is TypeDeclaration)
                    {
                        switch (((TypeDeclaration)node).ClassType)
                        {
                        case ClassType.Class:
                            formatter.WriteKeyword(Roles.ClassKeyword, "class");
                            break;

                        case ClassType.Struct:
                            formatter.WriteKeyword(Roles.StructKeyword, "struct");
                            break;

                        case ClassType.Interface:
                            formatter.WriteKeyword(Roles.InterfaceKeyword, "interface");
                            break;

                        case ClassType.Enum:
                            formatter.WriteKeyword(Roles.EnumKeyword, "enum");
                            break;

                        default:
                            throw new Exception("Invalid value for ClassType");
                        }
                        formatter.Space();
                    }
                    else if (node is DelegateDeclaration)
                    {
                        formatter.WriteKeyword(Roles.DelegateKeyword, "delegate");
                        formatter.Space();
                    }
                    else if (node is EventDeclaration)
                    {
                        formatter.WriteKeyword(EventDeclaration.EventKeywordRole, "event");
                        formatter.Space();
                    }
                }

                if ((ConversionFlags & ConversionFlags.ShowReturnType) == ConversionFlags.ShowReturnType)
                {
                    var rt = node.GetChildByRole(Roles.Type);
                    if (!rt.IsNull)
                    {
                        rt.AcceptVisitor(new CSharpOutputVisitor(formatter, formattingPolicy));
                        formatter.Space();
                    }
                }

                if (entity is ITypeDefinition)
                {
                    WriteTypeDeclarationName((ITypeDefinition)entity, formatter, formattingPolicy);
                }
                else
                {
                    WriteMemberDeclarationName((IMember)entity, formatter, formattingPolicy);
                }

                if ((ConversionFlags & ConversionFlags.ShowParameterList) == ConversionFlags.ShowParameterList && HasParameters(entity))
                {
                    if (entity.SymbolKind == SymbolKind.Indexer)
                    {
                        formatter.WriteToken(Roles.LBracket, "[");
                    }
                    else
                    {
                        formatter.WriteToken(Roles.LBrace, "(");
                    }
                    bool first = true;
                    foreach (var param in node.GetChildrenByRole(Roles.Parameter))
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            formatter.WriteToken(Roles.Comma, ",");
                            formatter.Space();
                        }
                        param.AcceptVisitor(new CSharpOutputVisitor(formatter, formattingPolicy));
                    }
                    if (entity.SymbolKind == SymbolKind.Indexer)
                    {
                        formatter.WriteToken(Roles.RBracket, "]");
                    }
                    else
                    {
                        formatter.WriteToken(Roles.RBrace, ")");
                    }
                }

                if ((ConversionFlags & ConversionFlags.ShowBody) == ConversionFlags.ShowBody && !(node is TypeDeclaration))
                {
                    IProperty property = entity as IProperty;
                    if (property != null)
                    {
                        formatter.Space();
                        formatter.WriteToken(Roles.LBrace, "{");
                        formatter.Space();
                        if (property.CanGet)
                        {
                            formatter.WriteKeyword(PropertyDeclaration.GetKeywordRole, "get");
                            formatter.WriteToken(Roles.Semicolon, ";");
                            formatter.Space();
                        }
                        if (property.CanSet)
                        {
                            formatter.WriteKeyword(PropertyDeclaration.SetKeywordRole, "set");
                            formatter.WriteToken(Roles.Semicolon, ";");
                            formatter.Space();
                        }
                        formatter.WriteToken(Roles.RBrace, "}");
                    }
                    else
                    {
                        formatter.WriteToken(Roles.Semicolon, ";");
                    }
                }
            }
예제 #18
0
            void WriteTypeDeclarationName(ITypeDefinition typeDef, TextWriterTokenWriter formatter, CSharpFormattingOptions formattingPolicy)
            {
                TypeSystemAstBuilder astBuilder = CreateAstBuilder();

                if (typeDef.DeclaringTypeDefinition != null)
                {
                    WriteTypeDeclarationName(typeDef.DeclaringTypeDefinition, formatter, formattingPolicy);
                    formatter.WriteToken(Roles.Dot, ".");
                }
                else if ((ConversionFlags & ConversionFlags.UseFullyQualifiedTypeNames) == ConversionFlags.UseFullyQualifiedTypeNames)
                {
                    formatter.WriteIdentifier(Identifier.Create(typeDef.Namespace));
                    formatter.WriteToken(Roles.Dot, ".");
                }
                formatter.WriteIdentifier(Identifier.Create(typeDef.Name));
                if ((ConversionFlags & ConversionFlags.ShowTypeParameterList) == ConversionFlags.ShowTypeParameterList)
                {
                    var outputVisitor = new CSharpOutputVisitor(formatter, formattingPolicy);
                    outputVisitor.WriteTypeParameters(astBuilder.ConvertEntity(typeDef).GetChildrenByRole(Roles.TypeParameter));
                }
            }
예제 #19
0
 protected Script(CSharpFormattingOptions formattingOptions)
 {
     if (formattingOptions == null)
         throw new ArgumentNullException("formattingOptions");
     this.formattingOptions = formattingOptions;
 }