Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1881] Fix type parameter handling for singular mappings in entity-view-processor #1882

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -116,24 +116,32 @@ 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;
break;
}
//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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -43,6 +45,9 @@ public interface AView<X extends Serializable> extends IdHolderView<Integer> {
@MappingParameter("listMappingParameter")
List<Object> getListMappingParameter();

@MappingSingular
Map<String, String> getMap();

class TestFilter extends ViewFilterProvider {

private static final String CONSTANT = "myParam";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public abstract class AViewBuilder<X extends Serializable, BuilderType extends E
protected byte[] bytes;
protected Integer id;
protected List<Object> listMappingParameter;
protected Map<String, String> map;
protected List<Set<String>> multiNames;
protected String name;
protected List<String> names;
Expand All @@ -45,6 +46,7 @@ public AViewBuilder(Map<String, Object> blazePersistenceOptionalParameters) {
this.bytes = null;
this.id = null;
this.listMappingParameter = (List<Object>) blazePersistenceOptionalParameters.get("listMappingParameter");
this.map = null;
this.multiNames = (List<Set<String>>) (java.util.List<?>) AView_.multiNames.getCollectionInstantiator().createCollection(0);
this.name = null;
this.names = (List<String>) (java.util.List<?>) AView_.names.getCollectionInstantiator().createCollection(0);
Expand Down Expand Up @@ -94,6 +96,16 @@ public BuilderType withListMappingParameter(List<Object> listMappingParameter) {
this.listMappingParameter = listMappingParameter;
return (BuilderType) this;
}
public Map<String, String> getMap() {
return map;
}
public void setMap(Map<String, String> map) {
this.map = map;
}
public BuilderType withMap(Map<String, String> map) {
this.map = map;
return (BuilderType) this;
}
public List<Set<String>> getMultiNames() {
return multiNames;
}
Expand Down Expand Up @@ -258,6 +270,8 @@ public <ElementType> 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":
Expand Down Expand Up @@ -299,6 +313,9 @@ public BuilderType with(String attribute, Object value) {
case "listMappingParameter":
this.listMappingParameter = value == null ? null : (List<Object>) value;
break;
case "map":
this.map = value == null ? null : (Map<String, String>) value;
break;
case "multiNames":
this.multiNames = value == null ? (List<Set<String>>) (java.util.List<?>) AView_.multiNames.getCollectionInstantiator().createCollection(0) : (List<Set<String>>) value;
break;
Expand Down Expand Up @@ -541,6 +558,7 @@ public AView build() {
this.age,
this.bytes,
this.listMappingParameter,
this.map,
this.multiNames,
this.name,
this.names,
Expand Down Expand Up @@ -581,6 +599,10 @@ public Init<X> withListMappingParameter(List<Object> listMappingParameter) {
this.listMappingParameter = listMappingParameter;
return (Init<X>) this;
}
public Init<X> withMap(Map<String, String> map) {
this.map = map;
return (Init<X>) this;
}
public Init<X> withMultiNames(List<Set<String>> multiNames) {
this.multiNames = multiNames;
return (Init<X>) this;
Expand Down Expand Up @@ -624,6 +646,9 @@ public Init<X> with(String attribute, Object value) {
case "listMappingParameter":
this.listMappingParameter = value == null ? null: (List<Object>) value;
break;
case "map":
this.map = value == null ? null : (Map<String, String>) value;
break;
case "multiNames":
this.multiNames = value == null ? (List<Set<String>>) (java.util.List<?>) AView_.multiNames.getCollectionInstantiator().createCollection(0) : (List<Set<String>>) value;
break;
Expand Down Expand Up @@ -920,6 +945,7 @@ public BuilderResult build() {
this.age,
this.bytes,
this.listMappingParameter,
this.map,
this.multiNames,
this.name,
this.names,
Expand Down Expand Up @@ -961,6 +987,10 @@ public Nested<X, BuilderResult> withListMappingParameter(List<Object> listMappin
this.listMappingParameter = listMappingParameter;
return (Nested<X, BuilderResult>) this;
}
public Nested<X, BuilderResult> withMap(Map<String, String> map) {
this.map = map;
return (Nested<X, BuilderResult>) this;
}
public Nested<X, BuilderResult> withMultiNames(List<Set<String>> multiNames) {
this.multiNames = multiNames;
return (Nested<X, BuilderResult>) this;
Expand Down Expand Up @@ -1004,6 +1034,9 @@ public Nested<X, BuilderResult> with(String attribute, Object value) {
case "listMappingParameter":
this.listMappingParameter = value == null ? null : (List<Object>) value;
break;
case "map":
this.map = value == null ? null : (Map<String, String>) value;
break;
case "multiNames":
this.multiNames = value == null ? (List<Set<String>>) (java.util.List<?>) AView_.multiNames.getCollectionInstantiator().createCollection(0) : (List<Set<String>>) value;
break;
Expand Down Expand Up @@ -1287,4 +1320,4 @@ public <KeyType, ElementType> Nested<X, BuilderResult> withEntry(MapAttribute<AV
throw new IllegalArgumentException("Unknown parameter index: " + parameterIndex);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class AViewImpl<X extends Serializable> implements AView<X>, EntityViewPr
private final byte[] bytes;
private final Integer id;
private final List<Object> listMappingParameter;
private final Map<String, String> map;
private final List<Set<String>> multiNames;
private String name;
private final List<String> names;
Expand All @@ -36,6 +37,7 @@ public AViewImpl(AViewImpl noop, Map<String, Object> blazePersistenceOptionalPar
this.bytes = null;
this.id = null;
this.listMappingParameter = (List<Object>) blazePersistenceOptionalParameters.get("listMappingParameter");
this.map = null;
this.multiNames = (List<Set<String>>) (java.util.List<?>) AView_.multiNames.getCollectionInstantiator().createCollection(0);
this.name = null;
this.names = (List<String>) (java.util.List<?>) AView_.names.getCollectionInstantiator().createCollection(0);
Expand All @@ -50,6 +52,7 @@ public AViewImpl(Integer id) {
this.bytes = null;
this.id = id;
this.listMappingParameter = null;
this.map = null;
this.multiNames = (List<Set<String>>) (java.util.List<?>) AView_.multiNames.getCollectionInstantiator().createCollection(0);
this.name = null;
this.names = (List<String>) (java.util.List<?>) AView_.names.getCollectionInstantiator().createCollection(0);
Expand All @@ -58,12 +61,13 @@ public AViewImpl(Integer id) {
this.test2 = null;
}

public AViewImpl(Integer id, int age, byte[] bytes, List<Object> listMappingParameter, List<Set<String>> multiNames, String name, List<String> names, Optional<BView> optionalValue, List<X> test, X test2) {
public AViewImpl(Integer id, int age, byte[] bytes, List<Object> listMappingParameter, Map<String, String> map, List<Set<String>> multiNames, String name, List<String> names, Optional<BView> optionalValue, List<X> 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;
Expand All @@ -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<Object>) tuple[offset + 3];
this.multiNames = (List<Set<String>>) tuple[offset + 4];
this.name = (String) tuple[offset + 5];
this.names = (List<String>) tuple[offset + 6];
this.optionalValue = (Optional<BView>) tuple[offset + 7];
this.test = (List<X>) tuple[offset + 8];
this.test2 = (X) tuple[offset + 9];
this.map = (Map<String, String>) tuple[offset + 4];
this.multiNames = (List<Set<String>>) tuple[offset + 5];
this.name = (String) tuple[offset + 6];
this.names = (List<String>) tuple[offset + 7];
this.optionalValue = (Optional<BView>) tuple[offset + 8];
this.test = (List<X>) tuple[offset + 9];
this.test2 = (X) tuple[offset + 10];
}

public AViewImpl(AViewImpl noop, int offset, int[] assignment, Object[] tuple) {
Expand All @@ -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<Object>) tuple[offset + assignment[3]];
this.multiNames = (List<Set<String>>) tuple[offset + assignment[4]];
this.name = (String) tuple[offset + assignment[5]];
this.names = (List<String>) tuple[offset + assignment[6]];
this.optionalValue = (Optional<BView>) tuple[offset + assignment[7]];
this.test = (List<X>) tuple[offset + assignment[8]];
this.test2 = (X) tuple[offset + assignment[9]];
this.map = (Map<String, String>) tuple[offset + assignment[4]];
this.multiNames = (List<Set<String>>) tuple[offset + assignment[5]];
this.name = (String) tuple[offset + assignment[6]];
this.names = (List<String>) tuple[offset + assignment[7]];
this.optionalValue = (Optional<BView>) tuple[offset + assignment[8]];
this.test = (List<X>) tuple[offset + assignment[9]];
this.test2 = (X) tuple[offset + assignment[10]];
}

@Override
Expand All @@ -120,6 +126,11 @@ public List<Object> getListMappingParameter() {
return listMappingParameter;
}

@Override
public Map<String, String> getMap() {
return map;
}

@Override
public List<Set<String>> getMultiNames() {
return multiNames;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -41,6 +43,11 @@ public AttributePath<T, List<Object>, List<Object>> listMappingParameter() {
return attribute == null ? getWrapped().<List<Object>>get("listMappingParameter") : getWrapped().get(attribute);
}

public AttributePath<T, Map<String, String>, Map<String, String>> map() {
MethodSingularAttribute<AView, Map<String, String>> attribute = AView_.map;
return attribute == null ? getWrapped().<Map<String, String>>get("map") : getWrapped().get(attribute);
}

public AttributePath<T, String, Set<String>> multiNames() {
MethodMultiListAttribute<AView, String, Set<String>> attribute = AView_.multiNames;
return attribute == null ? getWrapped().<String, Set<String>>getMulti("multiNames") : getWrapped().get(attribute);
Expand Down Expand Up @@ -75,4 +82,13 @@ public A attr() {
return (A) getWrapped().getAttributes().get(getWrapped().getAttributes().size() - 1);
}

}
public AttributeFilterMappingPath<T, Integer> id_filter() {
MethodSingularAttribute<AView, Integer> attribute = AView_.id;
return attribute == null ? new AttributeFilterMappingPath<>(getWrapped().get("id"), "") : new AttributeFilterMappingPath<>(getWrapped().get(attribute), AView_.id_filter);
}

public AttributeFilterMappingPath<T, String> name_filter() {
MethodSingularAttribute<AView, String> attribute = AView_.name;
return attribute == null ? new AttributeFilterMappingPath<>(getWrapped().get("name"), "") : new AttributeFilterMappingPath<>(getWrapped().get(attribute), AView_.name_filter);
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -40,6 +42,11 @@ public AttributePath<T, List<Object>, List<Object>> listMappingParameter() {
return attribute == null ? getWrapped().<List<Object>>get("listMappingParameter") : getWrapped().get(attribute);
}

public AttributePath<T, Map<String, String>, Map<String, String>> map() {
MethodSingularAttribute<AView, Map<String, String>> attribute = AView_.map;
return attribute == null ? getWrapped().<Map<String, String>>get("map") : getWrapped().get(attribute);
}

public AttributePath<T, String, Set<String>> multiNames() {
MethodMultiListAttribute<AView, String, Set<String>> attribute = AView_.multiNames;
return attribute == null ? getWrapped().<String, Set<String>>getMulti("multiNames") : getWrapped().get(attribute);
Expand Down Expand Up @@ -74,4 +81,13 @@ public A attr() {
return (A) getWrapped().getAttributes().get(getWrapped().getAttributes().size() - 1);
}

}
public AttributeFilterMappingPath<T, Integer> id_filter() {
MethodSingularAttribute<AView, Integer> attribute = AView_.id;
return attribute == null ? new AttributeFilterMappingPath<>(getWrapped().get("id"), "") : new AttributeFilterMappingPath<>(getWrapped().get(attribute), AView_.id_filter);
}

public AttributeFilterMappingPath<T, String> name_filter() {
MethodSingularAttribute<AView, String> attribute = AView_.name;
return attribute == null ? new AttributeFilterMappingPath<>(getWrapped().get("name"), "") : new AttributeFilterMappingPath<>(getWrapped().get(attribute), AView_.name_filter);
}
}
Loading
Loading