Add stubs for user methods too
This commit is contained in:
parent
456221df6c
commit
958b918ad2
3 changed files with 38 additions and 3 deletions
|
@ -8,6 +8,7 @@ part of 'stateful.dart';
|
|||
|
||||
abstract class _StatefulAppJaelTemplate implements Component<_AppState> {
|
||||
Timer get _timer;
|
||||
void beforeDestroy();
|
||||
@override
|
||||
DomNode render() {
|
||||
return h('div', {}, [text('Tick count: '), text(state.ticks.toString())]);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:build/build.dart';
|
||||
import 'package:code_builder/code_builder.dart';
|
||||
|
@ -75,6 +74,21 @@ class JaelComponentGenerator extends GeneratorForAnnotation<Jael> {
|
|||
}));
|
||||
}
|
||||
|
||||
// ... And methods too.
|
||||
for (var method in element.methods) {
|
||||
b.methods.add(Method((b) {
|
||||
b
|
||||
..name = method.name
|
||||
..returns = convertTypeReference(method.returnType)
|
||||
..requiredParameters.addAll(method.parameters
|
||||
.where(isRequiredParameter)
|
||||
.map(convertParameter))
|
||||
..optionalParameters.addAll(method.parameters
|
||||
.where(isOptionalParameter)
|
||||
.map(convertParameter));
|
||||
}));
|
||||
}
|
||||
|
||||
// Add a render() stub
|
||||
b.methods.add(Method((b) {
|
||||
b
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:analyzer/dart/element/element.dart';
|
||||
import 'package:analyzer/dart/element/type.dart';
|
||||
import 'package:build/build.dart';
|
||||
import 'package:code_builder/code_builder.dart';
|
||||
|
@ -18,6 +19,25 @@ TypeReference convertTypeReference(DartType t) {
|
|||
});
|
||||
}
|
||||
|
||||
bool isRequiredParameter(ParameterElement e) {
|
||||
return e.isNotOptional;
|
||||
}
|
||||
|
||||
bool isOptionalParameter(ParameterElement e) {
|
||||
return e.isOptional;
|
||||
}
|
||||
|
||||
Parameter convertParameter(ParameterElement e) {
|
||||
return Parameter((b) {
|
||||
b
|
||||
..name = e.name
|
||||
..type = convertTypeReference(e.type)
|
||||
..named = e.isNamed
|
||||
..defaultTo =
|
||||
e.defaultValueCode == null ? null : Code(e.defaultValueCode);
|
||||
});
|
||||
}
|
||||
|
||||
UnsupportedError _unsupported() =>
|
||||
UnsupportedError('Not support in R/O build file system.');
|
||||
|
||||
|
@ -183,8 +203,8 @@ class BuildSystemFile extends File {
|
|||
throw _unsupported();
|
||||
|
||||
@override
|
||||
Directory get parent =>
|
||||
BuildSystemDirectory(fileSystem, reader, package, fileSystem.path.dirname(path));
|
||||
Directory get parent => BuildSystemDirectory(
|
||||
fileSystem, reader, package, fileSystem.path.dirname(path));
|
||||
|
||||
@override
|
||||
Future<List<int>> readAsBytes() {
|
||||
|
|
Loading…
Reference in a new issue