initial commit for labryinth project on git_hub.
Signed-off-by: philippe lhardy <philippe@pavilionartlogiciel>
This commit is contained in:
74
java/generate_newclass.sh
Executable file
74
java/generate_newclass.sh
Executable file
@@ -0,0 +1,74 @@
|
||||
#!/bin/bash
|
||||
|
||||
PACKAGE=org.artisanlogiciel.games
|
||||
|
||||
while [[ $# > 0 ]]
|
||||
do
|
||||
case $1 in
|
||||
package=*)
|
||||
PACKAGE=${1/package=/}
|
||||
;;
|
||||
*)
|
||||
CLASS=${1}
|
||||
;;
|
||||
esac
|
||||
shift 1
|
||||
done
|
||||
|
||||
if [[ -z $CLASS ]]
|
||||
then
|
||||
echo "[ERROR] Missing class" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PACKAGE_DIR=${PACKAGE//\./\/}
|
||||
|
||||
if [[ ! -d $PACKAGE_DIR ]]
|
||||
then
|
||||
echo "Missing $PACKAGE_DIR" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
JAVA_FILE=$PACKAGE_DIR/$CLASS.java
|
||||
if [[ -e $JAVA_FILE ]]
|
||||
then
|
||||
echo "[ERROR] $JAVA_FILE already exists" >&2
|
||||
exit 1
|
||||
else
|
||||
|
||||
cat <<EOF >$JAVA_FILE
|
||||
package $PACKAGE;
|
||||
|
||||
/**
|
||||
$CLASS was autogenerated by $0
|
||||
**/
|
||||
public class $CLASS
|
||||
{
|
||||
Object param;
|
||||
|
||||
$CLASS(Object param)
|
||||
{
|
||||
this.param=param;
|
||||
}
|
||||
|
||||
void method()
|
||||
{
|
||||
System.out.println("Method of $PACKAGE.$CLASS");
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
if ( args.length > 1 )
|
||||
{
|
||||
$CLASS instance=new $CLASS(args[1]);
|
||||
instance.method();
|
||||
}
|
||||
else
|
||||
{
|
||||
System.err.println("Missing argument for $CLASS");
|
||||
}
|
||||
}
|
||||
}
|
||||
EOF
|
||||
fi
|
||||
|
||||
echo "$JAVA_FILE generated"
|
||||
Reference in New Issue
Block a user