Skip to content

Commit

Permalink
Refactored folders to refelct multi language
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengoldbaum committed Jun 15, 2024
1 parent 1d7e75f commit 80417b2
Show file tree
Hide file tree
Showing 10 changed files with 348 additions and 286 deletions.
258 changes: 0 additions & 258 deletions DataThread/src/graphql_server.js

This file was deleted.

35 changes: 7 additions & 28 deletions DataThread/src/main/java/datathread/backends/JavaEmitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public JavaEmitter(Context context) {
}

public TypeSpec handleDataset(Dataset dataset) {
String name = nameToJavaClassName(dataset.getName());
String name = nameToJava(dataset.getName());
List<FieldSpec> fields =
dataset.getFields().stream()
.map(f -> handleField(this.context, f))
Expand Down Expand Up @@ -62,15 +62,12 @@ public ClassName handleElementType(ElementType elementType) {
case "DateTime":
return ClassName.get(java.time.LocalDateTime.class);
case "Enum":
String name = ("" + elementType.getAdditionalProperties().get("name"))
.replaceAll("\\{", "").replaceAll("\\}", "");
return resolveReference(name);
return idToClassName(elementType.getAdditionalProperties().get("name").toString());
case "Number":
return ClassName.get(Double.class);
case "Reference":
String ref = ("" + elementType.getAdditionalProperties().get("Reference"))
.replaceAll("\\{", "").replaceAll("\\}", "");
return resolveReference(ref);
String ref = "" + elementType.getAdditionalProperties().get("Reference");
return idToClassName(ref);
case "Text":
return ClassName.get(String.class);
default:
Expand Down Expand Up @@ -111,33 +108,15 @@ public TypeSpec handleElement(Element element) {
}

//// Utils ////
public static ClassName resolveReference(String id) {
ClassName className = idToClassName(id);
ClassName result = className;

switch (className.canonicalName()) {
case "core.Integer":
result = ClassName.get(Integer.class);
break;
}

return result;
}

public static ClassName idToClassName(String id) {
String[] split = id.split(":");

String pkg = escape(split[1]);
String name = nameToJavaClassName(split[2]);
String pkg = nameToJava(split[1]);
String name = nameToJava(split[2]);

return ClassName.get(pkg, name);
}

public static String escape(String s) {
return s.replaceAll("\\W", "_");
}

public static String nameToJavaClassName(String name) {
public static String nameToJava(String name) {
return Arrays.stream(name.split("\\s+"))
.map(JavaEmitter::capitalize)
.collect(Collectors.joining("_"));
Expand Down
File renamed without changes.
Loading

0 comments on commit 80417b2

Please sign in to comment.