private string resolveType(PartialType type, string unresolvedType, string defaultValue) { string currentType = defaultValue; _typeResolver( new PartialType(type.File, type.Location, unresolvedType, type.Parent, (s) => currentType = s)); return(currentType); }
private string getNamespaceFromPoint(IOutputWriter cache, PartialType type) { var currentNamespace = cache.Namespaces .FirstOrDefault(x => x.File.File == type.File.File && x.Line <= type.Location.Line); if (currentNamespace != null) return currentNamespace.Name; return null; }
private Dictionary<string, UsingAlias[]> getUsingAliasesMap(IOutputWriter cache, PartialType[] types) { var usingsAliasesMap = new Dictionary<string,UsingAlias[]>(); types.GroupBy(x => x.File.File).ToList() .ForEach(x => usingsAliasesMap.Add( x.Key, cache.UsingAliases .Where(y => y.File.File == x.Key) .Select(y => y).ToArray())); return usingsAliasesMap; }
private string getNamespaceFromPoint(IOutputWriter cache, PartialType type) { var currentNamespace = cache.Namespaces .FirstOrDefault(x => x.File.File == type.File.File && x.Line <= type.Location.Line); if (currentNamespace != null) { return(currentNamespace.Name); } return(null); }
public string Resolve(PartialType type, string typeToMatch) { if (!typeToMatch.Contains(".") && !typeToMatch.Contains("(")) return null; if (_writer.ContainsType(typeToMatch)) return typeToMatch; var chunks = getChunks(typeToMatch); string currentType = null; string currentSignature = ""; var isUsing = false; // As we are dealing with members we need to handle member (method/field) and it's // parent class/struct... var parents = new[] { type.Parent, getParent(type.Parent) }; Func<string, string> typeFromSignature = _writer.VariableTypeFromSignature; foreach (var chunk in chunks) { // Prepare loop scoped variables to default isUsing = false; currentSignature = appendToSignature(currentSignature, chunk); // Match against scoped member variables local/member currentType = matchToInstanceTypes(currentType, parents, typeFromSignature, chunk); // Match against namespaces if (currentType == null) { currentType = matchToNamespaces(currentSignature); isUsing = true; } // Reset signature fetcher (only for static a single round) typeFromSignature = _writer.VariableTypeFromSignature; // Match against static containers (if not namespace it's static) if (currentType == null) { currentType = resolveType(type, chunk); if (currentType != null) typeFromSignature = _writer.StaticMemberFromSignature; } if (currentType == null) return null; // Resolve type if (!isUsing) currentType = resolveType(type, currentType, currentType); // Set resolved type / static class as next parent parents = new[] { currentType }; } return currentType; }
private List<string> getUsings(Dictionary<string, string[]> usingsMap, PartialType type) { string[] usings; if (!usingsMap.TryGetValue(type.File.File, out usings)) usings = new string[] { }; var list = new List<string>(); var chunks = type.Parent.Split(new[] { '.' }); var currentNS = ""; foreach (var chunk in chunks) { if (currentNS != "") currentNS += "."; currentNS += chunk; list.Add(currentNS); } list.AddRange(usings); return list; }
private List <string> getUsings(Dictionary <string, string[]> usingsMap, PartialType type) { string[] usings; if (!usingsMap.TryGetValue(type.File.File, out usings)) { usings = new string[] { } } ; var list = new List <string>(); var chunks = type.Parent.Split(new[] { '.' }); var currentNS = ""; foreach (var chunk in chunks) { if (currentNS != "") { currentNS += "."; } currentNS += chunk; list.Add(currentNS); } list.AddRange(usings); return(list); }
public void ResolveMatchingType(PartialType type) { ResolveMatchingType(new[] { type }); }
private bool resolveTypeFromCache(IOutputWriter cache, Dictionary<string, string[]> usingsMap, Dictionary<string, UsingAlias[]> usingAliasesMap, PartialType type) { // Cannot do this since expressions might start with System. //if (type.Type.StartsWith("System.")) // continue; var typeToMatch = type.Type.Replace("[]", ""); var matchingType = _expression.Resolve(type, typeToMatch); if (matchingType == null) matchingType = cache.VariableTypeFromSignature(type.Parent + "." + type.Type); var usings = getUsings(usingsMap, type); if (matchingType == null) { matchingType = matchToAliases(cache, type.File.File, typeToMatch, usingAliasesMap); } if (matchingType == null) { matchingType = getMatchingType(cache, typeToMatch, usings); if (matchingType == null) matchingType = cache.FirstMatchingTypeFromName(typeToMatch); } if (matchingType != null) type.Resolve(type.Type.Replace(typeToMatch, matchingType)); return matchingType != null; }
private bool resolveTypeFromCache(IOutputWriter cache, Dictionary <string, string[]> usingsMap, Dictionary <string, UsingAlias[]> usingAliasesMap, PartialType type) { // Cannot do this since expressions might start with System. //if (type.Type.StartsWith("System.")) // continue; var typeToMatch = type.Type.Replace("[]", ""); var matchingType = _expression.Resolve(type, typeToMatch); if (matchingType == null) { matchingType = cache.VariableTypeFromSignature(type.Parent + "." + type.Type); } var usings = getUsings(usingsMap, type); if (matchingType == null) { matchingType = matchToAliases(cache, type.File.File, typeToMatch, usingAliasesMap); } if (matchingType == null) { matchingType = getMatchingType(cache, typeToMatch, usings); if (matchingType == null) { matchingType = cache.FirstMatchingTypeFromName(typeToMatch); } } if (matchingType != null) { type.Resolve(type.Type.Replace(typeToMatch, matchingType)); } return(matchingType != null); }
public void ResolveMatchingType(PartialType type) { ResolveMatchingType(new[] { type }); }
private string resolveType(PartialType type, string unresolvedType) { return(resolveType(type, unresolvedType, null)); }
public string Resolve(PartialType type, string typeToMatch) { if (!typeToMatch.Contains(".") && !typeToMatch.Contains("(")) { return(null); } if (_writer.ContainsType(typeToMatch)) { return(typeToMatch); } var chunks = getChunks(typeToMatch); string currentType = null; string currentSignature = ""; var isUsing = false; // As we are dealing with members we need to handle member (method/field) and it's // parent class/struct... var parents = new[] { type.Parent, getParent(type.Parent) }; Func <string, string> typeFromSignature = _writer.VariableTypeFromSignature; foreach (var chunk in chunks) { // Prepare loop scoped variables to default isUsing = false; currentSignature = appendToSignature(currentSignature, chunk); // Match against scoped member variables local/member currentType = matchToInstanceTypes(currentType, parents, typeFromSignature, chunk); // Match against namespaces if (currentType == null) { currentType = matchToNamespaces(currentSignature); isUsing = true; } // Reset signature fetcher (only for static a single round) typeFromSignature = _writer.VariableTypeFromSignature; // Match against static containers (if not namespace it's static) if (currentType == null) { currentType = resolveType(type, chunk); if (currentType != null) { typeFromSignature = _writer.StaticMemberFromSignature; } } if (currentType == null) { return(null); } // Resolve type if (!isUsing) { currentType = resolveType(type, currentType, currentType); } // Set resolved type / static class as next parent parents = new[] { currentType }; } return(currentType); }
private string resolveType(PartialType type, string unresolvedType, string defaultValue) { string currentType = defaultValue; _typeResolver( new PartialType(type.File, type.Location, unresolvedType, type.Parent, (s) => currentType = s)); return currentType; }
private string resolveType(PartialType type, string unresolvedType) { return resolveType(type, unresolvedType, null); }