Examples of NType


Examples of org.python.indexer.types.NType

        NBinding method = mtable.lookupType("MyClass").getTable().lookup("__init__");
        assertNotNull(method);
        assertEquals(NBinding.Kind.CONSTRUCTOR, method.getKind());
        assertEquals("classtype_builtins.MyClass.__init__", method.getQname());

        NType ftype = mtable.lookupType("MyClass").getTable().lookupType("__init__");
        assertTrue(ftype.isFuncType());

        NBinding c = mtable.lookup("MyClass");
        for (String special : new String[]{"im_class", "__class__", "im_self", "__self__"}) {
            NBinding attr = ftype.getTable().lookup(special);
            assertNotNull("missing binding for " + special, attr);
            assertEquals(c.getType(), attr.getType());
        }
    }
View Full Code Here

Examples of org.python.indexer.types.NType

            "reassign.py",
            "app.foo = 'hello'",
            "app.foo = 2");
        assertScopeBinding("reassign.app");
        NBinding nb = assertAttributeBinding("reassign.app.foo");
        NType type = nb.getType();
        assertTrue(type.isUnionType());
        Set<NType> types = ((NUnionType)type).getTypes();
        assertEquals(2, types.size());
        assertTrue(types.contains(idx.builtins.BaseStr));
        assertTrue(types.contains(idx.builtins.BaseNum));
    }
View Full Code Here

Examples of org.python.indexer.types.NType

        String src = index(
            "test.py",
            "def foo():",
            "  return (foo,)");
        assertFunctionBinding("test.foo");
        NType ftype = idx.lookupQnameType("test.foo");
        assertTrue(ftype instanceof NFuncType);
        NType rtype = ftype.asFuncType().getReturnType();
        assertTrue(rtype instanceof NTupleType);
        assertEquals(1, rtype.asTupleType().getElementTypes().size());
        assertEquals(ftype, rtype.asTupleType().getElementTypes().get(0));
        assertEquals("<FuncType=#1:_:<TupleType:[<#1>]>>", ftype.toString());
    }
View Full Code Here

Examples of org.python.indexer.types.NType

        String src = index(
            "test.py",
            "x = (2,)",
            "y = [x]",
            "x = y");
        NType xtype = idx.lookupQnameType("test.x");
        assertTrue(xtype instanceof NUnionType);

        // Jump through some hoops to allow for either order in the union.
        Set<NType> types = xtype.asUnionType().getTypes();
        assertEquals(2, types.size());
        NType[] array = types.toArray(new NType[2]);
        boolean array0List = array[0] instanceof NListType;
        boolean array1List = array[1] instanceof NListType;

        assertTrue(array0List || array1List);
        int other = array0List ? 1 : 0;
        assertTrue("Expected tuple: " + array[other], array[other].isTupleType());
        assertEquals(1, array[other].asTupleType().getElementTypes().size());
        assertEquals(idx.builtins.BaseNum, array[other].asTupleType().getElementTypes().get(0));

        String s = xtype.toString();
        int index = s.indexOf("<TupleType=#");
        assertTrue(index != -1);
        int spot = index + "<TupleType=#".length();
        int num = Integer.parseInt(s.substring(spot, spot+1));
View Full Code Here

Examples of org.python.indexer.types.NType

            "fret.py",
            "def foo(x): return x",
            "a = foo('a')",
            "b = foo('b')",
            "c = foo('c')");
        NType ftype = idx.lookupQnameType("fret.foo");
        assertEquals("<FuncType:_:<UnknownType:null>>", ftype.toString());
        NType ctype = idx.lookupQnameType("fret.c");
        assertEquals(ctype.follow(), ftype.asFuncType().getReturnType());
    }
View Full Code Here

Examples of org.python.indexer.types.NType

        String[] names = qname.split("[.&@]");
        assertConstructed(qname, offset, names[names.length-1]);
    }

    public NType getTypeBinding(String typeQname) throws Exception {
        NType type = idx.lookupQnameType(typeQname);
        assertNotNull("No recorded type for " + typeQname, type);
        return type;
    }
View Full Code Here

Examples of org.python.indexer.types.NType

    // Assert that binding for qname has exactly one type (not a union),
    // and that type has a binding with typeQname.
    public NBinding assertBindingType(String bindingQname, String typeQname) throws Exception {
        NBinding b = getBinding(bindingQname);
        NType expected = getTypeBinding(typeQname);
        assertEquals("Wrong binding type", expected, NUnknownType.follow(b.getType()));
        return b;
    }
View Full Code Here

Examples of org.python.indexer.types.NType

        return b;
    }

    public NBinding assertBindingType(String bindingQname, Class type) throws Exception {
        NBinding b = getBinding(bindingQname);
        NType btype = NUnknownType.follow(b.getType());
        assertTrue("Wrong type: expected " + type + " but was " + btype,
                   type.isInstance(btype));
        return b;
    }
View Full Code Here

Examples of org.python.indexer.types.NType

     * asserts that the List type's element type is an existing binding with
     * {@code eltTypeQname}.
     */
    public void assertListType(String bindingQname, String eltTypeQname) throws Exception {
        NBinding b = getBinding(bindingQname);
        NType btype = b.followType();
        assertTrue(btype.isListType());
        if (eltTypeQname != null) {
            NType eltType = getTypeBinding(eltTypeQname);
            assertEquals(eltType, NUnknownType.follow(btype.asListType().getElementType()));
        }
    }
View Full Code Here

Examples of org.python.indexer.types.NType

            return;
        }

        // XXX:  we've disabled support for NInstanceType for now
        NBinding b = getBinding(bindingQname);
        NType btype = b.followType();
        assertTrue(btype.isInstanceType());
        NType ctype = getTypeBinding(classQname);
        assertEquals(btype.asInstanceType().getClassType(), ctype);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.