All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.evosuite.coverage.mutation.MutationPool Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (C) 2010-2018 Gordon Fraser, Andrea Arcuri and EvoSuite
 * contributors
 *
 * This file is part of EvoSuite.
 *
 * EvoSuite is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3.0 of the License, or
 * (at your option) any later version.
 *
 * EvoSuite is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with EvoSuite. If not, see .
 */
/**
 * 
 */
package org.evosuite.coverage.mutation;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.evosuite.graphs.cfg.BytecodeInstruction;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.InsnList;


/**
 * 

MutationPool class.

* * @author fraser */ public class MutationPool { // maps className -> method inside that class -> list of branches inside that method private static Map>> mutationMap = new HashMap>>(); // maps the mutationIDs assigned by this pool to their respective Mutations private static Map mutationIdMap = new HashMap(); private static int numMutations = 0; /** *

addMutation

* * @param className a {@link java.lang.String} object. * @param methodName a {@link java.lang.String} object. * @param mutationName a {@link java.lang.String} object. * @param instruction a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object. * @param mutation a {@link org.objectweb.asm.tree.AbstractInsnNode} object. * @param distance a {@link org.objectweb.asm.tree.InsnList} object. * @return a {@link org.evosuite.coverage.mutation.Mutation} object. */ public static Mutation addMutation(String className, String methodName, String mutationName, BytecodeInstruction instruction, AbstractInsnNode mutation, InsnList distance) { if (!mutationMap.containsKey(className)) mutationMap.put(className, new HashMap>()); if (!mutationMap.get(className).containsKey(methodName)) mutationMap.get(className).put(methodName, new ArrayList()); Mutation mutationObject = new Mutation(className, methodName, mutationName, numMutations++, instruction, mutation, distance); mutationMap.get(className).get(methodName).add(mutationObject); mutationIdMap.put(mutationObject.getId(), mutationObject); return mutationObject; } /** *

addMutation

* * @param className a {@link java.lang.String} object. * @param methodName a {@link java.lang.String} object. * @param mutationName a {@link java.lang.String} object. * @param instruction a {@link org.evosuite.graphs.cfg.BytecodeInstruction} object. * @param mutation a {@link org.objectweb.asm.tree.InsnList} object. * @param distance a {@link org.objectweb.asm.tree.InsnList} object. * @return a {@link org.evosuite.coverage.mutation.Mutation} object. */ public static Mutation addMutation(String className, String methodName, String mutationName, BytecodeInstruction instruction, InsnList mutation, InsnList distance) { if (!mutationMap.containsKey(className)) mutationMap.put(className, new HashMap>()); if (!mutationMap.get(className).containsKey(methodName)) mutationMap.get(className).put(methodName, new ArrayList()); Mutation mutationObject = new Mutation(className, methodName, mutationName, numMutations++, instruction, mutation, distance); mutationMap.get(className).get(methodName).add(mutationObject); mutationIdMap.put(mutationObject.getId(), mutationObject); return mutationObject; } /** * Returns a List containing all mutants in the given class and method * * Should no such mutant exist an empty List is returned * * @param className a {@link java.lang.String} object. * @param methodName a {@link java.lang.String} object. * @return a {@link java.util.List} object. */ public static List retrieveMutationsInMethod(String className, String methodName) { List r = new ArrayList(); if (mutationMap.get(className) == null) return r; List mutants = mutationMap.get(className).get(methodName); if (mutants != null) r.addAll(mutants); return r; } /** *

getMutants

* * @return a {@link java.util.List} object. */ public static List getMutants() { return new ArrayList(mutationIdMap.values()); } public static Mutation getMutant(int id) { return mutationIdMap.get(id); } /** * Remove all known mutants */ public static void clear() { mutationMap.clear(); mutationIdMap.clear(); numMutations = 0; } /** * Returns the number of currently known mutants * * @return The number of currently known mutants */ public static int getMutantCounter() { return numMutations; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy