Search in sources :

Example 1 with Comment

use of graphql.language.Comment in project graphql-java by graphql-java.

the class GraphqlAntlrToLanguage method getCommentOnChannel.

private List<Comment> getCommentOnChannel(List<Token> refChannel) {
    List<Comment> comments = new ArrayList<>();
    for (Token refTok : refChannel) {
        String text = refTok.getText();
        // consumers can decide that
        if (text == null) {
            continue;
        }
        text = text.replaceFirst("^#", "");
        comments.add(new Comment(text, new SourceLocation(refTok.getLine(), refTok.getCharPositionInLine())));
    }
    return comments;
}
Also used : SourceLocation(graphql.language.SourceLocation) Comment(graphql.language.Comment) ArrayList(java.util.ArrayList) Token(org.antlr.v4.runtime.Token) StringValueParsing.parseTripleQuotedString(graphql.parser.StringValueParsing.parseTripleQuotedString) StringValueParsing.parseSingleQuotedString(graphql.parser.StringValueParsing.parseSingleQuotedString)

Example 2 with Comment

use of graphql.language.Comment in project graphql-java by graphql-java.

the class SchemaPrinter method descriptionAndComments.

AstDescriptionAndComments descriptionAndComments(Supplier<String> stringSupplier, Supplier<Node> nodeSupplier, Supplier<Description> descriptionSupplier) {
    String runtimeDesc = stringSupplier.get();
    Node node = nodeSupplier.get();
    Description description = null;
    List<Comment> comments = null;
    if (node != null) {
        comments = node.getComments();
        description = descriptionSupplier.get();
    }
    return new AstDescriptionAndComments(runtimeDesc, description, comments);
}
Also used : Comment(graphql.language.Comment) Description(graphql.language.Description) Node(graphql.language.Node)

Example 3 with Comment

use of graphql.language.Comment in project graphql-java by graphql-java.

the class SchemaGeneratorHelper method buildDescription.

public String buildDescription(Node<?> node, Description description) {
    if (description != null) {
        return description.getContent();
    }
    List<Comment> comments = node.getComments();
    List<String> lines = new ArrayList<>();
    for (Comment comment : comments) {
        String commentLine = comment.getContent();
        if (commentLine.trim().isEmpty()) {
            lines.clear();
        } else {
            lines.add(commentLine);
        }
    }
    if (lines.size() == 0)
        return null;
    return lines.stream().collect(joining("\n"));
}
Also used : Comment(graphql.language.Comment) ArrayList(java.util.ArrayList)

Aggregations

Comment (graphql.language.Comment)3 ArrayList (java.util.ArrayList)2 Description (graphql.language.Description)1 Node (graphql.language.Node)1 SourceLocation (graphql.language.SourceLocation)1 StringValueParsing.parseSingleQuotedString (graphql.parser.StringValueParsing.parseSingleQuotedString)1 StringValueParsing.parseTripleQuotedString (graphql.parser.StringValueParsing.parseTripleQuotedString)1 Token (org.antlr.v4.runtime.Token)1