Package ar.edu.unlp.yaqc4j.exceptions

Examples of ar.edu.unlp.yaqc4j.exceptions.GenerationError


    }
    try {
      this.setObjects((E[]) enumName.getMethod("values", new Class[0])
          .invoke(null, new Object[0]));
    } catch (IllegalArgumentException e) {
      throw new GenerationError(e);
    } catch (SecurityException e) {
      throw new GenerationError(e);
    } catch (IllegalAccessException e) {
      throw new GenerationError(e);
    } catch (InvocationTargetException e) {
      throw new GenerationError(e);
    } catch (NoSuchMethodException e) {
      throw new GenerationError(e);
    }
  }
View Full Code Here


   */
  @Override
  public Long arbitrary(final Distribution random, final long minsize,
      final long maxsize) {
    if (maxsize < 0) {
      throw new GenerationError(
          "Cannot generate positive longs with maxsize = " + maxsize);
    }
    return LONG_GEN.arbitrary(random, Math.max(0, minsize), maxsize);
  }
View Full Code Here

      if (aClass.isInterface()) {
        return new InterfaceInstancesGen(aClass);
        // throw new GenerationException(
        // "No generator has been defined for " + aClass.getName());
      } else if (Modifier.isAbstract(aClass.getModifiers())) {
        throw new GenerationError(
            "The class " + aClass.getName() + " is abstract and no generator could be found for it or its subclasses.");
      } else {
        return new ConstructorBasedGen(aClass);
      }
    }
View Full Code Here

  List<Gen<?>> assignableGenerators = null;
  try {
      classes = ClassSearcher
      .getAssignableClasses(this.getSubjectClass());
  } catch (Exception e) {
      throw new GenerationError(e);
  }
  if (classes != null && !classes.isEmpty()) {
      // search declared generators for assignable classes
      assignableGenerators = new ArrayList<Gen<?>>();
      for (Class<?> assignableClass : classes) {
    // pick a random generator for the assignable (non-abstract)
    // class
    if (!Modifier.isAbstract(assignableClass.getModifiers())) {
        Set<Gen<?>> set = Arbitrary
        .getGeneratorsOf(assignableClass);
        if (!set.isEmpty()) {
      assignableGenerators.addAll(set);
        }
    }
      }
      if (assignableGenerators.size() > 0) {
    int index = (int) Arbitrary.choose(random, 0,
      assignableGenerators.size() - 1);
    return (T) assignableGenerators.get(index).arbitrary(random,
      minsize, maxsize);
      } else { // creates a constructor based generator for any
    // non-abstract class
    // List<Class<?>> concreteSubclasses = new
    // ArrayList<Class<?>>();
    // for (Class<?> clazz : classes) {
    // if (clazz.isAnnotation() || clazz.isEnum()
    // || clazz.isArray() || clazz.isPrimitive()
    // || !Modifier.isAbstract(clazz.getModifiers())
    // && clazz.getConstructors().length > 0) {
    // concreteSubclasses.add(clazz);
    // }
    // }
    // if (concreteSubclasses.size() > 0) {
    // new ConstructorBasedGenerator(concreteSubclasses
    // .get((int) Arbitrary.choose(random, 0,
    // concreteSubclasses.size()))).arbitrary(
    // random, minsize, maxsize);
    // } else {
    throw new GenerationError(
    "No generators available for classes in the class hierarchy");
    // }
      }
  } else {
      throw new GenerationError(
      "No subclasses defined for this class");
  }
    }
View Full Code Here

      if (this.getSubjectClass().isInterface()) {
        return new InterfaceInstancesGen<T>(
            this.getSubjectClass()).arbitrary(random, minsize,
            maxsize);
      } else {
        throw new GenerationError(this.getSubjectClass().toString()
            + " has no constructor.");
      }
    }
    int index = (int) Arbitrary.choose(random, 0, constructors.length - 1);
    Constructor<?> constructor = constructors[index];
    Class<?>[] classes = constructor.getParameterTypes();
    Object[] arguments = this.generateArguments(random, classes);
    try {
      return (T) constructor.newInstance(arguments);
    } catch (IllegalArgumentException e) {
      throw new GenerationError(e);
    } catch (InstantiationException e) {
      throw new GenerationError(e);
    } catch (IllegalAccessException e) {
      throw new GenerationError(e);
    } catch (InvocationTargetException e) {
      StringBuffer sb = new StringBuffer();
      sb.append("Error in arguments generation for constructor ");
      sb.append(constructor.getName());
      sb.append("(");
      for (int i = 0; i < constructor.getParameterTypes().length; i++) {
        Class<?> clazz = constructor.getParameterTypes()[i];
        sb.append(clazz.getName());
        if (i != constructor.getParameterTypes().length - 1)
          sb.append(",");
      }
      sb.append(")");
      GenerationError ex = new GenerationError(sb.toString());
      ex.initCause(e);
      throw ex;
    }
  }
View Full Code Here

      instance.set(cls, null);
      method = cls.getMethod(this.getSingletonMethod(), new Class[0]);
      // It is assumed that the method is static
      return (T) method.invoke(null, new Object[0]);
    } catch (ClassNotFoundException e) {
      throw new GenerationError(e);
    } catch (SecurityException e) {
      throw new GenerationError(e);
    } catch (NoSuchMethodException e) {
      throw new GenerationError(e);
    } catch (IllegalArgumentException e) {
      throw new GenerationError(e);
    } catch (IllegalAccessException e) {
      throw new GenerationError(e);
    } catch (InvocationTargetException e) {
      throw new GenerationError(e);
    } catch (NoSuchFieldException e) {
      throw new GenerationError(e);
    }
  }
View Full Code Here

    public final T arbitrary(final Distribution random, final long minsize,
      final long maxsize) {
  try {
      return this.cloneObject();
  } catch (IOException e) {
      throw new GenerationError("prototype "
        + this.getCloned().toString() + " is not serializable.");
  } catch (ClassNotFoundException e) {
      throw new GenerationError(e);
  }
    }
View Full Code Here

   */
  @Override
  public Long arbitrary(final Distribution random, final long minsize,
      final long maxsize) {
    if (maxsize < 0) {
      throw new GenerationError(
          "Cannot generate positive longs with maxsize = " + maxsize);
    }
    return LONG_GEN.arbitrary(random, Math.max(0, minsize), maxsize);
  }
View Full Code Here

   */
  @Override
  public Integer arbitrary(final Distribution random, final long minsize,
      final long maxsize) {
    if (maxsize < 0){
      throw new GenerationError("Cannot generate positive integers with maxsize = " + maxsize);
    }
    long max = Math.min(maxsize, Integer.MAX_VALUE);
    return INT_GEN.arbitrary(random, Math.max(0, minsize), max);
  }
View Full Code Here

      method = cls.getMethod(this.getSingletonMethod(), new Class[0]);
      // It is assumed that the method is static
      Object o = method.invoke(null, new Object[0]);
      return new CloneGen<T>((T) o).arbitrary(random, minsize, maxsize);
  } catch (ClassNotFoundException e) {
      throw new GenerationError(e);
  } catch (SecurityException e) {
      throw new GenerationError(e);
  } catch (NoSuchMethodException e) {
      throw new GenerationError(e);
  } catch (IllegalArgumentException e) {
      throw new GenerationError(e);
  } catch (IllegalAccessException e) {
      throw new GenerationError(e);
  } catch (InvocationTargetException e) {
      throw new GenerationError(e);
  }
    }
View Full Code Here

TOP

Related Classes of ar.edu.unlp.yaqc4j.exceptions.GenerationError

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.