Example #1
0
        private IdentifierHit GetType(string identifier, System.Type parent, bool allowVariables = false)
        {
            int arrayAccessIndex = identifier.IndexOf('[');

            if (arrayAccessIndex > -1)
            {
                identifier = identifier.Replace("[]", "");
            }
            int functionCallIndex = identifier.IndexOf('(');

            if (functionCallIndex > -1)
            {
                identifier = identifier.Replace("()", "");
            }
            IdentifierHit hit = new IdentifierHit()
            {
                name = identifier, isStatic = false
            };

            System.Type type = null;
            if (assembly.IsTypeName(identifier))
            {
                // Cannot call or access a static type name
                if (arrayAccessIndex > -1 || functionCallIndex > -1)
                {
                    return(null);
                }
                hit.type     = assembly.GetTypeDef(identifier).type;
                hit.isStatic = true;
            }
            else if ((type = GetMemberDataType(parent, identifier)) != null)
            {
                if (functionCallIndex > -1)
                {
                    type = Core.CompilerUtility.GetReturnType(type);
                }
                if (arrayAccessIndex > -1)
                {
                    type = type.GetElementType();
                }
                hit.type = type;
            }
            else if (allowVariables && _variables.TryGetValue(identifier, out type))
            {
                if (functionCallIndex > -1)
                {
                    type = Core.CompilerUtility.GetReturnType(type);
                }
                if (arrayAccessIndex > -1)
                {
                    type = type.GetElementType();
                }
                hit.type = type;
            }
            return(hit);
        }
Example #2
0
        private IdentifierHit GetType(string[] elements, int count)
        {
            int           i           = 1;
            IdentifierHit currentType = GetType(elements[0], contextType, true);

            while (i < elements.Length && i < count)
            {
                if (currentType == null || currentType.type == null)
                {
                    throw new System.Exception("Current Type is null, cannot trace path");
                }
                currentType = GetType(elements[i], currentType.type);
                i++;
            }
            return(currentType);
        }
Example #3
0
        public string[] Predict(string input)
        {
            if (_contextType == null)
            {
                throw new Exception("Code Helper does not have a contexttype!");
            }
            if (input == null || input == "")
            {
                return(emptyList);
            }

            if (CheckForNumeric(input))
            {
                return(emptyList);
            }

            string[]      elements = ParseIdentifierChain(input);
            List <string> output   = new List <string>();

            if (elements.Length == 1)
            {
                //UnityEngine.Debug.Log("Elem 0 " + elements[0]);
                PredictTypeFromAssembly(elements[0], output);
                PredictVariableName(elements[0], output);
                PredictMember(elements[0], contextType, output);
                PredictStaticMember(elements[0], contextType, output);
                return(output.ToArray());
            }
            else
            {
                IdentifierHit parentType = GetType(elements, elements.Length - 1);
                if (parentType.isStatic)
                {
                    PredictStaticMember(elements[elements.Length - 1], parentType.type, output);
                }
                else
                {
                    PredictMember(elements[elements.Length - 1], parentType.type, output);
                }
            }

            return(output.ToArray());
        }