public void TypeName_Write() { const string expected = "LP/T"; var actual = new CoReTypeName(expected).ToFormattedJson(); Assert.AreEqual(_(expected), actual); }
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); }
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); }
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); }
public void ClassContext() { var classCtx = new CoReTypeName("LStrangeType"); var actual = SmilePBNRecommenderConstants.NewClassContext(classCtx); const string expected = "LStrangeType"; Assert.AreEqual(expected, actual); }
public Query Find(CoReTypeName type) { var existsInCurrentScope = _typeToQuery.ContainsKey(type); if (existsInCurrentScope) { return(_typeToQuery[type]); } return(ParentResolver != null?ParentResolver.Find(type) : null); }
public bool IsExisting(CoReTypeName type) { var exists = IsExistingInCurrentScope(type); if (!exists && ParentResolver != null) { return(ParentResolver.IsExisting(type)); } return(exists); }
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)); }
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); } }
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); } }
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); }
public static string NewClassContext([NotNull] CoReTypeName typeName) { return(typeName.Name); }
public SmilePBNRecommender([NotNull] CoReTypeName type, [NotNull] Network network) { _type = type; _network = network; InitializeNodes(); }
private static string ValidationPattern() { return(string.Format(@"{0}\.[_a-zA-Z0-9äöüßÄÖÜ]+;{0}", CoReTypeName.ValidationPattern())); }
public bool IsAvailable(CoReTypeName type) { var fileName = GetNestedFileName(BasePath, type, "zip"); return(_io.FileExists(fileName)); }
public bool IsExistingInCurrentScope(CoReTypeName type) { return(_typeToQuery.ContainsKey(type)); }
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); }
private static string ValidationPattern() { // TODO @seb: add tests for more complex names (diff chars) return(string.Format(@"{0}\.([^\[\]{{}}<>'`!?..,:;]+|(\<init\>))\(({0};)*\){0};", CoReTypeName.ValidationPattern())); }