diff --git a/entity-view/processor/src/main/java/com/blazebit/persistence/view/processor/ImportContextImpl.java b/entity-view/processor/src/main/java/com/blazebit/persistence/view/processor/ImportContextImpl.java index edf7a5a4cd..c426e8fb8b 100644 --- a/entity-view/processor/src/main/java/com/blazebit/persistence/view/processor/ImportContextImpl.java +++ b/entity-view/processor/src/main/java/com/blazebit/persistence/view/processor/ImportContextImpl.java @@ -96,10 +96,10 @@ public String importType(String fqcn) { imports.add(pureFqcn); } - if (inSamePackage(fqcn) || (imports.contains(pureFqcn) && canBeSimple)) { - result = unqualify(result); - } else if (inJavaLang(fqcn)) { + if (inJavaLang(fqcn)) { result = result.substring("java.lang.".length()); + } else if (inSamePackage(fqcn) || (imports.contains(pureFqcn) && canBeSimple)) { + result = unqualify(result); } if (additionalTypePart != null) { @@ -116,16 +116,21 @@ public String importType(String fqcn) { private String importTypeArguments(String typeArguments, int start, int end) { StringBuilder sb = new StringBuilder(end - start); sb.append('<'); + int currentTypeIdx = 0; start++; for (int i = start; i < end; i++) { final char c = typeArguments.charAt(i); //CHECKSTYLE:OFF: MissingSwitchDefault switch (c) { case ',': - sb.append(importType(typeArguments.substring(start, i))); + if (currentTypeIdx++ > 0) { + sb.append(", "); + } + sb.append(importType(typeArguments.substring(start, i).trim())); start = i + 1; break; case '<': + currentTypeIdx = 1; int gtIdx = typeArguments.lastIndexOf('>', i); sb.append(importTypeArguments(typeArguments, i, gtIdx)); start = gtIdx + 1; @@ -133,7 +138,10 @@ private String importTypeArguments(String typeArguments, int start, int end) { } //CHECKSTYLE:ON: MissingSwitchDefault } - sb.append(importType(typeArguments.substring(start, end))); + if (currentTypeIdx > 0) { + sb.append(", "); + } + sb.append(importType(typeArguments.substring(start, end).trim())); sb.append('>'); return sb.toString(); } diff --git a/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/ProcessorTest.java b/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/ProcessorTest.java index f638f23448..d71f411f9d 100644 --- a/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/ProcessorTest.java +++ b/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/ProcessorTest.java @@ -73,6 +73,12 @@ private Compilation test(Class... views) { CompilationSubject.assertThat(compilation) .generatedSourceFile(views[i].getName() + "Builder") .hasSourceEquivalentTo(JavaFileObjects.forResource(views[i].getName().replace('.', '/') + "Builder.java")); + CompilationSubject.assertThat(compilation) + .generatedSourceFile(views[i].getName() + "Relation") + .hasSourceEquivalentTo(JavaFileObjects.forResource(views[i].getName().replace('.', '/') + "Relation.java")); + CompilationSubject.assertThat(compilation) + .generatedSourceFile(views[i].getName() + "MultiRelation") + .hasSourceEquivalentTo(JavaFileObjects.forResource(views[i].getName().replace('.', '/') + "MultiRelation.java")); } return compilation; } diff --git a/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AView.java b/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AView.java index 4895089f06..2b4ce752a6 100644 --- a/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AView.java +++ b/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AView.java @@ -5,12 +5,14 @@ import com.blazebit.persistence.view.EntityView; import com.blazebit.persistence.view.EntityViewManager; import com.blazebit.persistence.view.MappingParameter; +import com.blazebit.persistence.view.MappingSingular; import com.blazebit.persistence.view.ViewFilter; import com.blazebit.persistence.view.ViewFilterProvider; import com.blazebit.persistence.view.filter.StartsWithFilter; import java.io.Serializable; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Set; @@ -43,6 +45,9 @@ public interface AView extends IdHolderView { @MappingParameter("listMappingParameter") List getListMappingParameter(); + @MappingSingular + Map getMap(); + class TestFilter extends ViewFilterProvider { private static final String CONSTANT = "myParam"; diff --git a/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AViewBuilder.java b/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AViewBuilder.java index ea3ec3737a..f64d88788d 100644 --- a/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AViewBuilder.java +++ b/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AViewBuilder.java @@ -32,6 +32,7 @@ public abstract class AViewBuilder listMappingParameter; + protected Map map; protected List> multiNames; protected String name; protected List names; @@ -45,6 +46,7 @@ public AViewBuilder(Map blazePersistenceOptionalParameters) { this.bytes = null; this.id = null; this.listMappingParameter = (List) blazePersistenceOptionalParameters.get("listMappingParameter"); + this.map = null; this.multiNames = (List>) (java.util.List) AView_.multiNames.getCollectionInstantiator().createCollection(0); this.name = null; this.names = (List) (java.util.List) AView_.names.getCollectionInstantiator().createCollection(0); @@ -94,6 +96,16 @@ public BuilderType withListMappingParameter(List listMappingParameter) { this.listMappingParameter = listMappingParameter; return (BuilderType) this; } + public Map getMap() { + return map; + } + public void setMap(Map map) { + this.map = map; + } + public BuilderType withMap(Map map) { + this.map = map; + return (BuilderType) this; + } public List> getMultiNames() { return multiNames; } @@ -258,6 +270,8 @@ public ElementType get(String attribute) { return (ElementType) (Object) this.id; case "listMappingParameter": return (ElementType) (Object) this.listMappingParameter; + case "map": + return (ElementType) (Object) this.map; case "multiNames": return (ElementType) (Object) this.multiNames; case "name": @@ -299,6 +313,9 @@ public BuilderType with(String attribute, Object value) { case "listMappingParameter": this.listMappingParameter = value == null ? null : (List) value; break; + case "map": + this.map = value == null ? null : (Map) value; + break; case "multiNames": this.multiNames = value == null ? (List>) (java.util.List) AView_.multiNames.getCollectionInstantiator().createCollection(0) : (List>) value; break; @@ -541,6 +558,7 @@ public AView build() { this.age, this.bytes, this.listMappingParameter, + this.map, this.multiNames, this.name, this.names, @@ -581,6 +599,10 @@ public Init withListMappingParameter(List listMappingParameter) { this.listMappingParameter = listMappingParameter; return (Init) this; } + public Init withMap(Map map) { + this.map = map; + return (Init) this; + } public Init withMultiNames(List> multiNames) { this.multiNames = multiNames; return (Init) this; @@ -624,6 +646,9 @@ public Init with(String attribute, Object value) { case "listMappingParameter": this.listMappingParameter = value == null ? null: (List) value; break; + case "map": + this.map = value == null ? null : (Map) value; + break; case "multiNames": this.multiNames = value == null ? (List>) (java.util.List) AView_.multiNames.getCollectionInstantiator().createCollection(0) : (List>) value; break; @@ -920,6 +945,7 @@ public BuilderResult build() { this.age, this.bytes, this.listMappingParameter, + this.map, this.multiNames, this.name, this.names, @@ -961,6 +987,10 @@ public Nested withListMappingParameter(List listMappin this.listMappingParameter = listMappingParameter; return (Nested) this; } + public Nested withMap(Map map) { + this.map = map; + return (Nested) this; + } public Nested withMultiNames(List> multiNames) { this.multiNames = multiNames; return (Nested) this; @@ -1004,6 +1034,9 @@ public Nested with(String attribute, Object value) { case "listMappingParameter": this.listMappingParameter = value == null ? null : (List) value; break; + case "map": + this.map = value == null ? null : (Map) value; + break; case "multiNames": this.multiNames = value == null ? (List>) (java.util.List) AView_.multiNames.getCollectionInstantiator().createCollection(0) : (List>) value; break; @@ -1287,4 +1320,4 @@ public Nested withEntry(MapAttribute implements AView, EntityViewPr private final byte[] bytes; private final Integer id; private final List listMappingParameter; + private final Map map; private final List> multiNames; private String name; private final List names; @@ -36,6 +37,7 @@ public AViewImpl(AViewImpl noop, Map blazePersistenceOptionalPar this.bytes = null; this.id = null; this.listMappingParameter = (List) blazePersistenceOptionalParameters.get("listMappingParameter"); + this.map = null; this.multiNames = (List>) (java.util.List) AView_.multiNames.getCollectionInstantiator().createCollection(0); this.name = null; this.names = (List) (java.util.List) AView_.names.getCollectionInstantiator().createCollection(0); @@ -50,6 +52,7 @@ public AViewImpl(Integer id) { this.bytes = null; this.id = id; this.listMappingParameter = null; + this.map = null; this.multiNames = (List>) (java.util.List) AView_.multiNames.getCollectionInstantiator().createCollection(0); this.name = null; this.names = (List) (java.util.List) AView_.names.getCollectionInstantiator().createCollection(0); @@ -58,12 +61,13 @@ public AViewImpl(Integer id) { this.test2 = null; } - public AViewImpl(Integer id, int age, byte[] bytes, List listMappingParameter, List> multiNames, String name, List names, Optional optionalValue, List test, X test2) { + public AViewImpl(Integer id, int age, byte[] bytes, List listMappingParameter, Map map, List> multiNames, String name, List names, Optional optionalValue, List test, X test2) { super(); this.age = age; this.bytes = bytes; this.id = id; this.listMappingParameter = listMappingParameter; + this.map = map; this.multiNames = multiNames; this.name = name; this.names = names; @@ -78,12 +82,13 @@ public AViewImpl(AViewImpl noop, int offset, Object[] tuple) { this.bytes = (byte[]) tuple[offset + 2]; this.id = (Integer) tuple[offset + 0]; this.listMappingParameter = (List) tuple[offset + 3]; - this.multiNames = (List>) tuple[offset + 4]; - this.name = (String) tuple[offset + 5]; - this.names = (List) tuple[offset + 6]; - this.optionalValue = (Optional) tuple[offset + 7]; - this.test = (List) tuple[offset + 8]; - this.test2 = (X) tuple[offset + 9]; + this.map = (Map) tuple[offset + 4]; + this.multiNames = (List>) tuple[offset + 5]; + this.name = (String) tuple[offset + 6]; + this.names = (List) tuple[offset + 7]; + this.optionalValue = (Optional) tuple[offset + 8]; + this.test = (List) tuple[offset + 9]; + this.test2 = (X) tuple[offset + 10]; } public AViewImpl(AViewImpl noop, int offset, int[] assignment, Object[] tuple) { @@ -92,12 +97,13 @@ public AViewImpl(AViewImpl noop, int offset, int[] assignment, Object[] tuple) { this.bytes = (byte[]) tuple[offset + assignment[2]]; this.id = (Integer) tuple[offset + assignment[0]]; this.listMappingParameter = (List) tuple[offset + assignment[3]]; - this.multiNames = (List>) tuple[offset + assignment[4]]; - this.name = (String) tuple[offset + assignment[5]]; - this.names = (List) tuple[offset + assignment[6]]; - this.optionalValue = (Optional) tuple[offset + assignment[7]]; - this.test = (List) tuple[offset + assignment[8]]; - this.test2 = (X) tuple[offset + assignment[9]]; + this.map = (Map) tuple[offset + assignment[4]]; + this.multiNames = (List>) tuple[offset + assignment[5]]; + this.name = (String) tuple[offset + assignment[6]]; + this.names = (List) tuple[offset + assignment[7]]; + this.optionalValue = (Optional) tuple[offset + assignment[8]]; + this.test = (List) tuple[offset + assignment[9]]; + this.test2 = (X) tuple[offset + assignment[10]]; } @Override @@ -120,6 +126,11 @@ public List getListMappingParameter() { return listMappingParameter; } + @Override + public Map getMap() { + return map; + } + @Override public List> getMultiNames() { return multiNames; diff --git a/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AViewMultiRelation.java b/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AViewMultiRelation.java index 1505b769b0..37e4bf8dce 100644 --- a/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AViewMultiRelation.java +++ b/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AViewMultiRelation.java @@ -1,6 +1,7 @@ package com.blazebit.persistence.view.processor.model; import com.blazebit.persistence.view.StaticRelation; +import com.blazebit.persistence.view.metamodel.AttributeFilterMappingPath; import com.blazebit.persistence.view.metamodel.AttributePath; import com.blazebit.persistence.view.metamodel.AttributePathWrapper; import com.blazebit.persistence.view.metamodel.MethodListAttribute; @@ -10,6 +11,7 @@ import java.io.Serializable; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Set; import javax.annotation.Generated; @@ -41,6 +43,11 @@ public AttributePath, List> listMappingParameter() { return attribute == null ? getWrapped().>get("listMappingParameter") : getWrapped().get(attribute); } + public AttributePath, Map> map() { + MethodSingularAttribute> attribute = AView_.map; + return attribute == null ? getWrapped().>get("map") : getWrapped().get(attribute); + } + public AttributePath> multiNames() { MethodMultiListAttribute> attribute = AView_.multiNames; return attribute == null ? getWrapped().>getMulti("multiNames") : getWrapped().get(attribute); @@ -75,4 +82,13 @@ public A attr() { return (A) getWrapped().getAttributes().get(getWrapped().getAttributes().size() - 1); } -} \ No newline at end of file + public AttributeFilterMappingPath id_filter() { + MethodSingularAttribute attribute = AView_.id; + return attribute == null ? new AttributeFilterMappingPath<>(getWrapped().get("id"), "") : new AttributeFilterMappingPath<>(getWrapped().get(attribute), AView_.id_filter); + } + + public AttributeFilterMappingPath name_filter() { + MethodSingularAttribute attribute = AView_.name; + return attribute == null ? new AttributeFilterMappingPath<>(getWrapped().get("name"), "") : new AttributeFilterMappingPath<>(getWrapped().get(attribute), AView_.name_filter); + } +} diff --git a/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AViewRelation.java b/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AViewRelation.java index 8d9f0a0e57..9c108038a9 100644 --- a/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AViewRelation.java +++ b/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AViewRelation.java @@ -1,6 +1,7 @@ package com.blazebit.persistence.view.processor.model; import com.blazebit.persistence.view.StaticRelation; +import com.blazebit.persistence.view.metamodel.AttributeFilterMappingPath; import com.blazebit.persistence.view.metamodel.AttributePath; import com.blazebit.persistence.view.metamodel.AttributePathWrapper; import com.blazebit.persistence.view.metamodel.MethodAttribute; @@ -9,6 +10,7 @@ import com.blazebit.persistence.view.metamodel.MethodSingularAttribute; import java.io.Serializable; import java.util.List; +import java.util.Map; import java.util.Set; import javax.annotation.Generated; @@ -40,6 +42,11 @@ public AttributePath, List> listMappingParameter() { return attribute == null ? getWrapped().>get("listMappingParameter") : getWrapped().get(attribute); } + public AttributePath, Map> map() { + MethodSingularAttribute> attribute = AView_.map; + return attribute == null ? getWrapped().>get("map") : getWrapped().get(attribute); + } + public AttributePath> multiNames() { MethodMultiListAttribute> attribute = AView_.multiNames; return attribute == null ? getWrapped().>getMulti("multiNames") : getWrapped().get(attribute); @@ -74,4 +81,13 @@ public A attr() { return (A) getWrapped().getAttributes().get(getWrapped().getAttributes().size() - 1); } -} \ No newline at end of file + public AttributeFilterMappingPath id_filter() { + MethodSingularAttribute attribute = AView_.id; + return attribute == null ? new AttributeFilterMappingPath<>(getWrapped().get("id"), "") : new AttributeFilterMappingPath<>(getWrapped().get(attribute), AView_.id_filter); + } + + public AttributeFilterMappingPath name_filter() { + MethodSingularAttribute attribute = AView_.name; + return attribute == null ? new AttributeFilterMappingPath<>(getWrapped().get("name"), "") : new AttributeFilterMappingPath<>(getWrapped().get(attribute), AView_.name_filter); + } +} diff --git a/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AView_.java b/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AView_.java index b7aa0031c3..bf0204c718 100644 --- a/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AView_.java +++ b/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/AView_.java @@ -11,6 +11,7 @@ import java.io.Serializable; import java.util.List; +import java.util.Map; import java.util.Set; import javax.annotation.Generated; @@ -22,6 +23,7 @@ public abstract class AView_ { public static volatile MethodSingularAttribute bytes; public static volatile MethodSingularAttribute id; public static volatile MethodSingularAttribute> listMappingParameter; + public static volatile MethodSingularAttribute> map; public static volatile MethodMultiListAttribute> multiNames; public static volatile MethodSingularAttribute name; public static volatile MethodListAttribute names; @@ -35,6 +37,7 @@ public abstract class AView_ { public static final String BYTES = "bytes"; public static final String ID = "id"; public static final String LIST_MAPPING_PARAMETER = "listMappingParameter"; + public static final String MAP = "map"; public static final String MULTI_NAMES = "multiNames"; public static final String NAME = "name"; public static final String NAMES = "names"; diff --git a/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/BViewMultiRelation.java b/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/BViewMultiRelation.java index bf08fe2120..db2b6d1b1e 100644 --- a/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/BViewMultiRelation.java +++ b/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/BViewMultiRelation.java @@ -1,9 +1,9 @@ package com.blazebit.persistence.view.processor.model; import com.blazebit.persistence.view.StaticRelation; +import com.blazebit.persistence.view.metamodel.AttributeFilterMappingPath; import com.blazebit.persistence.view.metamodel.AttributePath; import com.blazebit.persistence.view.metamodel.AttributePathWrapper; -import com.blazebit.persistence.view.metamodel.MethodAttribute; import com.blazebit.persistence.view.metamodel.MethodPluralAttribute; import com.blazebit.persistence.view.metamodel.MethodSingularAttribute; import java.util.Collection; @@ -36,4 +36,8 @@ public A attr() { return (A) getWrapped().getAttributes().get(getWrapped().getAttributes().size() - 1); } + public AttributeFilterMappingPath id_filter() { + MethodSingularAttribute attribute = BView_.id; + return attribute == null ? new AttributeFilterMappingPath<>(getWrapped().get("id"), "") : new AttributeFilterMappingPath<>(getWrapped().get(attribute), BView_.id_filter); + } } diff --git a/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/BViewRelation.java b/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/BViewRelation.java index b73faa05d9..992c5126cb 100644 --- a/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/BViewRelation.java +++ b/entity-view/processor/src/test/java/com/blazebit/persistence/view/processor/model/BViewRelation.java @@ -1,6 +1,7 @@ package com.blazebit.persistence.view.processor.model; import com.blazebit.persistence.view.StaticRelation; +import com.blazebit.persistence.view.metamodel.AttributeFilterMappingPath; import com.blazebit.persistence.view.metamodel.AttributePath; import com.blazebit.persistence.view.metamodel.AttributePathWrapper; import com.blazebit.persistence.view.metamodel.MethodAttribute; @@ -34,4 +35,8 @@ public A attr() { return (A) getWrapped().getAttributes().get(getWrapped().getAttributes().size() - 1); } -} \ No newline at end of file + public AttributeFilterMappingPath id_filter() { + MethodSingularAttribute attribute = BView_.id; + return attribute == null ? new AttributeFilterMappingPath<>(getWrapped().get("id"), "") : new AttributeFilterMappingPath<>(getWrapped().get(attribute), BView_.id_filter); + } +}