From 64711e615e78328cee3250e83db0527f1c33c0f7 Mon Sep 17 00:00:00 2001 From: Muga Nishizawa Date: Wed, 20 Oct 2010 21:04:37 +0900 Subject: java: write test programs for org.msgpack.util.codegen.*.java --- .../msgpack/util/codegen/DynamicCodeGenBase.java | 66 ++++++++-------------- .../java/org/msgpack/util/codegen/FieldOption.java | 10 ++++ 2 files changed, 32 insertions(+), 44 deletions(-) create mode 100644 java/src/main/java/org/msgpack/util/codegen/FieldOption.java (limited to 'java/src/main') diff --git a/java/src/main/java/org/msgpack/util/codegen/DynamicCodeGenBase.java b/java/src/main/java/org/msgpack/util/codegen/DynamicCodeGenBase.java index 7cb9048..f1415d5 100644 --- a/java/src/main/java/org/msgpack/util/codegen/DynamicCodeGenBase.java +++ b/java/src/main/java/org/msgpack/util/codegen/DynamicCodeGenBase.java @@ -33,6 +33,9 @@ import org.slf4j.LoggerFactory; public class DynamicCodeGenBase implements Constants { + private static Logger LOG = LoggerFactory + .getLogger(DynamicCodeGenBase.class); + public static interface NullChecker { void setNullCheck(boolean nullCheck); } @@ -58,9 +61,6 @@ public class DynamicCodeGenBase implements Constants { } } - private static Logger LOG = LoggerFactory - .getLogger(DynamicCodeGenBase.class); - private static AtomicInteger COUNTER = new AtomicInteger(0); protected static int inc() { @@ -74,80 +74,58 @@ public class DynamicCodeGenBase implements Constants { } protected void checkTypeValidation(Class type) { - DynamicCodeGenException e = new DynamicCodeGenException("Fatal error: " - + type.getName()); + DynamicCodeGenException e = new DynamicCodeGenException(String.format( + "Fatal error: %s", new Object[] { type.getName() })); LOG.error(e.getMessage(), e); throw e; } - protected void throwTypeValidationException(Class origClass, - String message) throws DynamicCodeGenException { - DynamicCodeGenException e = new DynamicCodeGenException(message + ": " - + origClass.getName()); + protected void throwTypeValidationException(Class type, String message) + throws DynamicCodeGenException { + DynamicCodeGenException e = new DynamicCodeGenException(String.format( + "%s: %s", new Object[] { message, type.getName() })); LOG.error(e.getMessage(), e); throw e; } protected void checkDefaultConstructorValidation(Class type) { - DynamicCodeGenException e = new DynamicCodeGenException("Fatal error: " - + type.getName()); + DynamicCodeGenException e = new DynamicCodeGenException(String.format( + "Fatal error: %s", new Object[] { type.getName() })); LOG.error(e.getMessage(), e); throw e; } protected void throwConstructorValidationException(Class origClass) { - DynamicCodeGenException e = new DynamicCodeGenException( - "it must have a public zero-argument constructor: " - + origClass.getName()); + DynamicCodeGenException e = new DynamicCodeGenException(String.format( + "it must have a public zero-argument constructor: %s", + new Object[] { origClass.getName() })); LOG.error(e.getMessage(), e); throw e; } - protected void throwFieldValidationException(Field f) { - DynamicCodeGenException e = new DynamicCodeGenException( - "it must be a public field: " + f.getName()); + protected void throwFieldValidationException(Field field) { + DynamicCodeGenException e = new DynamicCodeGenException(String.format( + "it must be a public field: %s", + new Object[] { field.getName() })); LOG.debug(e.getMessage(), e); throw e; } protected static void throwMethodValidationException(Method method, String message) throws DynamicCodeGenException { - DynamicCodeGenException e = new DynamicCodeGenException(message + ": " - + method.getName()); + DynamicCodeGenException e = new DynamicCodeGenException(String.format( + "%s: %s", new Object[] { message, method.getName() })); LOG.error(e.getMessage(), e); throw e; } protected CtClass makeClass(String name) throws NotFoundException { - DynamicCodeGenException e = new DynamicCodeGenException("Fatal error: " - + name); + DynamicCodeGenException e = new DynamicCodeGenException(String.format( + "Fatal error: %s", new Object[] { name })); LOG.error(e.getMessage(), e); throw e; } - enum Color { - // TODO - RED, BLUE - } - - public static void main(String[] args) throws Exception { - // TODO - class Foo { - } - class Bar extends Foo { - } - Color c = Color.RED; - Color c1 = null; - - ClassPool pool = ClassPool.getDefault(); - CtClass barCtClass = pool.get(Bar.class.getName()); - CtClass sbarCtClass = barCtClass.getSuperclass(); - System.out.println("bar: " + sbarCtClass.getName()); - CtClass fooCtClass = pool.get(Foo.class.getName()); - CtClass sfooCtClass = fooCtClass.getSuperclass(); - System.out.println("foo: " + sfooCtClass.getName()); - } - protected void setSuperclass(CtClass newCtClass, Class superClass) throws NotFoundException, CannotCompileException { // check the specified super class diff --git a/java/src/main/java/org/msgpack/util/codegen/FieldOption.java b/java/src/main/java/org/msgpack/util/codegen/FieldOption.java new file mode 100644 index 0000000..723a765 --- /dev/null +++ b/java/src/main/java/org/msgpack/util/codegen/FieldOption.java @@ -0,0 +1,10 @@ +package org.msgpack.util.codegen; + +import org.msgpack.Template; + +public class FieldOption { + + public String name; + + public Template tmpl; +} -- cgit v1.2.1