use of org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ParamDocType in project jersey by jersey.
the class WadlGeneratorResourceDocSupportTest method wadlIsGeneratedWithUnknownCustomParameterAnnotation.
@Test
public void wadlIsGeneratedWithUnknownCustomParameterAnnotation() throws JAXBException {
/* Set up a ClassDocType that has something for a custom-annotated parameter */
ClassDocType cdt = new ClassDocType();
cdt.setClassName(TestResource.class.getName());
MethodDocType mdt = new MethodDocType();
mdt.setMethodName("method");
cdt.getMethodDocs().add(mdt);
ParamDocType pdt = new ParamDocType("x", "comment about x");
mdt.getParamDocs().add(pdt);
AnnotationDocType adt = new AnnotationDocType();
adt.setAnnotationTypeName(CustomParam.class.getName());
adt.getAttributeDocs().add(new NamedValueType("value", "x"));
pdt.getAnnotationDocs().add(adt);
ResourceDocType rdt = new ResourceDocType();
rdt.getDocs().add(cdt);
/* Generate WADL for that class */
WadlGenerator wg = new WadlGeneratorResourceDocSupport(new WadlGeneratorImpl(), rdt);
WadlBuilder wb = new WadlBuilder(wg, false, null);
Resource resource = Resource.from(TestResource.class);
ApplicationDescription app = wb.generate(Collections.singletonList(resource));
/* Confirm that it can be marshalled without error */
StringWriter sw = new StringWriter();
JAXBContext context = JAXBContext.newInstance(Application.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.marshal(app.getApplication(), sw);
}
use of org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ParamDocType in project jersey by jersey.
the class ResourceDoclet method addParamDocs.
private static void addParamDocs(final MethodDoc methodDoc, final MethodDocType methodDocType, final DocProcessor docProcessor) {
final Parameter[] parameters = methodDoc.parameters();
final ParamTag[] paramTags = methodDoc.paramTags();
/* only use both javadoc and reflection information when the number
* of params are the same
*/
if (parameters != null && paramTags != null && parameters.length == paramTags.length) {
for (int i = 0; i < parameters.length; i++) {
final Parameter parameter = parameters[i];
/* TODO: this only works if the params and tags are in the same
* order. If the param tags are mixed up, the comments for parameters
* will be wrong.
*/
final ParamTag paramTag = paramTags[i];
final ParamDocType paramDocType = new ParamDocType();
paramDocType.setParamName(paramTag.parameterName());
paramDocType.setCommentText(paramTag.parameterComment());
docProcessor.processParamTag(paramTag, parameter, paramDocType);
final AnnotationDesc[] annotations = parameter.annotations();
if (annotations != null) {
for (final AnnotationDesc annotationDesc : annotations) {
final AnnotationDocType annotationDocType = new AnnotationDocType();
final String typeName = annotationDesc.annotationType().qualifiedName();
annotationDocType.setAnnotationTypeName(typeName);
for (final ElementValuePair elementValuePair : annotationDesc.elementValues()) {
final NamedValueType namedValueType = new NamedValueType();
namedValueType.setName(elementValuePair.element().name());
namedValueType.setValue(elementValuePair.value().value().toString());
annotationDocType.getAttributeDocs().add(namedValueType);
}
paramDocType.getAnnotationDocs().add(annotationDocType);
}
}
methodDocType.getParamDocs().add(paramDocType);
}
}
}
use of org.glassfish.jersey.server.wadl.internal.generators.resourcedoc.model.ParamDocType in project jersey by jersey.
the class WadlGeneratorResourceDocSupport method createParam.
/**
* @param r Jersey resource component.
* @param m resource method.
* @param p method parameter.
* @return the enhanced {@link Param}.
* @see org.glassfish.jersey.server.wadl.WadlGenerator#createParam(org.glassfish.jersey.server.model.Resource,
* org.glassfish.jersey.server.model.ResourceMethod, org.glassfish.jersey.server.model.Parameter)
*/
public Param createParam(final org.glassfish.jersey.server.model.Resource r, final org.glassfish.jersey.server.model.ResourceMethod m, final Parameter p) {
final Param result = delegate.createParam(r, m, p);
if (result != null) {
final ParamDocType paramDoc = resourceDoc.getParamDoc(m.getInvocable().getDefinitionMethod().getDeclaringClass(), m.getInvocable().getDefinitionMethod(), p);
if (paramDoc != null && !isEmpty(paramDoc.getCommentText())) {
final Doc doc = new Doc();
doc.getContent().add(paramDoc.getCommentText());
result.getDoc().add(doc);
}
}
return result;
}
Aggregations