Skip to content

Commit

Permalink
Enable null safety #22
Browse files Browse the repository at this point in the history
  • Loading branch information
soloxiao committed Feb 13, 2023
1 parent 15904d5 commit de265b3
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 61 deletions.
2 changes: 1 addition & 1 deletion example/lib/hook_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ class AddDemo {

@Add("package:example/receiver_test.dart", "Receiver")
@pragma("vm:entry-point")
dynamic addTest(PointCut pointCut, int j, {String s, int i}) {
dynamic addTest(PointCut pointCut, int j, {String? s, int? i}) {
print('[beike_aspectd]: Add method');
}

Expand Down
10 changes: 5 additions & 5 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
MyHomePage({Key? key, this.title}) : super(key: key);

// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
Expand All @@ -80,16 +80,16 @@ class MyHomePage extends StatefulWidget {
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".

final String title;
final String? title;

@override
_MyHomePageState createState() => _MyHomePageState(i: 19);
}

class TextRightImageModel {
String showName;
String? showName;

String rightIcon;
String? rightIcon;

Widget showCardWidget(BuildContext context) {
return Container(
Expand Down Expand Up @@ -153,7 +153,7 @@ class _MyHomePageState extends State<MyHomePage> {
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
title: Text(widget.title??''),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
Expand Down
3 changes: 1 addition & 2 deletions example/lib/receiver_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @dart=2.10

class Receiver {

Expand All @@ -10,7 +9,7 @@ class Receiver {

}

void receiveTapped(int i, {int j}) {
void receiveTapped(int i, {int? j}) {
print('[KWLM]:onPluginDemo111 Called!');
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ description: A new Flutter application.
version: 1.0.0+1

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
Expand Down
Binary file modified inner/flutter_frontend_server/frontend_server.dart.snapshot
Binary file not shown.
43 changes: 31 additions & 12 deletions inner/snapshot.dart
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
import 'dart:io';

void main(List<String> args) async {

final String dartPath = Platform.executable;

List<String> command = <String>['--snapshot=../lib/bin/starter.snapshot', 'tool/starter.dart'];
List<String> command = <String>[
'--snapshot=../lib/bin/starter.snapshot',
'tool/starter.dart'
];

print('Start generating starter.snapshot...');
Process result = await Process.start(dartPath, command);

stdout.addStream(result.stdout);
stderr.addStream(result.stderr);

if (await result.exitCode == 0) {
print('Generated starter.snapshot successfully!');
} else {
print('Failed t0 generate starter.snapshot!');
}

command = <String>[
'--deterministic',
'--snapshot=flutter_frontend_server/frontend_server.dart.snapshot',
'flutter_frontend_server/starter.dart'
];

Process result = await Process.start(
dartPath,
command
print('Start generating frontend_server.dart.snapshot...');

);
result = await Process.start(dartPath, command);

command = <String>['--deterministic', '--snapshot=flutter_frontend_server/frontend_server.dart.snapshot', 'flutter_frontend_server/starter.dart'];
if (await result.exitCode == 0) {
print('Generated frontend_server.dart.snapshot successfully!');
} else {
print('Failed t0 generate frontend_server.dart.snapshot!');
}

result = await Process.start(
dartPath,
command
);
}
stdout.addStream(result.stdout);
stderr.addStream(result.stderr);
}
2 changes: 0 additions & 2 deletions lib/aspectd.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
// @dart=2.8

export 'package:beike_aspectd/src/plugins/aop/aop.dart';
Binary file modified lib/bin/starter.snapshot
Binary file not shown.
14 changes: 6 additions & 8 deletions lib/src/plugins/aop/annotation/annotation_info.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart=2.8

/// Indicating which (library, cls, method) pair to operate on.
@pragma('vm:entry-point')
class AnnotationInfo {
Expand All @@ -14,23 +12,23 @@ class AnnotationInfo {
this.superCls,});

/// Indicating which dart file to operate on.
final String importUri;
final String? importUri;

/// Indicating which dart class to operate on.
final String clsName;
final String? clsName;

/// Indicating which dart method to operate on.
final String methodName;
final String? methodName;

/// Indicating whether those specification above should be regarded as
/// regex expressions.
final bool isRegex;
final bool? isRegex;

/// Indicating which line to operate on.
/// This is only meaningful for inject grammar.
final int lineNum; //Line Number to insert at(Before), 1 based.
final int? lineNum; //Line Number to insert at(Before), 1 based.

/// Indicating which classes inherited from the superCls to operate on.
/// This is only meaningful for regex add grammer.
final String superCls;
final String? superCls;
}
6 changes: 2 additions & 4 deletions lib/src/plugins/aop/annotation/call.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart=2.8

import 'annotation_info.dart';

/// Call grammar is working on those callsites for the annotated method.
Expand All @@ -11,14 +9,14 @@ class Call extends AnnotationInfo {

@pragma('vm:entry-point')
const Call._(String importUri, String clsName, String methodName,
{bool isRegex,this.excludeCoreLib})
{bool? isRegex,this.excludeCoreLib})
: super(
importUri: importUri,
clsName: clsName,
methodName: methodName,
isRegex: isRegex);

/// Indicate whether to exclude flutter libs
final bool excludeCoreLib;
final bool? excludeCoreLib;

}
4 changes: 1 addition & 3 deletions lib/src/plugins/aop/annotation/execute.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart=2.8

import 'annotation_info.dart';

/// Execute grammar is working on method body.
Expand All @@ -13,7 +11,7 @@ class Execute extends AnnotationInfo {

@pragma('vm:entry-point')
const Execute._(String importUri, String clsName, String methodName,
{bool isRegex})
{bool? isRegex})
: super(
importUri: importUri,
clsName: clsName,
Expand Down
4 changes: 1 addition & 3 deletions lib/src/plugins/aop/annotation/inject.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart=2.8

import 'annotation_info.dart';

/// Inject grammar can help you to inject statements into specific method
Expand All @@ -12,7 +10,7 @@ class Inject extends AnnotationInfo {

@pragma('vm:entry-point')
const Inject._(String importUri, String clsName, String methodName,
{int lineNum, bool isRegex})
{int? lineNum, bool? isRegex})
: super(
importUri: importUri,
clsName: clsName,
Expand Down
20 changes: 9 additions & 11 deletions lib/src/plugins/aop/annotation/pointcut.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart=2.8

/// Object carrying callsite information and methods which can enable you to
/// call the original implementation.
@pragma('vm:entry-point')
Expand All @@ -14,35 +12,35 @@ class PointCut {
}

/// Source infomation like file, linenum, etc for a call.
final Map<dynamic, dynamic> sourceInfos;
final Map<dynamic, dynamic>? sourceInfos;

/// Target where a call is operating on, like x for x.foo().
final Object target;
final Object? target;

/// Function name for a call, like foo for x.foo().
final String function;
final String? function;

/// Unique key which can help the proceed function to distinguish a
/// mocked call.
final String stubKey;
final String? stubKey;

/// Positional parameters for a call.
final List<dynamic> positionalParams;
final List<dynamic>? positionalParams;

/// Named parameters for a call.
final Map<dynamic, dynamic> namedParams;
final Map<dynamic, dynamic>? namedParams;

/// Class's members. In Call mode, it's caller class's members. In execute mode, it's execution class's members.
final Map<dynamic, dynamic> members;
final Map<dynamic, dynamic>? members;

/// Class's annotations. In Call mode, it's caller class's annotations. In execute mode, it's execution class's annotations.
final Map<dynamic, dynamic> annotations;
final Map<dynamic, dynamic>? annotations;

/// Unified entrypoint to call a original method,
/// the method body is generated dynamically when being transformed in
/// compile time.
@pragma('vm:entry-point')
Object proceed() {
Object? proceed() {
return null;
}
}
2 changes: 0 additions & 2 deletions lib/src/plugins/aop/aop.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart=2.8

export 'annotation/aspect.dart';
export 'annotation/call.dart';
export 'annotation/execute.dart';
Expand Down
4 changes: 1 addition & 3 deletions lib/src/plugins/aop/beike_annotation/add.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart=2.8

import '../annotation/annotation_info.dart';

/// Call grammar is working on those callsites for the annotated method.
Expand All @@ -11,7 +9,7 @@ class Add extends AnnotationInfo {

@pragma('vm:entry-point')
const Add._(String importUri, String clsName,
{bool isRegex, String superCls})
{bool? isRegex, String? superCls})
: super(
importUri: importUri,
clsName: clsName,
Expand Down
4 changes: 1 addition & 3 deletions lib/src/plugins/aop/beike_annotation/field_get.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @dart=2.8

import '../annotation/annotation_info.dart';

/// Field get grammar is working on those callsites for the annotated method.
Expand All @@ -11,7 +9,7 @@ class FieldGet extends AnnotationInfo {

@pragma('vm:entry-point')
const FieldGet._(String importUri, String clsName, this.fieldName, this.isStatic,
{bool isRegex})
{bool? isRegex})
: super(
importUri: importUri,
clsName: clsName,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ homepage: https://github.com/LianjiaTech/Beike_AspectD.git
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.1
environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
Expand Down

0 comments on commit de265b3

Please sign in to comment.