Пример #1
0
		// Returns the longest declaration within the range.
		private CsDeclaration DoFindDeclaration(CsTypeScope scope, int offset, int length)
		{
			var decs = new List<CsDeclaration>(scope.Declarations.Length + 1);
			decs.Add(scope);
			
			CsDeclaration result = null;
			int resultLength = int.MinValue;
			
			// For every declaration,
			while (decs.Count > 0)
			{
				// if the declaration is within the range,
				CsDeclaration candidate = decs.Pop();
				if (offset <= candidate.Offset && candidate.Offset + candidate.Length <= offset + length)
				{
					// use the declaration if it is longer than what we have so far.
					if (candidate.Length > resultLength)
					{
						result = candidate;
						resultLength = candidate.Length;
					}
				}
				
				// If the declaration is a namespace or type then check the
				// inner declarations as well.
				CsTypeScope inner = candidate as CsTypeScope;
				if (inner != null)
					decs.AddRange(inner.Declarations);
			}
			
			return result;
		}
Пример #2
0
        private void DoFindTypes(CsTypeScope scope, List<CsType> types)
        {
            CsType candidate = scope as CsType;
            if (candidate != null)
                types.Add(candidate);

            for (int i = 0; i < scope.Types.Length; ++i)
                DoFindTypes(scope.Types[i], types);

            CsNamespace ns = scope as CsNamespace;
            if (ns != null)
            {
                for (int i = 0; i < ns.Namespaces.Length; ++i)
                    DoFindTypes(ns.Namespaces[i], types);
            }
        }
Пример #3
0
 private object DoGetTypes(CsTypeScope outer)
 {
     return outer.Types;
 }
Пример #4
0
 private object DoGetBody(CsTypeScope outer)
 {
     return outer.Body;
 }
Пример #5
0
 private object DoGetNamespace(CsTypeScope outer)
 {
     return outer.Namespace;
 }
Пример #6
0
 private object DoGetStructs(CsTypeScope outer)
 {
     return outer.Structs;
 }
Пример #7
0
 private object DoGetEnums(CsTypeScope outer)
 {
     return outer.Enums;
 }
Пример #8
0
 private object DoGetInterfaces(CsTypeScope outer)
 {
     return outer.Interfaces;
 }
Пример #9
0
 private object DoGetDelegates(CsTypeScope outer)
 {
     return outer.Delegates;
 }
Пример #10
0
 private object DoGetDeclarations(CsTypeScope outer)
 {
     return outer.Declarations;
 }
Пример #11
0
 private object DoGetClasses(CsTypeScope outer)
 {
     return outer.Classes;
 }
Пример #12
0
        private void DoGetDeclarations(CsTypeScope scope, string indent, List<Declaration> decs)
        {
            CsNamespace ns = scope as CsNamespace;
            if (ns != null)
            {
                foreach (CsNamespace n in ns.Namespaces)
                {
                    DoGetDeclarations(n, indent, decs);
                }

                foreach (CsType nested in scope.Types)
                {
                    DoGetDeclarations(nested, indent, decs);
                }
            }
            else
            {
                CsType type = scope as CsType;
                bool isType = (type is CsClass) || (type is CsStruct) || (type is CsInterface)  || type.DeclaringType == null;
                decs.Add(new Declaration(
                    indent + DoGetTypePrefix(type) + type.Name,
                    new NSRange(type.Offset, type.Length),
                    isType, false));

                string[] names = (from m in type.Members select DoGetShortName(m)).ToArray();
                for (int i = 0; i < names.Length - 1; ++i)
                {
                    bool ambiguous = false;
                    for (int j = i + 1; j < names.Length; ++j)
                    {
                        if (names[i] == names[j])
                        {
                            names[j] = DoGetFullName(type.Members[j]);
                            ambiguous = true;
                        }
                    }

                    if (ambiguous)
                        names[i] = DoGetFullName(type.Members[i]);
                }

                for (int i = 0; i < names.Length; ++i)
                {
                    if (!(type.Members[i] is CsField))
                        decs.Add(new Declaration(
                            indent + IndentLevel + names[i],
                            new NSRange(type.Members[i].Offset, type.Members[i].Length),
                            false, false));
                }

                foreach (CsType nested in scope.Types)
                {
                    DoGetDeclarations(nested, indent + IndentLevel, decs);
                }
            }
        }
Пример #13
0
        private void DoMatchScope(CsTypeScope scope, List<StyleRun> runs)
        {
            foreach (CsType type in scope.Types)
            {
                string name = type.GetType().Name;
                name = name.Substring(2);

                runs.Add(new StyleRun(type.NameOffset, type.Name.Length, name));

                foreach (CsMember member in type.Members)
                {
                    name = member.GetType().Name;
                    name = name.Substring(2);

                    if (member.Name != "<this>")
                        runs.Add(new StyleRun(member.NameOffset, member.Name.Length, name));
                    else
                        runs.Add(new StyleRun(member.NameOffset, member.Name.Length - 2, name));
                }

                DoMatchScope(type, runs);
            }

            CsNamespace ns = scope as CsNamespace;
            if (ns != null)
            {
                foreach (CsNamespace n in ns.Namespaces)
                {
                    DoMatchScope(n, runs);
                }
            }
        }