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;
		}
Example #2
0
 void FixAttributes(EntityDeclaration entity)
 {
     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));
         }
     }
 }
            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 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));	
			//		});
			//	});
		}
			void AddType (EntityDeclaration child)
			{
				if (typeStack.Count > 0) {
					typeStack.Peek ().AddChild (child, Roles.TypeMemberRole);
				} else {
					AddToNamespace (child);
				}
			}
			void AddModifiers (EntityDeclaration parent, LocationsBag.MemberLocations location)
			{
				if (location == null || location.Modifiers == null)
					return;
				foreach (var modifier in location.Modifiers) {
					ICSharpCode.NRefactory.PlayScript.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);
				}
			}
Example #7
0
 protected bool MatchAttributesAndModifiers(EntityDeclaration o, PatternMatching.Match match)
 {
     return((this.Modifiers == Modifiers.Any || this.Modifiers == o.Modifiers) && this.Attributes.DoMatch(o.Attributes, match));
 }
		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));
		}
			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;
			}
		protected bool MatchAttributesAndModifiers (EntityDeclaration o, PatternMatching.Match match)
		{
			return (this.Modifiers == Modifiers.Any || this.Modifiers == o.Modifiers) && this.Attributes.DoMatch (o.Attributes, match);
		}
        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.EntityType == EntityType.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.EntityType == EntityType.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(";");
                }
            }
        }
		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;
		}