com.github.javaparser.javadoc.Javadoc Java Examples
The following examples show how to use
com.github.javaparser.javadoc.Javadoc.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenApiObjectGenerator.java From flow with Apache License 2.0 | 6 votes |
private void parseClass(ClassOrInterfaceDeclaration classDeclaration, CompilationUnit compilationUnit) { Optional<AnnotationExpr> endpointAnnotation = classDeclaration .getAnnotationByClass(Endpoint.class); compilationUnit.getStorage().ifPresent(storage -> { String className = classDeclaration.getFullyQualifiedName() .orElse(classDeclaration.getNameAsString()); qualifiedNameToPath.put(className, storage.getPath().toString()); }); if (!endpointAnnotation.isPresent()) { nonEndpointMap.put(classDeclaration.resolve().getQualifiedName(), classDeclaration); } else { Optional<Javadoc> javadoc = classDeclaration.getJavadoc(); if (javadoc.isPresent()) { endpointsJavadoc.put(classDeclaration, javadoc.get().getDescription().toText()); } else { endpointsJavadoc.put(classDeclaration, ""); } pathItems.putAll(createPathItems( getEndpointName(classDeclaration, endpointAnnotation.get()), classDeclaration)); } }
Example #2
Source File: PackageInfoReader.java From jig with Apache License 2.0 | 6 votes |
Optional<PackageAlias> read(PackageInfoSource packageInfoSource) { CompilationUnit cu = StaticJavaParser.parse(packageInfoSource.toInputStream()); Optional<PackageIdentifier> optPackageIdentifier = cu.getPackageDeclaration() .map(NodeWithName::getNameAsString) .map(PackageIdentifier::new); Optional<Alias> optAlias = getJavadoc(cu) .map(Javadoc::getDescription) .map(JavadocDescription::toText) .map(JavadocAliasSource::new) .map(JavadocAliasSource::toAlias); return optPackageIdentifier.flatMap(packageIdentifier -> optAlias.map(alias -> new PackageAlias(packageIdentifier, alias))); }
Example #3
Source File: ImpSort.java From impsort-maven-plugin with Apache License 2.0 | 6 votes |
private static Stream<String> parseJavadoc(Javadoc javadoc) { // parse main doc description Stream<String> stringsFromJavadocDescription = Stream.of(javadoc.getDescription()).flatMap(ImpSort::parseJavadocDescription); // grab tag names and parsed descriptions for block tags Stream<String> stringsFromBlockTags = javadoc.getBlockTags().stream().flatMap(tag -> { // only @throws and @exception have names who are importable; @param and others don't EnumSet<JavadocBlockTag.Type> blockTagTypesWithImportableNames = EnumSet.of(THROWS, EXCEPTION); Stream<String> importableTagNames = blockTagTypesWithImportableNames.contains(tag.getType()) ? Stream.of(tag.getName()).filter(Optional::isPresent).map(Optional::get) : Stream.empty(); Stream<String> tagDescriptions = Stream.of(tag.getContent()).flatMap(ImpSort::parseJavadocDescription); return Stream.concat(importableTagNames, tagDescriptions); }); return Stream.concat(stringsFromJavadocDescription, stringsFromBlockTags); }
Example #4
Source File: JavaDocParser.java From quarkus with Apache License 2.0 | 6 votes |
public String parseConfigDescription(String javadocComment) { if (javadocComment == null || javadocComment.trim().isEmpty()) { return Constants.EMPTY; } // the parser expects all the lines to start with "* " // we add it as it has been previously removed javadocComment = START_OF_LINE.matcher(javadocComment).replaceAll("* "); Javadoc javadoc = StaticJavaParser.parseJavadoc(javadocComment); if (isAsciidoc(javadoc)) { return handleEolInAsciidoc(javadoc); } return htmlJavadocToAsciidoc(javadoc.getDescription()); }
Example #5
Source File: JavaDocParser.java From quarkus with Apache License 2.0 | 6 votes |
public SectionHolder parseConfigSection(String javadocComment, int sectionLevel) { if (javadocComment == null || javadocComment.trim().isEmpty()) { return new SectionHolder(Constants.EMPTY, Constants.EMPTY); } // the parser expects all the lines to start with "* " // we add it as it has been previously removed javadocComment = START_OF_LINE.matcher(javadocComment).replaceAll("* "); Javadoc javadoc = StaticJavaParser.parseJavadoc(javadocComment); if (isAsciidoc(javadoc)) { final String details = handleEolInAsciidoc(javadoc); final int endOfTitleIndex = details.indexOf(Constants.DOT); final String title = details.substring(0, endOfTitleIndex).replaceAll("^([^\\w])+", Constants.EMPTY).trim(); return new SectionHolder(title, details); } return generateConfigSection(javadoc, sectionLevel); }
Example #6
Source File: JavaDocParser.java From quarkus with Apache License 2.0 | 6 votes |
private SectionHolder generateConfigSection(Javadoc javadoc, int sectionLevel) { final String generatedAsciiDoc = htmlJavadocToAsciidoc(javadoc.getDescription()); if (generatedAsciiDoc.isEmpty()) { return new SectionHolder(Constants.EMPTY, Constants.EMPTY); } final String beginSectionDetails = IntStream .rangeClosed(0, Math.max(0, sectionLevel)) .mapToObj(x -> "=").collect(Collectors.joining()) + " "; final int endOfTitleIndex = generatedAsciiDoc.indexOf(Constants.DOT); if (endOfTitleIndex == -1) { return new SectionHolder(generatedAsciiDoc.trim(), beginSectionDetails + generatedAsciiDoc); } else { final String title = generatedAsciiDoc.substring(0, endOfTitleIndex).trim(); final String introduction = generatedAsciiDoc.substring(endOfTitleIndex + 1).trim(); final String details = beginSectionDetails + title + "\n\n" + introduction; return new SectionHolder(title, details.trim()); } }
Example #7
Source File: OperatorProcessor.java From java with Apache License 2.0 | 6 votes |
private String buildOpMethodJavadoc( TypeElement opClass, ExecutableElement endpointMethod, boolean copyClassDescription) { Javadoc methodJavadoc = parseJavadoc(endpointMethod); if (!copyClassDescription) { return methodJavadoc.toText(); } Javadoc classJavadoc = parseJavadoc(opClass); // Copy all endpoint method tags to the description, except for the `scope` parameter which // will be inferred by the Ops class methodJavadoc.getBlockTags().forEach(t -> { if (!t.getTagName().equals("param") || t.getName().map(s -> !s.equals("scope")).orElse(true)) { classJavadoc.addBlockTag(t); } }); return classJavadoc.toText(); }
Example #8
Source File: JavaDocParser.java From quarkus with Apache License 2.0 | 5 votes |
private String handleEolInAsciidoc(Javadoc javadoc) { // it's Asciidoc so we just pass through // it also uses platform specific EOL so we need to convert them back to \n String asciidoc = javadoc.getDescription().toText(); asciidoc = REPLACE_WINDOWS_EOL.matcher(asciidoc).replaceAll("\n"); asciidoc = REPLACE_MACOS_EOL.matcher(asciidoc).replaceAll("\n"); return asciidoc; }
Example #9
Source File: JavaDocParserVisitor.java From jaxrs-analyzer with Apache License 2.0 | 5 votes |
private Map<Integer, String> createResponseComments(Javadoc javadoc) { return javadoc.getBlockTags().stream() .filter(t -> ResponseCommentExtractor.RESPONSE_TAG_NAME.equalsIgnoreCase(t.getTagName())) .map(t -> t.getContent().toText()) .map(ResponseCommentExtractor::extract) .filter(Objects::nonNull) .collect(Collectors.toMap(Pair::getLeft, Pair::getRight)); }
Example #10
Source File: JavaDocParserVisitor.java From jaxrs-analyzer with Apache License 2.0 | 5 votes |
private void recordMethodComment(Javadoc javadoc, MethodDeclaration method) { MethodIdentifier identifier = calculateMethodIdentifier(method); String comment = javadoc.getDescription().toText(); List<MemberParameterTag> tags = createMethodParameterTags(javadoc, method); Map<Integer, String> responseComments = createResponseComments(javadoc); methodComments.put(identifier, new MethodComment(comment, tags, responseComments, classComments.get(className), isDeprecated(javadoc))); }
Example #11
Source File: JavaDocParserVisitor.java From jaxrs-analyzer with Apache License 2.0 | 5 votes |
private void createFieldComment(Javadoc javadoc, FieldDeclaration field) { ClassComment classComment = classComments.get(className); if (classComment == null) { classComment = new ClassComment(); classComments.put(className, classComment); } classComment.getFieldComments().add(createMemberParamTag(javadoc.getDescription(), field.getAnnotations().stream())); }
Example #12
Source File: JavaDocParser.java From quarkus with Apache License 2.0 | 5 votes |
private boolean isAsciidoc(Javadoc javadoc) { for (JavadocBlockTag blockTag : javadoc.getBlockTags()) { if ("asciidoclet".equals(blockTag.getTagName())) { return true; } } return false; }
Example #13
Source File: RemoveMethodParameter.java From Refactoring-Bot with MIT License | 5 votes |
/** * Removes the parameter with the given name from the Javadoc of the given * method declaration * * @param methodDeclaration * @param paramName */ private void removeParameterFromJavadoc(MethodDeclaration methodDeclaration, String paramName) { Optional<Javadoc> javadoc = methodDeclaration.getJavadoc(); if (javadoc.isPresent()) { Javadoc methodJavadoc = javadoc.get(); List<JavadocBlockTag> javadocTags = methodJavadoc.getBlockTags(); for (Iterator<JavadocBlockTag> it = javadocTags.iterator(); it.hasNext();) { JavadocBlockTag javadocTag = it.next(); Optional<String> javadocTagName = javadocTag.getName(); boolean isEqualParamName = javadocTagName.isPresent() && javadocTagName.get().equals(paramName); boolean isParamType = javadocTag.getType().equals(JavadocBlockTag.Type.PARAM); if (isParamType && isEqualParamName) { it.remove(); } } // create new Javadoc with remaining Javadoc tags because there is no way to // remove individual tags directly Javadoc newJavadoc = new Javadoc(methodJavadoc.getDescription()); for (JavadocBlockTag blockTag : javadocTags) { newJavadoc.addBlockTag(blockTag); } methodDeclaration.setJavadocComment(newJavadoc); } }
Example #14
Source File: PackageInfoReader.java From jig with Apache License 2.0 | 5 votes |
private Optional<Javadoc> getJavadoc(CompilationUnit cu) { // NodeWithJavadoc#getJavadocでやってることと同じことをする return cu.getComment() .filter(comment -> comment instanceof JavadocComment) .map(comment -> (JavadocComment) comment) .map(JavadocComment::parse); }
Example #15
Source File: ParseHelper.java From genDoc with Apache License 2.0 | 5 votes |
static Comment parseComment(Node node) { if (node.getComment().isPresent()) { Javadoc javadoc = JavaParser.parseJavadoc(node.getComment().get().getContent()); Comment comment = new Comment(); comment.setDescription(javadoc.getDescription().toText()); List<JavadocBlockTag> javadocBlockTags = javadoc.getBlockTags(); if (javadocBlockTags != null && javadocBlockTags.size() > 0) { List<Comment.Tag> tags = new ArrayList<Comment.Tag>(); for (JavadocBlockTag javadocBlockTag : javadocBlockTags) { Comment.Tag tag = new Comment.Tag(); tag.setTagName(javadocBlockTag.getTagName()); tag.setName(javadocBlockTag.getName().orElse(null)); tag.setContent(javadocBlockTag.getContent().toText()); tags.add(tag); } comment.setTags(tags); } return comment; } return null; }
Example #16
Source File: NodeWithComment.java From apigcc with MIT License | 5 votes |
/** * 解析注释 * @param comment */ public void accept(Comment comment) { if (!comment.isJavadocComment()) { this.setComment(comment.getContent()); return; } Javadoc javadoc = comment.asJavadocComment().parse(); this.setComment(CommentHelper.getDescription(javadoc.getDescription())); javadoc.getBlockTags().forEach(this::parse); }
Example #17
Source File: JavadocUtils.java From chrome-devtools-java-client with Apache License 2.0 | 5 votes |
/** * Creates a javadoc comment object given a comment string. * * @param comment Comment. * @param indentation Indentation. * @return Javadoc comment object. */ public JavadocComment createJavadocComment(String comment, String indentation) { JavadocSnippet javadocSnippet = new JavadocSnippet(""); if (StringUtils.isNotEmpty(comment)) { javadocSnippet = new JavadocSnippet(comment); } JavadocDescription description = new JavadocDescription(); description.addElement(javadocSnippet); Javadoc javadoc = new Javadoc(description); return javadoc.toComment(indentation); }
Example #18
Source File: AutoDoc.java From joyqueue with Apache License 2.0 | 5 votes |
/** * Write the method parameters and it's doc to target api doc * * @param doc target doc * @param comment parameters and method doc **/ private void fillParamDoc(APIDoc doc, JavadocComment comment, StringBuilder methodDesBuilder) { Javadoc javadoc = comment.parse(); toString(javadoc.getDescription(), methodDesBuilder); doc.setDesc(methodDesBuilder.toString()); methodDesBuilder.setLength(0); List<JavadocBlockTag> tags = javadoc.getBlockTags(); if (comment.getCommentedNode().isPresent()) { Node node = comment.getCommentedNode().get(); if (node instanceof MethodDeclaration) { MethodDeclaration method = (MethodDeclaration) node; for (Parameter p : method.getParameters()) { String type = p.getType().asString(); String name = p.getName().asString(); List<Param> params = doc.getParams(); Param param = new Param(); param.setName(name); param.setType(type); for (JavadocBlockTag t : tags) { if (t.getName().isPresent()) { if (name.endsWith(t.getName().get())) { toString(t.getContent(), methodDesBuilder); param.setComment(methodDesBuilder.toString()); methodDesBuilder.setLength(0); } } } if (params == null) { params = new ArrayList<>(); doc.setParams(params); } params.add(param); } } } }
Example #19
Source File: JavaDocParserVisitor.java From jaxrs-analyzer with Apache License 2.0 | 4 votes |
private Javadoc toJavaDoc(Comment comment) { return comment.asJavadocComment().parse(); }
Example #20
Source File: JavaDocParserVisitor.java From jaxrs-analyzer with Apache License 2.0 | 4 votes |
private boolean isDeprecated(Javadoc javadoc) { return javadoc.getBlockTags().stream().anyMatch(t -> t.getType() == JavadocBlockTag.Type.DEPRECATED); }
Example #21
Source File: JavaDocParserVisitor.java From jaxrs-analyzer with Apache License 2.0 | 4 votes |
private void recordClassComment(Javadoc javadoc) { String comment = javadoc.getDescription().toText(); Map<Integer, String> responseComments = createResponseComments(javadoc); classComments.put(className, new ClassComment(comment, responseComments, isDeprecated(javadoc))); }
Example #22
Source File: JavaDocParserVisitor.java From jaxrs-analyzer with Apache License 2.0 | 4 votes |
private List<MemberParameterTag> createMethodParameterTags(Javadoc javadoc, MethodDeclaration method) { return javadoc.getBlockTags().stream() .filter(t -> t.getType() == JavadocBlockTag.Type.PARAM) .map(t -> createMethodParameterTag(t, method)) .collect(Collectors.toList()); }