Exemplo n.º 1
0
 public Variable getVariable(string name)
 {
     if (m_variables.ContainsKey(name))
     {
         return(m_variables[name]);
     }
     if (m_parent != null)
     {
         return(m_parent.getVariable(name));
     }
     return(null);
 }
Exemplo n.º 2
0
        public Type getType(AutoCompleteData data, bool lastAsFuncion = false)
        {
            if (Elements.Count == 0)
            {
                return(null);
            }
            VariableManager variables = data.Variables;
            string          word      = Elements[0].Name;
            Type            t         = null;

            if (Elements[0].IsFunction || (Elements.Count == 1 && lastAsFuncion))
            {
                Function func = variables.getFunction(word);
                if (func != null)
                {
                    LastFunction = func;
                    t            = func.ReturnType;
                }
            }
            else
            {
                Variable var = variables.getVariable(word, Elements[0].StartPos);
                if (var != null)
                {
                    IsNamespace = var.IsNamespace;
                    t           = var.Type;
                }
                else
                {
                    t = data.Types.get(word);
                    if (t.OuterClass != null)
                    {
                        return(null);
                    }
                    IsNamespace = true;
                }
            }

            if (t == null)
            {
                return(null);
            }

            if (Elements.Count == 1)
            {
                return(t);
            }

            for (int i = 1; i < Elements.Count - 1; i++)
            {
                if (t == null)
                {
                    return(null);
                }
                string name = Elements[i].Name;

                if (Elements[i].IsFunction)
                {
                    Function f = t.getMethod(name);
                    if (f != null)
                    {
                        IsNamespace = false;
                        t           = f.ReturnType;
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    Variable v = t.getMember(name);
                    if (v != null)
                    {
                        IsNamespace = v.IsNamespace;
                        t           = v.Type;
                    }
                    else
                    {
                        Type c = t.getClass(name);
                        if (t != null)
                        {
                            IsNamespace = true;
                            t           = c;
                        }
                        else
                        {
                            return(null);
                        }
                    }
                }
            }
            if (t == null)
            {
                return(null);
            }
            //last
            string last = getLastElement();

            if (lastAsFuncion || Elements[Elements.Count - 1].IsFunction)
            {
                IsNamespace = false;
                Function f = t.getMethod(last);
                if (f != null)
                {
                    LastFunction = f;
                    return(f.ReturnType);
                }
                else
                {
                    return(t);
                }
            }
            else
            {
                Variable v = t.getMember(last);
                if (v != null)
                {
                    IsNamespace = v.IsNamespace;
                    return(v.Type);
                }
                else
                {
                    Type c = t.getClass(last);
                    if (c != null)
                    {
                        IsNamespace = true;
                        return(c);
                    }
                    else
                    {
                        return(t);
                    }
                }
            }
        }