private String getAnnotation(Concept concept, Name name) { Annotation annotation = concept.getAnnotation(name); if (annotation != null) { return annotation.parameters() .flatMap(AnnotationParameter::values) .collect(joining(", ")); } return ""; } }
private void writeAnnotations(Concept concept) { List<Annotation> annotations = concept.getAnnotations(); if (!annotations.isEmpty()) { writer.writeStartElement("annotations"); annotations.forEach(this::writeAnnotation); writer.writeEndElement(); } }
/** * Checks if the documentation of the given document only has a summary. * * @return {@code true} if the documentation of the concept only has a summary, {@code false} otherwise */ private boolean onlyHasSummary(Concept concept) { String doc = concept.getDoc(); if (doc == null) { return true; } int index = doc.indexOf('.'); if (index == -1) { return true; } return index == doc.length() - 1; }
private void analyzeDocletTag(DocletTag docTag, Concept concept) { // Calculate the name: Name name = NameParser.parseUsingCase(docTag.getName()); // Create the annotation if it doesn't exist in the concept yet: Annotation annotation = concept.getAnnotation(name); if (annotation == null) { annotation = new Annotation(); annotation.setName(name); concept.addAnnotation(annotation); } // Create the "value" parameter if it doesn't exist yet: String value = docTag.getValue(); if (value != null) { value = value.trim(); if (!value.isEmpty()) { AnnotationParameter parameter = annotation.getParameter(VALUE); if (parameter == null) { parameter = new AnnotationParameter(); parameter.setName(VALUE); annotation.addParameter(parameter); } parameter.addValue(docTag.getValue()); } } }
private void analyzeName(JavaParameter javaParameter, Concept concept) { String javaName = javaParameter.getName(); Name name = parseJavaName(javaName); concept.setName(name); }
private void analyzeSource(JavaModel javaModel, Concept concept) { String javaSource = javaModel.getCodeBlock(); if (javaSource != null && !javaSource.isEmpty()) { concept.setSource(javaSource); } }
private void analyzeDocumentation(JavaAnnotatedElement javaElement, Concept concept) { // Copy the text of the documentation (without the doclet tags): String javaComment = javaElement.getComment(); if (javaComment != null) { javaComment = javaComment.trim(); if (!javaComment.isEmpty()) { concept.setDoc(javaComment); } } // Make annotations for the javadoc tags: javaElement.getTags().stream().forEach(docTag -> { this.analyzeDocletTag(docTag, concept); }); }
concept.addAnnotation(annotation);
private String getName(Concept concept) { String name = concept.getName().toString(); String parent = null; if (concept instanceof StructMember) { StructMember member = (StructMember) concept; parent = member.getDeclaringType().getName().toString(); } else if (concept instanceof Method) { Method method = (Method) concept; parent = method.getDeclaringService().getName().toString(); } if (parent != null) { name = parent + "/" + name; } return name; }
private void analyzeName(JavaClass javaClass, Concept concept) { // Get the name of the Java class: String javaName = javaClass.getName(); // Parse the Java name and assign it to the concept: Name name = parseJavaName(javaName); concept.setName(name); }
protected void generateDoc(Concept concept) { List<String> lines = new ArrayList<>(); String doc = concept.getDoc(); if (doc != null) { Collections.addAll(lines, doc.split("\n")); } if (!lines.isEmpty()) { javaBuffer.addDocComment(lines); } } }
private void analyzeName(JavaMethod javaMethod, Concept concept) { String javaName = javaMethod.getName(); Name name = parseJavaName(javaName); concept.setName(name); }
private void writeAnnotations(Concept concept) { List<Annotation> annotations = concept.getAnnotations(); if (!annotations.isEmpty()) { writer.writeStartArray("annotations"); annotations.forEach(this::writeAnnotation); writer.writeEnd(); } }
private String getSummary(Concept concept) { // If there is no documentation then consider it empty: String doc = concept.getDoc(); if (doc == null) { doc = ""; } // The summary is the first sentence of the documentation, or the complete documentation if there is no dot // to end the first sentence. int index = doc.indexOf('.'); if (index != -1) { doc = doc.substring(0, index + 1); } // Apply document fixes, like replacing the forward slash with the id separator: doc = fixDoc(doc); return doc; }
private void analyzeName(JavaField javaField, Concept concept) { // Fields of classes are parsed using case, but enum values are also represented as fields and they need to be // parsed using underscore as the separator: String javaName = javaField.getName(); Name name; if (javaField.isEnumConstant()) { name = NameParser.parseUsingSeparator(javaName, '_'); } else { name = parseJavaName(javaName); } concept.setName(name); }
private void addDoc(Concept concept) { // Do nothing if the concept doesn't have documentation: String doc = concept.getDoc(); if (doc == null) { return; } // Apply document fixes, like replacing the forward slash with the id separator: doc = fixDoc(doc); // Split the documentation into lines, and add them to the buffer: List<String> lines = new ArrayList<>(); Collections.addAll(lines, doc.split("\n")); lines.forEach(docBuffer::addLine); docBuffer.addLine(); }
/** * Counts the number of items in a concept tha are documented. */ private int countDocuments(Concept concept) { int count = 0; if (concept.getDoc() != null) { count++; } if (concept instanceof StructType) { StructType type = (StructType) concept; count += type.attributes().mapToInt(this::countDocuments).sum(); count += type.links().mapToInt(this::countDocuments).sum(); } else if (concept instanceof EnumType) { EnumType type = (EnumType) concept; count += type.values().mapToInt(this::countDocuments).sum(); } else if (concept instanceof Service) { Service service = (Service) concept; count += service.methods().mapToInt(this::countDocuments).sum(); count += service.locators().mapToInt(this::countDocuments).sum(); } else if (concept instanceof Method) { Method method = (Method) concept; count += method.parameters().mapToInt(this::countDocuments).sum(); } return count; }
private void writeDoc(Concept concept) { String doc = concept.getDoc(); if (doc != null) { writer.writeElement("doc", doc); String html = htmlGenerator.toHtml(doc); if (html != null) { writer.writeElement("html", html); } } }
private void writeDoc(Concept concept) { String doc = concept.getDoc(); if (doc != null) { writer.write("doc", doc); String html = htmlGenerator.toHtml(doc); if (html != null) { writer.write("html", html); } } }