Skip to content

Commit

Permalink
Improve trimming of annotations, fix #345
Browse files Browse the repository at this point in the history
  • Loading branch information
julgus committed Jun 20, 2023
1 parent b711410 commit 8d384de
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,21 @@ private Type fieldType(Element field) {

private String trimAnnotations(Element field) {
final String fieldType = field.asType().toString();
final int index = fieldType.lastIndexOf(' ');
return index < 0 ? fieldType : fieldType.substring(index + 1);
final List<String> annotations = field.getAnnotationMirrors().stream()
.map(Object::toString)
.filter(s -> !(s.contains("jakarta")))
.collect(Collectors.toList());
if (annotations.isEmpty() && !fieldType.contains("@")) {
final int index = fieldType.lastIndexOf(' ');
return index < 0 ? fieldType : fieldType.substring(index + 1);
}
String result = fieldType;
for (String annotation : annotations) {
result = result.replace(annotation, "");
}
result = result.replace(" ", "");
result = result.replace(",", "");
return result;
}

private Type primitiveFieldType(Type fieldType, Type entityType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
package com.speedment.jpastreamer.fieldgenerator.test;

import jakarta.persistence.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.sql.Time;
import java.time.LocalDateTime;
import java.util.*;
Expand Down Expand Up @@ -76,9 +79,13 @@ public class Film {
private Integer rentalDuration;

@Column(name = "rental_rate", columnDefinition = "decimal(4,2)")
@NotNull
@NotEmpty
private Float rentalRate;

@Column(name = "length", columnDefinition = "smallint(5)")
@NotNull
@NotEmpty
private Integer length;

@Column(name = "replacement_cost", columnDefinition = "decimal(5,2)")
Expand All @@ -87,7 +94,9 @@ public class Film {
@Column(name = "rating", columnDefinition = "enum('G','PG','PG-13','R','NC-17')")
private String rating;

@Column(name = "special_features", columnDefinition = "set('Trailers','Commentaries','Deleted Scenes','Behind the Scenes')")
@Column(name = "special_features", columnDefinition = "set('Trailers','Commentaries','Deleted Scenes','Behind the Scenes')")
@NotNull
@NotEmpty
private Set<String> specialFeatures; // Should be Set<String>

@Column(name = "last_update", nullable = false, columnDefinition = "timestamp")
Expand Down

0 comments on commit 8d384de

Please sign in to comment.