summaryrefslogtreecommitdiff
path: root/java/src/main
diff options
context:
space:
mode:
authorMuga Nishizawa <muga@f11vm.(none)>2010-10-20 21:04:37 +0900
committerMuga Nishizawa <muga@f11vm.(none)>2010-10-20 21:04:37 +0900
commit64711e615e78328cee3250e83db0527f1c33c0f7 (patch)
treec09ce6f11d52f165fcce0d1e612978092e1c3d60 /java/src/main
parent2065affd45fbf74bdbeccee4cbd86aad4b321c7e (diff)
downloadmsgpack-python-64711e615e78328cee3250e83db0527f1c33c0f7.tar.gz
java: write test programs for org.msgpack.util.codegen.*.java
Diffstat (limited to 'java/src/main')
-rw-r--r--java/src/main/java/org/msgpack/util/codegen/DynamicCodeGenBase.java66
-rw-r--r--java/src/main/java/org/msgpack/util/codegen/FieldOption.java10
2 files changed, 32 insertions, 44 deletions
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;
+}