public void TypeName_Write()
        {
            const string expected = "LP/T";
            var          actual   = new CoReTypeName(expected).ToFormattedJson();

            Assert.AreEqual(_(expected), actual);
        }
Пример #2
0
        private string GetFlatFileName(string basePath, CoReTypeName typeName, string extension)
        {
            var typePart = _typePath.ToFlatPath(typeName);
            var fileName = Path.Combine(basePath, typePart + '.' + extension);

            return(fileName);
        }
        public void SimpleIntegrationTest()
        {
            var n = new Network();

            n.ReadFile(@"C:\Users\seb\Dropbox\Shared (Mac)\smile-export.xdsl");

            var tStringBuilder = new CoReTypeName("LSystem/Text/StringBuilder");
            var rec            = new SmilePBNRecommender(tStringBuilder, n);
            var query          = new Query
            {
                type       = tStringBuilder,
                classCtx   = new CoReTypeName("LCC"),
                methodCtx  = new CoReMethodName("LMC.m()LV;"),
                definition =
                    DefinitionSites.CreateDefinitionByConstructor("LSystem/Text/StringBuilder.<init>()LSystem/Void;")
            };

            var call = CallSites.CreateReceiverCallSite("LSystem/Text/StringBuilder.ToString()LSystem/String;");

            PrintProposals("before", rec.Query(query));
            query.sites.Add(call);
            PrintProposals("added ToString", rec.Query(query));
            query.sites.Remove(call);
            PrintProposals("removed ToString", rec.Query(query));
        }
        public void TypeName_Read()
        {
            const string id       = "LP/T";
            var          actual   = _(id).ParseJsonTo <CoReTypeName>();
            var          expected = new CoReTypeName(id);

            Assert.AreEqual(expected, actual);
        }
Пример #5
0
        public void TypeAsFlat()
        {
            var          name     = new CoReTypeName("La/b/C");
            var          actual   = _sut.ToFlatPath(name);
            const string expected = "La_b_C";

            Assert.AreEqual(expected, actual);
        }
Пример #6
0
        public void ShouldConvertTypeNames(string iName, string coReName)
        {
            var expected = new CoReTypeName(coReName);
            var original = Names.Type(iName);

            var actual = original.ToCoReName();

            Assert.AreEqual(expected, actual);
        }
Пример #7
0
        public void ClassContext()
        {
            var classCtx = new CoReTypeName("LStrangeType");

            var          actual   = SmilePBNRecommenderConstants.NewClassContext(classCtx);
            const string expected = "LStrangeType";

            Assert.AreEqual(expected, actual);
        }
Пример #8
0
        public Query Find(CoReTypeName type)
        {
            var existsInCurrentScope = _typeToQuery.ContainsKey(type);

            if (existsInCurrentScope)
            {
                return(_typeToQuery[type]);
            }
            return(ParentResolver != null?ParentResolver.Find(type) : null);
        }
Пример #9
0
        public bool IsExisting(CoReTypeName type)
        {
            var exists = IsExistingInCurrentScope(type);

            if (!exists && ParentResolver != null)
            {
                return(ParentResolver.IsExisting(type));
            }
            return(exists);
        }
Пример #10
0
        public IPBNRecommender Load(CoReTypeName type)
        {
            var zipFileName = GetNestedFileName(BasePath, type, "zip");

            Asserts.That(_io.FileExists(zipFileName));

            var tmpFolder    = _io.UnzipToTempFolder(zipFileName);
            var xdslFileName = GetFlatFileName(tmpFolder, type, "xdsl");

            Asserts.That(_io.FileExists(xdslFileName));

            var network = ReadNetwork(xdslFileName);

            return(new SmilePBNRecommender(type, network));
        }
Пример #11
0
        public void DefineVariable(string id, CoReTypeName type, DefinitionSite defSite)
        {
            if (NameResolver.IsExistingInCurrentScope(id))
            {
                return;
            }

            if (NameResolver.IsExistingInCurrentScope(type))
            {
                var q = NameResolver.Find(type);
                NameResolver.Register(id, q);
            }
            else
            {
                var q = NewQueryFor(type, defSite);
                NameResolver.Register(id, q);
                NameResolver.Register(type, q);
            }
        }
Пример #12
0
        private Query NewQueryFor(CoReTypeName type, DefinitionSite defSite)
        {
            var q = new Query();

            AllQueries.Add(q);
            try
            {
                q.definition = defSite;
                q.type       = type;
                q.classCtx   = Enclosings.Type.ToCoReName();
                q.methodCtx  = Enclosings.Method.ToCoReName();
                return(q);
            }
            catch (Exception)
            {
                Console.WriteLine("failed to create new Query, falling back to Unknown");
                return(q);
            }
        }
Пример #13
0
        private static CoReTypeName GetClassContext(CoReTypeName classCtx, ITypeHierarchy typeHierarchy)
        {
            var wasLambdaCtx = IsLambdaContext(classCtx);

            if (typeHierarchy.Extends != null)
            {
                // TODO @seb: fix analysis and remove check
                // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                if (typeHierarchy.Extends.Element != null)
                {
                    classCtx = typeHierarchy.Extends.Element.ToCoReName();
                }
            }
            var isLambdaCtx = IsLambdaContext(classCtx);

            if (wasLambdaCtx && !isLambdaCtx)
            {
                return(new CoReTypeName(classCtx + "$Lambda"));
            }
            return(classCtx);
        }
Пример #14
0
 public static string NewClassContext([NotNull] CoReTypeName typeName)
 {
     return(typeName.Name);
 }
 public SmilePBNRecommender([NotNull] CoReTypeName type, [NotNull] Network network)
 {
     _type    = type;
     _network = network;
     InitializeNodes();
 }
Пример #16
0
 private static string ValidationPattern()
 {
     return(string.Format(@"{0}\.[_a-zA-Z0-9äöüßÄÖÜ]+;{0}", CoReTypeName.ValidationPattern()));
 }
Пример #17
0
        public bool IsAvailable(CoReTypeName type)
        {
            var fileName = GetNestedFileName(BasePath, type, "zip");

            return(_io.FileExists(fileName));
        }
Пример #18
0
 public bool IsExistingInCurrentScope(CoReTypeName type)
 {
     return(_typeToQuery.ContainsKey(type));
 }
Пример #19
0
 public void Register(CoReTypeName type, Query q)
 {
     Asserts.Not(_typeToQuery.ContainsKey(type), "type '{0}' is already bound in current scope", type);
     _typeToQuery.Add(type, q);
 }
Пример #20
0
 private static string ValidationPattern()
 {
     // TODO @seb: add tests for more complex names (diff chars)
     return(string.Format(@"{0}\.([^\[\]{{}}<>'`!?..,:;]+|(\<init\>))\(({0};)*\){0};", CoReTypeName.ValidationPattern()));
 }