/* * MicroJIAC - A Lightweight Agent Framework * This file is part of MicroJIAC MIDlet-Maven-Plugin. * * Copyright (c) 2007-2012 DAI-Labor, Technische Universität Berlin * * This library includes software developed at DAI-Labor, Technische * Universität Berlin (http://www.dai-labor.de) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/> */ /* * $Id$ */ package de.jiac.micro.reflect; import java.io.IOException; import java.io.PrintStream; import java.text.DateFormat; import java.util.Date; /** * @author Marcel Patzlaff * @version $Revision:$ */ abstract class GeneratorUtil { private final static DateFormat DATE_FORMAT= DateFormat.getDateTimeInstance(); protected static String getJavaSourceClassName(Class clazz) { return clazz.getName().replace('$', '.'); } protected static void insertFromObjectConversion(Appendable out, Class<?> argType, CharSequence variable) { try { if(argType == boolean.class) { out.append("((Boolean)").append(variable).append(").booleanValue()"); } else if(argType == byte.class) { out.append("((Byte)").append(variable).append(").byteValue()"); } else if(argType == char.class) { out.append("((Character)").append(variable).append(").charValue()"); } else if(argType == double.class) { out.append("((Double)").append(variable).append(").doubleValue()"); } else if(argType == float.class) { out.append("((Float)").append(variable).append(").floatValue()"); } else if(argType == int.class) { out.append("((Integer)").append(variable).append(").intValue()"); } else if(argType == long.class) { out.append("((Long)").append(variable).append(").longValue()"); } else if(argType == short.class) { out.append("((Short)").append(variable).append(").shortValue()"); } else { out.append('(').append(getJavaSourceClassName(argType)).append(')').append(variable); } } catch (IOException ioe) { // should never happen throw new AssertionError(ioe); } } protected static void insertToObjectConversion(Appendable out, Class<?> type, CharSequence variable) { try { if(type == boolean.class) { out.append("new Boolean(").append(variable).append(')'); } else if(type == byte.class) { out.append("new Byte(").append(variable).append(')'); } else if(type == char.class) { out.append("new Character(").append(variable).append(')'); } else if(type == double.class) { out.append("new Double(").append(variable).append(')'); } else if(type == float.class) { out.append("new Float(").append(variable).append(')'); } else if(type == int.class) { out.append("new Integer(").append(variable).append(')'); } else if(type == long.class) { out.append("new Long(").append(variable).append(')'); } else if(type == short.class) { out.append("new Short(").append(variable).append(')'); } else { out.append(variable); } } catch (IOException ioe) { // should never happen throw new AssertionError(ioe); } } protected static void printHeader(PrintStream out) { out.println("//"); out.println("// This file was generated by the Maven-MIDlet-Plugin for MicroJIAC."); out.println("// Any modifications to this file will be lost upon re-running the plugin!"); out.append("// Generated on: ").println(DATE_FORMAT.format(new Date(System.currentTimeMillis()))); out.println("//"); out.println(); out.println(); } }