<commit_before>// Copyright (c) 2016, the Dart Team. All rights reserved. Use of this
// source code is governed by a BSD-style license that can be found in
// the LICENSE file.

// File being transformed by the reflectable transformer.
// Uses a function type in type annotations.

@reflector
library test_reflectable.test.function_type_annotation_test;

import 'package:reflectable/reflectable.dart';
import 'package:test/test.dart';
import 'function_type_annotation_test.reflectable.dart';

class Reflector extends Reflectable {
  const Reflector()
      : super(instanceInvokeCapability, topLevelInvokeCapability,
            declarationsCapability, reflectedTypeCapability, libraryCapability);
}

const reflector = const Reflector();

typedef int Int2IntFunc(int _);

Int2IntFunc int2int = (int x) => x;

@reflector
class C {
  Int2IntFunc get getter => int2int;
  void set setter(Int2IntFunc int2int) {}
  void method(int noNameType(int _), {Int2IntFunc int2int: null}) {}
}

main() {
  initializeReflectable();

  LibraryMirror libraryMirror = reflector
      .findLibrary("test_reflectable.test.function_type_annotation_test");
  VariableMirror variableMirror = libraryMirror.declarations["int2int"];
  ClassMirror classMirror = reflector.reflectType(C);
  MethodMirror getterMirror = classMirror.declarations["getter"];
  MethodMirror setterMirror = classMirror.declarations["setter="];
  MethodMirror methodMirror = classMirror.declarations["method"];
  ParameterMirror setterArgumentMirror = setterMirror.parameters[0];
  ParameterMirror methodArgument0Mirror = methodMirror.parameters[0];
  ParameterMirror methodArgument1Mirror = methodMirror.parameters[1];

  Type int2intType = const TypeValue<int Function(int)>().type;

  test('Function type as annotation', () {
    expect(variableMirror.hasReflectedType, true);
    expect(variableMirror.reflectedType, int2intType);
    expect(getterMirror.hasReflectedReturnType, true);
    expect(getterMirror.reflectedReturnType, int2intType);
    expect(setterArgumentMirror.hasReflectedType, true);
    expect(setterArgumentMirror.reflectedType, int2intType);
    expect(methodArgument1Mirror.hasReflectedType, true);
    expect(methodArgument1Mirror.reflectedType, int2intType);
    expect(variableMirror.hasDynamicReflectedType, true);
    expect(variableMirror.dynamicReflectedType, int2intType);
    expect(getterMirror.hasDynamicReflectedReturnType, true);
    expect(getterMirror.dynamicReflectedReturnType, int2intType);
    expect(setterArgumentMirror.hasDynamicReflectedType, true);
    expect(setterArgumentMirror.dynamicReflectedType, int2intType);
    expect(methodArgument0Mirror.hasReflectedType, true);
    expect(methodArgument0Mirror.reflectedType, int2intType);
    expect(methodArgument0Mirror.hasDynamicReflectedType, true);
    expect(methodArgument0Mirror.dynamicReflectedType, int2intType);
    expect(methodArgument1Mirror.hasDynamicReflectedType, true);
    expect(methodArgument1Mirror.dynamicReflectedType, int2intType);
  });
}
<commit_msg>Added testing of inline function types<commit_after>// Copyright (c) 2016, the Dart Team. All rights reserved. Use of this
// source code is governed by a BSD-style license that can be found in
// the LICENSE file.

// File being transformed by the reflectable transformer.
// Uses a function type in type annotations.

@reflector
library test_reflectable.test.function_type_annotation_test;

import 'package:reflectable/reflectable.dart';
import 'package:test/test.dart';
import 'function_type_annotation_test.reflectable.dart';

class Reflector extends Reflectable {
  const Reflector()
      : super(instanceInvokeCapability, topLevelInvokeCapability,
            declarationsCapability, reflectedTypeCapability, libraryCapability);
}

const reflector = const Reflector();

typedef int Int2IntFunc(int _);

Int2IntFunc int2int = (int x) => x;

@reflector
class C {
  Int2IntFunc get getter => int2int;
  void set setter(Int2IntFunc int2int) {}
  void method(int noNameType(int _), {Int2IntFunc int2int: null}) {}

  void inlineTypes(
    int Function() f1,
    int Function(int) f2,
    int Function(int, int) f3,
    int Function(int, [int]) f4,
    int Function([int, int]) f5,
    int Function(int, [int, int]) f6,
    int Function(int, {int a}) f7,
    int Function({int a, int b}) f8,
    int Function(int, {int a, int b}) f9,
    X Function<X>(X) f10,
    X Function<X>(X, X) f11,
    X Function<X>(X, [X]) f12,
    X Function<X>([X, X]) f13,
    X Function<X>(X, [X, X]) f14,
    X Function<X>(X, {X a}) f15,
    X Function<X>({X a, X b}) f16,
    X Function<X>(X, {X a, X b}) f17,
  ) {}
}

typedef typeF10 = X Function<X>(X);
typedef typeF11 = X Function<X>(X, X);
typedef typeF12 = X Function<X>(X, [X]);
typedef typeF13 = X Function<X>([X, X]);
typedef typeF14 = X Function<X>(X, [X, X]);
typedef typeF15 = X Function<X>(X, {X a});
typedef typeF16 = X Function<X>({X a, X b});
typedef typeF17 = X Function<X>(X, {X a, X b});

main() {
  initializeReflectable();

  LibraryMirror libraryMirror = reflector
      .findLibrary("test_reflectable.test.function_type_annotation_test");
  VariableMirror variableMirror = libraryMirror.declarations["int2int"];
  ClassMirror classMirror = reflector.reflectType(C);
  MethodMirror getterMirror = classMirror.declarations["getter"];
  MethodMirror setterMirror = classMirror.declarations["setter="];
  MethodMirror methodMirror = classMirror.declarations["method"];
  ParameterMirror setterArgumentMirror = setterMirror.parameters[0];
  ParameterMirror methodArgument0Mirror = methodMirror.parameters[0];
  ParameterMirror methodArgument1Mirror = methodMirror.parameters[1];
  Type int2intType = const TypeValue<int Function(int)>().type;

  test('Using a function type as an annotation', () {
    expect(variableMirror.hasReflectedType, true);
    expect(variableMirror.reflectedType, int2intType);
    expect(getterMirror.hasReflectedReturnType, true);
    expect(getterMirror.reflectedReturnType, int2intType);
    expect(setterArgumentMirror.hasReflectedType, true);
    expect(setterArgumentMirror.reflectedType, int2intType);
    expect(methodArgument0Mirror.hasReflectedType, true);
    expect(methodArgument0Mirror.reflectedType, int2intType);
    expect(methodArgument1Mirror.hasReflectedType, true);
    expect(methodArgument1Mirror.reflectedType, int2intType);

    expect(variableMirror.hasDynamicReflectedType, true);
    expect(variableMirror.dynamicReflectedType, int2intType);
    expect(getterMirror.hasDynamicReflectedReturnType, true);
    expect(getterMirror.dynamicReflectedReturnType, int2intType);
    expect(setterArgumentMirror.hasDynamicReflectedType, true);
    expect(setterArgumentMirror.dynamicReflectedType, int2intType);
    expect(methodArgument0Mirror.hasDynamicReflectedType, true);
    expect(methodArgument0Mirror.dynamicReflectedType, int2intType);
    expect(methodArgument1Mirror.hasDynamicReflectedType, true);
    expect(methodArgument1Mirror.dynamicReflectedType, int2intType);
  });

  MethodMirror inlineTypesMirror =
      classMirror.declarations["inlineTypes"];
  List<ParameterMirror> parameterMirrors = inlineTypesMirror.parameters;
  List<Type> expectedTypes = [
    new TypeValue<int Function()>().type,
    new TypeValue<int Function(int)>().type,
    new TypeValue<int Function(int, int)>().type,
    new TypeValue<int Function(int, [int])>().type,
    new TypeValue<int Function([int, int])>().type,
    new TypeValue<int Function(int, [int, int])>().type,
    new TypeValue<int Function(int, {int a})>().type,
    new TypeValue<int Function({int a, int b})>().type,
    new TypeValue<int Function(int, {int a, int b})>().type,
    // The following types cannot be recognized (SDK issue #32625):
    // typeF10, typeF11, typeF12, typeF13, typeF14, typeF15, typeF16, typeF17
  ];

  test('Using different kinds of function types', () {
    for (ParameterMirror parameterMirror in parameterMirrors) {
      expect(parameterMirror.hasReflectedType, true);
    }
    for (int index = 0; index < expectedTypes.length; index++) {
      expect(parameterMirrors[index].reflectedType, expectedTypes[index]);
    }
  });
}

{'fraction_non_alphanumeric': 0.1093519882179676, 'fraction_numerical': 0.017059401080019635, 'mean_word_length': 5.508785942492013, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 36, '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': '1354386', 'n_tokens_mistral': 2611, 'n_tokens_neox': 2444, 'n_words': 566}