blob: 39d7d78bafa200fecabcdd2ce7cc585618ee61fa [file] [log] [blame]
package org.codehaus.modello.plugin.store.tool;
/*
* Copyright (c) 2005, Codehaus.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.codehaus.modello.model.ModelField;
import org.codehaus.plexus.util.StringUtils;
/**
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @version $Id: JavaTool.java 803 2007-02-09 11:12:55Z brett $
*/
public class JavaTool
{
public String makeGetter( ModelField field )
{
if ( field.getType().equals( "boolean" ) )
{
return "is" + field.getName().substring( 0, 1 ).toUpperCase() + field.getName().substring( 1 );
}
return "get" + field.getName().substring( 0, 1 ).toUpperCase() + field.getName().substring( 1 );
}
public String makeSetter( ModelField field )
{
return "set" + field.getName().substring( 0, 1 ).toUpperCase() + field.getName().substring( 1 );
}
public void fail( String message )
throws Exception
{
throw new Exception( message );
}
public String uncapitalise( String s )
{
return StringUtils.uncapitalise( s );
}
public String capitalise( String s )
{
return StringUtils.capitalise( s );
}
public String singular( String name )
{
if ( name.endsWith( "ies" ) )
{
return name.substring( 0, name.length() - 3 ) + "y";
}
else if ( name.endsWith( "es" ) && name.endsWith( "ches" ) )
{
return name.substring( 0, name.length() - 2 );
}
else if ( name.endsWith( "s" ) )
{
return name.substring( 0, name.length() - 1 );
}
return name;
}
}