protected final void verifyClass(Class<? extends Annotation> annotation) { String annotationName = annotation.getSimpleName(); String structClassName = getStructClass().getName(); // Verify struct class is public and final if (!Modifier.isPublic(getStructClass().getModifiers())) { metadataErrors.addError("%s class '%s' is not public", annotationName, structClassName); } if (!getStructClass().isAnnotationPresent(annotation)) { metadataErrors.addError("%s class '%s' does not have a @%s annotation", annotationName, structClassName, annotationName); } }
protected final void verifyClass(Class<? extends Annotation> annotation) { String annotationName = annotation.getSimpleName(); String structClassName = getStructClass().getName(); // Verify struct class is public and final if (!Modifier.isPublic(getStructClass().getModifiers())) { metadataErrors.addError("%s class '%s' is not public", annotationName, structClassName); } if (!Modifier.isFinal(getStructClass().getModifiers())) { metadataErrors.addError("%s class '%s' is not final (thrift does not support polymorphic data types)", annotationName, structClassName); } if (!getStructClass().isAnnotationPresent(annotation)) { metadataErrors.addError("%s class '%s' does not have a @%s annotation", annotationName, structClassName, annotationName); } }
private Type extractBuilderType() { Class<?> builderClass = extractBuilderClass(); if (builderClass == null) { return null; } if (builderClass.getTypeParameters().length == 0) { return builderClass; } if (!(structType instanceof ParameterizedType)) { metadataErrors.addError("Builder class '%s' may only be generic if the type it builds ('%s') is also generic", builderClass.getName(), getStructClass().getName()); return builderClass; } if (builderClass.getTypeParameters().length != getStructClass().getTypeParameters().length) { metadataErrors.addError("Generic builder class '%s' must have the same number of type parameters as the type it builds ('%s')", builderClass.getName(), getStructClass().getName()); return builderClass; } ParameterizedType parameterizedStructType = (ParameterizedType) structType; return new MoreTypes.ParameterizedTypeImpl(builderClass.getEnclosingClass(), builderClass, parameterizedStructType.getActualTypeArguments()); }
private Type extractBuilderType() { Class<?> builderClass = extractBuilderClass(); if (builderClass == null) { return null; } if (builderClass.getTypeParameters().length == 0) { return builderClass; } if (!(structType instanceof ParameterizedType)) { metadataErrors.addError("Builder class '%s' may only be generic if the type it builds ('%s') is also generic", builderClass.getName(), getStructClass().getName()); return builderClass; } if (builderClass.getTypeParameters().length != getStructClass().getTypeParameters().length) { metadataErrors.addError("Generic builder class '%s' must have the same number of type parameters as the type it builds ('%s')", builderClass.getName(), getStructClass().getName()); return builderClass; } ParameterizedType parameterizedStructType = (ParameterizedType) structType; return new MoreTypes.ParameterizedTypeImpl(builderClass.getEnclosingClass(), builderClass, parameterizedStructType.getActualTypeArguments()); }
protected final void extractFromFields() { if (builderType == null) { // struct fields are readable and writable addFields(getStructClass(), true, true); } else { // builder fields are writable addFields(getBuilderClass(), false, true); // struct fields are readable addFields(getStructClass(), true, false); } }
protected final void extractFromFields() { if (builderType == null) { // struct fields are readable and writable addFields(getStructClass(), true, true); } else { // builder fields are writable addFields(getBuilderClass(), false, true); // struct fields are readable addFields(getStructClass(), true, false); } }
protected final void extractFromConstructors() { if (builderType == null) { // struct class must have a valid constructor addConstructors(structType); } else { // builder class must have a valid constructor addConstructors(builderType); // builder class must have a build method annotated with @ThriftConstructor addBuilderMethods(); // verify struct class does not have @ThriftConstructors for (Constructor<?> constructor : getStructClass().getConstructors()) { if (constructor.isAnnotationPresent(ThriftConstructor.class)) { metadataErrors.addWarning("Thrift class '%s' has a builder class, but constructor '%s' annotated with @ThriftConstructor", getStructClass().getName(), constructor); } } } }
protected final void extractFromConstructors() { if (builderType == null) { // struct class must have a valid constructor addConstructors(structType); } else { // builder class must have a valid constructor addConstructors(builderType); // builder class must have a build method annotated with @ThriftConstructor addBuilderMethods(); // verify struct class does not have @ThriftConstructors for (Constructor<?> constructor : getStructClass().getConstructors()) { if (constructor.isAnnotationPresent(ThriftConstructor.class)) { metadataErrors.addWarning("Thrift class '%s' has a builder class, but constructor '%s' annotated with @ThriftConstructor", getStructClass().getName(), constructor); } } } }
if (!getStructClass().isAssignableFrom(method.getReturnType())) { metadataErrors.addError( "'%s' says that '%s' is its builder class, but @ThriftConstructor method '%s' in the builder does not build an instance assignable to that type",
if (!getStructClass().isAssignableFrom(method.getReturnType())) { metadataErrors.addError( "'%s' says that '%s' is its builder class, but @ThriftConstructor method '%s' in the builder does not build an instance assignable to that type",
protected AbstractThriftMetadataBuilder(ThriftCatalog catalog, Type structType) { this.catalog = checkNotNull(catalog, "catalog is null"); this.structType = checkNotNull(structType, "structType is null"); this.metadataErrors = new MetadataErrors(catalog.getMonitor()); // assign the struct name from the annotation or from the Java class structName = extractName(); // get the builder type from the annotation or from the Java class builderType = extractBuilderType(); // grab any documentation from the annotation or saved JavaDocs documentation = ThriftCatalog.getThriftDocumentation(getStructClass()); // extract all of the annotated constructor and report an error if // there is more than one or none // also extract thrift fields from the annotated parameters and verify extractFromConstructors(); // extract thrift fields from the annotated fields and verify extractFromFields(); // extract thrift fields from the annotated methods (and parameters) and verify extractFromMethods(); }
protected AbstractThriftMetadataBuilder(ThriftCatalog catalog, Type structType) { this.catalog = checkNotNull(catalog, "catalog is null"); this.structType = checkNotNull(structType, "structType is null"); this.metadataErrors = new MetadataErrors(catalog.getMonitor()); // assign the struct name from the annotation or from the Java class structName = extractName(); // get the builder type from the annotation or from the Java class builderType = extractBuilderType(); // grab any documentation from the annotation or saved JavaDocs documentation = ThriftCatalog.getThriftDocumentation(getStructClass()); // extract all of the annotated constructor and report an error if // there is more than one or none // also extract thrift fields from the annotated parameters and verify extractFromConstructors(); // extract thrift fields from the annotated fields and verify extractFromFields(); // extract thrift fields from the annotated methods (and parameters) and verify extractFromMethods(); }