Skip to content
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
This repository provides the Dart packages `reflectable` and
`reflectable_builder`, along with a set of test cases and
examples in the repository `test_reflectable`.

This repository provides the Dart package `reflectable` along with a set of
test cases, `test_reflectable`.
## [reflectable](https://github.com/google/reflectable.dart/blob/master/packages/reflectable/README.md)

## [reflectable](https://github.com/google/reflectable.dart/blob/master/reflectable/README.md)
Support for implementing a large subset of the features offered by
'dart:mirrors' without relying on 'dart:mirrors' itself. Provides a system
based on capabilities to control the amount of reflection support.

Support for generating code that implements a large subset of the features
offered by 'dart:mirrors' without relying on 'dart:mirrors' itself.
Provides a system based on capabilities to control the amount of reflection
support.
## [reflectable_builder](https://github.com/google/reflectable.dart/blob/master/packages/reflectable_builder/README.md)

## [test_reflectable](https://github.com/google/reflectable.dart/blob/master/test_reflectable/README.md)
Support for generating the code that the package `reflectable` uses to provide
the reflection support described above.

## [test_reflectable](https://github.com/google/reflectable.dart/blob/master/packages/test_reflectable/README.md)

Used to test package `reflectable`. Also serves as a set of examples of how
`reflectable` can be used.
4 changes: 4 additions & 0 deletions packages/reflectable/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.2.1

- Fix bugs #354 and #325.

## 5.2.0

- Upgrade reflectable to use analyzer ^10.0.0 and lints ^6.0.0.
Expand Down
7 changes: 4 additions & 3 deletions packages/reflectable/example/bin/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class A {
int argNamed(int x, int y, {int z = 42}) => x + y - z;
int operator +(int x) => 42 + x;
int operator [](int x) => 42 + x;
void operator []=(x, v) {
void operator []=(int x, int v) {
f = x + v;
}

Expand All @@ -32,8 +32,9 @@ class A {
int f = 0;

static int noArguments() => 42;
static int oneArgument(x) => x - 42;
static int optionalArguments(x, y, [z = 0, w]) => x + y + z * 42;
static int oneArgument(int x) => x - 42;
static int optionalArguments(int x, int y, [int z = 0, int? w]) =>
x + y + z * 42;
static int namedArguments(int x, int y, {int z = 42}) => x + y - z;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/reflectable/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: reflectable
version: 5.2.0
version: 5.2.1
description: >
Reflection support based on code generation, using 'capabilities' to
specify which operations to support, on which objects. This is the
Expand Down
4 changes: 4 additions & 0 deletions packages/reflectable_builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.2.1

- Fix bugs #354 and #325.

## 1.2.0

- Upgrade the code generator to use analyzer ^10.0.0 and lints 6.0.0.
Expand Down
7 changes: 4 additions & 3 deletions packages/reflectable_builder/example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class A {
int argNamed(int x, int y, {int z = 42}) => x + y - z;
int operator +(int x) => 42 + x;
int operator [](int x) => 42 + x;
void operator []=(x, v) {
void operator []=(int x, int v) {
f = x + v;
}

Expand All @@ -32,8 +32,9 @@ class A {
int f = 0;

static int noArguments() => 42;
static int oneArgument(x) => x - 42;
static int optionalArguments(x, y, [z = 0, w]) => x + y + z * 42;
static int oneArgument(int x) => x - 42;
static int optionalArguments(int x, int y, [int z = 0, int? w]) =>
x + y + z * 42;
static int namedArguments(int x, int y, {int z = 42}) => x + y - z;
}

Expand Down
25 changes: 25 additions & 0 deletions packages/reflectable_builder/lib/src/builder_implementation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4897,6 +4897,30 @@ class BuilderImplementation {
}
imports.sort();

// Some "private" platform libraries are exported by public ones. To avoid
// the error caused by importing 'dart:_http', we transform it to 'dart:io'.
// Other cases are ambiguous and not handled.
final length = imports.length;
for (int index = 0; index < length; ++index) {
final import = imports[index];
if (import.contains("'dart:_")) {
if (import.contains("'dart:_http'")) {
final rest = import.substring(
"import 'dart:_http' ".length,
import.length,
);
imports[index] = "import 'dart:io' $rest";
} else {
// TODO(eernst): Perhaps we can handle some of the remaining cases.
final match = RegExp(r"'dart:_.*'").firstMatch(import);
final String name = match != null
? import.substring(match.start, match.end)
: import;
await _severe('Reference to an internal platform library: $name');
}
}
}

var result =
'''
// This file has been generated by the reflectable package.
Expand Down Expand Up @@ -5575,6 +5599,7 @@ const Set<String> sdkLibraryNames = <String>{
'web_audio',
'web_gl',
'web_sql',
'_http', // Special case, redirected to 'dart:io'.
};

// Helper for _extractMetadataCode.
Expand Down
2 changes: 1 addition & 1 deletion packages/reflectable_builder/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: reflectable_builder
version: 1.2.0
version: 1.2.1
description: >
Reflection support based on code generation, using 'capabilities' to
specify which operations to support, on which objects. This is the
Expand Down
38 changes: 38 additions & 0 deletions packages/test_reflectable/test/substitute_http_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// Test the special casing of declarations in 'dart:_http'.

library test_reflectable.test.substitute_http_test;

import 'dart:io';

@GlobalQuantifyCapability(r'\.Cookie$', reflector)
import 'package:reflectable/reflectable.dart';

import 'substitute_http_test.reflectable.dart';

class Reflector extends Reflectable {
const Reflector()
: super(
instanceInvokeCapability,
declarationsCapability,
superclassQuantifyCapability,
typeAnnotationQuantifyCapability,
);
}

const reflector = Reflector();

@reflector
class CookieHolder extends HttpException {
CookieHolder(super._);
final Cookie? cookie = null;
}

void main() {
initializeReflectable();
// Just checking that the program compiles, that is, it does not
// attempt to import `dart:_http`.
}