public static SuggestionTree <Type> BuildTypeSG() { SuggestionTree <Type> TSG = BuildPlainTypeSG_FromAssemblies(ConsideredAssemblies()); TSG.PullDownNamespaces(usings); return(TSG); }
public void PullDownNamespaces(SCG.IEnumerable <SCG.IEnumerable <string> > Namespaces) { // collect everything into a non lazy structure first var insertions = new SCG.List <SuggestionTree <Pay> .IntermFResult.single_suggestion>(); foreach (var ns in Namespaces) { var namespace_node_res = FindSequence(ns.ToArray(), last_query_is_exact: true); if (namespace_node_res.type == SuggestionTree <Pay> .FRType.unique_fit) { SuggestionTree <Pay> namespaceNode = namespace_node_res.suggs[0].val; foreach (var single_sugg in namespaceNode.FindAllWithPayload()) { insertions.Add(single_sugg); } } else { throw new Exception("no exact match for Namespace-pulling : " + string.Join(".", ns.ToArray())); // <- turn this into consumer catchable Exception as soon as user defined "usings" are a thing } } // second iteration to not intertwine access and modifying - and avoid reasoning headaches foreach (var single_sugg in insertions) { Add(single_sugg.steps, single_sugg.val.payload); // Add overrides the payload } }
/* * this whole thing is meant for fully qualified type names * since c# has inner types, both A and A.B could be a valid target for a completion with payload * -> an optional payload on inner nodes must be supported * -> leafs must be non-empty */ public bool Add(SCG.IEnumerable <string> edges, Pay payload) { // TODO: exception on null payload, want null to be used internally and get away with not doing the maybe<T> dance if (!edges.Any()) { throw new InterfaceE(); } if (edges.Any(e => string.IsNullOrEmpty(e) /*|| string.IsNullOrWhiteSpace(e)*/)) { throw new InterfaceE(); // <- empty strings as keys destroy pretty much all assumptions } // TODO !!! ^._____ not available in Unity string first = edges.First(); var Rest = edges.Skip(1); if (!Rest.Any()) { return(AddLeaf(first, payload)); } if (!D.Contains(first)) { D[first] = new SuggestionTree <Pay>(); } // D[first] is guaranteed to exist at this point, but it might be a leaf -> convert to inner node // TODO this is prob. still not enough, depending on how this is supposed to behave upon input in which a path is duplicate // for example when simulating "using directives", overrriding paths and even replacing whole subtrees must be supported // ( das braucht wahrscheinlich einen Join( SuggTree1 , SuggTree2 ) siehe lustig bunte A4 blaetter ) if (D[first] is SuggestionLeaf <Pay> ) { var nu_tree = new SuggestionTree <Pay>(); nu_tree.payload = D[first].payload; D[first] = nu_tree; } return(D[first].Add(Rest, payload)); }
static SuggestionTree <MethodInfo> BuildMethodTree(Type T, bool isStatic) { var BI = BindingFlags.Public | BindingFlags.NonPublic; BI = BI | (isStatic ? BindingFlags.Static : BindingFlags.Instance); var meths = T.GetMethods(BI); var R = new SuggestionTree <MethodInfo>(); foreach (var MI in meths) { R.Add(new [] { MI.Name }, MI); } return(R); }
static SuggestionTree <MemberInfo> BuildMembTree(Type T) { var R = new SuggestionTree <MemberInfo>(); foreach (var memI in T.GetFields(BI_inst)) { R.Add(new [] { memI.Name }, memI); } foreach (var memI in T.GetProperties(BI_inst)) { R.Add(new [] { memI.Name }, memI); } return(R); }
SCG.IEnumerable <IntermFResult.single_suggestion> rec_down(SCG.IEnumerable <string> pref) { if (payload != null) { yield return new IntermFResult.single_suggestion { steps = pref.ToArray(), val = this } } ; foreach (var kv in D.RangeAll()) { string name_edge = kv.Key; SuggestionTree <Pay> subtree = kv.Value; foreach (var sub_res in subtree.rec_down(pref.Concat(new [] { name_edge }).ToArray())) { yield return(sub_res); } } }
public static SuggestionTree <Type> BuildPlainTypeSG_FromAssemblies(IEnumerable <Assembly> assems) { if (recursion_trap) { throw new Exception("recursively building TypeSuggTree"); } else { recursion_trap = true; } // TODO : find a proper way to get the individual typenameComponents : // Namespace.Namspace.ParentTypeName.BasicBitchTypename // in particular isolate all the other potential junk that the "serialized" string properties of System.Type might contain const string name_split_pattern = @"\.|\+"; // <- prob not enough var RES = new SuggestionTree <Type> (); foreach (var assem in assems) { Console.WriteLine("loading types for " + assem.FullName); IEnumerable <Type> ts; try { ts = assem.GetTypes(); } catch (Exception e) { Console.WriteLine("\n\n !!! skipping Assembly !!! (" + e.Message + ")"); continue; } foreach (var type in ts) { RES.Add(Regex.Split(type.FullName, name_split_pattern), type); } } recursion_trap = false; return(RES); }