Skip to content

Commit 5781af0

Browse files
committed
#77 - Fix bug in rendering code
1 parent 3536d25 commit 5781af0

File tree

10 files changed

+145
-33
lines changed

10 files changed

+145
-33
lines changed

src/main/java/org/hibernate/models/internal/AbstractTypeDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void render(RenderingCollector collector, String name, Object attributeVa
5050

5151
@Override
5252
public void render(RenderingCollector collector, Object attributeValue) {
53-
collector.addLine( "%s = %s", attributeValue );
53+
collector.addLine( "%s", attributeValue );
5454
}
5555

5656
@Override

src/main/java/org/hibernate/models/internal/FloatTypeDescriptor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.hibernate.models.internal.jandex.FloatValueExtractor;
1212
import org.hibernate.models.internal.jandex.FloatValueWrapper;
1313
import org.hibernate.models.internal.jdk.PassThruExtractor;
14+
import org.hibernate.models.spi.RenderingCollector;
1415
import org.hibernate.models.spi.SourceModelBuildingContext;
1516
import org.hibernate.models.spi.ValueExtractor;
1617
import org.hibernate.models.spi.ValueWrapper;
@@ -59,4 +60,14 @@ public ValueExtractor<Annotation, Float> createJdkExtractor(SourceModelBuildingC
5960
public Object unwrap(Float value) {
6061
return value;
6162
}
63+
64+
@Override
65+
public void render(RenderingCollector collector, String name, Object attributeValue) {
66+
collector.addLine( "%s = %sF", name, attributeValue );
67+
}
68+
69+
@Override
70+
public void render(RenderingCollector collector, Object attributeValue) {
71+
collector.addLine( "%sF", attributeValue );
72+
}
6273
}

src/main/java/org/hibernate/models/internal/LongTypeDescriptor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.hibernate.models.internal.jandex.LongValueExtractor;
1212
import org.hibernate.models.internal.jandex.LongValueWrapper;
1313
import org.hibernate.models.internal.jdk.PassThruExtractor;
14+
import org.hibernate.models.spi.RenderingCollector;
1415
import org.hibernate.models.spi.SourceModelBuildingContext;
1516
import org.hibernate.models.spi.ValueExtractor;
1617
import org.hibernate.models.spi.ValueWrapper;
@@ -59,4 +60,14 @@ public ValueExtractor<Annotation, Long> createJdkExtractor(SourceModelBuildingCo
5960
public Object unwrap(Long value) {
6061
return value;
6162
}
63+
64+
@Override
65+
public void render(RenderingCollector collector, String name, Object attributeValue) {
66+
collector.addLine( "%s = %sL", name, attributeValue );
67+
}
68+
69+
@Override
70+
public void render(RenderingCollector collector, Object attributeValue) {
71+
collector.addLine( "%sL", attributeValue );
72+
}
6273
}

src/main/java/org/hibernate/models/internal/StringTypeDescriptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ public Object unwrap(String value) {
6363

6464
@Override
6565
public void render(RenderingCollector collector, String name, Object attributeValue) {
66-
super.render( collector, name, "\"" + attributeValue + "\"" );
66+
collector.addLine( "%s = \"%s\"", name, attributeValue );
6767
}
6868

6969
@Override
7070
public void render(RenderingCollector collector, Object attributeValue) {
71-
super.render( collector, attributeValue );
71+
collector.addLine( "\"%s\"", attributeValue );
7272
}
7373
}

src/main/java/org/hibernate/models/spi/AnnotationTarget.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.hibernate.models.AnnotationAccessException;
1919
import org.hibernate.models.IllegalCastException;
20+
import org.hibernate.models.internal.RenderingCollectorImpl;
2021

2122
/**
2223
* Abstract for something where an annotation can be {@linkplain AnnotationUsage used}.
@@ -328,6 +329,12 @@ default <T, A extends Annotation> T fromAnnotations(
328329

329330
void render();
330331

332+
default String renderToString() {
333+
final RenderingCollectorImpl renderingCollector = new RenderingCollectorImpl();
334+
render( renderingCollector );
335+
return renderingCollector.toString();
336+
}
337+
331338
void render(RenderingCollector collector);
332339

333340
/**

src/test/java/org/hibernate/models/RenderingSmokeTest.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77

88
package org.hibernate.models;
99

10+
import org.hibernate.models.annotations.AttributeAccessTests;
11+
import org.hibernate.models.annotations.EverythingBagel;
12+
import org.hibernate.models.annotations.Nested;
1013
import org.hibernate.models.annotations.SimpleEntity;
14+
import org.hibernate.models.annotations.Status;
1115
import org.hibernate.models.internal.SourceModelBuildingContextImpl;
1216
import org.hibernate.models.spi.ClassDetails;
1317

@@ -25,8 +29,34 @@ public class RenderingSmokeTest {
2529
void testRendering() {
2630
final SourceModelBuildingContextImpl buildingContext = createBuildingContext( (Index) null, SimpleEntity.class );
2731

28-
final ClassDetails classDetails = buildingContext.getClassDetailsRegistry()
29-
.resolveClassDetails( SimpleEntity.class.getName() );
32+
final ClassDetails classDetails = buildingContext.getClassDetailsRegistry().resolveClassDetails( SimpleEntity.class.getName() );
3033
classDetails.render();
3134
}
35+
36+
@Test
37+
void testRendering2() {
38+
final SourceModelBuildingContextImpl buildingContext = createBuildingContext( (org.jboss.jandex.Index) null, SimpleClass.class );
39+
final ClassDetails classDetails = buildingContext.getClassDetailsRegistry().resolveClassDetails( SimpleClass.class.getName() );
40+
41+
System.out.println( classDetails.renderToString() );
42+
}
43+
44+
45+
@EverythingBagel(
46+
theString = "hello",
47+
theEnum = Status.ACTIVE,
48+
theBoolean = true,
49+
theByte = 1,
50+
theShort = 2,
51+
theInteger = 3,
52+
theLong = 4L,
53+
theFloat = 5.1F,
54+
theDouble = 6.2,
55+
theClass = AttributeAccessTests.TheClass.class,
56+
theNested = @Nested(),
57+
theNesteds = {@Nested(), @Nested()},
58+
theStrings = {"a", "b", "c"}
59+
)
60+
public static class SimpleClass {
61+
}
3262
}

src/test/java/org/hibernate/models/annotations/AttributeAccessTests.java

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77

88
package org.hibernate.models.annotations;
99

10-
import java.lang.annotation.ElementType;
11-
import java.lang.annotation.Retention;
12-
import java.lang.annotation.RetentionPolicy;
13-
import java.lang.annotation.Target;
14-
1510
import org.hibernate.models.internal.SourceModelBuildingContextImpl;
1611
import org.hibernate.models.spi.AnnotationUsage;
1712
import org.hibernate.models.spi.ClassDetails;
@@ -71,33 +66,11 @@ void testAttributeAccess() {
7166
theDouble = 6.2,
7267
theClass = TheClass.class,
7368
theNested = @Nested(),
69+
theNesteds = {@Nested(), @Nested()},
7470
theStrings = {"a", "b", "c"}
7571
)
7672
public static class TheClass {
7773

7874
}
7975

80-
public enum Status { ACTIVE }
81-
82-
@Target(ElementType.TYPE)
83-
@Retention(RetentionPolicy.RUNTIME)
84-
public @interface Nested {
85-
}
86-
87-
@Target(ElementType.TYPE)
88-
@Retention(RetentionPolicy.RUNTIME)
89-
public @interface EverythingBagel {
90-
String theString();
91-
Status theEnum();
92-
boolean theBoolean();
93-
byte theByte();
94-
short theShort();
95-
int theInteger();
96-
long theLong();
97-
float theFloat();
98-
double theDouble();
99-
Class<?> theClass();
100-
Nested theNested();
101-
String[] theStrings();
102-
}
10376
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
* Copyright: Red Hat Inc. and Hibernate Authors
6+
*/
7+
8+
package org.hibernate.models.annotations;
9+
10+
import java.lang.annotation.ElementType;
11+
import java.lang.annotation.Retention;
12+
import java.lang.annotation.RetentionPolicy;
13+
import java.lang.annotation.Target;
14+
15+
/**
16+
* @author Steve Ebersole
17+
*/
18+
@Target(ElementType.TYPE)
19+
@Retention(RetentionPolicy.RUNTIME)
20+
public @interface EverythingBagel {
21+
String theString();
22+
23+
Status theEnum();
24+
25+
boolean theBoolean();
26+
27+
byte theByte();
28+
29+
short theShort();
30+
31+
int theInteger();
32+
33+
long theLong();
34+
35+
float theFloat();
36+
37+
double theDouble();
38+
39+
Class<?> theClass();
40+
41+
Nested theNested();
42+
43+
Nested[] theNesteds();
44+
45+
String[] theStrings();
46+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
* Copyright: Red Hat Inc. and Hibernate Authors
6+
*/
7+
8+
package org.hibernate.models.annotations;
9+
10+
import java.lang.annotation.ElementType;
11+
import java.lang.annotation.Retention;
12+
import java.lang.annotation.RetentionPolicy;
13+
import java.lang.annotation.Target;
14+
15+
/**
16+
* @author Steve Ebersole
17+
*/
18+
@Target(ElementType.TYPE)
19+
@Retention(RetentionPolicy.RUNTIME)
20+
public @interface Nested {
21+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
* Copyright: Red Hat Inc. and Hibernate Authors
6+
*/
7+
8+
package org.hibernate.models.annotations;
9+
10+
/**
11+
* @author Steve Ebersole
12+
*/
13+
public enum Status {ACTIVE}

0 commit comments

Comments
 (0)