• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dart-lang / ffigen / 4784152981

24 Apr 2023 08:39AM UTC coverage: 92.363% (-7.0%) from 99.366%
4784152981

push

github

GitHub
Merge pull request #560 from dart-lang/stable-to-7-x

1780 of 1780 new or added lines in 41 files covered. (100.0%)

3229 of 3496 relevant lines covered (92.36%)

25.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/lib/src/code_generator/typealias.dart
1
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
2
// for details. All rights reserved. Use of this source code is governed by a
3
// BSD-style license that can be found in the LICENSE file.
4

5
import 'package:ffigen/src/code_generator.dart';
6

7
import 'binding_string.dart';
8
import 'utils.dart';
9
import 'writer.dart';
10

11
/// A simple Typealias, Expands to -
12
///
13
/// ```dart
14
/// typedef $name = $type;
15
/// );
16
/// ```
17
class Typealias extends BindingType {
18
  final Type type;
19
  final bool _useDartType;
20

21
  Typealias({
19✔
22
    String? usr,
23
    String? originalName,
24
    String? dartDoc,
25
    required String name,
26
    required this.type,
27

28
    /// If true, the binding string uses Dart type instead of C type.
29
    ///
30
    /// E.g if C type is ffi.Void func(ffi.Int32), Dart type is void func(int).
31
    bool useDartType = false,
32
    bool isInternal = false,
33
  })  : _useDartType = useDartType,
34
        super(
19✔
35
          usr: usr,
36
          name: name,
37
          dartDoc: dartDoc,
38
          originalName: originalName,
39
          isInternal: isInternal,
40
        );
41

42
  @override
19✔
43
  void addDependencies(Set<Binding> dependencies) {
44
    if (dependencies.contains(this)) return;
19✔
45

46
    dependencies.add(this);
19✔
47
    type.addDependencies(dependencies);
38✔
48
  }
49

50
  @override
17✔
51
  BindingString toBindingString(Writer w) {
52
    final sb = StringBuffer();
17✔
53
    if (dartDoc != null) {
17✔
54
      sb.write(makeDartDoc(dartDoc!));
6✔
55
    }
56
    sb.write('typedef $name = ');
51✔
57
    sb.write('${_useDartType ? type.getDartType(w) : type.getCType(w)};\n');
89✔
58
    return BindingString(
17✔
59
        type: BindingStringType.typeDef, string: sb.toString());
17✔
60
  }
61

62
  @override
11✔
63
  Type get typealiasType => type.typealiasType;
22✔
64

65
  @override
13✔
66
  bool get isIncompleteCompound => type.isIncompleteCompound;
26✔
67

68
  @override
13✔
69
  String getCType(Writer w) => name;
13✔
70

71
  @override
11✔
72
  String getDartType(Writer w) {
73
    // Typealias cannot be used by name in Dart types unless both the C and Dart
74
    // type of the underlying types are same.
75
    if (sameDartAndCType(type, w)) {
22✔
76
      return name;
10✔
77
    } else {
78
      return type.getDartType(w);
6✔
79
    }
80
  }
81

82
  @override
2✔
83
  String cacheKey() => type.cacheKey();
4✔
84

85
  @override
×
86
  String? getDefaultValue(Writer w, String nativeLib) =>
87
      type.getDefaultValue(w, nativeLib);
×
88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc