def test_arrayTypeExp(self): g = JavaGrammar() self._parseStringTest( g.typeExpression(), 'float []', Schema.ArrayTypeExp(itemTypeExp=Schema.FloatTypeRef())) self._parseStringTest( g.typeExpression(), 'float [][]', Schema.ArrayTypeExp(itemTypeExp=Schema.ArrayTypeExp( itemTypeExp=Schema.FloatTypeRef()))) self._parseStringTest( g.typeExpression(), 'ArrayList []', Schema.ArrayTypeExp(itemTypeExp=Schema.ClassOrInterfaceTypeRef( name='ArrayList'))) self._parseStringTest( g.typeExpression(), 'ArrayList<Integer> []', Schema.ArrayTypeExp(itemTypeExp=Schema.GenericTypeExp( target='ArrayList', args=[Schema.ClassOrInterfaceTypeRef(name='Integer')]))) self._parseStringTest( g.typeExpression(), 'java.util.List []', Schema.ArrayTypeExp(itemTypeExp=Schema.MemberTypeExp( target=Schema.MemberTypeExp( target=Schema.ClassOrInterfaceTypeRef(name='java'), member=Schema.ClassOrInterfaceTypeRef(name='util')), member=Schema.ClassOrInterfaceTypeRef(name='List'))))
def test_typeClassExp(self): g = JavaGrammar() self._parseStringTest( g.primary(), 'float.class', Schema.TypeClassExp(typeExp=Schema.FloatTypeRef())) self._parseStringTest( g.primary(), 'ArrayList<Integer>.class', Schema.TypeClassExp(typeExp=Schema.GenericTypeExp( target='ArrayList', args=[Schema.ClassOrInterfaceTypeRef(name='Integer')]))) self._parseStringTest(g.primary(), 'void.class', Schema.VoidClassExp())
def test_primitiveTypeRef(self): g = JavaGrammar() self._parseStringTest(g.typeExpression(), 'boolean', Schema.BooleanTypeRef()) self._parseStringTest(g.typeExpression(), 'byte', Schema.ByteTypeRef()) self._parseStringTest(g.typeExpression(), 'short', Schema.ShortTypeRef()) self._parseStringTest(g.typeExpression(), 'int', Schema.IntTypeRef()) self._parseStringTest(g.typeExpression(), 'long', Schema.LongTypeRef()) self._parseStringTest(g.typeExpression(), 'char', Schema.CharTypeRef()) self._parseStringTest(g.typeExpression(), 'float', Schema.FloatTypeRef()) self._parseStringTest(g.typeExpression(), 'double', Schema.DoubleTypeRef())
def floatTypeRef(self): return Keyword(Keywords.floatKeyword).action( lambda input, begin, end, x, bindings: Schema.FloatTypeRef())