Commit 647e1f2d authored by Johannes Mey's avatar Johannes Mey
Browse files

remove import statement from generated code (this also implies Instant and...

remove import statement from generated code (this also implies Instant and Period must be qualified everywhere). some additional minor code quality improvements.
parent 3afecd7c
......@@ -141,7 +141,7 @@ aspect ComponentAnalysis {
//--- relationComponentsTransitive ---
syn Collection<RelationComponent> TypeDecl.relationComponentsTransitive() {
ArrayList<RelationComponent> list = new ArrayList<>();
Collection<RelationComponent> list = new ArrayList<>();
if (hasSuper() && getSuper().decl() != null) {
list.addAll(getSuper().decl().relationComponentsTransitive());
}
......@@ -192,7 +192,7 @@ aspect InstanceSupplier {
//--- subTypeDecls ---
syn Collection<TypeDecl> TypeDecl.subTypeDecls() {
java.util.List<TypeDecl> subDecls = new ArrayList();
Collection<TypeDecl> subDecls = new ArrayList();
for (TypeDecl decl : program().getTypeDeclList()) {
if (decl.hasSuper() && decl.getSuper().getID().equals(getID())) {
subDecls.add(decl);
......
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
// We have been careful to not import many types here because the imports are added for
// _ALL_ AST nodes and can cause collisions in the abstract grammar namespace.
aspect DumpTree {
private static final String ASTNode.DUMP_TREE_INDENT = " ";
public String ASTNode.dumpTree() {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
dumpTree(new PrintStream(bytes));
java.io.ByteArrayOutputStream bytes = new java.io.ByteArrayOutputStream();
dumpTree(new java.io.PrintStream(bytes));
return bytes.toString();
}
public void ASTNode.dumpTree(PrintStream out) {
public void ASTNode.dumpTree(java.io.PrintStream out) {
dumpTree(out, "");
out.flush();
}
public void ASTNode.dumpTree(PrintStream out, String indent) {
public void ASTNode.dumpTree(java.io.PrintStream out, String indent) {
out.print(indent + getClass().getSimpleName());
out.print(getTokens());
String extra = extraDumpInfo();
......@@ -40,26 +33,20 @@ aspect DumpTree {
public String ASTNode.extraDumpInfo() { return ""; }
public String ASTNode.getTokens() {
java.util.TreeSet<java.lang.reflect.Method> methods = new java.util.TreeSet<>(
new java.util.Comparator<java.lang.reflect.Method>() {
public int compare(java.lang.reflect.Method m1, java.lang.reflect.Method m2) {
return m1.getName().compareTo(m2.getName());
}
});
java.util.TreeSet<java.lang.reflect.Method> methods = new java.util.TreeSet<>(Comparator.comparing(Method::getName));
methods.addAll(java.util.Arrays.asList(getClass().getMethods()));
String result = "";
StringBuilder result = new StringBuilder();
for (java.lang.reflect.Method method : methods) {
ASTNodeAnnotation.Token token = method.getAnnotation(ASTNodeAnnotation.Token.class);
if (token != null) {
try {
result += String.format(" %s=\"%s\"", token.name(), method.invoke(this));
} catch (IllegalAccessException ignored) {
} catch (InvocationTargetException ignored) {
result.append(String.format(" %s=\"%s\"", token.name(), method.invoke(this)));
} catch (IllegalAccessException | java.lang.reflect.InvocationTargetException ignored) {
}
}
}
return result;
return result.toString();
}
}
\ No newline at end of file
}
......@@ -3,6 +3,7 @@ aspect BackendAbstractGrammar {
public static String ASTNode.listInterface = "java.util.List";
public static String ASTNode.listClass = "java.util.ArrayList";
public static String ASTNode.jastAddListType = "List";
public static String ASTNode.jastAddOptType = "Opt";
public static boolean ASTNode.resolverHelper = false;
public static boolean ASTNode.serializer = false;
......
......@@ -6,9 +6,6 @@ aspect BackendAspect {
}
public void Program.generateAspect(StringBuilder sb) {
sb.append("import java.util.Collections;\n");
sb.append("import java.time.Instant;\n");
sb.append("import java.time.Period;\n");
sb.append("aspect RelAstAPI {\n");
for (TypeDecl td: getTypeDecls()) {
......@@ -52,7 +49,7 @@ aspect BackendAspect {
return ASTNode.jastAddListType + "<" + getTypeUse() + "> " + getID();
}
public String OptComponent.constructorParameter() {
return "Opt<" + getTypeUse() + "> " + getID();
return ASTNode.jastAddOptType + "<" + getTypeUse() + "> " + getID();
}
public String Component.constructorSetMethod() {
return "set" + getID();
......
......@@ -72,7 +72,7 @@ aspect BackendBidirectionalAPI {
sb.append(ind(3) + "}\n");
sb.append(ind(2) + "}\n");
}
sb.append(ind(2) + "return l != null ? Collections.unmodifiableList(l) : Collections.emptyList();\n");
sb.append(ind(2) + "return l != null ? java.util.Collections.unmodifiableList(l) : java.util.Collections.emptyList();\n");
sb.append(ind(1) + "}\n");
// Add
......@@ -175,7 +175,7 @@ aspect BackendBidirectionalAPI {
sb.append(ind(3) + "}\n");
sb.append(ind(2) + "}\n");
}
sb.append(ind(2) + "return l != null ? Collections.unmodifiableList(l) : Collections.emptyList();\n");
sb.append(ind(2) + "return l != null ? java.util.Collections.unmodifiableList(l) : java.util.Collections.emptyList();\n");
sb.append(ind(1) + "}\n");
// Add
......
......@@ -48,7 +48,7 @@ aspect BackendDirectedAPI {
sb.append(ind(3) + "}\n");
sb.append(ind(2) + "}\n");
}
sb.append(ind(2) + "return l != null ? Collections.unmodifiableList(l) : Collections.emptyList();\n");
sb.append(ind(2) + "return l != null ? java.util.Collections.unmodifiableList(l) : java.util.Collections.emptyList();\n");
sb.append(ind(1) + "}\n");
// Add
......
......@@ -169,10 +169,10 @@ aspect Serializer {
case "String":
sb.append(ind(indent) + "g.writeStringField(\"" + getID() + "\", get" + getID() + "());\n");
break;
case "Instant":
case "java.time.Instant":
sb.append(ind(indent) + "g.writeStringField(\"" + getID() + "\", get" + getID() + "().toString());\n");
break;
case "Period":
case "java.time.Period":
sb.append(ind(indent) + "g.writeStringField(\"" + getID() + "\", get" + getID() + "().toString());\n");
break;
default:
......@@ -390,11 +390,11 @@ aspect Serializer {
case "String":
sb.append(ind(indent) + "element.set" + getID() + "(children.get(\"" + getID() + "\").asText());\n");
break;
case "Instant":
sb.append(ind(indent) + "element.set" + getID() + "(Instant.parse(children.get(\"" + getID() + "\").asText()));\n");
case "java.time.Instant":
sb.append(ind(indent) + "element.set" + getID() + "(java.time.Instant.parse(children.get(\"" + getID() + "\").asText()));\n");
break;
case "Period":
sb.append(ind(indent) + "element.set" + getID() + "(Period.parse(children.get(\"" + getID() + "\").asText()));\n");
case "java.time.Period":
sb.append(ind(indent) + "element.set" + getID() + "(java.time.Period.parse(children.get(\"" + getID() + "\").asText()));\n");
break;
default:
// assume that the type is an enum. there is no way of checking this here
......
......@@ -13,8 +13,8 @@ C:NamedElement ::= D1:D [D2:D] D3:D*
<C1:char> <C2:Character>
<T1:String>
<T2>
<N:Instant>
<P:Period>
<N:java.time.Instant>
<P:java.time.Period>
<Day:Weekday>;
D:NamedElement;
......
......@@ -13,8 +13,8 @@ C:NamedElement ::= D1:D [D2:D] D3:D*
<C1:char> <C2:Character>
<T1:String>
<T2>
<N:Instant>
<P:Period>
<N:java.time.Instant>
<P:java.time.Period>
<Day:Weekday>;
D:NamedElement;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment