-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce unformatted toString #239
Introduce unformatted toString #239
Conversation
PR Review ChecklistDo not edit the content of this comment. The PR reviewer should simply update this comment by ticking each review item below, as they get completed. Code
Architecture
|
@@ -54,7 +54,9 @@ public Negation(T pattern) { | |||
this.pattern = pattern; | |||
} | |||
|
|||
public T pattern() { return pattern; } | |||
public T pattern() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reformatting
@@ -71,4 +71,6 @@ default Conjunctable asConjunctable() { | |||
|
|||
@Override | |||
String toString(); | |||
|
|||
String toString(boolean pretty); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new interface method
@@ -171,15 +171,27 @@ private static void validateThen(String label, @Nullable Conjunction<? extends P | |||
|
|||
@Override | |||
public String toString() { | |||
return toString(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default is that we pretty print
body.append(NEW_LINE).append(CURLY_CLOSE); | ||
rule.append(indent(body)); | ||
} else { | ||
rule.append(COLON); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new branch
.filter(s -> !s.isEmpty()).collect(COMMA_NEW_LINE.joiner()); | ||
constraints = indent(constraints).trim(); | ||
} else { | ||
constraints = Stream.of(isaSyntax(), hasSyntax()).filter(s -> !s.isEmpty()).collect(COMMA.joiner()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new branch
constraints = Stream.of(thingSyntax(), hasSyntax()).filter(s -> !s.isEmpty()).collect(COMMA_NEW_LINE.joiner()); | ||
constraints = indent(constraints).trim(); | ||
} else { | ||
constraints = Stream.of(thingSyntax(), hasSyntax()).filter(s -> !s.isEmpty()).collect(COMMA.joiner()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new branch
@@ -109,12 +110,17 @@ public TypeQLMatch.Group.Aggregate asMatchGroupAggregate() { | |||
} | |||
} | |||
|
|||
protected void appendSubQuery(StringBuilder query, TypeQLToken.Command command, List<?> elements) { | |||
protected void appendSubQuery(StringBuilder query, TypeQLToken.Command command, Stream<String> elements, boolean pretty) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this is a very generic method that can't even take a generic, we just pass in the string stream that must be pre-prepared
What is the goal of this PR?
We introduce an unformatted
toString
method which will not introduce any indentation or newlines.This fixes a bug where a user's strings with newlines in them receive indentation in the middle of the attribute. Now, to avoid this visual or downstream effect the API exists to disable newlines and indentation.
What are the changes implemented in this PR?
toString(boolean pretty)
which allows enabling or disabling pretty-printing. This API is available onDefineable
,TypeQLQuery
, andPattern
, but notConstraint
since these are very short and don't do any pretty printing themselves.toString()
on all objects does do pretty printing when the option is available