Exemplo n.º 1
0
        private ISet <IMethodDeclaration> findMemberCandidates(bool checkInstance)
        {
            MethodSelector selector = methodCall.getSelector();

            if (selector.getParent() == null)
            {
                // if called from a member method, could be a member method called without this/self
                InstanceContext instance = context.getClosestInstanceContext();
                if (instance != null)
                {
                    IType type = instance.getInstanceType();
                    ConcreteCategoryDeclaration cd = context.getRegisteredDeclaration <ConcreteCategoryDeclaration>(type.GetTypeName());
                    if (cd != null)
                    {
                        MethodDeclarationMap members = cd.getMemberMethods(context, selector.getName());
                        if (members != null)
                        {
                            return(new HashSet <IMethodDeclaration>(members.Values));
                        }
                    }
                }
                return(new HashSet <IMethodDeclaration>());
            }
            else
            {
                IType parentType = selector.checkParentType(context, checkInstance);
                return(parentType != null?parentType.getMemberMethods(context, selector.getName()) : new HashSet <IMethodDeclaration>());
            }
        }
Exemplo n.º 2
0
 private IMethodDeclaration findRegistered(Context context)
 {
     if (selector.getParent() == null)
     {
         try
         {
             Object o = context.getValue(selector.getName());
             if (o is ClosureValue)
             {
                 return(getClosureDeclaration(context, (ClosureValue)o));
             }
             else if (o is ArrowValue)
             {
                 return(new ArrowDeclaration((ArrowValue)o));
             }
         }
         catch (PromptoError)
         {
         }
     }
     return(null);
 }
Exemplo n.º 3
0
        public IMethodDeclaration findCandidateReference(bool checkInstance)
        {
            MethodSelector selector = methodCall.getSelector();

            if (selector.getParent() != null)
            {
                return(null);
            }
            if (checkInstance)
            {
                if (context.hasValue(selector.getName()))
                {
                    IValue value = context.getValue(selector.getName());
                    if (value is ClosureValue)
                    {
                        return(getClosureDeclaration(context, (ClosureValue)value));
                    }

                    else if (value is ArrowValue)
                    {
                        return(getArrowDeclaration((ArrowValue)value));
                    }
                }
            }
            else
            {
                INamed named = context.getInstance(selector.getName(), true);
                if (named == null)
                {
                    return(null);
                }
                IType type = named.GetIType(context).Resolve(context);
                if (type is MethodType)
                {
                    return(((MethodType)type).Method.AsReference());
                }
            }
            return(null);
        }
Exemplo n.º 4
0
        private IMethodDeclaration getClosureDeclaration(Context context, ClosureValue closure)
        {
            IMethodDeclaration decl = closure.Method;

            if (decl.getMemberOf() != null)
            {
                // the closure references a member method (useful when a method reference is needed)
                // in which case we may simply want to return that method to avoid spilling context into method body
                // this is only true if the closure comes straight from the method's instance context
                // if the closure comes from an accessible context that is not the instance context
                // then it is a local variable that needs the closure context to be interpreted
                MethodSelector selector  = methodCall.getSelector();
                Context        declaring = context.contextForValue(selector.getName());
                if (declaring == closure.getContext())
                {
                    return(decl);
                }
            }
            return(new ClosureDeclaration(closure));
        }
Exemplo n.º 5
0
        private ISet <IMethodDeclaration> findGlobalCandidates(bool checkInstance)
        {
            MethodSelector selector = methodCall.getSelector();

            if (selector.getParent() != null)
            {
                return(new HashSet <IMethodDeclaration>());
            }
            MethodDeclarationMap globals = context.getRegisteredDeclaration <MethodDeclarationMap>(selector.getName());

            return(globals != null ? new HashSet <IMethodDeclaration>(globals.Values) : new HashSet <IMethodDeclaration>());
        }