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
 				}
178
 				}
179
 				case INDEXGET: {
179
 				case INDEXGET: {
180
 					StringBuilder result = new StringBuilder();
180
 					StringBuilder result = new StringBuilder();
181
-					result.append(expression.target);
181
+					result.append(((GetLocalVariableExpression) expression.target).variable.name);
182
 					result.append("[");
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
 						if (i > 0)
185
 						if (i > 0)
185
 							result.append(", ");
186
 							result.append(", ");
186
 						
187
 						

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

132
 	public Void visitExpression(ExpressionStatement statement) {
132
 	public Void visitExpression(ExpressionStatement statement) {
133
 		WhitespaceInfo whitespace = statement.getTag(WhitespaceInfo.class);
133
 		WhitespaceInfo whitespace = statement.getTag(WhitespaceInfo.class);
134
 		beginSingleLine(whitespace);
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
 		endSingleLine(whitespace);
137
 		endSingleLine(whitespace);
138
 		return null;
138
 		return null;
139
 	}
139
 	}
278
 		}
278
 		}
279
 		if (statement.initializer != null) {
279
 		if (statement.initializer != null) {
280
 			output.append(" = ");
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
 		output.append(";");
284
 		output.append(";");
284
 		endSingleLine(whitespace);
285
 		endSingleLine(whitespace);

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

90
 	@Override
90
 	@Override
91
 	public String visitDefinition(DefinitionTypeID definition) {
91
 	public String visitDefinition(DefinitionTypeID definition) {
92
 		String importedName = importer.importDefinition(definition.definition);
92
 		String importedName = importer.importDefinition(definition.definition);
93
-		if (definition.typeArguments == null)
93
+		if (definition.typeArguments == null || definition.typeArguments.length == 0)
94
 			return importedName;
94
 			return importedName;
95
 		
95
 		
96
 		StringBuilder result = new StringBuilder();
96
 		StringBuilder result = new StringBuilder();

Loading…
Cancel
Save