package code;
import model.Method;
import model.Set;

class Code {
	public static function extractFieldName(accessorName : String, prefixLength : Int = 3) : String {
		return accessorName.charAt(prefixLength).toLowerCase() + accessorName.substr(prefixLength + 1);
	}

	public static function overrides(set : Set, method : Method) : Bool { //REFACTOR : common
		var value : Bool;
		if (method.isStatic || set.superset == null) {
			value = false;
		} else {
			if (Lambda.exists(set.superset.methods, m -> m.className == method.className)) {
				value = true;
			} else {
				value = overrides(set.superset, method);
			}
		}
		return value;
	}

	public static function getDefaultValue(classType : String, newArray : String, nullValue : String = "null" ) : String {
		var value : String = "";
		if (classType.substr(0, 5) == "Array") {
			value = newArray;
		} else {
			value = switch (classType) {
				case "String" : "\"\"";
				case "Int" | "Double" | "Float": "0";
				case "Bool" : "false";
				default : nullValue;
			}
		}
		return value;
	}
}
