Ideally I'm looking for something like :
typedef Json = Map<String, dynamic>;
From what I understand, this language feature is under review typedef for simple type aliases with ETA Q1'19
But for a immediate alternative, what would be the simplest way to "extend" a Map in Dart ? All the solutions I could find are quite old and look overkill. At the end I just want an alias for my Map.
Thanks in advance.
Dart 2.13
Update analysis_options.yaml
analyzer:
enable-experiment:
- nonfunction-type-aliases
Run
flutter run --enable-experiment=nonfunction-type-aliases
Related
Is it possible to add a package in the reflection-config.json?
Something like:
[
{
"name" : "org.apache.tinkerpop.shaded.kryo.serializers.*",
"allDeclaredConstructors" : true
}
}
Instead of doing it one by one.
Thanks :)
As far as I know, that isn't possible yet. There is an open feature request for this: https://github.com/oracle/graal/issues/1236
Probably the best would be to create a Feature class which would register classes for reflection programmatically. Here's a short example: https://www.graalvm.org/reference-manual/native-image/Reflection/#configuration-with-features
The feature class needs to be on classpath then referenced using the --features= command line option.
I am using tracing agent features to auto generate a list for reflection/jni/resources, this should be quite convenient until one day the wildcard features is implemented. (I bet it will not be implemented due to performance concern.)
I need to analyse kotlin files code, to detect the keyword "data" and "?".
The issue is I don't find any libs like JavaParser.
I don't need powerfull tools, just something who return me the number of the lines.
Any idea?
I use antlr4 to do it. And I create an open source lib:
https://github.com/sarahBuisson/kotlin-parser
<dependency
<groupId>com.github.sarahbuisson</groupId>
<artifactId>kotlin-parser</artifactId>
</dependency>
Besides the tools mentioned in other answers, here is another one someone may find useful:
https://github.com/kotlinx/ast
You would need to either find a Kotlin parser, or write your own.
For this subset of parsing you may be able to cheat, as data is a keyword, so if you see data with non letters each side you know it is the keyword.
For ?, it depends which meaning you want, the elvis one can be detected by the dot else try the nullable meaning if the ? is next to a letter.
You can try Kastree -- simple library to manipulate Kotlin source code as a set of AST objects.
https://github.com/cretz/kastree
See this [0] Kotlin code parsing related discussion. They talk about using antlr v4 grammar to parse the Kotlin code.
[0] https://discuss.kotlinlang.org/t/kotlin-parser/1728
I have not yet written a Kotlin language grammar for it.
But I have implemented a parser in Kotlin, id that is any use.
It is Kotlin common code, so should work for any target platform.
There is an article about it here, and the code is on github.
https://medium.com/#dr.david.h.akehurst/agl-your-dsl-in-the-web-c9f54595691b
I am developing an app using Angular 2 and Ionic. I am using a bluetooth library for Cordova, so not writing using ES6-modules and exports.
The library defines a global variable called 'bluetoothle', and it works as expected when I run it. However, I get a lot of complaints from the typescript compiler. I would like to either:
(Preferred) Have some better way to import the ES5-library to my typescript-project.
Tell the compiler to ignore this error.
Declare the variable, and then let the library assign value to it(however, I don't know how to declare globals in typescript the way it was possible in ES6.
Thanks in advance,
Markus
You have two options there which depend on how much work you want to put in them.
The first and easy option is to just declare the variable at the top. This will tell TypeScript that this is a variable of type any and that it doesn't need to care about where it came from or which members it has:
declare var bluetoothle;
The other route, which would be cleaner but is way more work is writing a type definition file.
I'm currently playing with the Dart version of Angular 2.
I have seen that the library is using a lot of Metadata as #Component for example.
I would like to know how are those directives working?
I went on http://www.darlang.org. They explain how to define an annotation but not how to use it to construct an object as it is done in angular.io.
Could someone explain how the magic is working?
In Dart annotations by itself don't do anything than exist beside the code element where they are added.
At runtime:
You can use dart:mirrors to query the imported libraries for elements like fields, functions, classes, parameters, ... for these annotations.
dart:mirrors is discouraged for browser applications. In this case you can use the reflectable package with quite similar capabilities.
See also:
https://www.dartlang.org/articles/reflection-with-mirrors/
https://api.dartlang.org/1.14.1/dart-mirrors/dart-mirrors-library.html
https://stackoverflow.com/search?q=%5Bdart-mirrors%5D+annotations
At buildtime
You can create a transformer and register it in pubspec.yaml to be run by pub serve and pub build.
In this case the Dart analyzer can be utilized to query the source files for annotations and, like Angular does, modify the source code in a build step to add/replace/remove arbitrary code.
For more details about transformers
- https://www.dartlang.org/tools/pub/assets-and-transformers.html
- https://www.dartlang.org/tools/pub/transformers/
- https://www.dartlang.org/tools/pub/transformers/examples/
- https://www.dartlang.org/tools/pub/transformers/aggregate.html
- https://pub.dartlang.org/packages/code_transformers
Is there a way to list an objects properties and methods like python's dir?
https://docs.python.org/2/library/functions.html#dir
.g would do something similar. Use .help for more information at the cling command prompt.