/**
 * Copyright (c) 2015 committers of YAKINDU and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * Contributors:
 * 	committers of YAKINDU - initial API and implementation
 * 
 */
package org.yakindu.base.types.typesystem;

import static org.yakindu.base.types.typesystem.ITypeSystem.BOOLEAN;
import static org.yakindu.base.types.typesystem.ITypeSystem.INTEGER;
import static org.yakindu.base.types.typesystem.ITypeSystem.REAL;
import static org.yakindu.base.types.typesystem.ITypeSystem.STRING;
import static org.yakindu.base.types.typesystem.ITypeSystem.VOID;

import java.util.List;

import org.eclipse.emf.common.util.EList;
import org.yakindu.base.types.ComplexType;
import org.yakindu.base.types.EnumerationType;
import org.yakindu.base.types.Enumerator;
import org.yakindu.base.types.Type;

import com.google.inject.Inject;

/**
 * 
 * @author andreas muelder - Initial contribution and API
 * 
 */
public class GenericTypeValueProvider implements ITypeValueProvider {

	@Inject
	private ITypeSystem typeSystem;

	@Override
	public Object defaultValue(Type type) {
		type = type.getOriginType();
		if (is(type, VOID)) {
			return null;
		}
		if (is(type, INTEGER)) {
			return new Long(0);
		}
		if (is(type, REAL)) {
			return new Double(0.0);
		}
		if (is(type, BOOLEAN)) {
			return Boolean.FALSE;
		}
		if (is(type, STRING)) {
			return new String("");
		}
		if (type instanceof EnumerationType) {
			return new Long(0);
		}
		if (type instanceof ComplexType) {
			return null;
		}
		List<Type> superTypes = typeSystem.getSuperTypes(type);
		if (!superTypes.isEmpty())
			return defaultValue(superTypes.get(0));
		throw new IllegalArgumentException("Unknown type " + type);
	}

	protected boolean is(Type type, String typeName) {
		return typeSystem.isSame(type, typeSystem.getType(typeName));
	}

}

@@ -1619,34 +1619,27 @@
 %0A%09%09%09return n
-ew Long(0)
+ull
 ;%0A%09%09%7D%0A%09%09if (

revert #1836 due to side effects with code generation