public boolean equalTo(TypeDescriptor type) { return equalTo(type.getRawType()); }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } else if (obj instanceof MethodDescriptor) { MethodDescriptor other = (MethodDescriptor) obj; return this.declaringType.equals(other.declaringType) && this.method.equals(other.method); } else { return false; } }
public ConstructorDescriptor getDefaultConstructor() { return getConstructors().get(DEFAULT_CONSTRUCTOR); }
public boolean isSubTypeOf(TypeDescriptor type) { return isSubTypeOf(type.getRawType()); }
public String getSimpleName() { return getSimpleName(getRawType()); }
@Override public boolean applies(PropertyPath path, TypeContext typeContext) { TypeDescriptor typeDescriptor = typeContext.type; return typeDescriptor.getRawType().equals(type); }
private void assignConstructor(TypeDescriptor type) { type.getConstructors().values().forEach(this::add); type.getMethods().values().forEach(this::add); if (!type.isAbstract()) { Check.that(creator.isPreset(), "%s: creator method or constructor not found.", type.getSimpleName()); creatorParameters = ImmutableSet.copyOf(getCreatorParameters()); } }
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)))); }
@Override public boolean applies(PropertyPath path, TypeContext typeContext) { return typeContext.type.isSubTypeOf(Instant.class); }
public boolean isSuperTypeOf(TypeDescriptor type) { return isSuperTypeOf(type.getRawType()); }
public String toString() { StringBuilder sb = new StringBuilder(); sb.append(type.getSimpleName()); if (parent != null) { sb.append("@"); sb.append(parent); } return sb.toString(); }
public Map<String, BeanProperty> getProperties() { try { ImmutableMap.Builder<String, BeanProperty> properties = ImmutableMap.builder(); BeanInfo beanInfo = Introspector.getBeanInfo(getRawType(), Object.class); for (PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) { MethodDescriptor readMethod = getMethodDescriptor(propertyDescriptor.getReadMethod()); MethodDescriptor writeMethod = getMethodDescriptor(propertyDescriptor.getWriteMethod()); if (readMethod != null || writeMethod != null) { BeanProperty property = new BeanProperty(propertyDescriptor.getName(), readMethod, writeMethod); properties.put(property.getName(), property); } } return properties.build(); } catch (Exception e) { throw new ReflectionException(toString(), e); } }
@Nonnull @Override public Result<Map<TypeDescriptor, String>> subclasses(TypeDescriptor type) { JsonSubTypes jsonSubType = type.getAnnotation(JsonSubTypes.class); if (jsonSubType != null && jsonSubType.value().length > 0) { TypeDescriptors typeDescriptors = type.getTypeDescriptors(); Map<TypeDescriptor, String> aliasesByTypes = asList(jsonSubType.value()).stream() .collect(toMap(subType -> typeDescriptors.get(subType.value()), Type::name)); return Result.of(aliasesByTypes); } return Result.notFound(); }
public Map<MethodSignature, MethodDescriptor> getMethods() { Map<MethodSignature, MethodDescriptor> result = new HashMap<>(); collectMethods(getRawType(), result); return ImmutableMap.copyOf(result); }
@Override public int hashCode() { return 31 * declaringType.hashCode() + method.hashCode(); }
public Object newInstance() { Constructor<?> constructor; try { constructor = getRawType().getDeclaredConstructor(); constructor.setAccessible(true); return constructor.newInstance(); } catch (Exception e) { throw new ReflectionException(toString(), e); } }
void add(String alias, TypeDescriptor type) { clear(); this.alias = alias; this.type = type; assignConstructor(type); type.getProperties().values().forEach(this::add); type.getFields().values().forEach(this::add); ObjectCreator objectConstructor = getObjectConstructor(); BasicObjectType objectType = BasicObjectType.of(type, alias, objectConstructor, identifier, properties); if (root == null) { root = objectType; } else { subclasses.add(objectType); } }
public boolean hasField(String fieldName) { return getFields().containsKey(fieldName); }
public boolean applies(TypeDescriptor typeDescriptor) { return typeDescriptor.equalTo(constructor.getDeclaringClass()); }
TypeDescriptors getTypeDescriptors() { return declaringType.getTypeDescriptors(); }