Ejemplo n.º 1
0
        private INode GetAlreadyBoundNode(Type t)
        {
            string[] outerClassNames = ClassNameParser.GetEnclosingClassShortNames(t);
            string   outerClassName  = outerClassNames[0];
            INode    current         = rootNode.Get(outerClassName);

            if (current == null)
            {
                throw new NameResolutionException(t.FullName, outerClassName);
            }

            for (int i = 1; i < outerClassNames.Length; i++)
            {
                current = current.Get(outerClassNames[i]);
                if (current == null)
                {
                    StringBuilder sb = new StringBuilder(outerClassName);
                    for (int j = 0; j < i; j++)
                    {
                        sb.Append(outerClassNames[j]);
                        if (j != i - 1)
                        {
                            sb.Append(".");
                        }
                    }
                    throw new NameResolutionException(t.FullName, sb.ToString());
                }
            }
            return(current);
        }
Ejemplo n.º 2
0
 public void TestGetEnclosingClassShortNameByName()
 {
     string[] path = ClassNameParser.GetEnclosingClassShortNames("Com.Microsoft.Tang.Examples.A+B+C");
     Assert.AreEqual(path[0], "A");
     Assert.AreEqual(path[1], "B");
     Assert.AreEqual(path[2], "C");
 }
Ejemplo n.º 3
0
        //starting from the root, get child for each eclosing class excluding the type itsself
        //all enclosing classes should be already in the hierarchy
        private INode GetParentNode(Type type)
        {
            INode current = rootNode;

            string[] enclosingPath = ClassNameParser.GetEnclosingClassShortNames(type);
            for (int i = 0; i < enclosingPath.Length - 1; i++)
            {
                current = current.Get(enclosingPath[i]);
            }
            return(current);
        }
Ejemplo n.º 4
0
        public INode GetNode(Type type)
        {
            this.RegisterType(type);
            INode current = rootNode;

            string[] enclosingPath = ClassNameParser.GetEnclosingClassShortNames(type);
            for (int i = 0; i < enclosingPath.Length; i++)
            {
                current = current.Get(enclosingPath[i]);
            }
            return(current);
        }
Ejemplo n.º 5
0
        //private string[] GetEnclosingClassShortNames(Type t)
        //{
        //    string[] path = t.FullName.Split('+');

        //    if (path.Length == 1)
        //    {
        //        return new string[1] { t.Name };
        //    }

        //    string[] first = path[0].Split('.');
        //    path[0] = first[first.Length - 1];
        //    return path;
        //}

        //return immidiate enclosing class
        private Type GetIEnclosingClass(Type t)
        {
            //get full name of t, parse it to check if there is any name before it like A+B
            //sample  t = Com.Microsoft.Tang.Examples.B+B1+B2
            //return type of Com.Microsoft.Tang.Examples.B+B1
            string[] path = ClassNameParser.GetEnclosingClassFullNames(t);
            if (path.Length > 1)
            {
                string p = path[path.Length - 2];
                return(GetType(p));
            }
            return(null); // TODO
        }
Ejemplo n.º 6
0
        public ProtocolJsonConverter()
        {
            executingAssembly = Assembly.GetExecutingAssembly();

            eventDictionary    = new Dictionary <string, Type>(12);
            requestDictionary  = new Dictionary <string, Type>(40);
            responseDictionary = new Dictionary <string, Type>(40);

            foreach (var type in executingAssembly.GetTypes())
            {
                string name     = null;
                Type   baseType = type.BaseType;
                if (baseType == null)
                {
                    continue;
                }
                switch (type.Namespace)
                {
                case "DebugAdapterProtocol.Protocol.Event":
                    if (baseType == typeof(Event) || (baseType.IsGenericType && baseType.GetGenericTypeDefinition() == typeof(Event <>)))
                    {
                        name = ClassNameParser.Parse(type.Name, "Event");
                        if (name != null)
                        {
                            eventDictionary.Add(name, type);
                        }
                    }
                    break;

                case "DebugAdapterProtocol.Protocol.Request":
                case "DebugAdapterProtocol.Protocol.ReverseRequest":
                    if (baseType == typeof(Request) || (baseType.IsGenericType && baseType.GetGenericTypeDefinition() == typeof(Request <>)))
                    {
                        name = ClassNameParser.Parse(type.Name, "Request");
                        if (name != null)
                        {
                            requestDictionary.Add(name, type);
                        }
                    }
                    else if (baseType == typeof(Response) || (baseType.IsGenericType && baseType.GetGenericTypeDefinition() == typeof(Response <>)))
                    {
                        name = ClassNameParser.Parse(type.Name, "Response");
                        if (name != null)
                        {
                            responseDictionary.Add(name, type);
                        }
                    }
                    break;
                }
            }
        }
        public INode GetNode(String fullName)
        {
            INode current = rootNode;

            string[] enclosingPath = ClassNameParser.GetEnclosingClassShortNames(fullName);
            for (int i = 0; i < enclosingPath.Length; i++)
            {
                current = current.Get(enclosingPath[i]);
                if (current == null)
                {
                    throw new NameResolutionException(fullName, enclosingPath[i]);
                }
            }

            return(current);
        }
Ejemplo n.º 8
0
        public void TestGetEnclosingClassShortNameByType()
        {
            var  asm     = Assembly.Load(@"Com.Microsoft.Tang.Examples");
            Type seconds = asm.GetType(@"Com.Microsoft.Tang.Examples.Timer+Seconds");
            Type B2      = asm.GetType(@"Com.Microsoft.Tang.Examples.B+B1+B2");
            Type timer   = typeof(Com.Microsoft.Tang.Examples.Timer);

            string[] pathSeconds = ClassNameParser.GetEnclosingClassShortNames(seconds);
            Assert.AreEqual(pathSeconds[0], "Timer");
            Assert.AreEqual(pathSeconds[1], "Seconds");

            string[] pathB2 = ClassNameParser.GetEnclosingClassShortNames(B2);
            Assert.AreEqual(pathB2[0], "B");
            Assert.AreEqual(pathB2[1], "B1");
            Assert.AreEqual(pathB2[2], "B2");

            string[] pathTime = ClassNameParser.GetEnclosingClassShortNames(timer);
            Assert.AreEqual(pathTime[0], "Timer");
        }
        public void UpdateClassAliases(string nameTemplate, CaseConverter converter, IUpdateBehaviour behaviour, bool dryRun)
        {
            var parser       = new ClassNameParser(nameTemplate, converter);
            var classesAdmin = Vault.ClassOperations.GetAllObjectClassesAdmin()?.Cast <ObjectClassAdmin>();

            if (classesAdmin == null)
            {
                return;
            }

            foreach (var classAdmin in classesAdmin)
            {
                UpdateAlias(classAdmin,
                            (ca) => UpdateClassAdmin(ca),
                            parser,
                            behaviour,
                            classAdmin.SemanticAliases,
                            dryRun);
            }
        }