/// <summary>
        /// Attempts to get the namespace encompasing the function
        /// returns true on success and false if it does not have one.
        /// NOTE: if it's a method then even if the class it belongs to
        /// has a namespace the method will not have a namespace since
        /// it should be placed under the class node and not the namespace node
        /// </summary>
        protected bool GetNamespace(Tag tag, string ctags_output)
        {
            string n;

            if ((n = tag.Namespace) != null)
            {
                int index = n.LastIndexOf(':');

                if (index > 0)
                {
                    n = n.Substring(index + 1);
                }

                try {
                    Tag namespaceTag = TagDatabaseManager.Instance.FindTag(
                        n, TagKind.Namespace, ctags_output);

                    if (namespaceTag != null)
                    {
                        parent = new Namespace(namespaceTag, project, ctags_output);
                    }
                } catch (IOException ex) {
                    IdeApp.Services.MessageService.ShowError(ex);
                }

                return(true);
            }

            return(false);
        }
		/// <summary>
		/// Attempts to get the namespace encompasing the function
		/// returns true on success and false if it does not have one.
		/// NOTE: if it's a method then even if the class it belongs to
		/// has a namespace the method will not have a namespace since
		/// it should be placed under the class node and not the namespace node
		/// </summary>
		protected bool GetNamespace (Tag tag, string ctags_output)
		{
			string n;
			
			if ((n = tag.Namespace) != null) {
				int index = n.LastIndexOf (':');
				
				if (index > 0)
					n = n.Substring (index + 1);
				
				try {
					Tag namespaceTag = TagDatabaseManager.Instance.FindTag (
					    n, TagKind.Namespace, ctags_output);
					
					if (namespaceTag != null)
						parent = new Namespace (namespaceTag, project, ctags_output);
					
				} catch (IOException ex) {
					LoggingService.LogInternalError (ex);
					return false;
				}
				
				return true;
			}
			
			return false;
		}
Beispiel #3
0
        /// <summary>
        /// Create an IMember from a LanguageItem,
        /// using the source document to locate declaration bounds.
        /// </summary>
        /// <param name="pi">
        /// A <see cref="ProjectInformation"/> for the current project.
        /// </param>
        /// <param name="item">
        /// A <see cref="LanguageItem"/>: The item to convert.
        /// </param>
        /// <param name="contentLines">
        /// A <see cref="System.String[]"/>: The document in which item is defined.
        /// </param>
        static IMember LanguageItemToIMember(ProjectInformation pi, LanguageItem item, string[] contentLines)
        {
            if (item is Class || item is Structure)
            {
                DomType klass = new DomType(new CompilationUnit(item.File), ClassType.Class, item.Name, new DomLocation((int)item.Line, 1), string.Empty, new DomRegion((int)item.Line + 1, FindFunctionEnd(contentLines, (int)item.Line - 1) + 2), new List <IMember> ());

                foreach (LanguageItem li in pi.AllItems())
                {
                    if (klass.Equals(li.Parent) && FilePath.Equals(li.File, item.File))
                    {
                        klass.Add(LanguageItemToIMember(pi, li, contentLines));
                    }
                }
                return(klass);
            }
            if (item is Enumeration)
            {
                return(new DomType(new CompilationUnit(item.File), ClassType.Enum, item.Name, new DomLocation((int)item.Line, 1), string.Empty, new DomRegion((int)item.Line + 1, (int)item.Line + 1), new List <IMember> ()));
            }
            if (item is Function)
            {
                return(new DomMethod(item.Name, Modifiers.None, MethodModifier.None, new DomLocation((int)item.Line, 1), new DomRegion((int)item.Line + 1, FindFunctionEnd(contentLines, (int)item.Line - 1) + 2), new DomReturnType()));
            }
            if (item is Member)
            {
                return(new DomField(item.Name, Modifiers.None, new DomLocation((int)item.Line, 1), new DomReturnType()));
            }
            return(null);
        }
        protected bool GetStructure(Tag tag, string ctags_output)
        {
            string s;

            if ((s = tag.Structure) != null)
            {
                int index = s.LastIndexOf(':');

                if (index > 0)
                {
                    s = s.Substring(index + 1);
                }

                try {
                    Tag classTag = TagDatabaseManager.Instance.FindTag(
                        s, TagKind.Structure, ctags_output);

                    if (classTag != null)
                    {
                        parent = new Structure(classTag, project, ctags_output);
                    }
                } catch (IOException ex) {
                    IdeApp.Services.MessageService.ShowError(ex);
                }

                return(true);
            }

            return(false);
        }
        protected bool GetEnumeration(Tag tag, string ctags_output)
        {
            string e;

            if ((e = tag.Enum) != null)
            {
                int index = e.LastIndexOf(':');

                if (index > 0)
                {
                    e = e.Substring(index + 1);
                }

                try {
                    Tag enumTag = TagDatabaseManager.Instance.FindTag(
                        e, TagKind.Enumeration, ctags_output);

                    if (enumTag != null)
                    {
                        parent = new Enumeration(enumTag, project, ctags_output);
                    }
                } catch (IOException ex) {
                    IdeApp.Services.MessageService.ShowError(ex);
                }

                return(true);
            }

            return(false);
        }
        protected bool GetUnion(Tag tag, string ctags_output)
        {
            string u;

            if ((u = tag.Union) != null)
            {
                int index = u.LastIndexOf(':');

                if (index > 0)
                {
                    u = u.Substring(index + 1);
                }

                try {
                    Tag unionTag = TagDatabaseManager.Instance.FindTag(
                        u, TagKind.Union, ctags_output);

                    if (unionTag != null)
                    {
                        parent = new Union(unionTag, project, ctags_output);
                    }
                } catch (IOException ex) {
                    IdeApp.Services.MessageService.ShowError(ex);
                }

                return(true);
            }

            return(false);
        }
    static IUnresolvedField LanguageItemToIField(IUnresolvedTypeDefinition type, LanguageItem item, string[] contentLines)
    {
        var result = new DefaultUnresolvedField(type, item.Name);

        result.Region = new DomRegion((int)item.Line, 1, (int)item.Line + 1, 1);
        return(result);
    }
        protected bool GetClass(Tag tag, string ctags_output)
        {
            string c;

            if ((c = tag.Class) != null)
            {
                int index = c.LastIndexOf(':');

                if (index > 0)
                {
                    c = c.Substring(index + 1);
                }

                try {
                    Tag classTag = TagDatabaseManager.Instance.FindTag(
                        c, TagKind.Class, ctags_output);

                    if (classTag != null)
                    {
                        parent = new Class(classTag, project, ctags_output);
                    }
                } catch (IOException ex) {
                    IdeApp.Services.MessageService.ShowError(ex);
                }

                return(true);
            }

            return(false);
        }
        public override bool Equals(object o)
        {
            LanguageItem other = o as LanguageItem;

            if (other != null &&
                other.FullName.Equals(FullName) &&
                other.Project.Equals(project))
            {
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Create an IMember from a LanguageItem,
        /// using the source document to locate declaration bounds.
        /// </summary>
        /// <param name="pi">
        /// A <see cref="ProjectInformation"/> for the current project.
        /// </param>
        /// <param name="item">
        /// A <see cref="LanguageItem"/>: The item to convert.
        /// </param>
        /// <param name="contentLines">
        /// A <see cref="System.String[]"/>: The document in which item is defined.
        /// </param>
        static IMember LanguageItemToIMember(ProjectInformation pi, LanguageItem item, string[] contentLines)
        {
            if (item is Class || item is Structure)
            {
                DomType klass = new DomType(new CompilationUnit(item.File), ClassType.Class, item.Name, new DomLocation((int)item.Line, 1), string.Empty, new DomRegion((int)item.Line + 1, FindFunctionEnd(contentLines, (int)item.Line - 1) + 2), new List <IMember> ());

                foreach (LanguageItem li in pi.AllItems())
                {
                    if (klass.Equals(li.Parent) && FilePath.Equals(li.File, item.File))
                    {
                        klass.Add(LanguageItemToIMember(pi, li, contentLines));
                    }
                }
                return(klass);
            }
            if (item is Enumeration)
            {
                return(new DomType(new CompilationUnit(item.File), ClassType.Enum, item.Name, new DomLocation((int)item.Line, 1), string.Empty, new DomRegion((int)item.Line + 1, (int)item.Line + 1), new List <IMember> ()));
            }
            if (item is Function)
            {
                DomMethod         method   = new DomMethod(item.Name, Modifiers.None, MethodModifier.None, new DomLocation((int)item.Line, 1), new DomRegion((int)item.Line + 1, FindFunctionEnd(contentLines, (int)item.Line - 1) + 2), new DomReturnType());
                Function          function = (Function)item;
                Match             match;
                bool              abort      = false;
                List <IParameter> parameters = new List <IParameter> ();

                foreach (string parameter in function.Parameters)
                {
                    match = paramExpression.Match(parameter);
                    if (null == match)
                    {
                        abort = true;
                        break;
                    }
                    DomParameter p = (new DomParameter(method, match.Groups["name"].Value,
                                                       new DomReturnType(string.Format("{0}{1}{2}", match.Groups["type"].Value, match.Groups["subtype"].Value, match.Groups["array"].Value))));
                    parameters.Add(p);
                }
                if (!abort)
                {
                    method.Add(parameters);
                }
                return(method);
            }
            if (item is Member)
            {
                return(new DomField(item.Name, Modifiers.None, new DomLocation((int)item.Line, 1), new DomReturnType()));
            }
            return(null);
        }
		/// <summary>
		/// Create an IMember from a LanguageItem,
		/// using the source document to locate declaration bounds.
		/// </summary>
		/// <param name="pi">
		/// A <see cref="ProjectInformation"/> for the current project.
		/// </param>
		/// <param name="item">
		/// A <see cref="LanguageItem"/>: The item to convert.
		/// </param>
		/// <param name="contentLines">
		/// A <see cref="System.String[]"/>: The document in which item is defined.
		/// </param>
		static IMember LanguageItemToIMember (ProjectInformation pi, LanguageItem item, string[] contentLines)
		{
			if (item is Class || item is Structure) {
				DomType klass = new DomType (new CompilationUnit (item.File), ClassType.Class, item.Name, new DomLocation ((int)item.Line, 1), string.Empty, new DomRegion ((int)item.Line+1, FindFunctionEnd (contentLines, (int)item.Line-1)+2), new List<IMember> ());
				
				foreach (LanguageItem li in pi.AllItems ()) {
					if (klass.Equals (li.Parent) && FilePath.Equals (li.File, item.File)) {
						klass.Add (LanguageItemToIMember (pi, li, contentLines));
					}
				}
				return klass;
			}
			if (item is Enumeration) {
				return new DomType (new CompilationUnit (item.File), ClassType.Enum, item.Name, new DomLocation ((int)item.Line, 1), string.Empty, new DomRegion ((int)item.Line+1, (int)item.Line+1), new List<IMember> ());
			}
			if (item is Function) {
				return new DomMethod (item.Name, Modifiers.None, MethodModifier.None, new DomLocation ((int)item.Line, 1), new DomRegion ((int)item.Line+1, FindFunctionEnd (contentLines, (int)item.Line-1)+2), new DomReturnType ());
			}
			if (item is Member) {
				return new DomField (item.Name, Modifiers.None, new DomLocation ((int)item.Line, 1), new DomReturnType ());
			}
			return null;
		}
		public LanguageItemEventArgs (LanguageItem item)
		{
			this.item = item;
		}
Beispiel #13
0
		static object AddLanguageItem (ProjectInformation pi, DefaultUnresolvedTypeDefinition klass, LanguageItem li, string[] contentLines)
		{
			
			if (li is Class || li is Structure || li is Enumeration) {
				var type = LanguageItemToIType (pi, li, contentLines);
				klass.NestedTypes.Add (type);
				return type;
			}
			
			if (li is Function) {
				var method = FunctionToIMethod (pi, klass, (Function)li, contentLines);
				klass.Members.Add (method);
				return method;
			}
			
			var field = LanguageItemToIField (klass, li, contentLines);
			klass.Members.Add (field);
			return field;
		}
Beispiel #14
0
		/// <summary>
		/// Create an IMember from a LanguageItem,
		/// using the source document to locate declaration bounds.
		/// </summary>
		/// <param name="pi">
		/// A <see cref="ProjectInformation"/> for the current project.
		/// </param>
		/// <param name="item">
		/// A <see cref="LanguageItem"/>: The item to convert.
		/// </param>
		/// <param name="contentLines">
		/// A <see cref="System.String[]"/>: The document in which item is defined.
		/// </param>
		static DefaultUnresolvedTypeDefinition LanguageItemToIType (ProjectInformation pi, LanguageItem item, string[] contentLines)
		{
			var klass = new DefaultUnresolvedTypeDefinition ("", item.File);
			if (item is Class || item is Structure) {
				klass.Region = new DomRegion ((int)item.Line, 1, FindFunctionEnd (contentLines, (int)item.Line-1) + 2, 1);
				klass.Kind = item is Class ? TypeKind.Class : TypeKind.Struct;
				foreach (LanguageItem li in pi.AllItems ()) {
					if (klass.Equals (li.Parent) && FilePath.Equals (li.File, item.File))
						AddLanguageItem (pi, klass, li, contentLines);
				}
				return klass;
			}
			
			klass.Region = new DomRegion ((int)item.Line, 1, (int)item.Line + 1, 1);
			klass.Kind = TypeKind.Enum;
			return klass;
		}
		protected bool GetClass (Tag tag, string ctags_output)
		{
			string c;
			
			if ((c = tag.Class) != null) {
				int index = c.LastIndexOf (':');
				
				if (index > 0)
					c = c.Substring (index + 1);
				
				try {
					Tag classTag = TagDatabaseManager.Instance.FindTag (
					    c, TagKind.Class, ctags_output);
					
					if (classTag != null)
						parent = new Class (classTag, project, ctags_output);
					
				} catch (IOException ex) {
					LoggingService.LogInternalError (ex);
					return false;
				}
				
				return true;
			}
			
			return false;
		}
Beispiel #16
0
		static IUnresolvedField LanguageItemToIField (IUnresolvedTypeDefinition type, LanguageItem item, string[] contentLines)
		{
			var result = new DefaultUnresolvedField (type, item.Name);
			result.Region = new DomRegion ((int)item.Line, 1, (int)item.Line + 1, 1);
			return result;
		}
		protected bool GetUnion (Tag tag, string ctags_output)
		{
			string u;
			
			if ((u = tag.Union) != null) {
				int index = u.LastIndexOf (':');
				
				if (index > 0)
					u = u.Substring (index + 1);
				
				try {
					Tag unionTag = TagDatabaseManager.Instance.FindTag (
					    u, TagKind.Union, ctags_output);
					
					if (unionTag != null)
						parent = new Union (unionTag, project, ctags_output);
					
				} catch (IOException ex) {
					LoggingService.LogInternalError (ex);
					return false;
				}
				
				return true;
			}
			
			return false;
		}
Beispiel #18
0
		public CompletionData (LanguageItem item)
		{
			if (item is Class)
				image = Stock.Class;
			else if (item is Structure)
				image = Stock.Struct;
			else if (item is Union)
				image = "md-union";
			else if (item is Enumeration)
				image = Stock.Enum;
			else if (item is Enumerator)
				image = Stock.Literal;
			else if (item is Function)
				image = Stock.Method;
			else if (item is Namespace)
				image = Stock.NameSpace;
			else if (item is Typedef)
				image = Stock.Interface;
			else if (item is Member)
				image = Stock.Field;
			else if (item is Variable)
				image = Stock.Field;
			else if (item is Macro)
				image = Stock.Literal;
			else
				image = Stock.Literal;
			
			this.text = item.Name;
			this.completion_string = item.Name;
			this.description = string.Empty;
		}
    static object AddLanguageItem(ProjectInformation pi, DefaultUnresolvedTypeDefinition klass, LanguageItem li, string[] contentLines)
    {
        if (li is Class || li is Structure || li is Enumeration)
        {
            var type = LanguageItemToIType(pi, li, contentLines);
            klass.NestedTypes.Add(type);
            return(type);
        }

        if (li is Function)
        {
            var method = FunctionToIMethod(pi, klass, (Function)li, contentLines);
            klass.Members.Add(method);
            return(method);
        }

        var field = LanguageItemToIField(klass, li, contentLines);

        klass.Members.Add(field);
        return(field);
    }
    /// <summary>
    /// Create an IMember from a LanguageItem,
    /// using the source document to locate declaration bounds.
    /// </summary>
    /// <param name="pi">
    /// A <see cref="ProjectInformation"/> for the current project.
    /// </param>
    /// <param name="item">
    /// A <see cref="LanguageItem"/>: The item to convert.
    /// </param>
    /// <param name="contentLines">
    /// A <see cref="System.String[]"/>: The document in which item is defined.
    /// </param>
    static DefaultUnresolvedTypeDefinition LanguageItemToIType(ProjectInformation pi, LanguageItem item, string[] contentLines)
    {
        var klass = new DefaultUnresolvedTypeDefinition("", item.File);

        if (item is Class || item is Structure)
        {
            klass.Region = new DomRegion((int)item.Line, 1, FindFunctionEnd(contentLines, (int)item.Line - 1) + 2, 1);
            klass.Kind   = item is Class ? TypeKind.Class : TypeKind.Struct;
            foreach (LanguageItem li in pi.AllItems())
            {
                if (klass.Equals(li.Parent) && FilePath.Equals(li.File, item.File))
                {
                    AddLanguageItem(pi, klass, li, contentLines);
                }
            }
            return(klass);
        }

        klass.Region = new DomRegion((int)item.Line, 1, (int)item.Line + 1, 1);
        klass.Kind   = TypeKind.Enum;
        return(klass);
    }
		protected bool GetStructure (Tag tag, string ctags_output)
		{
			string s;
			
			if ((s = tag.Structure) != null) {
				int index = s.LastIndexOf (':');
				
				if (index > 0)
					s = s.Substring (index + 1);
				
				try {
					Tag classTag = TagDatabaseManager.Instance.FindTag (
					    s, TagKind.Structure, ctags_output);
					
					if (classTag != null)
						parent = new Structure (classTag, project, ctags_output);
					
				} catch (IOException ex) {
					LoggingService.LogInternalError (ex);
					return false;
				}
				
				return true;
			}
			
			return false;
		}
		protected bool GetEnumeration (Tag tag, string ctags_output)
		{
			string e;
			
			if ((e = tag.Enum) != null) {
				int index = e.LastIndexOf (':');
				
				if (index > 0)
					e = e.Substring (index + 1);
				
				try {
					Tag enumTag = TagDatabaseManager.Instance.FindTag (
					    e, TagKind.Enumeration, ctags_output);
					
					if (enumTag != null)
						parent = new Enumeration (enumTag, project, ctags_output);
					
				} catch (IOException ex) {
					LoggingService.LogInternalError (ex);
					return false;
				}
				
				return true;
			}
			
			return false;
		}
		/// <summary>
		/// Adds completion data for children to a list
		/// </summary>
		/// <param name="list">
		/// The list to which completion data will be added
		/// <see cref="CompletionDataList"/>
		/// </param>
		/// <param name="items">
		/// A list of items to search
		/// <see cref="IEnumerable"/>
		/// </param>
		/// <param name="parent">
		/// The parent that will be matched
		/// </param>
		public static void AddItemsWithParent(CompletionDataList list, IEnumerable<LanguageItem> items, LanguageItem parent) {
			foreach (LanguageItem li in items) {
				if (li.Parent != null && li.Parent.Equals (parent))
					list.Add (new CompletionData (li));
			}
		}
		/// <summary>
		/// Create an IMember from a LanguageItem,
		/// using the source document to locate declaration bounds.
		/// </summary>
		/// <param name="pi">
		/// A <see cref="ProjectInformation"/> for the current project.
		/// </param>
		/// <param name="item">
		/// A <see cref="LanguageItem"/>: The item to convert.
		/// </param>
		/// <param name="contentLines">
		/// A <see cref="System.String[]"/>: The document in which item is defined.
		/// </param>
		static IMember LanguageItemToIMember (ProjectInformation pi, LanguageItem item, string[] contentLines)
		{
			if (item is Class || item is Structure) {
				DomType klass = new DomType (new CompilationUnit (item.File), ClassType.Class, item.Name, new DomLocation ((int)item.Line, 1), string.Empty, new DomRegion ((int)item.Line+1, FindFunctionEnd (contentLines, (int)item.Line-1)+2), new List<IMember> ());
				
				foreach (LanguageItem li in pi.AllItems ()) {
					if (klass.Equals (li.Parent) && FilePath.Equals (li.File, item.File)) {
						klass.Add (LanguageItemToIMember (pi, li, contentLines));
					}
				}
				return klass;
			}
			if (item is Enumeration) {
				return new DomType (new CompilationUnit (item.File), ClassType.Enum, item.Name, new DomLocation ((int)item.Line, 1), string.Empty, new DomRegion ((int)item.Line+1, (int)item.Line+1), new List<IMember> ());
			}
			if (item is Function) {
				DomMethod method = new DomMethod (item.Name, Modifiers.None, MethodModifier.None, new DomLocation ((int)item.Line, 1), new DomRegion ((int)item.Line+1, FindFunctionEnd (contentLines, (int)item.Line-1)+2), new DomReturnType ());
				Function function = (Function)item;
				Match match;
				bool abort = false;
				List<IParameter> parameters = new List<IParameter> ();
				
				foreach (string parameter in function.Parameters) {
					match = paramExpression.Match (parameter);
					if (null == match) {
						abort = true;
						break;
					}
					DomParameter p =  (new DomParameter (method, match.Groups["name"].Value,
					  new DomReturnType (string.Format ("{0}{1}{2}", match.Groups["type"].Value, match.Groups["subtype"].Value, match.Groups["array"].Value))));
					parameters.Add (p);
				}
				if (!abort)
					method.Add (parameters);
				return method;
			}
			if (item is Member) {
				return new DomField (item.Name, Modifiers.None, new DomLocation ((int)item.Line, 1), new DomReturnType ());
			}
			return null;
		}