예제 #1
0
 /** Convert a collection of ConstantSets to the format expected by GenTest.addClassLiterals. */
 public static MultiMap<Class<?>, PrimitiveOrStringOrNullDecl> toMap(
     Collection<ConstantSet> constantSets) {
   final MultiMap<Class<?>, PrimitiveOrStringOrNullDecl> map =
       new MultiMap<Class<?>, PrimitiveOrStringOrNullDecl>();
   for (ConstantSet cs : constantSets) {
     Class<?> clazz;
     try {
       clazz = Class.forName(cs.classname);
     } catch (ClassNotFoundException e) {
       throw new Error("Class " + cs.classname + " not found on the classpath.");
     }
     for (Integer x : cs.ints) {
       map.add(clazz, new PrimitiveOrStringOrNullDecl(int.class, x.intValue()));
     }
     for (Long x : cs.longs) {
       map.add(clazz, new PrimitiveOrStringOrNullDecl(long.class, x.longValue()));
     }
     for (Float x : cs.floats) {
       map.add(clazz, new PrimitiveOrStringOrNullDecl(float.class, x.floatValue()));
     }
     for (Double x : cs.doubles) {
       map.add(clazz, new PrimitiveOrStringOrNullDecl(double.class, x.doubleValue()));
     }
     for (String x : cs.strings) {
       map.add(clazz, new PrimitiveOrStringOrNullDecl(String.class, x));
     }
     for (Class<?> x : cs.classes) {
       map.add(clazz, new PrimitiveOrStringOrNullDecl(Class.class, x));
     }
   }
   return map;
 }
예제 #2
0
 private void createCode(Element code) throws IllegalXMLVMException {
   List<Element> instructions = code.getChildren();
   for (Element inst : instructions) {
     String name = inst.getName();
     String opcMethodName =
         "createInstruction" + name.substring(0, 1).toUpperCase() + name.substring(1);
     Class appClazz;
     Method opcMeth;
     Class[] paramTypes = {Element.class};
     Object[] params = {inst};
     appClazz = this.getClass();
     Object newInstr = null;
     try {
       opcMeth = appClazz.getMethod(opcMethodName, paramTypes);
       newInstr = opcMeth.invoke(this, params);
     } catch (NoSuchMethodException ex) {
       throw new IllegalXMLVMException(
           "Illegal instruction 1, unable to find method "
               + opcMethodName
               + " for '"
               + name
               + "'");
     } catch (InvocationTargetException ex) {
       ex.printStackTrace();
       throw new IllegalXMLVMException("Illegal instruction 2 '" + name + "'");
     } catch (IllegalAccessException ex) {
       throw new IllegalXMLVMException("Illegal instruction 3 '" + name + "'");
     }
     if (newInstr != null) {
       InstructionHandle ih = null;
       if (newInstr instanceof BranchInstruction) ih = il.append((BranchInstruction) newInstr);
       else if (newInstr instanceof CompoundInstruction)
         ih = il.append((CompoundInstruction) newInstr);
       else if (newInstr instanceof Instruction) ih = il.append((Instruction) newInstr);
       instructionHandlerManager.registerInstructionHandle(ih);
     }
   }
 }