From d622e09f4300e0641b95f48f9543d1a95e935c28 Mon Sep 17 00:00:00 2001 From: frascu Date: Sat, 17 Jul 2021 17:12:52 +0200 Subject: [PATCH] fix type parsing when the fields have annotations --- .../internal/typeparser/TypeParser.java | 4 +++ .../internal/typeparser/TypeParserTest.java | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/fieldgenerator/fieldgenerator-standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/internal/typeparser/TypeParser.java b/fieldgenerator/fieldgenerator-standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/internal/typeparser/TypeParser.java index b1b7a05a..2bf177e0 100644 --- a/fieldgenerator/fieldgenerator-standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/internal/typeparser/TypeParser.java +++ b/fieldgenerator/fieldgenerator-standard/src/main/java/com/speedment/jpastreamer/fieldgenerator/internal/typeparser/TypeParser.java @@ -49,6 +49,10 @@ private Type render(Node node) { } private Node parseNode(String s) { + // Remove annotations in the type + if (s.startsWith("@")) { + s = s.substring(s.indexOf(' ') + 1); + } // Base case returns leaf without children if (!(s.contains("<") || s.contains(","))) { return new Node(SimpleType.create(s)); diff --git a/fieldgenerator/fieldgenerator-standard/src/test/java/com/speedment/jpastreamer/fieldgenerator/internal/typeparser/TypeParserTest.java b/fieldgenerator/fieldgenerator-standard/src/test/java/com/speedment/jpastreamer/fieldgenerator/internal/typeparser/TypeParserTest.java index 4164c3aa..84b9f204 100644 --- a/fieldgenerator/fieldgenerator-standard/src/test/java/com/speedment/jpastreamer/fieldgenerator/internal/typeparser/TypeParserTest.java +++ b/fieldgenerator/fieldgenerator-standard/src/test/java/com/speedment/jpastreamer/fieldgenerator/internal/typeparser/TypeParserTest.java @@ -105,4 +105,38 @@ void renderMapOfMapOfListOfSetOfDoubleAndIntegerAndLong() { assertEquals(expected, actual); } + @Test + void renderStringWithAnnotations() { + String type = "@javax.validation.constraints.Email,@javax.validation.constraints.Size(max=255) java.lang.String"; + SimpleType expected = SimpleType.create("java.lang.String"); + Type actual = typeParser.render(type); + assertEquals(expected, actual); + } + + @Test + void renderStringWithAnnotation() { + String type = "@javax.validation.constraints.Size(max=255) java.lang.String"; + SimpleType expected = SimpleType.create("java.lang.String"); + Type actual = typeParser.render(type); + assertEquals(expected, actual); + } + + @Test + void renderMapOfStringWithAnnotations() { + String type = "@javax.validation.constraints.Email,@javax.validation.constraints.Size(max=255) java.util.Map"; + SimpleParameterizedType expected = SimpleParameterizedType.create( + SimpleType.create("java.util.Map"), SimpleType.create("java.lang.String")); + Type actual = typeParser.render(type); + assertEquals(expected, actual); + } + + @Test + void renderMapOfStringWithAnnotation() { + String type = "@javax.validation.constraints.Size(max=255) java.util.Map"; + SimpleParameterizedType expected = SimpleParameterizedType.create( + SimpleType.create("java.util.Map"), SimpleType.create("java.lang.String")); + Type actual = typeParser.render(type); + assertEquals(expected, actual); + } + }