public boolean process(Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) { try { if (roundEnv.processingOver()) { return true; } Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(UriEndpoint.class); for (Element element : elements) { if (element instanceof TypeElement) { processEndpointClass(roundEnv, (TypeElement) element); } } } catch (Throwable e) { dumpExceptionToErrorFile("camel-apt-error.log", "Error processing @UriEndpoint", e); } return true; }
protected void writeJSonSchemeDocumentation(PrintWriter writer, RoundEnvironment roundEnv, TypeElement classElement, UriEndpoint uriEndpoint, String title, String scheme, String extendsScheme, String label) { // gather component information ComponentModel componentModel = findComponentProperties(roundEnv, uriEndpoint, classElement, title, scheme, extendsScheme, label); // get endpoint information which is divided into paths and options (though there should really only be one path) Set<EndpointPath> endpointPaths = new LinkedHashSet<EndpointPath>(); Set<EndpointOption> endpointOptions = new LinkedHashSet<EndpointOption>(); Set<ComponentOption> componentOptions = new LinkedHashSet<ComponentOption>(); TypeElement componentClassElement = findTypeElement(roundEnv, componentModel.getJavaType()); if (componentClassElement != null) { findComponentClassProperties(writer, roundEnv, componentModel, componentOptions, componentClassElement, ""); } findClassProperties(writer, roundEnv, componentModel, endpointPaths, endpointOptions, classElement, "", uriEndpoint.excludeProperties()); String json = createParameterJsonSchema(componentModel, componentOptions, endpointPaths, endpointOptions); writer.println(json); }
protected void processEndpointClass(final RoundEnvironment roundEnv, final TypeElement classElement) { final UriEndpoint uriEndpoint = classElement.getAnnotation(UriEndpoint.class); if (uriEndpoint != null) { String scheme = uriEndpoint.scheme(); String extendsScheme = uriEndpoint.extendsScheme(); String title = uriEndpoint.title(); final String label = uriEndpoint.label(); if (!isNullOrEmpty(scheme)) { // support multiple schemes separated by comma, which maps to the exact same component // for example camel-mail has a bunch of component schema names that does that String[] schemes = scheme.split(","); String[] titles = title.split(","); String[] extendsSchemes = extendsScheme != null ? extendsScheme.split(",") : null; for (int i = 0; i < schemes.length; i++) { final String alias = schemes[i]; final String extendsAlias = extendsSchemes != null ? (i < extendsSchemes.length ? extendsSchemes[i] : extendsSchemes[0]) : null; final String aliasTitle = i < titles.length ? titles[i] : titles[0]; // write html documentation String name = canonicalClassName(classElement.getQualifiedName().toString()); String packageName = name.substring(0, name.lastIndexOf(".")); String fileName = alias + ".html"; Func1<PrintWriter, Void> handler = new Func1<PrintWriter, Void>() { @Override public Void call(PrintWriter writer) { writeHtmlDocumentation(writer, roundEnv, classElement, uriEndpoint, aliasTitle, alias, extendsAlias, label); return null; } }; processFile(packageName, fileName, handler); // write json schema fileName = alias + ".json"; handler = new Func1<PrintWriter, Void>() { @Override public Void call(PrintWriter writer) { writeJSonSchemeDocumentation(writer, roundEnv, classElement, uriEndpoint, aliasTitle, alias, extendsAlias, label); return null; } }; processFile(packageName, fileName, handler); } } } }
protected void writeHtmlDocumentation(PrintWriter writer, RoundEnvironment roundEnv, TypeElement classElement, UriEndpoint uriEndpoint, String title, String scheme, String extendsScheme, String label) { // gather component information ComponentModel componentModel = findComponentProperties(roundEnv, uriEndpoint, classElement, title, scheme, extendsScheme, label); String syntax = componentModel.getSyntax(); String alternativeSyntax = componentModel.getAlternativeSyntax(); String description = componentModel.getDescription(); writer.println("<html>"); writer.println("<header>"); writer.println("<title>" + title + "</title>"); writer.println("</header>"); writer.println("<body>"); writer.println("<h1>" + title + "</h1>"); writer.println("<b>Scheme:</b> " + scheme + "<br/>"); writer.println("<b>Syntax:</b> " + syntax + "<br/>"); if (alternativeSyntax != null) { writer.println("<b>Alternative Syntax:</b> " + alternativeSyntax + "<br/>"); } writer.println("<b>Description:</b> " + description + "<br/>"); writer.println("<b>Deprecated:</b>" + componentModel.isDeprecated() + "<br/>"); if (componentModel.isConsumerOnly()) { writer.println("<b>ConsumerOnly:</b>" + "true" + "<br/>"); } if (componentModel.isProducerOnly()) { writer.println("<b>ProducerOnly:</b>" + "true" + "<br/>"); } writer.println("<b>Async:</b>" + componentModel.isAsync() + "<br/>"); writer.println("<b>Maven:</b> " + componentModel.getGroupId() + "/" + componentModel.getArtifactId() + "/" + componentModel.getVersionId() + "<br/>"); writeHtmlDocumentationAndFieldInjections(writer, roundEnv, componentModel, classElement, "", uriEndpoint.excludeProperties()); // This code is not my fault, it seems to honestly be the hacky way to find a class name in APT :) TypeMirror consumerType = null; try { uriEndpoint.consumerClass(); } catch (MirroredTypeException mte) { consumerType = mte.getTypeMirror(); } boolean found = false; String consumerClassName = null; String consumerPrefix = getOrElse(uriEndpoint.consumerPrefix(), ""); if (consumerType != null) { consumerClassName = consumerType.toString(); TypeElement consumerElement = findTypeElement(roundEnv, consumerClassName); if (consumerElement != null) { writer.println("<h2>" + scheme + " consumer" + "</h2>"); writeHtmlDocumentationAndFieldInjections(writer, roundEnv, componentModel, consumerElement, consumerPrefix, uriEndpoint.excludeProperties()); found = true; } } if (!found && consumerClassName != null) { warning("APT could not find consumer class " + consumerClassName); } writer.println("</body>"); writer.println("</html>"); }