<commit_before>/**
 * MethodTypeInstance.java
 */

package jltools.types;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
import jltools.util.TypedList;


/**
 * MethodTypeInstance
 * 
 * An instance of a particular method type ( a method type is 
 * a name with arguments. An instance also contains the return type
 * exception types and access flags
 */
public class MethodTypeInstance extends MethodType implements TypeInstance
{
  static final long serialVersionUID = 327848486110215910L;

  // RI: every element is a Type.  May be null.  Immutable.
  protected TypedList exceptionTypes;
  // RI: May be null.
  protected AccessFlags flags;
  // RI: May be null.
  protected Type returnType;
  // The encompassing class
  protected ReferenceType enclosingType;
  // The constructor flag
  protected boolean isConstructor;
  
  /**
   *    ExceptionTypes, returnType, and AccessFlags may be null.
   **/
  public MethodTypeInstance(TypeSystem ts, 
                            ReferenceType enclosingType, 
                            String methodName, 
                            Type returnType,
                            List argumentTypes,
                            List exceptionTypes,
                            AccessFlags flags,
							boolean isConstructor) {
    super( ts, methodName, argumentTypes);

    this.enclosingType = enclosingType;
    this.returnType = returnType;
    if (exceptionTypes != null)
      this.exceptionTypes = TypedList.copy(exceptionTypes,
					   Type.class, false);

    if (flags != null)
      this.flags = flags.copy();
	
	this.isConstructor = isConstructor;
	
	if (isConstructor==true) {
		super.name = enclosingType.getTypeString() + ".[Constructor]";
		this.returnType = ts.getVoid(); 
	}
  }
  
  public MethodTypeInstance(TypeSystem ts, 
                            ReferenceType enclosingType, 
                            String methodName, 
                            Type returnType,
                            List argumentTypes,
                            List exceptionTypes,
							AccessFlags flags) {
	this(ts, enclosingType, methodName, returnType, argumentTypes, 
		 exceptionTypes, flags, false);
  }

  public void setEnclosingType(ReferenceType enclosingType)
  {
    this.enclosingType = enclosingType;
  }
  
  public ReferenceType getEnclosingType()
  {
    return enclosingType;
  }
  
  public Type getReturnType()
  {
    return returnType; 
  }

  public void setReturnType( Type returnType)  
  {
    this.returnType = returnType;
  }

  public TypedList exceptionTypes() { 
    if (exceptionTypes == null)
      exceptionTypes = new TypedList(new ArrayList(),
				     Type.class, true);   
    return exceptionTypes; 
  }

  public AccessFlags getAccessFlags() { return flags.copy(); }

  public Type getType()
  {
    return returnType;
  }
  
  public boolean isConstructor() {
	return isConstructor;
  }

  public MethodTypeInstance copyInstance()
  {
    return new MethodTypeInstance( getTypeSystem(), 
               enclosingType, 
               getName(), 
               returnType, 
               argumentTypes(),                    
               (exceptionTypes != null ? exceptionTypes.copy() : null),
               (flags != null ? flags.copy() : null),
			   isConstructor);
  }

  public String toString() {
    return getEnclosingType()+"."+getTypeString()+argumentTypes()+" throws "+exceptionTypes();
  }

  public int hashCode() {
    return returnType.hashCode() + name.hashCode() + enclosingType.hashCode();
  }
}<commit_msg>Added the "Equal" method.<commit_after>/**
 * MethodTypeInstance.java
 */

package jltools.types;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
import jltools.util.TypedList;


/**
 * MethodTypeInstance
 * 
 * An instance of a particular method type ( a method type is 
 * a name with arguments. An instance also contains the return type
 * exception types and access flags
 */
public class MethodTypeInstance extends MethodType implements TypeInstance
{
  static final long serialVersionUID = 327848486110215910L;

  // RI: every element is a Type.  May be null.  Immutable.
  protected TypedList exceptionTypes;
  // RI: May be null.
  protected AccessFlags flags;
  // RI: May be null.
  protected Type returnType;
  // The encompassing class
  protected ReferenceType enclosingType;
  // The constructor flag
  protected boolean isConstructor;
  
  /**
   *    ExceptionTypes, returnType, and AccessFlags may be null.
   **/
  public MethodTypeInstance(TypeSystem ts, 
                            ReferenceType enclosingType, 
                            String methodName, 
                            Type returnType,
                            List argumentTypes,
                            List exceptionTypes,
                            AccessFlags flags,
							boolean isConstructor) {
    super( ts, methodName, argumentTypes);

    this.enclosingType = enclosingType;
    this.returnType = returnType;
    if (exceptionTypes != null)
      this.exceptionTypes = TypedList.copy(exceptionTypes,
					   Type.class, false);

    if (flags != null)
      this.flags = flags.copy();
	
	this.isConstructor = isConstructor;
	
	if (isConstructor==true) {
		super.name = enclosingType.getTypeString() + ".[Constructor]";
		this.returnType = ts.getVoid(); 
	}
  }
  
  public MethodTypeInstance(TypeSystem ts, 
                            ReferenceType enclosingType, 
                            String methodName, 
                            Type returnType,
                            List argumentTypes,
                            List exceptionTypes,
							AccessFlags flags) {
	this(ts, enclosingType, methodName, returnType, argumentTypes, 
		 exceptionTypes, flags, false);
  }

  public void setEnclosingType(ReferenceType enclosingType)
  {
    this.enclosingType = enclosingType;
  }
  
  public ReferenceType getEnclosingType()
  {
    return enclosingType;
  }
  
  public Type getReturnType()
  {
    return returnType; 
  }

  public void setReturnType( Type returnType)  
  {
    this.returnType = returnType;
  }

  public TypedList exceptionTypes() { 
    if (exceptionTypes == null)
      exceptionTypes = new TypedList(new ArrayList(),
				     Type.class, true);   
    return exceptionTypes; 
  }

  public AccessFlags getAccessFlags() { return flags.copy(); }

  public Type getType()
  {
    return returnType;
  }
  
  public boolean isConstructor() {
	return isConstructor;
  }

  public MethodTypeInstance copyInstance()
  {
    return new MethodTypeInstance( getTypeSystem(), 
               enclosingType, 
               getName(), 
               returnType, 
               argumentTypes(),                    
               (exceptionTypes != null ? exceptionTypes.copy() : null),
               (flags != null ? flags.copy() : null),
			   isConstructor);
  }

  public String toString() {
    return getEnclosingType()+"."+getTypeString()+argumentTypes()+" throws "+exceptionTypes();
  }

  public int hashCode() {
    return returnType.hashCode() + name.hashCode() + enclosingType.hashCode();
  }
  
  public boolean equals(Object obj) {
    if (!(obj instanceof MethodTypeInstance)) return false;
    MethodTypeInstance mti = (MethodTypeInstance) obj;
    return super.equals(obj) &&
	   getTypeSystem().isSameType(enclosingType, mti.enclosingType);
  }
}
{'fraction_non_alphanumeric': 0.08567567567567567, 'fraction_numerical': 0.004864864864864865, 'mean_word_length': 2.3322827555155334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7547019', 'n_tokens_mistral': 2101, 'n_tokens_neox': 1918, 'n_words': 527}