package emn.fr.ascola.extractor;

import org.eclipse.jdt.core.Signature;

/**
 * Simple utility class.
 * @author jroyer
 * TODO voir si tutile
 *
 */
public class Utility {
	
	/**
	 * Simple decoder for types.
	 * @param str from a Signature
	 * TODO partiel n'y a t'il pas mieux !!!!
	 * @return
	 */
	public final static String decoder(String str) {
		//System.out.println(" utility first char " + str.charAt(0) + " test " + (str.charAt(0) == Signature.C_BOOLEAN));
		switch (str.charAt(0)) {
		case Signature.C_BOOLEAN : return "boolean";
		case Signature.C_BYTE : return "byte";
		case Signature.C_CHAR : return "char";
		case Signature.C_FLOAT : return "float";
		case Signature.C_INT : return "int";
		case Signature.C_LONG : return "long";
		case Signature.C_VOID : return "void";
		case Signature.C_DOUBLE : return "double";
		case Signature.C_SHORT : return "short";
		default : return str.substring(1, str.length() - 1);
		}
	}
	
	/**
	 * Build a full binary name from a resolved.
	 * TODO if several ?
	 * TODO find the dot constant 
	 * @param resolved
	 * @return
	 */
	public final static String buildFullName(String name, String [] [] resolved) {
		//System.out.println("Utility.buildfullName " + name + " " + resolved);
		if (resolved != null) {
			if (resolved[0][0].length() == 0) {
				return resolved[0][1];
			} else {
				return resolved[0][0] + "." + resolved[0][1];
			}
		} else {
			// TODO problem with primitif
			//return "";
			return name;
		}
	}

}
