Created
December 7, 2021 19:38
-
-
Save jkschneider/1a39146049165f82f9953a5042166187 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.openrewrite.java; | |
import org.openrewrite.ExecutionContext; | |
import org.openrewrite.Recipe; | |
import org.openrewrite.SourceFile; | |
import org.openrewrite.Tree; | |
import org.openrewrite.internal.ListUtils; | |
import org.openrewrite.java.tree.J; | |
import org.openrewrite.marker.Markers; | |
import org.openrewrite.text.PlainText; | |
import java.nio.file.Paths; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
public class GenerateDocs extends Recipe { | |
@Override | |
public String getDisplayName() { | |
return "Generic docs"; | |
} | |
@Override | |
public String getDescription() { | |
return "Generate docs based on some things."; | |
} | |
@Override | |
protected List<SourceFile> visit(List<SourceFile> before, ExecutionContext ctx) { | |
List<String> classNames = new ArrayList<>(); | |
for (SourceFile sourceFile : before) { | |
new JavaIsoVisitor<Integer>() { | |
@Override | |
public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Integer integer) { | |
classNames.add(classDecl.getType().getFullyQualifiedName()); | |
return super.visitClassDeclaration(classDecl, integer); | |
} | |
}.visit(sourceFile, 0); | |
} | |
PlainText doc = new PlainText(Tree.randomId(), Paths.get("docs/class-list.asciidoc"), Markers.EMPTY, | |
"= A list of classes" + classNames.stream().map(name -> "* " + name).collect(Collectors.joining("\n", "\n", ""))); | |
return ListUtils.concat(before, doc); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Relativization of the doc path relative to the project root will be handled for you.