Describe(PropertyPath path, TypeContext typeContext, DescribeContext context) { this.path = path; this.typeContext = typeContext; this.context = context; setType = typeContext.type; elementType = setType.resolveGenericParameter(Set.class, 0); setKey = findSetKey(typeContext.parent, elementType); }
@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); }
@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(); }
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)))); }