Explorar el Código

Started work on definition formatting.

Stan Hebben hace 6 años
padre
commit
4441f43381

+ 14
- 2
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/DefinitionFormatter.java Ver fichero

@@ -21,7 +21,7 @@ import org.openzen.zenscript.codemodel.definition.StructDefinition;
21 21
 public class DefinitionFormatter implements DefinitionVisitor<Void> {
22 22
 	private final FormattingSettings settings;
23 23
 	private final TypeFormatter typeFormatter;
24
-	private final StringBuilder builder = new StringBuilder();
24
+	private final StringBuilder output = new StringBuilder();
25 25
 	private final String indent;
26 26
 	
27 27
 	public DefinitionFormatter(FormattingSettings settings, TypeFormatter typeFormatter, String indent) {
@@ -32,6 +32,18 @@ public class DefinitionFormatter implements DefinitionVisitor<Void> {
32 32
 
33 33
 	@Override
34 34
 	public Void visitClass(ClassDefinition definition) {
35
+		FormattingUtils.formatModifiers(output, definition.modifiers);
36
+		output.append("class ");
37
+		output.append(definition.name);
38
+		if (definition.genericParameters.length > 0) {
39
+			
40
+		}
41
+		output.append(" ");
42
+		if (definition.superType != null) {
43
+			output.append("extends ");
44
+			output.append(definition.superType.accept(typeFormatter));
45
+			output.append(" ");
46
+		}
35 47
 		return null;
36 48
 	}
37 49
 
@@ -66,6 +78,6 @@ public class DefinitionFormatter implements DefinitionVisitor<Void> {
66 78
 	}
67 79
 	
68 80
 	public String toString() {
69
-		return builder.toString();
81
+		return output.toString();
70 82
 	}
71 83
 }

+ 43
- 0
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/FormattingUtils.java Ver fichero

@@ -0,0 +1,43 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.formatter;
7
+
8
+import org.openzen.zenscript.codemodel.Modifiers;
9
+
10
+/**
11
+ *
12
+ * @author Hoofdgebruiker
13
+ */
14
+public class FormattingUtils {
15
+	private FormattingUtils() {}
16
+	
17
+	public static void formatModifiers(StringBuilder output, int modifiers) {
18
+		if (Modifiers.isPrivate(modifiers))
19
+			output.append("private ");
20
+		if (Modifiers.isProtected(modifiers))
21
+			output.append("protected ");
22
+		if (Modifiers.isPublic(modifiers))
23
+			output.append("public ");
24
+		if (Modifiers.isExport(modifiers))
25
+			output.append("export ");
26
+		if (Modifiers.isStatic(modifiers))
27
+			output.append("static ");
28
+		if (Modifiers.isAbstract(modifiers))
29
+			output.append("abstract ");
30
+		if (Modifiers.isVirtual(modifiers))
31
+			output.append("virtual ");
32
+		if (Modifiers.isFinal(modifiers))
33
+			output.append("final ");
34
+		if (Modifiers.isExtern(modifiers))
35
+			output.append("extern ");
36
+		if (Modifiers.isImplicit(modifiers))
37
+			output.append("implicit ");
38
+		if (Modifiers.isConst(modifiers))
39
+			output.append("const ");
40
+		if (Modifiers.isConstOptional(modifiers))
41
+			output.append("const? ");
42
+	}
43
+}

Loading…
Cancelar
Guardar