Skip to content
This repository was archived by the owner on Jun 26, 2022. It is now read-only.

Commit aa42d5f

Browse files
committed
New TypeQL code style: patterns and constraints are printed on new, indented lines
1 parent 02b1bf9 commit aa42d5f

18 files changed

+430
-324
lines changed

common/TypeQLToken.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
package com.vaticle.typeql.lang.common;
2323

2424
import com.vaticle.typeql.lang.common.exception.TypeQLException;
25+
import java.util.stream.Collector;
26+
import java.util.stream.Collectors;
2527
import static com.vaticle.typedb.common.util.Objects.className;
2628
import static com.vaticle.typeql.lang.common.exception.ErrorMessage.INVALID_CASTING;
2729

@@ -116,9 +118,11 @@ public enum Char {
116118
EQUAL("="),
117119
COLON(":"),
118120
SEMICOLON(";"),
121+
SEMICOLON_NEW_LINE(";\n"),
119122
SPACE(" "),
120123
COMMA(","),
121124
COMMA_SPACE(", "),
125+
COMMA_NEW_LINE(",\n"),
122126
CURLY_OPEN("{"),
123127
CURLY_CLOSE("}"),
124128
PARAN_OPEN("("),
@@ -128,6 +132,7 @@ public enum Char {
128132
QUOTE_DOUBLE("\""),
129133
QUOTE_SINGLE("'"),
130134
NEW_LINE("\n"),
135+
INDENTATION(" "),
131136
UNDERSCORE("_"),
132137
$_("$_"),
133138
$("$");
@@ -138,6 +143,10 @@ public enum Char {
138143
this.character = character;
139144
}
140145

146+
public Collector<CharSequence, ?, String> joiner() {
147+
return Collectors.joining(character);
148+
}
149+
141150
@Override
142151
public String toString() {
143152
return this.character;

common/util/Strings.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323

2424
import java.text.DecimalFormat;
2525
import java.text.DecimalFormatSymbols;
26+
import java.util.Arrays;
2627
import java.util.Locale;
28+
import static com.vaticle.typeql.lang.common.TypeQLToken.Char.INDENTATION;
29+
import static com.vaticle.typeql.lang.common.TypeQLToken.Char.NEW_LINE;
2730

2831
public class Strings {
2932

@@ -43,6 +46,14 @@ public static String quoteString(String string) {
4346
return "\"" + string + "\"";
4447
}
4548

49+
public static String indent(Object object) {
50+
return indent(object.toString());
51+
}
52+
53+
public static String indent(String string) {
54+
return Arrays.stream(string.split("\n")).map(s -> INDENTATION + s).collect(NEW_LINE.joiner());
55+
}
56+
4657
/**
4758
* @param value a value in the graph
4859
* @return the string representation of the value (using quotes if it is already a string)

0 commit comments

Comments
 (0)