Browse Source

Started work on definition formatting.

Stan Hebben 6 years ago
parent
commit
4441f43381

+ 14
- 2
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/DefinitionFormatter.java View File

21
 public class DefinitionFormatter implements DefinitionVisitor<Void> {
21
 public class DefinitionFormatter implements DefinitionVisitor<Void> {
22
 	private final FormattingSettings settings;
22
 	private final FormattingSettings settings;
23
 	private final TypeFormatter typeFormatter;
23
 	private final TypeFormatter typeFormatter;
24
-	private final StringBuilder builder = new StringBuilder();
24
+	private final StringBuilder output = new StringBuilder();
25
 	private final String indent;
25
 	private final String indent;
26
 	
26
 	
27
 	public DefinitionFormatter(FormattingSettings settings, TypeFormatter typeFormatter, String indent) {
27
 	public DefinitionFormatter(FormattingSettings settings, TypeFormatter typeFormatter, String indent) {
32
 
32
 
33
 	@Override
33
 	@Override
34
 	public Void visitClass(ClassDefinition definition) {
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
 		return null;
47
 		return null;
36
 	}
48
 	}
37
 
49
 
66
 	}
78
 	}
67
 	
79
 	
68
 	public String toString() {
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 View File

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…
Cancel
Save