void FixAttributesAndDocComment(EntityDeclaration entity)
        {
            var node = entity.FirstChild;

            while (node != null && node.Role == Roles.Comment)
            {
                node = node.GetNextSibling(NoWhitespacePredicate);
                FixIndentation(node);
            }
            if (entity.Attributes.Count > 0)
            {
                AstNode n = null;
                entity.Attributes.First().AcceptVisitor(this);
                foreach (var attr in entity.Attributes.Skip(1))
                {
                    FixIndentation(attr);
                    attr.AcceptVisitor(this);
                    n = attr;
                }
                if (n != null)
                {
                    FixIndentation(n.GetNextNode(NoWhitespacePredicate));
                }
                else
                {
                    FixIndentation(entity.Attributes.First().GetNextNode(NoWhitespacePredicate));
                }
            }
        }
示例#2
0
 /// <summary>
 /// Appends node attributes.
 /// </summary>
 /// <param name="buffer">the buffer</param>
 /// <param name="node">the node</param>
 /// <param name="stack">the stack</param>
 /// <example>
 /// <code>
 ///     [XmlIgnore]
 ///     [ConditionalAttribute("CODE_ANALYSIS")]
 ///     int DoSomething();
 /// </code>
 /// </example>
 public static void AppendAttributes(StringBuilder buffer, EntityDeclaration node, int stack)
 {
     foreach (var attribute in node.Attributes)
     {
         buffer.AppendLine(attribute.ToString().Trim(), stack);
     }
 }
示例#3
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));
            }
        }
        protected static ModelV2.Visibility AdjustVisibilityForClassesInterfacesAndStructs(EntityDeclaration ed)
        {
            VisibilityMode mode = VisibilityMapper.Map(ed.Modifiers);
            mode = mode == VisibilityMode.@private ? VisibilityMode.@internal : VisibilityMode.@public;

            return new ModelV2.Visibility(mode);
        }
		static bool CheckBody(EntityDeclaration node)
		{
			var custom = node as CustomEventDeclaration;
			if (custom != null && !(IsValidBody (custom.AddAccessor.Body) || IsValidBody (custom.RemoveAccessor.Body)))
			    return false;
			if (node is PropertyDeclaration || node is IndexerDeclaration) {
				var setter = node.GetChildByRole(PropertyDeclaration.SetterRole);
				var getter = node.GetChildByRole(PropertyDeclaration.GetterRole);
				return IsValidBody(setter.Body) && IsValidBody(getter.Body);
			} 
			return IsValidBody(node.GetChildByRole(Roles.Body));
		}
示例#6
0
		static bool IsObsolete (EntityDeclaration entity)
		{
			if (entity == null)
				return false;
			foreach (var section in entity.Attributes) {
				foreach (var attr in section.Attributes) {
					var attrText = attr.Type.GetText ();
					if (attrText == "Obsolete" || attrText == "ObsoleteAttribute" || attrText == "System.Obsolete" || attrText == "System.ObsoleteAttribute" )
						return true;
				}
			}
			return false;
		}
		static ThrowStatement ImplementStub (RefactoringContext context, EntityDeclaration newNode)
		{
			ThrowStatement throwStatement = null;
			if (newNode is PropertyDeclaration || newNode is IndexerDeclaration) {
				var setter = newNode.GetChildByRole(PropertyDeclaration.SetterRole);
				if (!setter.IsNull)
					setter.AddChild(CreateNotImplementedBody(context, out throwStatement), Roles.Body); 

				var getter = newNode.GetChildByRole(PropertyDeclaration.GetterRole);
				if (!getter.IsNull)
					getter.AddChild(CreateNotImplementedBody(context, out throwStatement), Roles.Body); 
			} else {
				newNode.AddChild(CreateNotImplementedBody(context, out throwStatement), Roles.Body); 
			}
			return throwStatement;
		}
示例#8
0
        protected virtual bool TryGetAttribute(EntityDeclaration type, string attributeName, out NRAttribute attribute)
        {
            foreach (var i in type.Attributes)
            {
                foreach (var j in i.Attributes)
                {
                    if (j.Type.ToString() == attributeName)
                    {
                        attribute = j;
                        return true;
                    }

                    // FIXME: Will not try to get the attribute via Resolver.ResolveNode() (see above): it returns a
                    //        different type, without minimum information needed to make a full NRAttribute -fzm
                }
            }

            attribute = default(NRAttribute);
            return false;
        }
示例#9
0
        protected virtual bool HasAttribute(EntityDeclaration type, string name)
        {
            foreach (var i in type.Attributes)
            {
                foreach (var j in i.Attributes)
                {
                    if (j.Type.ToString() == name)
                    {
                        return true;
                    }

                    var resolveResult = this.Resolver.ResolveNode(j, null);
                    if (resolveResult != null && resolveResult.Type != null && resolveResult.Type.FullName == (name + "Attribute"))
                    {
                        return true;
                    }
                }
            }

            return false;
        }
示例#10
0
            GeneratedCodeMember GetCodeMemberCategory(EntityDeclaration x)
            {
                bool isStatic = x.HasModifier(Modifiers.Static) || x.HasModifier(Modifiers.Const);

                if (x is FieldDeclaration)
                {
                    return(isStatic ? GeneratedCodeMember.StaticFields : GeneratedCodeMember.InstanceFields);
                }
                if (x is IndexerDeclaration)
                {
                    return(GeneratedCodeMember.Indexer);
                }
                if (x is PropertyDeclaration)
                {
                    return(isStatic ? GeneratedCodeMember.StaticProperties : GeneratedCodeMember.InstanceProperties);
                }
                if (x is ConstructorDeclaration || x is DestructorDeclaration)
                {
                    return(GeneratedCodeMember.Constructors);
                }
                if (x is MethodDeclaration)
                {
                    return(isStatic ? GeneratedCodeMember.StaticMethods : GeneratedCodeMember.InstanceMethods);
                }
                if (x is OperatorDeclaration)
                {
                    return(GeneratedCodeMember.Operators);
                }
                if (x is EventDeclaration || x is CustomEventDeclaration)
                {
                    return(isStatic ? GeneratedCodeMember.StaticEvents : GeneratedCodeMember.InstanceEvents);
                }

                if (x is TypeDeclaration)
                {
                    return(GeneratedCodeMember.NestedTypes);
                }

                return(GeneratedCodeMember.Unknown);
            }
 void FixAttributesAndDocComment(EntityDeclaration entity)
 {
     var node = entity.FirstChild;
     while (node != null && node.Role == Roles.Comment) {
         node = node.GetNextSibling(NoWhitespacePredicate);
         FixIndentation(node);
     }
     if (entity.Attributes.Count > 0) {
         AstNode n = null;
         foreach (var attr in entity.Attributes.Skip (1)) {
             FixIndentation(attr);
             n = attr;
         }
         if (n != null) {
             FixIndentation(n.GetNextNode(NoWhitespacePredicate));
         } else {
             FixIndentation(entity.Attributes.First().GetNextNode(NoWhitespacePredicate));
         }
     }
 }
		internal static string GetCorrectFileName (MDRefactoringContext context, EntityDeclaration type)
		{
			if (type == null)
				return context.Document.FileName;
			return Path.Combine (Path.GetDirectoryName (context.Document.FileName), type.Name + Path.GetExtension (context.Document.FileName));
		}
示例#13
0
 private void MaybeCompileAndAddMethodToType(JsClass jsClass, EntityDeclaration node, BlockStatement body, IMethod method, MethodScriptSemantics options)
 {
     if (options.GenerateCode) {
         var typeParamNames = options.IgnoreGenericArguments ? (IEnumerable<string>)new string[0] : method.TypeParameters.Select(tp => _namer.GetTypeParameterName(tp)).ToList();
         JsMethod jsMethod;
         if (method.IsAbstract) {
             jsMethod = new JsMethod(method, options.Name, typeParamNames, null);
         }
         else {
             var compiled = CompileMethod(node, body, method, options);
             jsMethod = new JsMethod(method, options.Name, typeParamNames, compiled);
         }
         AddCompiledMethodToType(jsClass, method, options, jsMethod);
     }
 }
示例#14
0
 private JsFunctionDefinitionExpression CompileMethod(EntityDeclaration node, BlockStatement body, IMethod method, MethodScriptSemantics options)
 {
     var mc = CreateMethodCompiler();
     var result = mc.CompileMethod(node, body, method, options);
     OnMethodCompiled(method, result, mc);
     return result;
 }
示例#15
0
 protected bool MatchAttributesAndModifiers(EntityDeclaration o, PatternMatching.Match match)
 {
     return((this.Modifiers == Modifiers.Any || this.Modifiers == o.Modifiers) && this.Attributes.DoMatch(o.Attributes, match));
 }
示例#16
0
 protected virtual bool HasScript(EntityDeclaration declaration)
 {
     return this.HasAttribute(declaration, Translator.Bridge_ASSEMBLY + ".Script");
 }
 public NamespacedEntityDeclaration(string @namespace, EntityDeclaration entityDeclaration)
 {
     Namespace = @namespace;
     EntityDeclaration = entityDeclaration;
 }
示例#18
0
 protected virtual bool HasInline(EntityDeclaration declaration)
 {
     return this.HasAttribute(declaration, Translator.Bridge_ASSEMBLY + ".Template");
 }
		string ConvertMember(EntityDeclaration entity)
		{
			return ConvertHelper(entity, (p,obj,w,opt) => p.GenerateCodeFromMember((CodeTypeMember)obj, w, opt));
		}
示例#20
0
        public virtual string GetInline(EntityDeclaration method)
        {
            var attr = this.GetAttribute(method.Attributes, Bridge.Translator.Translator.Bridge_ASSEMBLY + ".Template");

            return attr != null && attr.Arguments.Count > 0 ? ((string)((PrimitiveExpression)attr.Arguments.First()).Value) : null;
        }
			GeneratedCodeMember GetCodeMemberCategory(EntityDeclaration x)
			{
				bool isStatic = x.HasModifier(Modifiers.Static) || x.HasModifier(Modifiers.Const);
				if (x is FieldDeclaration)
					return isStatic ? GeneratedCodeMember.StaticFields : GeneratedCodeMember.InstanceFields;
				if (x is IndexerDeclaration)
					return GeneratedCodeMember.Indexer;
				if (x is PropertyDeclaration)
					return isStatic ? GeneratedCodeMember.StaticProperties : GeneratedCodeMember.InstanceProperties;
				if (x is ConstructorDeclaration || x is DestructorDeclaration)
					return GeneratedCodeMember.Constructors;
				if (x is MethodDeclaration)
					return isStatic ? GeneratedCodeMember.StaticMethods : GeneratedCodeMember.InstanceMethods;
				if (x is OperatorDeclaration)
					return GeneratedCodeMember.Operators;
				if (x is EventDeclaration)
					return isStatic ? GeneratedCodeMember.StaticEvents : GeneratedCodeMember.InstanceEvents;

				if (x is TypeDeclaration)
					return GeneratedCodeMember.NestedTypes;

				return GeneratedCodeMember.Unknown;
			}
示例#22
0
 protected bool MatchAttributesAndModifiers(EntityDeclaration o, PatternMatching.Match match)
 {
     return (this.Modifiers == Modifiers.Any || this.Modifiers == o.Modifiers) && this.Attributes.DoMatch (o.Attributes, match);
 }
		static AstNode WrapInType(IUnresolvedTypeDefinition entity, EntityDeclaration decl)
		{
			if (entity == null)
				return decl;
			// Wrap decl in TypeDeclaration
			decl = new TypeDeclaration {
				ClassType = GetClassType(entity),
				Modifiers = Modifiers.Partial,
				Name = entity.Name,
				Members = { decl }
			};
			if (entity.DeclaringTypeDefinition != null) {
				// Handle nested types
				return WrapInType(entity.DeclaringTypeDefinition, decl);
			} 
			if (string.IsNullOrEmpty(entity.Namespace))
				return decl;
			return new NamespaceDeclaration(entity.Namespace) {
				Members = {
					decl
				}
			};
		}
示例#24
0
文件: CxxBinder.cs 项目: corefan/urho
		void UpdateMembers(EntityDeclaration baseDeclaration, EntityDeclaration declaration)
		{
			if (declaration.Modifiers.HasFlag(Modifiers.Static)) {
				declaration.Modifiers |= Modifiers.New;
			} else {
				declaration.Modifiers |= Modifiers.Override;
				baseDeclaration.Modifiers |= Modifiers.Virtual;
			}
		}
示例#25
0
        /// <summary>
        ///   Inserts the given EntityDeclaration with the given
        ///   script at the end of the type declaration under the
        ///   cursor (e.g. class / struct).
        /// </summary>
        /// <remarks>
        ///   Alters the given script. Returns its CurrentDocument
        ///   property. Alters the given memberDeclaration, adding
        ///   Modifiers.Override to its Modifiers as well as removing
        ///   Modifiers.Virtual.
        /// </remarks>
        IDocument runOverrideTargetWorker
            ( Request                     request
            , OmniSharpRefactoringContext refactoringContext
            , ParsedResult                parsedContent
            , EntityDeclaration           memberDeclaration
            , OmniSharpScript             script) {

            // Add override flag
            memberDeclaration.Modifiers |= Modifiers.Override;
            // Remove virtual flag
            memberDeclaration.Modifiers &= ~ Modifiers.Virtual;

            // The current type declaration, e.g. class, struct..
            var typeDeclaration = parsedContent.SyntaxTree.GetNodeAt
                ( refactoringContext.Location
                , n => n.NodeType == NodeType.TypeDeclaration);

            // Even empty classes have nodes, so this works
            var lastNode =
                typeDeclaration.Children.Last();

            script.InsertBefore
                ( node    : lastNode
                , newNode : memberDeclaration);
            script.FormatText(memberDeclaration);

            return script.CurrentDocument;
        }
		string ConvertTypeDeclaration(EntityDeclaration decl)
		{
			return ConvertHelper(decl, (p,obj,w,opt) => p.GenerateCodeFromType((CodeTypeDeclaration)obj, w, opt));
		}
		void UpdatePath (object sender, Mono.TextEditor.DocumentLocationEventArgs e)
		{
			var parsedDocument = Document.ParsedDocument;
			if (parsedDocument == null || parsedDocument.ParsedFile == null)
				return;
			amb = new AstAmbience (document.GetFormattingOptions ());
			
			var unit = parsedDocument.GetAst<SyntaxTree> ();
			if (unit == null)
				return;

			var loc = Document.Editor.Caret.Location;

			var curType = (EntityDeclaration)unit.GetNodeAt (loc, n => n is TypeDeclaration || n is DelegateDeclaration);
			var curMember = unit.GetNodeAt<EntityDeclaration> (loc);
			if (curType == curMember)
				curMember = null;
			if (isPathSet && curType == lastType && lastMember == curMember)
				return;

			var curTypeMakeup = GetEntityMarkup (curType);
			var curMemberMarkup = GetEntityMarkup (curMember);
			if (isPathSet && curType != null && lastType != null && curType.StartLocation == lastType.StartLocation && curTypeMakeup == lastTypeMarkup &&
			    curMember != null && lastMember != null && curMember.StartLocation == lastMember.StartLocation && curMemberMarkup == lastMemberMarkup)
				return;

			lastType = curType;
			lastTypeMarkup = curTypeMakeup;

			lastMember = curMember;
			lastMemberMarkup = curMemberMarkup;

			if (curType == null) {
				if (CurrentPath != null && CurrentPath.Length == 1 && CurrentPath [0].Tag is IUnresolvedFile)
					return;
				var prevPath = CurrentPath;
				CurrentPath = new PathEntry[] { new PathEntry (GettextCatalog.GetString ("No selection")) { Tag = unit } };
				OnPathChanged (new DocumentPathChangedEventArgs (prevPath));	
				return;
			}
			
			//	ThreadPool.QueueUserWorkItem (delegate {
			var result = new List<PathEntry> ();

			if (curType != null) {
				var type = curType;
				while (type != null) {
					var declaringType = type.Parent as TypeDeclaration;
					result.Insert (0, new PathEntry (ImageService.GetPixbuf (type.GetStockIcon (false), Gtk.IconSize.Menu), GetEntityMarkup (type)) { Tag = (AstNode)declaringType ?? unit });
					type = declaringType;
				}
			}
				
			if (curMember != null) {
				result.Add (new PathEntry (ImageService.GetPixbuf (curMember.GetStockIcon (true), Gtk.IconSize.Menu), curMemberMarkup) { Tag = curMember });
				if (curMember is Accessor) {
					var parent = curMember.Parent as EntityDeclaration;
					if (parent != null)
						result.Insert (result.Count - 1, new PathEntry (ImageService.GetPixbuf (parent.GetStockIcon (true), Gtk.IconSize.Menu), GetEntityMarkup (parent)) { Tag = parent });
				}
			}
				
			var entry = GetRegionEntry (parsedDocument, loc);
			if (entry != null)
				result.Add (entry);
				
			PathEntry noSelection = null;
			if (curType == null) {
				noSelection = new PathEntry (GettextCatalog.GetString ("No selection")) { Tag = unit };
			} else if (curMember == null && !(curType is DelegateDeclaration)) { 
				noSelection = new PathEntry (GettextCatalog.GetString ("No selection")) { Tag = curType };
			}

			if (noSelection != null) 
				result.Add (noSelection);

			var prev = CurrentPath;
			if (prev != null && prev.Length == result.Count) {
				bool equals = true;
				for (int i = 0; i < prev.Length; i++) {
					if (prev [i].Markup != result [i].Markup) {
						equals = false;
						break;
					}
				}
				if (equals)
					return;
			}
			//		Gtk.Application.Invoke (delegate {
			CurrentPath = result.ToArray ();
			OnPathChanged (new DocumentPathChangedEventArgs (prev));	
			//		});
			//	});
		}
示例#28
0
        public virtual string GetEntityName(EntityDeclaration entity, bool forcePreserveMemberCase = false, bool ignoreInterface = false)
        {
            var rr = this.Resolver.ResolveNode(entity, this) as MemberResolveResult;

            if (rr != null)
            {
                return this.GetEntityName(rr.Member, forcePreserveMemberCase, ignoreInterface);
            }

            return null;
        }
示例#29
0
        public void ConvertEntity(IEntity entity, IOutputFormatter 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("class");
                        break;

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

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

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

                    default:
                        throw new Exception("Invalid value for ClassType");
                    }
                    formatter.Space();
                }
                else if (node is DelegateDeclaration)
                {
                    formatter.WriteKeyword("delegate");
                    formatter.Space();
                }
                else if (node is EventDeclaration)
                {
                    formatter.WriteKeyword("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))
            {
                formatter.WriteToken(entity.SymbolKind == SymbolKind.Indexer ? "[" : "(");
                bool first = true;
                foreach (var param in node.GetChildrenByRole(Roles.Parameter))
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        formatter.WriteToken(",");
                        formatter.Space();
                    }
                    param.AcceptVisitor(new CSharpOutputVisitor(formatter, formattingPolicy));
                }
                formatter.WriteToken(entity.SymbolKind == SymbolKind.Indexer ? "]" : ")");
            }

            if ((ConversionFlags & ConversionFlags.ShowBody) == ConversionFlags.ShowBody && !(node is TypeDeclaration))
            {
                IProperty property = entity as IProperty;
                if (property != null)
                {
                    formatter.Space();
                    formatter.WriteToken("{");
                    formatter.Space();
                    if (property.CanGet)
                    {
                        formatter.WriteKeyword("get");
                        formatter.WriteToken(";");
                        formatter.Space();
                    }
                    if (property.CanSet)
                    {
                        formatter.WriteKeyword("set");
                        formatter.WriteToken(";");
                        formatter.Space();
                    }
                    formatter.WriteToken("}");
                }
                else
                {
                    formatter.WriteToken(";");
                }
            }
        }
示例#30
0
        public virtual IEnumerable<string> GetScript(EntityDeclaration method)
        {
            var attr = this.GetAttribute(method.Attributes, Bridge.Translator.Translator.Bridge_ASSEMBLY + ".Script");

            return this.GetScriptArguments(attr);
        }
示例#31
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, ";");
                }
            }
        }
示例#32
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));
            }
        }
示例#33
0
			static void AddModifiers(EntityDeclaration parent, LocationsBag.MemberLocations location)
			{
				if (location == null || location.Modifiers == null)
					return;
				foreach (var modifier in location.Modifiers) {
					Modifiers mod;
					if (!modifierTable.TryGetValue(modifier.Item1, out mod)) {
						Console.WriteLine("modifier " + modifier.Item1 + " can't be converted,");
					}
					
					parent.AddChild(new CSharpModifierToken(Convert(modifier.Item2), mod), EntityDeclaration.ModifierRole);
				}
			}
示例#34
0
        private void AddMethod(bool ctor, EntityDeclaration methodDeclaration, AstNodeCollection<ParameterDeclaration> parameters)
        {
            CLRType t = m_clrTypes.Value.Last.Value;

            List<KeyValuePair<string, string>> args = parameters.Select(p =>
                                                        new KeyValuePair<string, string>(p.Name, p.Type.ToString())
                                                      )
                                                      .ToList();

            Method m = new Method(
                CheckFlag(methodDeclaration.Modifiers, Modifiers.Override),
                ctor,
                CheckFlag(methodDeclaration.Modifiers, Modifiers.Static),
                new Visibility(VisibilityMapper.Map(methodDeclaration.Modifiers)),
                CheckFlag(methodDeclaration.Modifiers, Modifiers.Virtual),
                methodDeclaration.Name,
                CheckFlag(methodDeclaration.Modifiers, Modifiers.Abstract),
                args,
                methodDeclaration.ReturnType.ToString()

            );

            t.Methods.Add(m);   // connect
        }
 string ConvertMember(EntityDeclaration entity)
 {
     return(ConvertHelper(entity, (p, obj, w, opt) => p.GenerateCodeFromMember((CodeTypeMember)obj, w, opt)));
 }
示例#36
0
			void AddType(EntityDeclaration child)
			{
				if (typeStack.Count > 0) {
					typeStack.Peek().AddChild(child, Roles.TypeMemberRole);
				} else {
					AddToNamespace(child);
				}
			}
 string ConvertTypeDeclaration(EntityDeclaration decl)
 {
     return(ConvertHelper(decl, (p, obj, w, opt) => p.GenerateCodeFromType((CodeTypeDeclaration)obj, w, opt)));
 }
		static bool GetAccessibility (EntityDeclaration element, out Accessibility acc)
		{
			if (element.Parent is TypeDeclaration && ((TypeDeclaration)element.Parent).ClassType == ClassType.Interface) {
				acc = Accessibility.Public;
				return true;
			}
			bool result = false;
			acc = Accessibility.Private;
			if (element is TypeDeclaration && !(element.Parent is TypeDeclaration))
				acc = Accessibility.Internal;
			if (element.HasModifier (Modifiers.Public)) {
				acc = Accessibility.Public;
				result = true;
			} else if (element.HasModifier (Modifiers.Private)) {
				acc = Accessibility.Private;
				result = true;
			} else if (element.HasModifier (Modifiers.Protected | Modifiers.Internal)) {
				acc = Accessibility.ProtectedOrInternal;
				result = true;
			} else if (element.HasModifier (Modifiers.Protected)) {
				acc = Accessibility.Protected;
				result = true;
			} else if (element.HasModifier (Modifiers.Internal)) {
				acc = Accessibility.Internal;
				result = true;
			} 
			return result;
		}
		void UpdatePath (object sender, Mono.TextEditor.DocumentLocationEventArgs e)
		{
			var parsedDocument = Document.ParsedDocument;
			if (parsedDocument == null || parsedDocument.ParsedFile == null)
				return;
			amb = new AstAmbience (document.GetFormattingOptions ());
			
			var unit = parsedDocument.GetAst<SyntaxTree> ();
			if (unit == null)
				return;

			var loc = Document.Editor.Caret.Location;
			var compExt = Document.GetContent<CSharpCompletionTextEditorExtension> ();
			var caretOffset = Document.Editor.Caret.Offset;
			var segType = compExt.GetTypeAt (caretOffset);
			if (segType != null)
				loc = segType.Region.Begin;

			var curType = (EntityDeclaration)unit.GetNodeAt (loc, n => n is TypeDeclaration || n is DelegateDeclaration);

			var curProject = ownerProjects.Count > 1 ? Document.Project : null;

			var segMember = compExt.GetMemberAt (caretOffset);
			if (segMember != null) {
				loc = segMember.Region.Begin;
			} else {
				loc = Document.Editor.Caret.Location;
			}

			var curMember = unit.GetNodeAt<EntityDeclaration> (loc);
			if (curType == curMember || curType is DelegateDeclaration)
				curMember = null;
			if (isPathSet && curType == lastType && curMember == lastMember && curProject == lastProject)
				return;

			var curTypeMakeup = GetEntityMarkup (curType);
			var curMemberMarkup = GetEntityMarkup (curMember);
			if (isPathSet && curType != null && lastType != null && curType.StartLocation == lastType.StartLocation && curTypeMakeup == lastTypeMarkup &&
				curMember != null && lastMember != null && curMember.StartLocation == lastMember.StartLocation && curMemberMarkup == lastMemberMarkup && curProject == lastProject)
				return;

			lastType = curType;
			lastTypeMarkup = curTypeMakeup;

			lastMember = curMember;
			lastMemberMarkup = curMemberMarkup;

			lastProject = curProject;

			var result = new List<PathEntry> ();

			if (ownerProjects.Count > 1) {
				// Current project if there is more than one
				result.Add (new PathEntry (ImageService.GetIcon (Document.Project.StockIcon), GLib.Markup.EscapeText (Document.Project.Name)) { Tag = Document.Project });
			}

			if (curType == null) {
				if (CurrentPath != null && CurrentPath.Length == 1 && CurrentPath [0].Tag is IUnresolvedFile)
					return;
				if (CurrentPath != null && CurrentPath.Length == 2 && CurrentPath [1].Tag is IUnresolvedFile)
					return;
				var prevPath = CurrentPath;
				result.Add (new PathEntry (GettextCatalog.GetString ("No selection")) { Tag = unit });
				CurrentPath = result.ToArray ();
				OnPathChanged (new DocumentPathChangedEventArgs (prevPath));	
				return;
			}

			if (curType != null) {
				var type = curType;
				var pos = result.Count;
				while (type != null) {
					var declaringType = type.Parent as TypeDeclaration;
					result.Insert (pos, new PathEntry (ImageService.GetIcon (type.GetStockIcon (), Gtk.IconSize.Menu), GetEntityMarkup (type)) { Tag = (AstNode)declaringType ?? unit });
					type = declaringType;
				}
			}
				
			if (curMember != null) {
				result.Add (new PathEntry (ImageService.GetIcon (curMember.GetStockIcon (), Gtk.IconSize.Menu), curMemberMarkup) { Tag = curMember });
				if (curMember is Accessor) {
					var parent = curMember.Parent as EntityDeclaration;
					if (parent != null)
						result.Insert (result.Count - 1, new PathEntry (ImageService.GetIcon (parent.GetStockIcon (), Gtk.IconSize.Menu), GetEntityMarkup (parent)) { Tag = parent });
				}
			}
				
			var entry = GetRegionEntry (parsedDocument, loc);
			if (entry != null)
				result.Add (entry);
				
			PathEntry noSelection = null;
			if (curType == null) {
				noSelection = new PathEntry (GettextCatalog.GetString ("No selection")) { Tag = unit };
			} else if (curMember == null && !(curType is DelegateDeclaration)) { 
				noSelection = new PathEntry (GettextCatalog.GetString ("No selection")) { Tag = curType };
			}

			if (noSelection != null)
				result.Add (noSelection);

			var prev = CurrentPath;
			if (prev != null && prev.Length == result.Count) {
				bool equals = true;
				for (int i = 0; i < prev.Length; i++) {
					if (prev [i].Markup != result [i].Markup) {
						equals = false;
						break;
					}
				}
				if (equals)
					return;
			}
			//		Gtk.Application.Invoke (delegate {
			CurrentPath = result.ToArray ();
			OnPathChanged (new DocumentPathChangedEventArgs (prev));	
			//		});
			//	});
		}