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);
        }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
 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;
 }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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;
        }
Esempio n. 6
0
 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;
 }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
 public void ResolveMatchingType(PartialType type)
 {
     ResolveMatchingType(new[] { type });
 }
Esempio n. 9
0
 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;
 }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
 public void ResolveMatchingType(PartialType type)
 {
     ResolveMatchingType(new[] { type });
 }
Esempio n. 12
0
 private string resolveType(PartialType type, string unresolvedType)
 {
     return(resolveType(type, unresolvedType, null));
 }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
 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;
 }
Esempio n. 15
0
 private string resolveType(PartialType type, string unresolvedType)
 {
     return resolveType(type, unresolvedType, null);
 }