Ejemplo n.º 1
0
        public void MissingParameters()
        {
            var lexer  = new DescriptorLexer("V".AsMemory());
            var parser = new MethodDescriptorParser(lexer.Lex());

            Assert.Throws <DescriptorParserException>(() => parser.Parse());
        }
Ejemplo n.º 2
0
        public void ArrayGeneric()
        {
            var lexer      = new DescriptorLexer("([[Ljava/util/Pair<[Lcom/company/CustomStuff;[[[Ljava/lang/String;>;)[[[[Ljava/util/HashMap<Ljava/lang/Integer;Ljava/lang/String;>;".AsMemory());
            var parser     = new MethodDescriptorParser(lexer.Lex());
            var descriptor = parser.Parse();

            Assert.Equal(1, descriptor.Parameters.Count);
            Assert.IsType <NonPrimitiveFieldDescriptor>(descriptor.Parameters[0]);
            Assert.Equal(2, descriptor.Parameters[0].ArrayRank);
            var pair = (NonPrimitiveFieldDescriptor)descriptor.Parameters[0];

            Assert.Equal("java/util/Pair", pair.ClassName);
            Assert.Equal(2, pair.GenericParameters.Count);
            Assert.Equal(1, pair.GenericParameters[0].ArrayRank);
            Assert.Equal("com/company/CustomStuff", Assert.IsType <NonPrimitiveFieldDescriptor>(pair.GenericParameters[0]).ClassName);
            Assert.Equal(3, pair.GenericParameters[1].ArrayRank);
            Assert.Equal("java/lang/String", Assert.IsType <NonPrimitiveFieldDescriptor>(pair.GenericParameters[1]).ClassName);
            Assert.IsType <NonPrimitiveFieldDescriptor>(descriptor.ReturnType);
            var returnType = (NonPrimitiveFieldDescriptor)descriptor.ReturnType;

            Assert.Equal(4, returnType.ArrayRank);
            Assert.Equal("java/util/HashMap", returnType.ClassName);
            Assert.Equal(2, returnType.GenericParameters.Count);
            Assert.Equal("java/lang/Integer", Assert.IsType <NonPrimitiveFieldDescriptor>(returnType.GenericParameters[0]).ClassName);
            Assert.Equal("java/lang/String", Assert.IsType <NonPrimitiveFieldDescriptor>(returnType.GenericParameters[1]).ClassName);
        }
Ejemplo n.º 3
0
        public void AllNonPrimitive(string input, string[] parameters, string returnType)
        {
            var lexer      = new DescriptorLexer(input.AsMemory());
            var parser     = new MethodDescriptorParser(lexer.Lex());
            var descriptor = parser.Parse();

            for (int i = 0; i < descriptor.Parameters.Count; i++)
            {
                Assert.Equal(parameters[i], Assert.IsType <NonPrimitiveFieldDescriptor>(descriptor.Parameters[i]).ClassName);
            }

            Assert.Equal(returnType, Assert.IsType <NonPrimitiveFieldDescriptor>(descriptor.ReturnType).ClassName);
        }
Ejemplo n.º 4
0
        public void ArrayAllPrimitive(string input, PrimitiveKind[] parameterTypes, int[] parameterArrayRanks, PrimitiveKind returnType, int returnArrayRank)
        {
            var lexer      = new DescriptorLexer(input.AsMemory());
            var parser     = new MethodDescriptorParser(lexer.Lex());
            var descriptor = parser.Parse();

            for (int i = 0; i < descriptor.Parameters.Count; i++)
            {
                Assert.Equal(parameterTypes[i], Assert.IsType <PrimitiveFieldDescriptor>(descriptor.Parameters[i]).Kind);
                Assert.Equal(parameterArrayRanks[i], descriptor.Parameters[i].ArrayRank);
            }

            Assert.Equal(returnType, Assert.IsType <PrimitiveFieldDescriptor>(descriptor.ReturnType).Kind);
            Assert.Equal(returnArrayRank, descriptor.ReturnType.ArrayRank);
        }