use of org.evosuite.utils.generic.GenericClass in project evosuite by EvoSuite.
the class TestCluster method invalidateGeneratorCache.
public void invalidateGeneratorCache(GenericClass klass) {
Iterator<Map.Entry<GenericClass, Set<GenericAccessibleObject<?>>>> iter = generatorCache.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = iter.next();
GenericClass gen = (GenericClass) entry.getKey();
if (gen.isAssignableFrom(klass)) {
iter.remove();
}
}
}
use of org.evosuite.utils.generic.GenericClass in project evosuite by EvoSuite.
the class TestCluster method getRandomizedCallsToEnvironment.
public List<GenericAccessibleObject<?>> getRandomizedCallsToEnvironment() {
if (environmentMethods.isEmpty()) {
return null;
}
List<GenericAccessibleObject<?>> list = new ArrayList<>();
for (GenericAccessibleObject<?> obj : environmentMethods) {
try {
if (obj.getOwnerClass().hasWildcardOrTypeVariables()) {
GenericClass concreteClass = obj.getOwnerClass().getGenericInstantiation();
obj = obj.copyWithNewOwner(concreteClass);
}
if (obj.hasTypeParameters()) {
obj = obj.getGenericInstantiation();
}
} catch (ConstructionFailedException e) {
logger.error("Failed generic instantiation in " + obj);
continue;
}
list.add(obj);
}
Collections.shuffle(list);
return list;
}
use of org.evosuite.utils.generic.GenericClass in project evosuite by EvoSuite.
the class TestCluster method getRandomObjectGenerator.
/**
* Randomly select a generator for an Object.class instance
*
* @return a generator of type GenericAccessibleObject<?> or <code>null</code>
* @throws ConstructionFailedException
*/
public GenericAccessibleObject<?> getRandomObjectGenerator() throws ConstructionFailedException {
logger.debug("Getting random object generator");
GenericAccessibleObject<?> generator = Randomness.choice(getObjectGenerators());
if (generator == null) {
// should NOT occur (from getObjectGenerators())
logger.warn("Random object generator is null");
throw new ConstructionFailedException("Random object generator is null");
}
if (generator.getOwnerClass().hasWildcardOrTypeVariables()) {
logger.debug("Generator has wildcard or type: " + generator);
GenericClass concreteClass = generator.getOwnerClass().getGenericInstantiation();
generator = generator.copyWithNewOwner(concreteClass);
}
if (generator.hasTypeParameters()) {
logger.debug("Generator has type parameters");
generator = generator.getGenericInstantiation();
}
return generator;
}
use of org.evosuite.utils.generic.GenericClass in project evosuite by EvoSuite.
the class TestCluster method getRandomGenerator.
/**
* Randomly select one generator
*
* @param clazz
* @return
* @throws ConstructionFailedException
*/
public GenericAccessibleObject<?> getRandomGenerator(GenericClass clazz) throws ConstructionFailedException {
if (clazz.hasWildcardOrTypeVariables()) {
GenericClass concreteClass = clazz.getGenericInstantiation();
if (concreteClass.hasWildcardOrTypeVariables())
throw new ConstructionFailedException("Could not found concrete instantiation of generic type");
return getRandomGenerator(concreteClass);
}
GenericAccessibleObject<?> generator = null;
if (isSpecialCase(clazz)) {
Collection<GenericAccessibleObject<?>> generators = getGeneratorsForSpecialCase(clazz);
if (generators.isEmpty()) {
logger.warn("No generators for class: " + clazz);
}
generator = Randomness.choice(generators);
} else {
if (!hasGenerator(clazz))
throw new ConstructionFailedException("No generators of type " + clazz);
generator = Randomness.choice(generatorCache.get(clazz));
}
if (generator == null)
throw new ConstructionFailedException("No generators of type " + clazz);
if (generator.hasTypeParameters()) {
generator = generator.getGenericInstantiation(clazz);
}
return generator;
}
use of org.evosuite.utils.generic.GenericClass in project evosuite by EvoSuite.
the class TestCluster method getTestCalls.
/**
* Get a list of all test calls (i.e., constructors and methods)
*
* @return
* @throws ConstructionFailedException
*/
public List<GenericAccessibleObject<?>> getTestCalls() {
// TODO: Check for generic methods
List<GenericAccessibleObject<?>> result = new ArrayList<>();
for (GenericAccessibleObject<?> ao : testMethods) {
if (ao.getOwnerClass().hasWildcardOrTypeVariables()) {
try {
GenericClass concreteClass = ao.getOwnerClass().getGenericInstantiation();
result.add(ao.copyWithNewOwner(concreteClass));
} catch (ConstructionFailedException e) {
logger.debug("Failed to instantiate " + ao);
}
} else {
result.add(ao);
}
}
return result;
}
Aggregations