Skip to content
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

Merged

Conversation

flyingsilverfin
Copy link
Member

@flyingsilverfin flyingsilverfin commented Oct 21, 2022

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?

  • introduce toString(boolean pretty) which allows enabling or disabling pretty-printing. This API is available on Defineable, TypeQLQuery, and Pattern, but not Constraint since these are very short and don't do any pretty printing themselves.
  • the default toString() on all objects does do pretty printing when the option is available

@typedb-bot
Copy link
Member

typedb-bot commented Oct 21, 2022

PR Review Checklist

Do 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

  • Packages, classes, and methods have a single domain of responsibility.
  • Packages, classes, and methods are grouped into cohesive and consistent domain model.
  • The code is canonical and the minimum required to achieve the goal.
  • Modules, libraries, and APIs are easy to use, robust (foolproof and not errorprone), and tested.
  • Logic and naming has clear narrative that communicates the accurate intent and responsibility of each module (e.g. method, class, etc.).
  • The code is algorithmically efficient and scalable for the whole application.

Architecture

  • Any required refactoring is completed, and the architecture does not introduce technical debt incidentally.
  • Any required build and release automations are updated and/or implemented.
  • Any new components follows a consistent style with respect to the pre-existing codebase.
  • The architecture intuitively reflects the application domain, and is easy to understand.
  • The architecture has a well-defined hierarchy of encapsulated components.
  • The architecture is extensible and scalable.

@@ -54,7 +54,9 @@ public Negation(T pattern) {
this.pattern = pattern;
}

public T pattern() { return pattern; }
public T pattern() {
Copy link
Member Author

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);
Copy link
Member Author

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);
Copy link
Member Author

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);
Copy link
Member Author

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());
Copy link
Member Author

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());
Copy link
Member Author

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) {
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants