Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/main/java/graphql/language/AstPrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class AstPrinter {

private final boolean compactMode;

private AstPrinter(boolean compactMode) {
AstPrinter(boolean compactMode) {
this.compactMode = compactMode;
printers.put(Argument.class, argument());
printers.put(ArrayValue.class, value());
Expand Down Expand Up @@ -463,11 +463,11 @@ private String node(Node node, Class startClass) {
}

@SuppressWarnings("unchecked")
private <T extends Node> NodePrinter<T> _findPrinter(Node node) {
<T extends Node> NodePrinter<T> _findPrinter(Node node) {
return _findPrinter(node, null);
}

private <T extends Node> NodePrinter<T> _findPrinter(Node node, Class startClass) {
<T extends Node> NodePrinter<T> _findPrinter(Node node, Class startClass) {
if (node == null) {
return (out, type) -> {
};
Expand Down Expand Up @@ -689,7 +689,7 @@ public static void printAst(Writer writer, Node node) {

/**
* This will print the Ast node in graphql language format in a compact manner, with no new lines
* and comments stripped out of the text.
* and descriptions stripped out of the text.
*
* @param node the AST node to print
*
Expand All @@ -712,7 +712,16 @@ private static void printImpl(StringBuilder writer, Node node, boolean compactMo
*
* @param <T> the type of node
*/
private interface NodePrinter<T extends Node> {
interface NodePrinter<T extends Node> {
void print(StringBuilder out, T node);
}

/**
* Allow subclasses to replace a printer for a specific {@link Node}
* @param nodeClass the class of the {@link Node}
* @param nodePrinter the custom {@link NodePrinter}
*/
void replacePrinter(Class<? extends Node> nodeClass, NodePrinter<? extends Node> nodePrinter) {
this.printers.put(nodeClass, nodePrinter);
}
}
Loading