use of org.evosuite.utils.generic.GenericClass in project evosuite by EvoSuite.
the class ObjectPoolManager method initialisePool.
public void initialisePool() {
if (!Properties.OBJECT_POOLS.isEmpty()) {
String[] poolFiles = Properties.OBJECT_POOLS.split(File.pathSeparator);
if (poolFiles.length > 1)
LoggingUtils.getEvoLogger().info("* Reading object pools:");
else
LoggingUtils.getEvoLogger().info("* Reading object pool:");
for (String fileName : poolFiles) {
logger.info("Adding object pool from file " + fileName);
ObjectPool pool = ObjectPool.getPoolFromFile(fileName);
if (pool == null) {
logger.error("Failed to load object from " + fileName);
} else {
LoggingUtils.getEvoLogger().info(" - Object pool " + fileName + ": " + pool.getNumberOfSequences() + " sequences for " + pool.getNumberOfClasses() + " classes");
addPool(pool);
}
}
if (logger.isDebugEnabled()) {
for (GenericClass key : pool.keySet()) {
logger.debug("Have sequences for " + key + ": " + pool.get(key).size());
}
}
}
if (Properties.CARVE_OBJECT_POOL) {
CarvingManager manager = CarvingManager.getInstance();
for (Class<?> targetClass : manager.getClassesWithTests()) {
List<TestCase> tests = manager.getTestsForClass(targetClass);
logger.info("Carved tests for {}: {}", targetClass.getName(), tests.size());
GenericClass cut = new GenericClass(targetClass);
for (TestCase test : tests) {
this.addSequence(cut, test);
}
}
logger.info("Pool after carving: " + this.getNumberOfClasses() + "/" + this.getNumberOfSequences());
}
}
use of org.evosuite.utils.generic.GenericClass in project evosuite by EvoSuite.
the class CastClassManager method getAssignableClasses.
private List<GenericClass> getAssignableClasses(TypeVariable<?> typeVariable, boolean allowRecursion, Map<TypeVariable<?>, Type> ownerVariableMap) {
Map<GenericClass, Integer> assignableClasses = new LinkedHashMap<GenericClass, Integer>();
logger.debug("Getting assignable classes for type variable " + typeVariable);
for (Entry<GenericClass, Integer> entry : classMap.entrySet()) {
GenericClass key = entry.getKey();
logger.debug("Current class for type variable " + typeVariable + ": " + key);
if (!key.satisfiesBoundaries(typeVariable, ownerVariableMap)) {
logger.debug("Bounds not satisfied");
continue;
}
if (!allowRecursion && key.hasWildcardOrTypeVariables()) {
logger.debug("Recursion not allowed but type has wildcard or type variables");
continue;
}
assignableClasses.put(entry.getKey(), entry.getValue());
}
logger.debug("Found assignable classes: " + assignableClasses.size());
return sortByValue(assignableClasses);
}
use of org.evosuite.utils.generic.GenericClass in project evosuite by EvoSuite.
the class CastClassManager method getAssignableClasses.
private List<GenericClass> getAssignableClasses(WildcardType wildcardType, boolean allowRecursion, Map<TypeVariable<?>, Type> ownerVariableMap) {
Map<GenericClass, Integer> assignableClasses = new LinkedHashMap<GenericClass, Integer>();
logger.debug("Getting assignable classes for wildcard type " + wildcardType);
for (Entry<GenericClass, Integer> entry : classMap.entrySet()) {
GenericClass key = entry.getKey();
logger.debug("Current class for wildcard " + wildcardType + ": " + key);
if (!key.satisfiesBoundaries(wildcardType, ownerVariableMap)) {
logger.debug("Does not satisfy boundaries");
continue;
}
if (!allowRecursion && key.hasWildcardOrTypeVariables()) {
logger.debug("Stopping because of type recursion");
continue;
}
logger.debug("Is assignable");
assignableClasses.put(entry.getKey(), entry.getValue());
}
return sortByValue(assignableClasses);
}
use of org.evosuite.utils.generic.GenericClass in project evosuite by EvoSuite.
the class CastClassManager method addAssignableClass.
private boolean addAssignableClass(TypeVariable<?> typeVariable, Map<TypeVariable<?>, Type> typeMap) {
Set<Class<?>> classes = TestCluster.getInstance().getAnalyzedClasses();
Set<Class<?>> assignableClasses = new LinkedHashSet<Class<?>>();
for (Class<?> clazz : classes) {
if (!TestUsageChecker.canUse(clazz))
continue;
GenericClass genericClass = new GenericClass(clazz).getWithWildcardTypes();
if (!genericClass.satisfiesBoundaries(typeVariable, typeMap)) {
logger.debug("Not assignable: " + clazz);
} else {
logger.debug("Assignable");
assignableClasses.add(clazz);
}
}
for (Type t : typeMap.values()) {
if (t instanceof WildcardType)
// TODO: For now.
continue;
Class<?> clazz = GenericTypeReflector.erase(t);
if (!TestUsageChecker.canUse(GenericTypeReflector.erase(clazz)))
continue;
GenericClass genericClass = new GenericClass(clazz).getWithWildcardTypes();
if (!genericClass.satisfiesBoundaries(typeVariable, typeMap)) {
logger.debug("Not assignable: " + clazz);
} else {
logger.debug("Assignable");
assignableClasses.add(clazz);
}
}
/*
for (Type t : typeVariable.getBounds()) {
if (typeMap.containsKey(t))
t = typeMap.get(t);
Class<?> clazz = GenericTypeReflector.erase(t);
logger.debug("Checking bound: " + t);
if (!TestClusterGenerator.canUse(clazz))
continue;
GenericClass genericClass = new GenericClass(t);
//if (genericClass.hasTypeVariables()) {
logger.debug("Has type variables: " + genericClass
+ ", checking wildcard version with type map " + typeMap);
GenericClass wildcardClass = genericClass.getWithWildcardTypes();
//if (!wildcardClass.satisfiesBoundaries(typeVariable, typeMap)) {
// logger.debug("Not assignable: " + clazz);
//} else {
// logger.debug("Assignable");
assignableClasses.add(clazz);
//}
//} else {
// logger.debug("Adding directly: " + genericClass);
// assignableClasses.add(genericClass.getRawClass());
// classMap.put(genericClass, 10);
//}
}
*/
logger.debug("Found assignable classes for type variable " + typeVariable + ": " + assignableClasses.size());
if (!assignableClasses.isEmpty()) {
Class<?> clazz = Randomness.choice(assignableClasses);
GenericClass castClass = new GenericClass(clazz);
logger.debug("Adding cast class " + castClass);
classMap.put(castClass, 10);
return true;
} else {
InheritanceTree inheritanceTree = DependencyAnalysis.getInheritanceTree();
Set<Class<?>> boundCandidates = new LinkedHashSet<Class<?>>();
for (Type bound : typeVariable.getBounds()) {
Class<?> rawBound = GenericTypeReflector.erase(bound);
boundCandidates.add(rawBound);
logger.debug("Getting concrete classes for " + rawBound);
boundCandidates.addAll(ConcreteClassAnalyzer.getInstance().getConcreteClasses(rawBound, inheritanceTree));
}
for (Class<?> clazz : boundCandidates) {
if (!TestUsageChecker.canUse(clazz))
continue;
boolean isAssignable = true;
for (Type bound : typeVariable.getBounds()) {
if (GenericTypeReflector.erase(bound).equals(Enum.class)) {
if (clazz.isEnum())
continue;
}
if (!GenericClass.isAssignable(bound, clazz)) {
isAssignable = false;
logger.debug("Not assignable: " + clazz + " to bound " + bound);
break;
}
if (bound instanceof ParameterizedType) {
if (Arrays.asList(((ParameterizedType) bound).getActualTypeArguments()).contains(typeVariable)) {
isAssignable = false;
break;
}
}
}
if (isAssignable) {
assignableClasses.add(clazz);
}
}
logger.debug("After adding bounds, found " + assignableClasses.size() + " assignable classes for type variable " + typeVariable + ": " + assignableClasses);
if (!assignableClasses.isEmpty()) {
// TODO: Add all classes?
// for(Class<?> clazz : assignableClasses) {
// GenericClass castClass = new GenericClass(clazz);
// logger.debug("Adding cast class " + castClass);
// classMap.put(castClass, 10);
// }
Class<?> clazz = Randomness.choice(assignableClasses);
GenericClass castClass = new GenericClass(clazz);
logger.debug("Adding cast class " + castClass);
classMap.put(castClass, 10);
return true;
}
}
return false;
}
use of org.evosuite.utils.generic.GenericClass in project evosuite by EvoSuite.
the class CastClassManager method initDefaultClasses.
private void initDefaultClasses() {
classMap.put(new GenericClass(Object.class), 0);
classMap.put(new GenericClass(String.class), 1);
classMap.put(new GenericClass(Integer.class), 1);
}
Aggregations