<commit_before>part of drails;

/**
 * Get Value of annotations of Type [T] on [InstanceMirror]s and [DeclarationMirror]s
 */
class GetValueOfAnnotation<T> {
 final _iat = new IsAnnotation<T>();
  /**
   * Get the Instance of the Annotation of type [T] from the reflected annotated object [im]
   */
  T fromInstance(InstanceMirror im) => fromAnnotations(im.type.metadata);

  /**
   * Get the Instance of the Annotation of type [T] from the reflected annotated declaration (method or property) [obj]
   */
  T fromDeclaration(DeclarationMirror dm) => fromAnnotations(dm.metadata);

  /**
   * Get the Instance of the Annotation of type [T] from the list of annotations' [InstanceMirror]s
   */
  T fromAnnotations(List<InstanceMirror> ams) {
    if (_iat.anyOf(ams))
      return ams.singleWhere(_iat._isType).reflectee as T;
    return null;
  }

}

/**
 * Check if Annotation is on [InstanceMirror] or [DeclarationMirror]
 */
class IsAnnotation<T> {

  /**
   * Check if the Annotation of type [T] is on the reflected annotated object [im]
   */
  bool onInstance(InstanceMirror im) => anyOf(im.type.metadata);

  /**
   * Check if the Annotation of type [T] is on the reflected annotated declaration (method or property) [dm]
   */
  bool onDeclaration(DeclarationMirror dm) => anyOf(dm.metadata);

  /**
   * Check if any element of the list of annotations' InstanceMirrors mirros [am] is type [T]
   */
  bool anyOf(List<InstanceMirror> ams) {
    return ams.any(_isType);
  }

  /**
   * Checks if the annotation [InstanceMirror] is type [T]
   */
  bool _isType(InstanceMirror am) => am.reflectee is T;
}

/**
 * Get Declarations (methods and variables) annotated with [T] and are type [DM]
 */
class GetDeclarationsAnnotatedWith<T, DM> {
  /**
   * Get the iterable of [DeclarationMirror] that are annotated with [T]
   */
  Iterable<DM> from(InstanceMirror im) =>
      new List<DM>.from(im.type.declarations.values
          .where((declartionMirror) => 
              declartionMirror is DM
              && declartionMirror.metadata.any((am) => am.reflectee is T)));

}

/**
 * Get List of methods annotated with [T]
 */
class GetMethodsAnnotatedWith<T> {
  /**
   * Get List of methods annotated with [T] from the InstanceMirror [im]
   */
  Iterable<MethodMirror> from(InstanceMirror im) => new GetDeclarationsAnnotatedWith<T, MethodMirror>().from(im);
}
/**
 * Get List of variables annotated with [T]
 */
class GetVariablesAnnotatedWith<T> {
  /**
   * Get List of variables annotated with [T] from the InstanceMirror [im]
   */
  Iterable<VariableMirror> from(InstanceMirror im) => new GetDeclarationsAnnotatedWith<T, VariableMirror>().from(im);
}
/**
 * Get the list of [MethodMirrors] from [ClassMirror] cm
 */
Iterable<MethodMirror> getMethodMirrorsFromClass(ClassMirror cm) {
  var methodMirrors = [];

  if (cm.superclass != reflectClass(Object)) {
    methodMirrors.addAll(getMethodMirrorsFromClass(cm.superclass));
  }

  return methodMirrors..addAll(
      cm.declarations.values.where((dm) => 
        dm is MethodMirror && (dm as MethodMirror).isRegularMethod));
}

/**
 * Gets the object that extends the [injectableCm] from [declarationCms]
 */
Object getObjectThatExtend(ClassMirror injectableCm, Iterable<DeclarationMirror> declarationCms) {
  ClassMirror result;
  int counter = 0, counter2 = 0;
  for(ClassMirror cm in declarationCms) {<commit_msg>Get declarations (methods and variables) of superclass<commit_after>part of drails;

/**
 * Get Value of annotations of Type [T] on [InstanceMirror]s and [DeclarationMirror]s
 */
class GetValueOfAnnotation<T> {
 final _iat = new IsAnnotation<T>();
  /**
   * Get the Instance of the Annotation of type [T] from the reflected annotated object [im]
   */
  T fromInstance(InstanceMirror im) => fromAnnotations(im.type.metadata);

  /**
   * Get the Instance of the Annotation of type [T] from the reflected annotated declaration (method or property) [obj]
   */
  T fromDeclaration(DeclarationMirror dm) => fromAnnotations(dm.metadata);

  /**
   * Get the Instance of the Annotation of type [T] from the list of annotations' [InstanceMirror]s
   */
  T fromAnnotations(List<InstanceMirror> ams) {
    if (_iat.anyOf(ams))
      return ams.singleWhere(_iat._isType).reflectee as T;
    return null;
  }

}

/**
 * Check if Annotation is on [InstanceMirror] or [DeclarationMirror]
 */
class IsAnnotation<T> {

  /**
   * Check if the Annotation of type [T] is on the reflected annotated object [im]
   */
  bool onInstance(InstanceMirror im) => anyOf(im.type.metadata);

  /**
   * Check if the Annotation of type [T] is on the reflected annotated declaration (method or property) [dm]
   */
  bool onDeclaration(DeclarationMirror dm) => anyOf(dm.metadata);

  /**
   * Check if any element of the list of annotations' InstanceMirrors mirros [am] is type [T]
   */
  bool anyOf(List<InstanceMirror> ams) {
    return ams.any(_isType);
  }

  /**
   * Checks if the annotation [InstanceMirror] is type [T]
   */
  bool _isType(InstanceMirror am) => am.reflectee is T;
}

/**
 * Get Declarations (methods and variables) annotated with [T] and are type [DM]
 */
class GetDeclarationsAnnotatedWith<T, DM> {
  /**
   * Get the iterable of [DeclarationMirror] that are annotated with [T]
   */
  Iterable<DM> from(InstanceMirror im) =>
      getDeclarationsFromClassIf(im.type, (dm) => dm is DM && dm.metadata.any((am) => am.reflectee is T)).values;
  

}

/**
 * Get List of methods annotated with [T]
 */
class GetMethodsAnnotatedWith<T> {
  /**
   * Get List of methods annotated with [T] from the InstanceMirror [im]
   */
  Iterable<MethodMirror> from(InstanceMirror im) => new GetDeclarationsAnnotatedWith<T, MethodMirror>().from(im);
}
/**
 * Get List of variables annotated with [T]
 */
class GetVariablesAnnotatedWith<T> {
  /**
   * Get List of variables annotated with [T] from the InstanceMirror [im]
   */
  Iterable<VariableMirror> from(InstanceMirror im) => new GetDeclarationsAnnotatedWith<T, VariableMirror>().from(im);
}

typedef bool _IfDeclarationFunct(DeclarationMirror dm);

/// Get the List of [DeclarationMirror]s from [ClassMirror] cm if the [ifDeclarationFunct] is true
getDeclarationsFromClassIf(ClassMirror cm, _IfDeclarationFunct ifDeclarationFunct) {

  var dms = {};

  if (cm.superclass != reflectClass(Object)) {
    dms.addAll(getDeclarationsFromClassIf(cm.superclass, ifDeclarationFunct));
  }
               
  cm.declarations.forEach((symbol, dm) {
    if(ifDeclarationFunct(dm)) {
      dms.putIfAbsent(symbol, () => dm);
    }
  });
  
  return dms;
}

/// Get the list of public [MethodMirror] from [ClassMirror] [cm]
Map<Symbol, MethodMirror> getPublicMethodsFromClass(ClassMirror cm) => 
    getDeclarationsFromClassIf(cm, (dm) => !dm.isPrivate && dm is MethodMirror && (dm as MethodMirror).isRegularMethod);

/// Get the list of public [VariableMirror] from [ClassMirror] [cm]
Map<Symbol, VariableMirror> getPublicVariablesFromClass(ClassMirror cm)=> 
    getDeclarationsFromClassIf(cm, (dm) => !dm.isPrivate && dm is VariableMirror || (dm is MethodMirror && dm.isGetter)); 

/// Gets the object that extends the [injectableCm] from [declarationCms]
Object getObjectThatExtend(ClassMirror injectableCm, Iterable<DeclarationMirror> declarationCms) {
  ClassMirror result;
  int counter = 0, counter2 = 0;
  for(ClassMirror cm in declarationCms) {
{'fraction_non_alphanumeric': 0.11737535660915636, 'fraction_numerical': 0.0008151066431191414, 'mean_word_length': 4.032125768967874, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 61, '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': '4187986', 'n_tokens_mistral': 2415, 'n_tokens_neox': 2251, 'n_words': 681}