org.evosuite.testcase.NullStatement.java Source code

Java tutorial

Introduction

Here is the source code for org.evosuite.testcase.NullStatement.java

Source

/**
 * Copyright (C) 2011,2012 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 Public License as published by the Free Software Foundation,
 * either version 3 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 Public License for more details.
 * 
 * You should have received a copy of the GNU Public License along with
 * EvoSuite. If not, see <http://www.gnu.org/licenses/>.
 */
/**
 * 
 */
package org.evosuite.testcase;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.evosuite.utils.GenericAccessibleObject;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.commons.GeneratorAdapter;

/**
 * The concept of variableReferences is: that they are created by some
 * statement. This Statement serves the purpose of defining null references. We
 * need it, as various places in the code assume, that VariableReferences are
 * generated by statements.
 * 
 * @author steenbuck
 */
public class NullStatement extends PrimitiveStatement<Void> {

    private static final long serialVersionUID = -7141670041216163032L;

    /**
     * <p>
     * Constructor for NullStatement.
     * </p>
     * 
     * @param tc
     *            a {@link org.evosuite.testcase.TestCase} object.
     * @param type
     *            a {@link java.lang.reflect.Type} object.
     */
    public NullStatement(TestCase tc, java.lang.reflect.Type type) {
        super(tc, new NullReference(tc, type), null);
    }

    /* (non-Javadoc)
     * @see org.evosuite.testcase.StatementInterface#clone(org.evosuite.testcase.TestCase)
     */
    /** {@inheritDoc} */
    @Override
    public StatementInterface copy(TestCase newTestCase, int offset) {
        return new NullStatement(newTestCase, retval.getType());
    }

    /* (non-Javadoc)
     * @see org.evosuite.testcase.StatementInterface#execute(org.evosuite.testcase.Scope, java.io.PrintStream)
     */
    /** {@inheritDoc} */
    @Override
    public Throwable execute(Scope scope, PrintStream out) throws InvocationTargetException,
            IllegalArgumentException, IllegalAccessException, InstantiationException {
        return null;
    }

    /* (non-Javadoc)
     * @see org.evosuite.testcase.StatementInterface#getBytecode(org.objectweb.asm.commons.GeneratorAdapter, java.util.Map, java.lang.Throwable)
     */
    /** {@inheritDoc} */
    @Override
    public void getBytecode(GeneratorAdapter mg, Map<Integer, Integer> locals, Throwable exception) {
        mg.visitInsn(Opcodes.ACONST_NULL);
        retval.storeBytecode(mg, locals);
    }

    /* (non-Javadoc)
     * @see org.evosuite.testcase.StatementInterface#getUniqueVariableReferences()
     */
    /** {@inheritDoc} */
    @Override
    public List<VariableReference> getUniqueVariableReferences() {
        return new ArrayList<VariableReference>(getVariableReferences());
    }

    /* (non-Javadoc)
     * @see org.evosuite.testcase.StatementInterface#getVariableReferences()
     */
    /** {@inheritDoc} */
    @Override
    public Set<VariableReference> getVariableReferences() {
        Set<VariableReference> references = new LinkedHashSet<VariableReference>();
        references.add(retval);
        return references;
    }

    /* (non-Javadoc)
     * @see org.evosuite.testcase.StatementInterface#replace(org.evosuite.testcase.VariableReference, org.evosuite.testcase.VariableReference)
     */
    /** {@inheritDoc} */
    @Override
    public void replace(VariableReference var1, VariableReference var2) {
    }

    /* (non-Javadoc)
     * @see org.evosuite.testcase.StatementInterface#same(org.evosuite.testcase.StatementInterface)
     */
    /** {@inheritDoc} */
    @Override
    public boolean same(StatementInterface s) {
        if (this == s)
            return true;
        if (s == null)
            return false;
        if (getClass() != s.getClass())
            return false;

        NullStatement ns = (NullStatement) s;
        return retval.same(ns.retval);
    }

    /** {@inheritDoc} */
    @Override
    public GenericAccessibleObject<?> getAccessibleObject() {
        return null;
    }

    /** {@inheritDoc} */
    @Override
    public void delta() {
        logger.error("Method delta not implemented: What is the delta for null?");
    }

    /** {@inheritDoc} */
    @Override
    public void zero() {
        logger.error("Method zero not implemented: How to zero null?");
    }

    /** {@inheritDoc} */
    @Override
    protected void pushBytecode(GeneratorAdapter mg) {
        mg.push((String) null);
    }

    /** {@inheritDoc} */
    @Override
    public void randomize() {
        logger.error("Method randomize not implemented: How to randomize null?");
    }

    private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
        ois.defaultReadObject();
        value = null;
    }
}