Skip to content

Commit

Permalink
Binding -> Bind
Browse files Browse the repository at this point in the history
  • Loading branch information
safris committed Aug 15, 2023
1 parent febe92e commit 88f5e50
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 64 deletions.
6 changes: 3 additions & 3 deletions generator/src/main/java/org/jsonx/AnyModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ private AnyModel(final Registry registry, final Declarer declarer, final AnyProp
final Class<?> requiredFieldType = types.length == 0 ? defaultClass() : getFieldType(types);
final boolean isRegex = isMultiRegex(property.name());
if (isRegex && !Map.class.isAssignableFrom(getMethod.getReturnType()))
throw new IllegalAnnotationException(property, getMethod.getDeclaringClass().getName() + "." + fieldName + ": @" + AnyProperty.class.getSimpleName() + " of type " + Binding.Type.getClassName(getMethod, property.nullable(), property.use()) + " with regex name=\"" + property.name() + "\" must be of type that extends " + Map.class.getName());
throw new IllegalAnnotationException(property, getMethod.getDeclaringClass().getName() + "." + fieldName + ": @" + AnyProperty.class.getSimpleName() + " of type " + Bind.Type.getClassName(getMethod, property.nullable(), property.use()) + " with regex name=\"" + property.name() + "\" must be of type that extends " + Map.class.getName());

if (!isAssignable(getMethod, true, requiredFieldType, isRegex, property.nullable(), property.use()))
throw new IllegalAnnotationException(property, getMethod.getDeclaringClass().getName() + "." + fieldName + ": @" + AnyProperty.class.getSimpleName() + " of type " + Binding.Type.getClassName(getMethod, property.nullable(), property.use()) + " is not assignable for the specified types attribute");
throw new IllegalAnnotationException(property, getMethod.getDeclaringClass().getName() + "." + fieldName + ": @" + AnyProperty.class.getSimpleName() + " of type " + Bind.Type.getClassName(getMethod, property.nullable(), property.use()) + " is not assignable for the specified types attribute");

validateTypeBinding();
}
Expand Down Expand Up @@ -407,7 +407,7 @@ Registry.Type typeDefault(final boolean primitive) {
}

@Override
String isValid(final Binding.Type typeBinding) {
String isValid(final Bind.Type typeBinding) {
return typeBinding.type == null ? null : "Cannot override the type for \"any\"";
}

Expand Down
2 changes: 1 addition & 1 deletion generator/src/main/java/org/jsonx/ArrayModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ Registry.Type typeDefault(final boolean primitive) {
}

@Override
String isValid(final Binding.Type typeBinding) {
String isValid(final Bind.Type typeBinding) {
return typeBinding.type == null ? null : "Cannot override the type for \"array\"";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,10 @@
import org.libj.lang.ObjectUtil;
import org.libj.util.ArrayUtil;

final class Binding {
final class Bind {
static class Type {
static Type from(final Registry registry, final $TypeBinding.Type$ type, final $TypeBinding.Decode$ decode, final $TypeBinding.Encode$ encode) {
return type == null && decode == null && encode == null ? null : new Type(registry, type == null ? null : type.text(), decode == null ? null : decode.text(), encode == null ? null : encode.text());
// return (type == null || type.text() == null) && (decode == null || decode.text() == null) && (encode == null || encode.text() == null) ? null : new Type(registry, type == null ? null : type.text(), decode == null ? null : decode.text(), encode == null ? null : encode.text());
}

static Type from2(final Type typeBinding, final $TypeBinding.Decode$ decode, final $TypeBinding.Encode$ encode) {
return (typeBinding == null || typeBinding.type == null) && decode == null && encode == null ? null : new Type(typeBinding, decode, encode);
}

static Type from(final Registry registry, final Method getMethod, final boolean nullable, final Use use, final String decode, final String encode, final Class<?> defaultClass) {
Expand Down Expand Up @@ -248,6 +243,6 @@ public static Map<String,Object> toXmlAttributes(final Element owner, final Type
return attributes;
}

private Binding() {
private Bind() {
}
}
18 changes: 9 additions & 9 deletions generator/src/main/java/org/jsonx/BooleanModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ static Reference referenceOrDeclare(final Registry registry, final Referrer<?> r
}

static Reference referenceOrDeclare(final Registry registry, final Referrer<?> referrer, final BooleanElement element) {
final BooleanModel model = new BooleanModel(registry, referrer, element.nullable(), Binding.Type.from(registry, element.type(), element.decode(), element.encode(), Boolean.class));
final BooleanModel model = new BooleanModel(registry, referrer, element.nullable(), Bind.Type.from(registry, element.type(), element.decode(), element.encode(), Boolean.class));
final Id id = model.id();

final BooleanModel registered = (BooleanModel)registry.getModel(id);
Expand All @@ -221,7 +221,7 @@ static Reference referenceOrDeclare(final Registry registry, final Referrer<?> r

static BooleanModel referenceOrDeclare(final Registry registry, final Referrer<?> referrer, final BooleanType type) {
// Note: Explicitly setting nullable=false, because nullable for *Type annotations is set at the AnyElement/AnyProperty level
final BooleanModel model = new BooleanModel(registry, referrer, false, Binding.Type.from(registry, type.type(), type.decode(), type.encode(), Boolean.class));
final BooleanModel model = new BooleanModel(registry, referrer, false, Bind.Type.from(registry, type.type(), type.decode(), type.encode(), Boolean.class));
final Id id = model.id();

final BooleanModel registered = (BooleanModel)registry.getModel(id);
Expand All @@ -246,25 +246,25 @@ private static BooleanModel newBooleanModel(final Registry registry, final Decla
if (binding == null)
return new BooleanModel(registry, declarer, xsb, null, null);

return new BooleanModel(registry, declarer, xsb, binding.getField$(), Binding.Type.from(registry, binding.getType$(), binding.getDecode$(), binding.getEncode$()));
return new BooleanModel(registry, declarer, xsb, binding.getField$(), Bind.Type.from(registry, binding.getType$(), binding.getDecode$(), binding.getEncode$()));
}

private BooleanModel(final Registry registry, final Declarer declarer, final $Boolean xsb, final $FieldIdentifier fieldName, final Binding.Type typeBinding) {
private BooleanModel(final Registry registry, final Declarer declarer, final $Boolean xsb, final $FieldIdentifier fieldName, final Bind.Type typeBinding) {
super(registry, declarer, Id.hashed("b", typeBinding), xsb.getDoc$(), xsb.getName$(), xsb.getNullable$(), xsb.getUse$(), fieldName, typeBinding);
validateTypeBinding();
}

private BooleanModel(final Registry registry, final Declarer declarer, final $Array.Boolean xsb, final Binding.Type typeBinding) {
private BooleanModel(final Registry registry, final Declarer declarer, final $Array.Boolean xsb, final Bind.Type typeBinding) {
super(registry, declarer, Id.hashed("b", typeBinding), xsb.getDoc$(), xsb.getNullable$(), xsb.getMinOccurs$(), xsb.getMaxOccurs$(), typeBinding);
validateTypeBinding();
}

private static BooleanModel newBooleanModel(final Registry registry, final Declarer declarer, final BooleanProperty property, final Method getMethod, final String fieldName) {
final Binding.Type typeBinding = Binding.Type.from(registry, getMethod, property.nullable(), property.use(), property.decode(), property.encode(), Boolean.class);
final Bind.Type typeBinding = Bind.Type.from(registry, getMethod, property.nullable(), property.use(), property.decode(), property.encode(), Boolean.class);
return new BooleanModel(registry, declarer, property, getMethod, fieldName, typeBinding);
}

private BooleanModel(final Registry registry, final Declarer declarer, final BooleanProperty property, final Method getMethod, final String fieldName, final Binding.Type typeBinding) {
private BooleanModel(final Registry registry, final Declarer declarer, final BooleanProperty property, final Method getMethod, final String fieldName, final Bind.Type typeBinding) {
super(registry, declarer, Id.hashed("b", typeBinding), property.nullable(), property.use(), fieldName, typeBinding);
// If there is a "decode" spec, then skip the check to verify field<-->{CharSequence,char[]} compatibility
final boolean hasDecode = typeBinding != null && typeBinding.decode != null;
Expand All @@ -275,7 +275,7 @@ private BooleanModel(final Registry registry, final Declarer declarer, final Boo
validateTypeBinding();
}

private BooleanModel(final Registry registry, final Declarer declarer, final Boolean nullable, final Binding.Type typeBinding) {
private BooleanModel(final Registry registry, final Declarer declarer, final Boolean nullable, final Bind.Type typeBinding) {
super(registry, declarer, Id.hashed("b", typeBinding), nullable, null, null, typeBinding);
validateTypeBinding();
}
Expand All @@ -286,7 +286,7 @@ Registry.Type typeDefault(final boolean primitive) {
}

@Override
String isValid(final Binding.Type typeBinding) {
String isValid(final Bind.Type typeBinding) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion generator/src/main/java/org/jsonx/Deferred.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Registry.Type typeDefault(final boolean primitive) {
}

@Override
String isValid(final Binding.Type typeBinding) {
String isValid(final Bind.Type typeBinding) {
throw new UnsupportedOperationException();
}

Expand Down
2 changes: 1 addition & 1 deletion generator/src/main/java/org/jsonx/Id.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static String hash(final Object ... variables) {
}

static Id hashed(final String prefix, final Object ... variables) {
if (!"!".equals(prefix) && !"a".equals(prefix) && variables != null && variables.length > 1 && variables[0] != null && !(variables[0] instanceof Binding.Type || variables[0] instanceof $Binding))
if (!"!".equals(prefix) && !"a".equals(prefix) && variables != null && variables.length > 1 && variables[0] != null && !(variables[0] instanceof Bind.Type || variables[0] instanceof $Binding))
throw new IllegalArgumentException("First variable expected to be Binding, but was: " + Arrays.toString(variables));

return variables == null || variables.length == 0 ? new Id(prefix) : new Id(prefix + hash(variables));
Expand Down
20 changes: 10 additions & 10 deletions generator/src/main/java/org/jsonx/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ abstract class Member extends Element {
return null;
}

static Binding.Type getBinding(final Registry registry, final $TypeBinding binding) {
return binding == null ? null : Binding.Type.from(registry, binding.getType$(), binding.getDecode$(), binding.getEncode$());
static Bind.Type getBinding(final Registry registry, final $TypeBinding binding) {
return binding == null ? null : Bind.Type.from(registry, binding.getType$(), binding.getDecode$(), binding.getEncode$());
}

static Binding.Type getBinding(final Registry registry, final List<? extends $TypeBinding> bindings) {
static Bind.Type getBinding(final Registry registry, final List<? extends $TypeBinding> bindings) {
final $TypeBinding binding = getBinding(bindings);
return getBinding(registry, binding);
}
Expand Down Expand Up @@ -169,10 +169,10 @@ static String fullyQualifiedDisplayName(final Declarer member) {
final Spec<Use> use;
final Spec<Integer> minOccurs;
final Spec<Integer> maxOccurs;
final Binding.Field fieldBinding;
final Binding.Type typeBinding;
final Bind.Field fieldBinding;
final Bind.Type typeBinding;

Member(final Registry registry, final Declarer declarer, final boolean isFromSchema, final Id id, final $Documented.Doc$ doc, final String name, final Boolean nullable, final Use use, final Integer minOccurs, final Integer maxOccurs, final String fieldName, final Binding.Type typeBinding) {
Member(final Registry registry, final Declarer declarer, final boolean isFromSchema, final Id id, final $Documented.Doc$ doc, final String name, final Boolean nullable, final Use use, final Integer minOccurs, final Integer maxOccurs, final String fieldName, final Bind.Type typeBinding) {
super(name, doc);
this.registry = registry;
this.declarer = declarer;
Expand All @@ -184,15 +184,15 @@ static String fullyQualifiedDisplayName(final Declarer member) {
this.minOccurs = Spec.from(minOccurs, minOccurs == null || minOccurs == 1 ? null : minOccurs);
this.maxOccurs = Spec.from(maxOccurs, maxOccurs == null || maxOccurs == Integer.MAX_VALUE ? null : maxOccurs);
checkMinMaxOccurs(name, minOccurs, maxOccurs);
this.fieldBinding = Binding.Field.from(name, fieldName);
this.fieldBinding = Bind.Field.from(name, fieldName);
this.typeBinding = typeBinding;
}

Member(final Registry registry, final Declarer declarer, final boolean isFromSchema, final Id id, final $Documented.Doc$ doc, final yAA.$Boolean nullable, final yAA.$NonNegativeInteger minOccurs, final $MaxOccurs maxOccurs, final Binding.Type typeBinding) {
Member(final Registry registry, final Declarer declarer, final boolean isFromSchema, final Id id, final $Documented.Doc$ doc, final yAA.$Boolean nullable, final yAA.$NonNegativeInteger minOccurs, final $MaxOccurs maxOccurs, final Bind.Type typeBinding) {
this(registry, declarer, isFromSchema, id, doc, null, nullable == null || nullable.isDefault() ? null : nullable.text(), null, minOccurs.text().intValue(), parseMaxCardinality((BigInteger)minOccurs.text(), maxOccurs, "Occurs", Integer.MAX_VALUE), null, typeBinding);
}

Member(final Registry registry, final Declarer declarer, final boolean isFromSchema, final Id id, final $Documented.Doc$ doc, final yAA.$AnySimpleType<?> name, final yAA.$Boolean nullable, final yAA.$String use, final $FieldIdentifier fieldName, final Binding.Type typeBinding) {
Member(final Registry registry, final Declarer declarer, final boolean isFromSchema, final Id id, final $Documented.Doc$ doc, final yAA.$AnySimpleType<?> name, final yAA.$Boolean nullable, final yAA.$String use, final $FieldIdentifier fieldName, final Bind.Type typeBinding) {
this(registry, declarer, isFromSchema, id, doc, (String)name.text(), nullable == null || nullable.isDefault() ? null : nullable.text(), use == null || use.isDefault() ? null : Use.valueOf(use.text().toUpperCase()), null, null, fieldName == null ? null : fieldName.text(), typeBinding);
}

Expand Down Expand Up @@ -524,7 +524,7 @@ public final boolean isAssignableFrom(final Member m) {
}

abstract Registry.Type typeDefault(boolean primitive);
abstract String isValid(Binding.Type typeBinding);
abstract String isValid(Bind.Type typeBinding);
abstract String elementName();
abstract Class<?> defaultClass();
abstract Class<? extends Annotation> propertyAnnotation();
Expand Down
12 changes: 6 additions & 6 deletions generator/src/main/java/org/jsonx/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ static boolean isAssignable(final Method getMethod, final boolean canWrap, final
return cls == null || cls.isAssignableFrom(genericTypes[0]);
}

Model(final Registry registry, final Declarer declarer, final Id id, final $Documented.Doc$ doc, final $AnySimpleType<?> name, final $Boolean nullable, final $String use, final $FieldIdentifier fieldName, final Binding.Type typeBinding) {
Model(final Registry registry, final Declarer declarer, final Id id, final $Documented.Doc$ doc, final $AnySimpleType<?> name, final $Boolean nullable, final $String use, final $FieldIdentifier fieldName, final Bind.Type typeBinding) {
super(registry, declarer, true, id, doc, name, nullable, use, fieldName, typeBinding);
}

Model(final Registry registry, final Declarer declarer, final Id id, final $Documented.Doc$ doc, final $Boolean nullable, final $NonNegativeInteger minOccurs, final $MaxOccurs maxOccurs, final Binding.Type typeBinding) {
Model(final Registry registry, final Declarer declarer, final Id id, final $Documented.Doc$ doc, final $Boolean nullable, final $NonNegativeInteger minOccurs, final $MaxOccurs maxOccurs, final Bind.Type typeBinding) {
super(registry, declarer, true, id, doc, nullable, minOccurs, maxOccurs, typeBinding);
}

Model(final Registry registry, final Declarer declarer, final Id id, final $Documented.Doc$ doc, final String name, final Binding.Type typeBinding) {
Model(final Registry registry, final Declarer declarer, final Id id, final $Documented.Doc$ doc, final String name, final Bind.Type typeBinding) {
super(registry, declarer, true, id, doc, name, null, null, null, null, null, typeBinding);
}

Model(final Registry registry, final Declarer declarer, final Id id, final Boolean nullable, final Use use, final String fieldName, final Binding.Type typeBinding) {
Model(final Registry registry, final Declarer declarer, final Id id, final Boolean nullable, final Use use, final String fieldName, final Bind.Type typeBinding) {
super(registry, declarer, false, id, null, null, nullable, use, null, null, fieldName, typeBinding);
}

Expand All @@ -124,7 +124,7 @@ Map<String,Object> toXmlAttributes(final Element owner, final String packageName
XmlElement toXml(final Element owner, final String packageName) {
final Map<String,Object> attributes = toXmlAttributes(owner, packageName);
final XmlElement element = new XmlElement(owner instanceof ObjectModel ? "property" : elementName(), attributes, null);
final Map<String,Object> bindingAttributes = Binding.toXmlAttributes(owner, typeBinding, fieldBinding);
final Map<String,Object> bindingAttributes = Bind.toXmlAttributes(owner, typeBinding, fieldBinding);
if (bindingAttributes != null)
element.setElements(CollectionUtil.asCollection(new ArrayList<>(), new XmlElement("binding", bindingAttributes)));

Expand All @@ -141,7 +141,7 @@ Map<String,Object> toJson(final Element owner, final String packageName) {
attributes.remove("xsi:type");

properties.putAll(attributes);
final Map<String,Object> bindingAttributes = Binding.toXmlAttributes(owner, typeBinding, fieldBinding);
final Map<String,Object> bindingAttributes = Bind.toXmlAttributes(owner, typeBinding, fieldBinding);
if (bindingAttributes != null)
properties.put("bindings", Collections.singletonList(bindingAttributes));

Expand Down
Loading

0 comments on commit 88f5e50

Please sign in to comment.