Exemple #1
0
 def test_integerLiteral(self):
     g = JavaGrammar()
     self._parseStringTest(
         g.literal(), '123',
         Schema.IntLiteral(format='decimal', numType='int', value='123'))
     self._parseStringTest(
         g.literal(), '123l',
         Schema.IntLiteral(format='decimal', numType='long', value='123'))
     self._parseStringTest(
         g.literal(), '123L',
         Schema.IntLiteral(format='decimal', numType='long', value='123'))
     self._parseStringFailTest(g.literal(), '12a')
     self._parseStringTest(
         g.literal(), '0x123abc',
         Schema.IntLiteral(format='hex', numType='int', value='0x123abc'))
     self._parseStringTest(
         g.literal(), '0x123abcl',
         Schema.IntLiteral(format='hex', numType='long', value='0x123abc'))
     self._parseStringTest(
         g.literal(), '0x123ABCL',
         Schema.IntLiteral(format='hex', numType='long', value='0x123ABC'))
     self._parseStringFailTest(g.literal(), '0x12g')
     self._parseStringTest(
         g.literal(), '0123',
         Schema.IntLiteral(format='oct', numType='int', value='0123'))
     self._parseStringTest(
         g.literal(), '0123l',
         Schema.IntLiteral(format='oct', numType='long', value='0123'))
     self._parseStringTest(
         g.literal(), '0123L',
         Schema.IntLiteral(format='oct', numType='long', value='0123'))
     self._parseStringFailTest(g.literal(), '012a')
     self._parseStringFailTest(g.literal(), '0128')
Exemple #2
0
 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())
Exemple #3
0
 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())
Exemple #4
0
 def test_classOrInterfaceTypeRef(self):
     g = JavaGrammar()
     self._parseStringTest(g.typeExpression(), 'ArrayList',
                           Schema.ClassOrInterfaceTypeRef(name='ArrayList'))
     self._parseStringTest(
         g.typeExpression(), 'java.util.List',
         Schema.MemberTypeExp(
             target=Schema.MemberTypeExp(
                 target=Schema.ClassOrInterfaceTypeRef(name='java'),
                 member=Schema.ClassOrInterfaceTypeRef(name='util')),
             member=Schema.ClassOrInterfaceTypeRef(name='List')))
Exemple #5
0
 def test_stringLiteral(self):
     g = JavaGrammar()
     self._parseStringTest(g.literal(), '"x"',
                           Schema.StringLiteral(value='x'))
Exemple #6
0
 def test_charLiteral(self):
     g = JavaGrammar()
     self._parseStringTest(g.literal(), '\'a\'',
                           Schema.CharLiteral(value='a'))
     self._parseStringTest(g.literal(), '\'\\n\'',
                           Schema.CharLiteral(value='\\n'))
Exemple #7
0
 def shortTypeRef(self):
     return Keyword(Keywords.shortKeyword).action(
         lambda input, begin, end, x, bindings: Schema.ShortTypeRef())
Exemple #8
0
 def charTypeRef(self):
     return Keyword(Keywords.charKeyword).action(
         lambda input, begin, end, x, bindings: Schema.CharTypeRef())
Exemple #9
0
 def decimalIntLiteral(self):
     return Tokens.decimalIntegerNoOctal.action(
         lambda input, begin, end, x, bindings: Schema.IntLiteral(
             format='decimal', numType='int', value=x))
Exemple #10
0
 def test_genericTypeExp(self):
     g = JavaGrammar()
     self._parseStringTest(
         g.typeExpression(), 'ArrayList<Integer>',
         Schema.GenericTypeExp(
             target='ArrayList',
             args=[Schema.ClassOrInterfaceTypeRef(name='Integer')]))
     self._parseStringTest(
         g.typeExpression(), 'ArrayList<Integer,Double>',
         Schema.GenericTypeExp(
             target='ArrayList',
             args=[
                 Schema.ClassOrInterfaceTypeRef(name='Integer'),
                 Schema.ClassOrInterfaceTypeRef(name='Double')
             ]))
     self._parseStringTest(
         g.typeExpression(), 'X.ArrayList<Integer>',
         Schema.MemberTypeExp(
             target=Schema.ClassOrInterfaceTypeRef(name='X'),
             member=Schema.GenericTypeExp(
                 target='ArrayList',
                 args=[Schema.ClassOrInterfaceTypeRef(name='Integer')])))
     self._parseStringTest(
         g.typeExpression(), 'ArrayList<Integer>.X',
         Schema.MemberTypeExp(
             target=Schema.GenericTypeExp(
                 target='ArrayList',
                 args=[Schema.ClassOrInterfaceTypeRef(name='Integer')]),
             member=Schema.ClassOrInterfaceTypeRef(name='X')))
     self._parseStringTest(
         g.typeExpression(), 'Vector<ArrayList<Integer>>',
         Schema.GenericTypeExp(
             target='Vector',
             args=[
                 Schema.GenericTypeExp(
                     target='ArrayList',
                     args=[Schema.ClassOrInterfaceTypeRef(name='Integer')])
             ]))
     self._parseStringTest(
         g.typeExpression(), 'ArrayList<Integer[]>',
         Schema.GenericTypeExp(
             target='ArrayList',
             args=[
                 Schema.ArrayTypeExp(
                     itemTypeExp=Schema.ClassOrInterfaceTypeRef(
                         name='Integer'))
             ]))
     self._parseStringTest(
         g.typeExpression(), 'ArrayList<int[]>',
         Schema.GenericTypeExp(
             target='ArrayList',
             args=[Schema.ArrayTypeExp(itemTypeExp=Schema.IntTypeRef())]))
     self._parseStringTest(
         g.typeExpression(), 'ArrayList<? extends Q>',
         Schema.GenericTypeExp(
             target='ArrayList',
             args=[
                 Schema.WildCardTypeArgument(
                     extendsOrSuper='extends',
                     typeExp=Schema.ClassOrInterfaceTypeRef(name='Q'))
             ]))
     self._parseStringTest(
         g.typeExpression(), 'ArrayList<? super Q>',
         Schema.GenericTypeExp(
             target='ArrayList',
             args=[
                 Schema.WildCardTypeArgument(
                     extendsOrSuper='super',
                     typeExp=Schema.ClassOrInterfaceTypeRef(name='Q'))
             ]))
     self._parseStringTest(
         g.typeExpression(), 'ArrayList<?>',
         Schema.GenericTypeExp(
             target='ArrayList',
             args=[
                 Schema.WildCardTypeArgument(
                     extendsOrSuper='super',
                     typeExp=Schema.ClassOrInterfaceTypeRef(name='Q'))
             ]))
     self._parseStringFailTest(g.typeExpression(), 'ArrayList<int>')
Exemple #11
0
 def intTypeRef(self):
     return Keyword(Keywords.intKeyword).action(
         lambda input, begin, end, x, bindings: Schema.IntTypeRef())
Exemple #12
0
 def voidClassExp(self):
     return (
         Keyword(Keywords.voidKeyword) + Literal('.') +
         Keyword(Keywords.classKeyword)
     ).action(lambda input, begin, end, xs, bindings: Schema.VoidClassExp())
Exemple #13
0
 def superExp(self):
     return Keyword(Keywords.superKeyword).action(
         lambda input, begin, end, x, bindings: Schema.SuperExp())
Exemple #14
0
 def thisExp(self):
     return Keyword(Keywords.thisKeyword).action(
         lambda input, begin, end, x, bindings: Schema.ThisExp())
Exemple #15
0
 def classOrInterfaceTypeRef(self):
     return self.simpleName().action(lambda input, begin, end, x, bindings:
                                     Schema.ClassOrInterfaceTypeRef(name=x))
Exemple #16
0
 def doubleTypeRef(self):
     return Keyword(Keywords.doubleKeyword).action(
         lambda input, begin, end, x, bindings: Schema.DoubleTypeRef())
Exemple #17
0
 def floatTypeRef(self):
     return Keyword(Keywords.floatKeyword).action(
         lambda input, begin, end, x, bindings: Schema.FloatTypeRef())
Exemple #18
0
 def test_booleanLiteral(self):
     g = JavaGrammar()
     self._parseStringTest(g.literal(), 'false',
                           Schema.BooleanLiteral(value='false'))
Exemple #19
0
 def test_nullLiteral(self):
     g = JavaGrammar()
     self._parseStringTest(g.literal(), 'null', Schema.NullLiteral())
Exemple #20
0
 def classInstanceCreationExpression(self):
     return ( Keyword( Keywords.newKeyword ) + self.classOrInterfaceTypeRef() + Literal( '(' ) + SeparatedList( self.expression(), 0, -1, SeparatedList.TrailingSeparatorPolicy.NEVER ) + Literal( ')' ) ).action( \
             lambda input, begin, end, xs, bindings: Schema.ClassInstanceCreation( classTypeRef=xs[1], args=xs[3] ) )
Exemple #21
0
 def _action(input, begin, end, x, bindings):
     exp = x[0]
     for i in x[1]:
         exp = Schema.ArrayAccess(target=exp, index=i[1])
     return exp
Exemple #22
0
 def test_thisExp(self):
     g = JavaGrammar()
     self._parseStringTest(g.thisExp(), 'this', Schema.ThisExp())
Exemple #23
0
 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'))))
Exemple #24
0
 def octIntLiteral(self):
     return Tokens.octalInteger.action(
         lambda input, begin, end, x, bindings: Schema.IntLiteral(
             format='oct', numType='int', value=x))
Exemple #25
0
 def arrayCreationExpression(self):
     return ( Keyword( Keywords.newKeyword ) + ( self.classOrInterfaceTypeRef() | self.primitiveTypeRef() ) + self.dimExpr().oneOrMore() ).action( \
             lambda input, begin, end, xs, bindings: Schema.ClassInstanceCreation( classTypeRef=xs[1], args=xs[3] ) )
Exemple #26
0
 def longTypeRef(self):
     return Keyword(Keywords.longKeyword).action(
         lambda input, begin, end, x, bindings: Schema.LongTypeRef())
Exemple #27
0
 def decimalLongLiteral(self):
     return (Tokens.decimalIntegerNoOctal +
             Suppress(Literal('l') | Literal('L'))).action(
                 lambda input, begin, end, x, bindings: Schema.IntLiteral(
                     format='decimal', numType='long', value=x[0]))
Exemple #28
0
 def test_floatLiteral(self):
     g = JavaGrammar()
     self._parseStringTest(g.literal(), '123.45',
                           Schema.FloatLiteral(value='123.45'))
Exemple #29
0
 def floatLiteral(self):
     return Tokens.floatingPoint.action(
         lambda input, begin, end, x, bindings: Schema.FloatLiteral(value=x
                                                                    ))
Exemple #30
0
 def byteTypeRef(self):
     return Keyword(Keywords.byteKeyword).action(
         lambda input, begin, end, x, bindings: Schema.ByteTypeRef())