private void add(String name, AccessibleProperty property, TypeContext typeContext) { if (!property.isWritable() && !creatorParameters.contains(name)) { throw new IllegalArgumentException(type.getSimpleName() + "." + name + " should have a matching setter or constructor parameter"); } SubPath subPath = path.property(name); if (!properties.containsKey(name)) { properties.put(name, property); context.describeAsync(subPath, typeContext); } }
@Override public ValueType describe(PropertyPath path, TypeDescriptor listType, DescribeContext context) { TypeDescriptor elementType = listType.resolveGenericParameter(List.class, 0); context.describeAsync(path.anyIndex(), new TypeContext(listType, elementType)); return new ListType(); }
@Override public ValueType describe(PropertyPath path, TypeDescriptor collectionType, DescribeContext context) { TypeDescriptor elementType = collectionType.resolveGenericParameter(Collection.class, 0); context.describeAsync(path.anyIndex(), new TypeContext(collectionType, elementType)); return new CollectionType(); }
public static ValueType describeReference(TypeDescriptor type, PropertyPath targetPath, DescribeContext context) { TypeContext typeContext = new TypeContext(type); context.describeAsync(targetPath.anyIndex(), typeContext); IdentifiableType identifiableType = (IdentifiableType) context.describeNow(targetPath.anyKey(), typeContext); return new ReferenceType(identifiableType, targetPath); } }
@Override public ValueType describe(PropertyPath path, TypeDescriptor mapType, DescribeContext context) { TypeDescriptor keyType = mapType.resolveGenericParameter(Map.class, 0); TypeDescriptor valueType = mapType.resolveGenericParameter(Map.class, 1); context.describeAsync(path.any(), new TypeContext(mapType, valueType)); ValueType keyValueType = context.describeNow(null, new TypeContext(mapType, keyType)); if (!(keyValueType instanceof ScalarType)) { throw new IllegalArgumentException("Key of " + path + ": " + mapType + " is not a scalar (ScalarType)"); } return newMapType((ScalarType) keyValueType); }
private ValueType functionSetType() { context.describeAsync(path.any(), new TypeContext(setType, elementType)); TypeDescriptor functionType = setType.getTypeDescriptors().get(setKey.by()); TypeDescriptor input = functionType.resolveGenericParameter(Function.class, 0); TypeDescriptor output = functionType.resolveGenericParameter(Function.class, 1); if (!input.isSuperTypeOf(elementType)) { throw new IllegalArgumentException("Input type of Function provided by @SetKey(by=+" + input + ") should be super type of Set's element type " + elementType); } IdentifiableType delegate = requireIdentifiable(context.describeNow(null, new TypeContext(output))); return newSetType(ImmutableList.of((new FunctionKey((Function) functionType.newInstance(), delegate)))); }