Browse Source

Fixed code formatter for map lookups

Jared 5 years ago
parent
commit
45616e31c4
No account linked to committer's email address

+ 3
- 2
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/ExpressionFormatter.java View File

@@ -178,9 +178,10 @@ public class ExpressionFormatter implements ExpressionVisitor<ExpressionString>
178 178
 				}
179 179
 				case INDEXGET: {
180 180
 					StringBuilder result = new StringBuilder();
181
-					result.append(expression.target);
181
+					result.append(((GetLocalVariableExpression) expression.target).variable.name);
182 182
 					result.append("[");
183
-					for (int i = 0; i < expression.arguments.arguments.length - 1; i++) {
183
+					//why -1?
184
+					for (int i = 0; i < expression.arguments.arguments.length; i++) {
184 185
 						if (i > 0)
185 186
 							result.append(", ");
186 187
 						

+ 4
- 3
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/StatementFormatter.java View File

@@ -132,8 +132,8 @@ public class StatementFormatter implements StatementVisitor<Void> {
132 132
 	public Void visitExpression(ExpressionStatement statement) {
133 133
 		WhitespaceInfo whitespace = statement.getTag(WhitespaceInfo.class);
134 134
 		beginSingleLine(whitespace);
135
-		output.append(statement.expression.accept(expressionFormatter).value)
136
-			  .append(";");
135
+        String value = statement.expression.accept(expressionFormatter).value;
136
+        output.append(value).append(";");
137 137
 		endSingleLine(whitespace);
138 138
 		return null;
139 139
 	}
@@ -278,7 +278,8 @@ public class StatementFormatter implements StatementVisitor<Void> {
278 278
 		}
279 279
 		if (statement.initializer != null) {
280 280
 			output.append(" = ");
281
-			output.append(statement.initializer.accept(expressionFormatter).value);
281
+            String value = statement.initializer.accept(expressionFormatter).value;
282
+            output.append(value);
282 283
 		}
283 284
 		output.append(";");
284 285
 		endSingleLine(whitespace);

+ 1
- 1
CodeFormatter/src/main/java/org/openzen/zenscript/formatter/TypeFormatter.java View File

@@ -90,7 +90,7 @@ public class TypeFormatter implements TypeVisitor<String>, GenericParameterBound
90 90
 	@Override
91 91
 	public String visitDefinition(DefinitionTypeID definition) {
92 92
 		String importedName = importer.importDefinition(definition.definition);
93
-		if (definition.typeArguments == null)
93
+		if (definition.typeArguments == null || definition.typeArguments.length == 0)
94 94
 			return importedName;
95 95
 		
96 96
 		StringBuilder result = new StringBuilder();

Loading…
Cancel
Save