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

spoon.support.reflect.declaration.CtExecutableImpl Maven / Gradle / Ivy

/* 
 * Spoon - http://spoon.gforge.inria.fr/
 * Copyright (C) 2006 INRIA Futurs 
 * 
 * This software is governed by the CeCILL-C License under French law and
 * abiding by the rules of distribution of free software. You can use, modify 
 * and/or redistribute the software under the terms of the CeCILL-C license as 
 * circulated by CEA, CNRS and INRIA at http://www.cecill.info. 
 * 
 * This program 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 CeCILL-C License for more details.
 *  
 * The fact that you are presently reading this means that you have had
 * knowledge of the CeCILL-C license and that you accept its terms.
 */

package spoon.support.reflect.declaration;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import spoon.reflect.code.CtBlock;
import spoon.reflect.declaration.CtExecutable;
import spoon.reflect.declaration.CtParameter;
import spoon.reflect.reference.CtExecutableReference;
import spoon.reflect.reference.CtTypeReference;

/**
 * The implementation for {@link spoon.reflect.declaration.CtExecutable}.
 * 
 * @author Renaud Pawlak
 */
public abstract class CtExecutableImpl extends CtNamedElementImpl implements
		CtExecutable {

	private static final long serialVersionUID = 1L;

	CtBlock body;

	List> formalTypeParameters = EMPTY_LIST();

	List> parameters = EMPTY_LIST();

	Set> thrownTypes = EMPTY_SET();

	public CtExecutableImpl() {
		super();
	}

	public boolean addParameter(CtParameter parameter) {
		if (parameters == CtElementImpl.> EMPTY_LIST()) {
			parameters = new ArrayList>();
		}
		return parameters.add(parameter);
	}

	public boolean removeParameter(CtParameter parameter) {
		return parameters.remove(parameter);
	}

	public boolean addThrownType(CtTypeReference throwType) {
		if (thrownTypes == CtElementImpl
				.> EMPTY_SET()) {
			thrownTypes = new TreeSet>();
		}
		return thrownTypes.add(throwType);
	}

	public boolean removeThrownType(
			CtTypeReference throwType) {
		return thrownTypes.remove(throwType);
	}

	public boolean addFormalTypeParameter(
			CtTypeReference formalTypeParameter) {
		if (formalTypeParameters == CtElementImpl
				.> EMPTY_LIST()) {
			formalTypeParameters = new ArrayList>();
		}
		return formalTypeParameters.add(formalTypeParameter);
	}

	public boolean removeFormalTypeParameter(
			CtTypeReference formalTypeParameter) {
		return formalTypeParameters.remove(formalTypeParameter);
	}

	@SuppressWarnings("unchecked")
	public  CtBlock getBody() {
		return (CtBlock) body;
	}

	public List> getFormalTypeParameters() {
		return formalTypeParameters;
	}

	public List> getParameters() {
		return parameters;
	}

	public Set> getThrownTypes() {
		return thrownTypes;
	}

	public  void setBody(CtBlock body) {
		this.body = body;
	}

	public void setFormalTypeParameters(
			List> formalTypeParameters) {
		this.formalTypeParameters = formalTypeParameters;
	}

	public void setParameters(List> parameters) {
		this.parameters = parameters;
	}

	public void setThrownTypes(
			Set> thrownTypes) {
		this.thrownTypes = thrownTypes;
	}

	@Override
	public CtExecutableReference getReference() {
		return getFactory().Executable().createReference(this);
	}

}