Exemplo n.º 1
0
        void WriteQualifiedName(string name, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
        {
            var node          = AstType.Create(name);
            var outputVisitor = new CSharpOutputVisitor(writer, formattingPolicy);

            node.AcceptVisitor(outputVisitor);
        }
Exemplo n.º 2
0
        void WriteTypeDeclarationName(ITypeDefinition typeDef, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
        {
            TypeSystemAstBuilder astBuilder = CreateAstBuilder();
            EntityDeclaration    node       = astBuilder.ConvertEntity(typeDef);

            if (typeDef.DeclaringTypeDefinition != null)
            {
                WriteTypeDeclarationName(typeDef.DeclaringTypeDefinition, writer, formattingPolicy);
                writer.WriteToken(Roles.Dot, ".");
            }
            else if ((ConversionFlags & ConversionFlags.UseFullyQualifiedEntityNames) == ConversionFlags.UseFullyQualifiedEntityNames)
            {
                if (!string.IsNullOrEmpty(typeDef.Namespace))
                {
                    WriteQualifiedName(typeDef.Namespace, writer, formattingPolicy);
                    writer.WriteToken(Roles.Dot, ".");
                }
            }
            writer.WriteIdentifier(node.NameToken);
            if ((ConversionFlags & ConversionFlags.ShowTypeParameterList) == ConversionFlags.ShowTypeParameterList)
            {
                var outputVisitor = new CSharpOutputVisitor(writer, formattingPolicy);
                outputVisitor.WriteTypeParameters(node.GetChildrenByRole(Roles.TypeParameter));
            }
        }
Exemplo n.º 3
0
 protected DecoratingTokenWriter(TokenWriter decoratedWriter)
 {
     if (decoratedWriter == null)
     {
         throw new ArgumentNullException("decoratedWriter");
     }
     this.decoratedWriter = decoratedWriter;
 }
Exemplo n.º 4
0
 public static TokenWriter WrapInWriterThatSetsLocationsInAST(TokenWriter writer)
 {
     if (!(writer is ILocatable))
     {
         throw new InvalidOperationException("writer does not provide locations!");
     }
     return(new InsertSpecialsDecorator(new InsertRequiredSpacesDecorator(new InsertMissingTokensDecorator(writer, (ILocatable)writer))));
 }
Exemplo n.º 5
0
        public void ConvertType(IType type, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
        {
            TypeSystemAstBuilder astBuilder = CreateAstBuilder();

            astBuilder.AlwaysUseShortTypeNames = (ConversionFlags & ConversionFlags.UseFullyQualifiedEntityNames) != ConversionFlags.UseFullyQualifiedEntityNames;
            AstType astType = astBuilder.ConvertType(type);

            astType.AcceptVisitor(new CSharpOutputVisitor(writer, formattingPolicy));
        }
Exemplo n.º 6
0
		public CSharpOutputVisitor (TextWriter textWriter, CSharpFormattingOptions formattingPolicy)
		{
			if (textWriter == null) {
				throw new ArgumentNullException ("textWriter");
			}
			if (formattingPolicy == null) {
				throw new ArgumentNullException ("formattingPolicy");
			}
			this.writer = TokenWriter.Create(textWriter);
			this.policy = formattingPolicy;
		}
Exemplo n.º 7
0
 void PrintModifiers(Modifiers modifiers, TokenWriter writer)
 {
     foreach (var m in CSharpModifierToken.AllModifiers)
     {
         if ((modifiers & m) == m)
         {
             writer.WriteKeyword(EntityDeclaration.ModifierRole, CSharpModifierToken.GetModifierName(m));
             writer.Space();
         }
     }
 }
Exemplo n.º 8
0
		public CSharpOutputVisitor (TokenWriter writer, CSharpFormattingOptions formattingPolicy)
		{
			if (writer == null) {
				throw new ArgumentNullException ("writer");
			}
			if (formattingPolicy == null) {
				throw new ArgumentNullException ("formattingPolicy");
			}
			this.writer = new InsertSpecialsDecorator(new InsertRequiredSpacesDecorator(writer));
			this.policy = formattingPolicy;
		}
        void AssertOutput(AstNode node)
        {
            RemoveTokens(node);
            StringWriter w = new StringWriter();

            w.NewLine = "\n";
            node.AcceptVisitor(new CSharpOutputVisitor(TokenWriter.CreateWriterThatSetsLocationsInAST(w), FormattingOptionsFactory.CreateSharpDevelop()));
            var doc = new ReadOnlyDocument(w.ToString());

            ConsistencyChecker.CheckMissingTokens(node, "test.cs", doc);
            ConsistencyChecker.CheckPositionConsistency(node, "test.cs", doc);
        }
Exemplo n.º 10
0
 public void ConvertEntity(IEntity entity, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
 {
     ConvertSymbol(entity, writer, formattingPolicy);
 }
Exemplo n.º 11
0
		protected DecoratingTokenWriter(TokenWriter decoratedWriter)
		{
			if (decoratedWriter == null)
				throw new ArgumentNullException("decoratedWriter");
			this.decoratedWriter = decoratedWriter;
		}
Exemplo n.º 12
0
		public void ConvertType(IType type, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
		{
			TypeSystemAstBuilder astBuilder = CreateAstBuilder();
			astBuilder.AlwaysUseShortTypeNames = (ConversionFlags & ConversionFlags.UseFullyQualifiedEntityNames) != ConversionFlags.UseFullyQualifiedEntityNames;
			AstType astType = astBuilder.ConvertType(type);
			astType.AcceptVisitor(new CSharpOutputVisitor(writer, formattingPolicy));
		}
Exemplo n.º 13
0
 private void ConvertType(IType type, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
 {
     TypeSystemAstBuilder astBuilder = CreateAstBuilder();
     astBuilder.AlwaysUseShortTypeNames = true;
     AstType astType = astBuilder.ConvertType(type);
     astType.AcceptVisitor(new CSharpOutputVisitor(writer, formattingPolicy));
 }
Exemplo n.º 14
0
		public static TokenWriter WrapInWriterThatSetsLocationsInAST(TokenWriter writer)
		{
			if (!(writer is ILocatable))
				throw new InvalidOperationException("writer does not provide locations!");
			return new InsertSpecialsDecorator(new InsertRequiredSpacesDecorator(new InsertMissingTokensDecorator(writer, (ILocatable)writer)));
		}
Exemplo n.º 15
0
		public void ConvertEntity(IEntity entity, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
		{
			if (entity == null)
				throw new ArgumentNullException("entity");
			if (writer == null)
				throw new ArgumentNullException("writer");
			if (formattingPolicy == null)
				throw new ArgumentNullException("options");
			
			TypeSystemAstBuilder astBuilder = CreateAstBuilder();
			EntityDeclaration node = astBuilder.ConvertEntity(entity);
			PrintModifiers(node.Modifiers, writer);
			
			if ((ConversionFlags & ConversionFlags.ShowDefinitionKeyword) == ConversionFlags.ShowDefinitionKeyword) {
				if (node is TypeDeclaration) {
					switch (((TypeDeclaration)node).ClassType) {
						case ClassType.Class:
							writer.WriteKeyword(Roles.ClassKeyword, "class");
							break;
						case ClassType.Struct:
							writer.WriteKeyword(Roles.StructKeyword, "struct");
							break;
						case ClassType.Interface:
							writer.WriteKeyword(Roles.InterfaceKeyword, "interface");
							break;
						case ClassType.Enum:
							writer.WriteKeyword(Roles.EnumKeyword, "enum");
							break;
						default:
							throw new Exception("Invalid value for ClassType");
					}
					writer.Space();
				} else if (node is DelegateDeclaration) {
					writer.WriteKeyword(Roles.DelegateKeyword, "delegate");
					writer.Space();
				} else if (node is EventDeclaration) {
					writer.WriteKeyword(EventDeclaration.EventKeywordRole, "event");
					writer.Space();
				}
			}
			
			if ((ConversionFlags & ConversionFlags.ShowReturnType) == ConversionFlags.ShowReturnType) {
				var rt = node.GetChildByRole(Roles.Type);
				if (!rt.IsNull) {
					rt.AcceptVisitor(new CSharpOutputVisitor(writer, formattingPolicy));
					writer.Space();
				}
			}
			
			if (entity is ITypeDefinition)
				WriteTypeDeclarationName((ITypeDefinition)entity, writer, formattingPolicy);
			else
				WriteMemberDeclarationName((IMember)entity, writer, formattingPolicy);
			
			if ((ConversionFlags & ConversionFlags.ShowParameterList) == ConversionFlags.ShowParameterList && HasParameters(entity)) {
				writer.WriteToken(entity.SymbolKind == SymbolKind.Indexer ? Roles.LBracket : Roles.LPar, entity.SymbolKind == SymbolKind.Indexer ? "[" : "(");
				bool first = true;
				foreach (var param in node.GetChildrenByRole(Roles.Parameter)) {
					if (first) {
						first = false;
					} else {
						writer.WriteToken(Roles.Comma, ",");
						writer.Space();
					}
					param.AcceptVisitor(new CSharpOutputVisitor(writer, formattingPolicy));
				}
				writer.WriteToken(entity.SymbolKind == SymbolKind.Indexer ? Roles.RBracket : Roles.RPar, entity.SymbolKind == SymbolKind.Indexer ? "]" : ")");
			}
			
			if ((ConversionFlags & ConversionFlags.ShowBody) == ConversionFlags.ShowBody && !(node is TypeDeclaration)) {
				IProperty property = entity as IProperty;
				if (property != null) {
					writer.Space();
					writer.WriteToken(Roles.LBrace, "{");
					writer.Space();
					if (property.CanGet) {
						writer.WriteKeyword(PropertyDeclaration.GetKeywordRole, "get");
						writer.WriteToken(Roles.Semicolon, ";");
						writer.Space();
					}
					if (property.CanSet) {
						writer.WriteKeyword(PropertyDeclaration.SetKeywordRole, "set");
						writer.WriteToken(Roles.Semicolon, ";");
						writer.Space();
					}
					writer.WriteToken(Roles.RBrace, "}");
				} else {
					writer.WriteToken(Roles.Semicolon, ";");
				}
			}
		}
Exemplo n.º 16
0
        public void ConvertSymbol(ISymbol symbol, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException("symbol");
            }
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (formattingPolicy == null)
            {
                throw new ArgumentNullException("formattingPolicy");
            }

            TypeSystemAstBuilder astBuilder = CreateAstBuilder();
            AstNode           node          = astBuilder.ConvertSymbol(symbol);
            EntityDeclaration entityDecl    = node as EntityDeclaration;

            if (entityDecl != null)
            {
                PrintModifiers(entityDecl.Modifiers, writer);
            }

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

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

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

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

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

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

            if (symbol is ITypeDefinition)
            {
                WriteTypeDeclarationName((ITypeDefinition)symbol, writer, formattingPolicy);
            }
            else if (symbol is IMember)
            {
                WriteMemberDeclarationName((IMember)symbol, writer, formattingPolicy);
            }
            else
            {
                writer.WriteIdentifier(Identifier.Create(symbol.Name));
            }

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

            if ((ConversionFlags & ConversionFlags.ShowBody) == ConversionFlags.ShowBody && !(node is TypeDeclaration))
            {
                IProperty property = symbol as IProperty;
                if (property != null)
                {
                    writer.Space();
                    writer.WriteToken(Roles.LBrace, "{");
                    writer.Space();
                    if (property.CanGet)
                    {
                        writer.WriteKeyword(PropertyDeclaration.GetKeywordRole, "get");
                        writer.WriteToken(Roles.Semicolon, ";");
                        writer.Space();
                    }
                    if (property.CanSet)
                    {
                        writer.WriteKeyword(PropertyDeclaration.SetKeywordRole, "set");
                        writer.WriteToken(Roles.Semicolon, ";");
                        writer.Space();
                    }
                    writer.WriteToken(Roles.RBrace, "}");
                }
                else
                {
                    writer.WriteToken(Roles.Semicolon, ";");
                }
            }
        }
Exemplo n.º 17
0
		void PrintModifiers(Modifiers modifiers, TokenWriter writer)
		{
			foreach (var m in CSharpModifierToken.AllModifiers) {
				if ((modifiers & m) == m) {
					writer.WriteKeyword(EntityDeclaration.ModifierRole, CSharpModifierToken.GetModifierName(m));
					writer.Space();
				}
			}
		}
Exemplo n.º 18
0
		void WriteMemberDeclarationName(IMember member, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
		{
			TypeSystemAstBuilder astBuilder = CreateAstBuilder();
			EntityDeclaration node = astBuilder.ConvertEntity(member);
			if ((ConversionFlags & ConversionFlags.ShowDeclaringType) == ConversionFlags.ShowDeclaringType) {
				ConvertType(member.DeclaringType, writer, formattingPolicy);
				writer.WriteToken(Roles.Dot, ".");
			}
			switch (member.SymbolKind) {
				case SymbolKind.Indexer:
					writer.WriteKeyword(Roles.Identifier, "this");
					break;
				case SymbolKind.Constructor:
					WriteQualifiedName(member.DeclaringType.Name, writer, formattingPolicy);
					break;
				case SymbolKind.Destructor:
					writer.WriteToken(DestructorDeclaration.TildeRole, "~");
					WriteQualifiedName(member.DeclaringType.Name, writer, formattingPolicy);
					break;
				case SymbolKind.Operator:
					switch (member.Name) {
						case "op_Implicit":
							writer.WriteKeyword(OperatorDeclaration.ImplicitRole, "implicit");
							writer.Space();
							writer.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator");
							writer.Space();
							ConvertType(member.ReturnType, writer, formattingPolicy);
							break;
						case "op_Explicit":
							writer.WriteKeyword(OperatorDeclaration.ExplicitRole, "explicit");
							writer.Space();
							writer.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator");
							writer.Space();
							ConvertType(member.ReturnType, writer, formattingPolicy);
							break;
						default:
							writer.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator");
							writer.Space();
							var operatorType = OperatorDeclaration.GetOperatorType(member.Name);
							if (operatorType.HasValue)
								writer.WriteToken(OperatorDeclaration.GetRole(operatorType.Value), OperatorDeclaration.GetToken(operatorType.Value));
							else
								writer.WriteIdentifier(node.NameToken);
							break;
					}
					break;
				default:
					writer.WriteIdentifier(Identifier.Create(member.Name));
					break;
			}
			if ((ConversionFlags & ConversionFlags.ShowTypeParameterList) == ConversionFlags.ShowTypeParameterList && member.SymbolKind == SymbolKind.Method) {
				var outputVisitor = new CSharpOutputVisitor(writer, formattingPolicy);
				outputVisitor.WriteTypeParameters(node.GetChildrenByRole(Roles.TypeParameter));
			}
		}
Exemplo n.º 19
0
		void WriteTypeDeclarationName(ITypeDefinition typeDef, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
		{
			TypeSystemAstBuilder astBuilder = CreateAstBuilder();
			EntityDeclaration node = astBuilder.ConvertEntity(typeDef);
			if (typeDef.DeclaringTypeDefinition != null) {
				WriteTypeDeclarationName(typeDef.DeclaringTypeDefinition, writer, formattingPolicy);
				writer.WriteToken(Roles.Dot, ".");
			} else if ((ConversionFlags & ConversionFlags.UseFullyQualifiedTypeNames) == ConversionFlags.UseFullyQualifiedTypeNames) {
				WriteQualifiedName(typeDef.Namespace, writer, formattingPolicy);
				writer.WriteToken(Roles.Dot, ".");
			}
			writer.WriteIdentifier(node.NameToken);
			if ((ConversionFlags & ConversionFlags.ShowTypeParameterList) == ConversionFlags.ShowTypeParameterList) {
				var outputVisitor = new CSharpOutputVisitor(writer, formattingPolicy);
				outputVisitor.WriteTypeParameters(node.GetChildrenByRole(Roles.TypeParameter));
			}
		}
		public InsertRequiredSpacesDecorator(TokenWriter writer)
			: base(writer)
		{
		}
Exemplo n.º 21
0
		public InsertSpecialsDecorator(TokenWriter writer) : base(writer)
		{
		}
Exemplo n.º 22
0
 public InsertSpecialsDecorator(TokenWriter writer) : base(writer)
 {
 }
Exemplo n.º 23
0
        void WriteMemberDeclarationName(IMember member, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
        {
            TypeSystemAstBuilder astBuilder = CreateAstBuilder();
            EntityDeclaration node = astBuilder.ConvertEntity(member);
            switch (member.SymbolKind)
            {
                case SymbolKind.Indexer:
                    writer.WriteKeyword(Roles.Identifier, "this");
                    break;
                case SymbolKind.Constructor:
                    WriteQualifiedName(member.DeclaringType.Name, writer, formattingPolicy);
                    var typeNode = astBuilder.ConvertEntity(member.DeclaringTypeDefinition);
                    WriteTypeParameters(writer, typeNode.GetChildrenByRole(Roles.TypeParameter));
                    break;
                case SymbolKind.Destructor:
                    writer.WriteToken(DestructorDeclaration.TildeRole, "~");
                    WriteQualifiedName(member.DeclaringType.Name, writer, formattingPolicy);
                    break;
                case SymbolKind.Operator:
                    switch (member.Name)
                    {
                        case "op_Implicit":
                            writer.WriteKeyword(OperatorDeclaration.ImplicitRole, "implicit");
                            writer.Space();
                            writer.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator");
                            writer.Space();
                            ConvertType(member.ReturnType, writer, formattingPolicy);
                            break;
                        case "op_Explicit":
                            writer.WriteKeyword(OperatorDeclaration.ExplicitRole, "explicit");
                            writer.Space();
                            writer.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator");
                            writer.Space();
                            ConvertType(member.ReturnType, writer, formattingPolicy);
                            break;
                        default:
                            writer.WriteKeyword(OperatorDeclaration.OperatorKeywordRole, "operator");
                            writer.Space();
                            var operatorType = OperatorDeclaration.GetOperatorType(member.Name);
                            if (operatorType.HasValue)
                                writer.WriteToken(OperatorDeclaration.GetRole(operatorType.Value), OperatorDeclaration.GetToken(operatorType.Value));
                            else
                                writer.WriteIdentifier(node.NameToken);
                            break;
                    }
                    break;
                default:
                    writer.WriteIdentifier(Identifier.Create(member.Name));
                    if (member is IMethod)
                    {
                        var method = ((IMethod)member);

                        var methodParameterTypeArguments =
                            from p in method.Parameters
                            from type in ExpandIntersections(p.Type)
                            from typeArgument in type.TypeArguments
                            select typeArgument.Name;

                        IEnumerable<AstNode> typeArgs = node.GetChildrenByRole(Roles.TypeParameter).Where(arg => !methodParameterTypeArguments.Contains(arg.Name));
                        WriteTypeParameters(writer, typeArgs);
                    }
                    break;
            }
        }
Exemplo n.º 24
0
		public DebugInfoTokenWriterDecorator(TokenWriter writer)
			: base(writer)
		{
		}
Exemplo n.º 25
0
		public void ConvertEntity(IEntity entity, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
		{
			ConvertSymbol(entity, writer, formattingPolicy);
		}
 public InsertRequiredSpacesDecorator(TokenWriter writer)
     : base(writer)
 {
 }
 public InsertMissingTokensDecorator(TokenWriter writer, ILocatable locationProvider)
     : base(writer)
 {
     this.locationProvider = locationProvider;
     currentList           = new List <AstNode>();
 }
Exemplo n.º 28
0
 public void WriteTypeParameters(TokenWriter writer, IEnumerable<AstNode> typeParameters)
 {
     if (typeParameters.Any())
     {
         writer.WriteToken(Roles.LChevron, "<");
         WriteCommaSeparatedList(typeParameters);
         writer.WriteToken(Roles.RChevron, ">");
     }
 }
		public InsertMissingTokensDecorator(TokenWriter writer, ILocatable locationProvider)
			: base(writer)
		{
			this.locationProvider = locationProvider;
			currentList = new List<AstNode>();
		}
Exemplo n.º 30
0
 void WriteQualifiedName(string name, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
 {
     var node = AstType.Create(name);
     var outputVisitor = new CSharpOutputVisitor(writer, formattingPolicy);
     node.AcceptVisitor(outputVisitor);
 }
Exemplo n.º 31
0
        void WriteMemberDeclarationName(IMember member, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
        {
            TypeSystemAstBuilder astBuilder = CreateAstBuilder();
            EntityDeclaration    node       = astBuilder.ConvertEntity(member);

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

            case SymbolKind.Constructor:
                WriteQualifiedName(member.DeclaringType.Name, writer, formattingPolicy);
                break;

            case SymbolKind.Destructor:
                writer.WriteToken(DestructorDeclaration.TildeRole, "~");
                WriteQualifiedName(member.DeclaringType.Name, writer, formattingPolicy);
                break;

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

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

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

            default:
                writer.WriteIdentifier(Identifier.Create(member.Name));
                break;
            }
            if ((ConversionFlags & ConversionFlags.ShowTypeParameterList) == ConversionFlags.ShowTypeParameterList && member.SymbolKind == SymbolKind.Method)
            {
                var outputVisitor = new CSharpOutputVisitor(writer, formattingPolicy);
                outputVisitor.WriteTypeParameters(node.GetChildrenByRole(Roles.TypeParameter));
            }
        }
Exemplo n.º 32
0
 void WriteTypeDeclarationName(ITypeDefinition typeDef, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
 {
     var astBuilder = new TypeSystemAstBuilder();
     EntityDeclaration node = astBuilder.ConvertEntity(typeDef);
     if (typeDef.DeclaringTypeDefinition != null)
     {
         WriteTypeDeclarationName(typeDef.DeclaringTypeDefinition, writer, formattingPolicy);
         writer.WriteToken(Roles.Dot, ".");
     }
     writer.WriteIdentifier(node.NameToken);
     WriteTypeParameters(writer, node.GetChildrenByRole(Roles.TypeParameter));
 }
Exemplo n.º 33
0
		void WriteTypeDeclarationName(ITypeDefinition typeDef, TokenWriter writer, CSharpFormattingOptions formattingPolicy)
		{
			TypeSystemAstBuilder astBuilder = CreateAstBuilder();
			EntityDeclaration node = astBuilder.ConvertEntity(typeDef);
			if (typeDef.DeclaringTypeDefinition != null) {
				WriteTypeDeclarationName(typeDef.DeclaringTypeDefinition, writer, formattingPolicy);
				writer.WriteTokenOperator(Roles.Dot, ".");
			} else if ((ConversionFlags & ConversionFlags.UseFullyQualifiedEntityNames) == ConversionFlags.UseFullyQualifiedEntityNames) {
				if (!string.IsNullOrEmpty(typeDef.Namespace)) {
					WriteQualifiedName(typeDef.Namespace, writer, formattingPolicy);
					writer.WriteTokenOperator(Roles.Dot, ".");
				}
			}
			writer.WriteIdentifier(node.NameToken, BoxedTextColor.Text);
			if ((ConversionFlags & ConversionFlags.ShowTypeParameterList) == ConversionFlags.ShowTypeParameterList) {
				var outputVisitor = new CSharpOutputVisitor(writer, formattingPolicy);
				outputVisitor.WriteTypeParameters(node.GetChildrenByRole(Roles.TypeParameter), CodeBracesRangeFlags.AngleBrackets);
			}
		}