use of org.robolectric.annotation.processing.DocumentedMethod in project robolectric by robolectric.
the class ImplementsValidator method captureJavadoc.
private void captureJavadoc(TypeElement elem) {
List<String> imports = new ArrayList<>();
try {
List<? extends ImportTree> importLines = Trees.instance(env).getPath(elem).getCompilationUnit().getImports();
for (ImportTree importLine : importLines) {
imports.add(importLine.getQualifiedIdentifier().toString());
}
} catch (IllegalArgumentException e) {
// Trees relies on javac APIs and is not available in all annotation processing
// implementations
}
List<TypeElement> enclosedTypes = ElementFilter.typesIn(elem.getEnclosedElements());
for (TypeElement enclosedType : enclosedTypes) {
imports.add(enclosedType.getQualifiedName().toString());
}
Elements elementUtils = env.getElementUtils();
modelBuilder.documentType(elem, elementUtils.getDocComment(elem), imports);
for (Element memberElement : ElementFilter.methodsIn(elem.getEnclosedElements())) {
try {
ExecutableElement methodElement = (ExecutableElement) memberElement;
Implementation implementation = memberElement.getAnnotation(Implementation.class);
DocumentedMethod documentedMethod = new DocumentedMethod(memberElement.toString());
for (Modifier modifier : memberElement.getModifiers()) {
documentedMethod.modifiers.add(modifier.toString());
}
documentedMethod.isImplementation = implementation != null;
if (implementation != null) {
documentedMethod.minSdk = sdkOrNull(implementation.minSdk());
documentedMethod.maxSdk = sdkOrNull(implementation.maxSdk());
}
for (VariableElement variableElement : methodElement.getParameters()) {
documentedMethod.params.add(variableElement.toString());
}
documentedMethod.returnType = methodElement.getReturnType().toString();
for (TypeMirror typeMirror : methodElement.getThrownTypes()) {
documentedMethod.exceptions.add(typeMirror.toString());
}
String docMd = elementUtils.getDocComment(methodElement);
if (docMd != null) {
documentedMethod.setDocumentation(docMd);
}
modelBuilder.documentMethod(elem, documentedMethod);
} catch (Exception e) {
throw new RuntimeException("failed to capture javadoc for " + elem + "." + memberElement, e);
}
}
}
use of org.robolectric.annotation.processing.DocumentedMethod in project robolectric by robolectric.
the class ImplementsValidatorTest method javadocMarkdownFormatting.
@Test
public void javadocMarkdownFormatting() throws Exception {
DocumentedMethod documentedMethod = new DocumentedMethod("name");
documentedMethod.setDocumentation(" First sentence.\n \n Second sentence.\n \n ASCII art:\n * * *\n @return null\n");
assertThat(documentedMethod.getDocumentation()).isEqualTo("First sentence.\n\nSecond sentence.\n\nASCII art:\n * * *\n@return null\n");
}
Aggregations