Package org.cx4a.rsense.ruby

Examples of org.cx4a.rsense.ruby.IRubyObject


    public Result resolveMethodAnnotation(Template template) {
        Method method = template.getMethod();
        if (method.getAnnotations() != null) {
            ClassType classType = RuntimeHelper.getEnclosingClassAnnotation(method.getModule());
            TemplateAttribute attr = template.getAttribute();
            IRubyObject receiver = attr.getMutableReceiver();
            IRubyObject[] args = attr.getMutableArgs();
            Vertex returnVertex = template.getReturnVertex();

            for (MethodType type : method.getAnnotations()) {
                List<TypeVariable> types = type.getTypes();
View Full Code Here


                return false;
            }

            for (int i = 0; i < list.size(); i++) {
                argType = list.get(i);
                IRubyObject arg;
                switch (argType.getType()) {
                case SPLAT: {
                    int len = Math.max(args.length - i, 0);
                    Vertex[] elements = new Vertex[len];
                    for (int j = 0; j < len; j++) {
                        elements[j] = graph.createFreeSingleTypeVertex(args[j]);
                    }
                    arg = RuntimeHelper.createArray(graph, elements);
                    break;
                }
                default:
                    arg = i < args.length ? args[i] : runtime.getNil();
                }

                if (!resolveMethodArg(template, classType, argType, receiver, arg)) {
                    return false;
                }
            }

            return true;
        }
        default:
            if (!checkArity(Arrays.asList(argType), args)) {
                //Logger.warn("Wrong number of argument");
                return false;
            }
            IRubyObject arg = args.length > 0 ? args[0] : runtime.getNil();
            return resolveMethodArg(template, classType, argType, receiver, arg);
        }
    }
View Full Code Here

            return true;
        }
        case APPLICATION: {
            TypeApplication app = (TypeApplication) argType;
            List<TypeExpression> types = app.getTypes();
            IRubyObject ret = resolveIdentity(template, app.getIdentity());
            if (!(ret instanceof RubyModule) || !arg.isKindOf((RubyModule) ret)) {
                return false;
            } else {
                RubyModule klass = (RubyModule) ret;
                ClassType klassType = RuntimeHelper.getClassAnnotation(klass);
                TypeVarMap typeVarMap = RuntimeHelper.getTypeVarMap(arg);
                if (klassType != null && typeVarMap != null) {
                    List<TypeVariable> vars = klassType.getTypes();
                    for (int i = 0; i < vars.size(); i++) {
                        TypeVariable var = vars.get(i);
                        Vertex vertex = typeVarMap.get(var);
                        if (i < types.size() && vertex != null) {
                            TypeExpression expr = types.get(i);
                            for (IRubyObject a : vertex.getTypeSet()) {
                                if (!resolveMethodArg(template, klassType, expr, receiver, a)) {
                                    return false;
                                }
                            }
                        }
                    }
                }
            }
            return true;
        }
        case SCOPED_IDENTITY:
        case ABSOLUTE_IDENTITY:
        case RELATIVE_IDENTITY: {
            IRubyObject guard = resolveIdentity(template, (TypeIdentity) argType);
            return (guard instanceof RubyClass) && arg.isKindOf((RubyClass) guard);
        }
        case UNION:
            for (TypeExpression expr : (TypeUnion) argType) {
                if (resolveMethodArg(template, classType, expr, receiver, arg)) {
View Full Code Here

            return result;
        }
        case APPLICATION: {
            TypeApplication app = (TypeApplication) returnType;
            List<TypeExpression> types = app.getTypes();
            IRubyObject ret = resolveIdentity(template, app.getIdentity());
            if (ret != null && ret instanceof RubyClass) {
                RubyClass klass = (RubyClass) ret;
                ret = graph.newInstanceOf(klass);
                ClassType klassType = RuntimeHelper.getClassAnnotation(klass);
                TypeVarMap typeVarMap = RuntimeHelper.getTypeVarMap(ret);
                if (klassType != null && typeVarMap != null) {
                    List<TypeVariable> vars = klassType.getTypes();
                    for (int i = 0; i < vars.size(); i++) {
                        TypeVariable var = vars.get(i);
                        if (i < types.size()) {
                            TypeExpression expr = types.get(i);
                            TypeSet ts = processMethodReturn(template, classType, expr, receiver);
                            Vertex vertex = graph.createFreeVertex();
                            vertex.addTypes(ts);
                            typeVarMap.put(var, vertex);
                        }
                    }
                }
                result.add(ret);
            }
            return result;
        }
        case SCOPED_IDENTITY:
        case ABSOLUTE_IDENTITY:
        case RELATIVE_IDENTITY: {
            IRubyObject ret = resolveIdentity(template, (TypeIdentity) returnType);
            if (ret != null && ret instanceof RubyClass) {
                ret = graph.newInstanceOf((RubyClass) ret);
                result.add(ret);
            }
            return result;
View Full Code Here

    public IRubyObject resolveIdentity(Template template, TypeIdentity ident, RubyModule module) {
        if (ident.getType() == TypeExpression.Type.ABSOLUTE_IDENTITY) {
            return resolveIdentity(template, ident.getPath(), runtime.getObject());
        }

        IRubyObject value = module.getConstant(ident.getName());
        if (value instanceof VertexHolder) {
            module = null;
            for (IRubyObject t : ((VertexHolder) value).getVertex().getTypeSet()) {
                if (t instanceof RubyModule) {
                    module = (RubyModule) t;
View Full Code Here

        RubyClass superClass = null;
        if (node.getSuperNode() != null) {
            Vertex v = createVertex(node.getSuperNode());
            if (v != null) {
                IRubyObject superObj = v.singleType();
                if (superObj instanceof RubyClass) {
                    superClass = (RubyClass) superObj;
                }
            }
            if (superClass == null) {
View Full Code Here

    }
   
    public Object visitColon2Node(Colon2Node node) {
        RubyModule target = RuntimeHelper.getNamespace(this, node);
        if (target != null) {
            IRubyObject value = target.getConstant(node.getName());
            if (value instanceof VertexHolder) {
                return ((VertexHolder) value).getVertex();
            } else if (value != null) {
                return createSingleTypeVertex(node, value);
            } else {
View Full Code Here

            return Vertex.EMPTY;
        }
    }
   
    public Object visitColon3Node(Colon3Node node) {
        IRubyObject value = runtime.getObject().getConstant(node.getName());
        if (value instanceof VertexHolder) {
            return ((VertexHolder) value).getVertex();
        } else if (value != null) {
            return createSingleTypeVertex(node, value);
        } else {
View Full Code Here

            return Vertex.EMPTY;
        }
    }
   
    public Object visitConstNode(ConstNode node) {
        IRubyObject value = context.getConstant(node.getName());
        if (value instanceof VertexHolder) {
            return ((VertexHolder) value).getVertex();
        } else if (value != null) {
            return createSingleTypeVertex(node, value);
        } else {
View Full Code Here

            Method singletonMethod = new DefaultMethod(cbase, name, bodyNode, argsNode, visibility, SourceLocation.of(node));
            singletonMethod.setVisibility(Visibility.PUBLIC);
            klass.getSingletonClass().addMethod(name, singletonMethod);
        }

        IRubyObject receiver = newInstanceOf((klass instanceof RubyClass) ? (RubyClass) klass : runtime.getObject());
       
        RuntimeHelper.methodPartialUpdate(this, node, newMethod, oldMethod, receiver);
        RuntimeHelper.setMethodTag(newMethod, node, AnnotationHelper.parseAnnotations(node.getCommentList(), node.getPosition().getStartLine()));

        dummyCallQueue.offer(new DummyCall(node, newMethod, oldMethod, receiver));
View Full Code Here

TOP

Related Classes of org.cx4a.rsense.ruby.IRubyObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.