<commit_before>package chameleon.core.method;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.rejuse.association.OrderedMultiAssociation;
import org.rejuse.association.SingleAssociation;

import chameleon.core.MetamodelException;
import chameleon.core.declaration.Declaration;
import chameleon.core.element.Element;
import chameleon.core.lookup.DeclarationSelector;
import chameleon.core.lookup.LookupException;
import chameleon.core.namespace.NamespaceElement;
import chameleon.core.namespace.NamespaceElementImpl;
import chameleon.core.type.Type;
import chameleon.core.type.generics.TypeParameter;
import chameleon.core.type.generics.TypeParameterBlock;
import chameleon.core.variable.FormalParameter;
import chameleon.core.variable.VariableContainer;
/**
 * A class of objects representing method headers. A method header contains for example the name and parameters of a method.
 * 
 * @author <NAME>
 *
 * @param <E>
 * @param <P>
 * @param <S>
 */
public abstract class MethodHeader<E extends MethodHeader, P extends NamespaceElement, S extends MethodSignature> extends NamespaceElementImpl <E,P> implements VariableContainer<E, P> { //extends Signature<E, P> 
  
  public E clone() {
    E result = cloneThis();
    for(FormalParameter param:formalParameters()) {
      result.addParameter(param.clone());
    }
    return result;
  }

  /**
   * Return the signature of the method of this method header. The signature is generated based on
   * the information in the header.
   * @return
   */
  public abstract S signature();
  
  protected abstract E cloneThis();
  
  public List<Element> children() {
  	List<Element> result = new ArrayList<Element>();
  	result.addAll(formalParameters());
  	return result;
  }
  
  public String name() {
  	return signature().name();
  }
  
  /*********************
   * FORMAL PARAMETERS *
   *********************/

  public List<FormalParameter> formalParameters() {
    return _parameters.getOtherEnds();
  }


  public void addParameter(FormalParameter arg) {
    _parameters.add(arg.parentLink());
  }

  public int getNbParameters() {
    return _parameters.size();
  }

  private OrderedMultiAssociation<MethodHeader,FormalParameter> _parameters = new OrderedMultiAssociation<MethodHeader,FormalParameter>(this);
  
  /**
   * Return the type of the formal parameters of this signature.
   * 
   * @return
   * @throws MetamodelException
   */
  public List<Type> getParameterTypes() throws LookupException {
    List<Type> result = new ArrayList<Type>();
    for(FormalParameter param:formalParameters()) {
      result.add(param.getType());
    }
    return result;
  }

//  /**
//   * Check whether or not this method contains a formal parameter with the given name.
//   *
//   * @param name
//   *        The name that has to be checked.
//   */
//  /*@
//   @ public behavior
//   @
//   @ post \result == (\exists FormalParameter fp; getFormalParameters.contains(fp);
//   @                   fp.getName().equals(name);
//   @*/
//  public boolean containsParameterWithName(final String name) {
//    return new SafePredicate() {
//      public boolean eval(Object o) {
//        return ((FormalParameter)o).getName().equals(name);
//      }
//    }.exists(getParameters());
//  }

//  public Type getNearestType() {
//  	return parent().getNearestType();
//  }
  
  public List<Declaration> declarations() {
    List<Declaration>  result = new ArrayList<Declaration>();
    result.addAll(formalParameters());
    result.addAll(typeParameters());
    return result;
  }<commit_msg>added some specs fixed a bug in children of MethodHeader<commit_after>package chameleon.core.method;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.rejuse.association.OrderedMultiAssociation;
import org.rejuse.association.SingleAssociation;

import chameleon.core.MetamodelException;
import chameleon.core.declaration.Declaration;
import chameleon.core.element.Element;
import chameleon.core.lookup.DeclarationSelector;
import chameleon.core.lookup.LookupException;
import chameleon.core.namespace.NamespaceElement;
import chameleon.core.namespace.NamespaceElementImpl;
import chameleon.core.type.Type;
import chameleon.core.type.generics.TypeParameter;
import chameleon.core.type.generics.TypeParameterBlock;
import chameleon.core.variable.FormalParameter;
import chameleon.core.variable.VariableContainer;
import chameleon.util.Util;
/**
 * A class of objects representing method headers. A method header contains for example the name and parameters of a method.
 * 
 * @author <NAME>
 *
 * @param <E>
 * @param <P>
 * @param <S>
 */
public abstract class MethodHeader<E extends MethodHeader, P extends NamespaceElement, S extends MethodSignature> extends NamespaceElementImpl <E,P> implements VariableContainer<E, P> { //extends Signature<E, P> 
  
  public E clone() {
    E result = cloneThis();
    for(FormalParameter param:formalParameters()) {
      result.addParameter(param.clone());
    }
    return result;
  }

  /**
   * Return the signature of the method of this method header. The signature is generated based on
   * the information in the header.
   * @return
   */
  public abstract S signature();
  
  protected abstract E cloneThis();
  
  /**
   * The children of a method header are its formal parameters and the type parameter block.
   */
 /*@
   @ public behavior
   @
   @ post \result != null;
   @ post \result.containsAll(formalParameters());
   @ post parameterBlock() != null ==> \result.contains(parameterBlock());
   @*/
  public List<Element> children() {
  	List<Element> result = new ArrayList<Element>();
  	result.addAll(formalParameters());
  	Util.addNonNull(parameterBlock(), result);
  	return result;
  }
  
  /**
   * The name of a method header is the name of its signature.
   */
 /*@
   @ public behavior
   @
   @ post \result == signature().name();
   @*/
  public String name() {
  	return signature().name();
  }
  
  /*********************
   * FORMAL PARAMETERS *
   *********************/

  public List<FormalParameter> formalParameters() {
    return _parameters.getOtherEnds();
  }


  public void addParameter(FormalParameter arg) {
    _parameters.add(arg.parentLink());
  }

  public int getNbParameters() {
    return _parameters.size();
  }

  private OrderedMultiAssociation<MethodHeader,FormalParameter> _parameters = new OrderedMultiAssociation<MethodHeader,FormalParameter>(this);
  
  /**
   * Return the type of the formal parameters of this signature.
   * 
   * @return
   * @throws MetamodelException
   */
  public List<Type> getParameterTypes() throws LookupException {
    List<Type> result = new ArrayList<Type>();
    for(FormalParameter param:formalParameters()) {
      result.add(param.getType());
    }
    return result;
  }

//  /**
//   * Check whether or not this method contains a formal parameter with the given name.
//   *
//   * @param name
//   *        The name that has to be checked.
//   */
//  /*@
//   @ public behavior
//   @
//   @ post \result == (\exists FormalParameter fp; getFormalParameters.contains(fp);
//   @                   fp.getName().equals(name);
//   @*/
//  public boolean containsParameterWithName(final String name) {
//    return new SafePredicate() {
//      public boolean eval(Object o) {
//        return ((FormalParameter)o).getName().equals(name);
//      }
//    }.exists(getParameters());
//  }

//  public Type getNearestType() {
//  	return parent().getNearestType();
//  }
  
  /**
   * The declarations of a method header are its formal parameters and its type parameters.
   */
 /*@
   @ public behavior
   @
   @ post \result != null;
   @ post \result.containsAll(formalParameters());
   @ post \result.containsAll(typeParameters());
   @*/
  public List<Declaration> declarations() {
    List<Declaration>  result = new ArrayList<Declaration>();
    result.addAll(formalParameters());
    result.addAll(typeParameters());
    return result;
  }
{'fraction_non_alphanumeric': 0.1288404360753221, 'fraction_numerical': 0.0, 'mean_word_length': 3.605248146035368, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2756131', 'n_tokens_mistral': 2367, 'n_tokens_neox': 2317, 'n_words': 589}