Extend Dart analyzer features - dart

I'm currently building a framework on Dart and would like to throw static errors and warnings for the user on the 'Problems' tab on VS Code.
If not possible, throw warnings based on annotations would be very helpful, like the meta package.
I more or so understand the dart analyzer package but I can't see how could I integrate it (if possible at all) with the dart-code extension for VS Code.
Will I have to implement a whole extension for VS Code?

Related

How to get the path of a file that defines a class, in Dart/Flutter?

In a Flutter app, I have a dart file located at FlutterTest\sandbox\lib\my_widget\my_widget.dart, containing a class called MyWidget.
Can I, from this class, get the location of the file where it is defined?
This is not possible. Flutter disable dart:mirror so you can't use reflection.
As mentioned in another answer/comments, that information is stripped out at runtime.
However, if you're motivated enough you could write a pub transformer that uses regex to pick up a special symbol you define and exchange it for the file path at runtime. Edit: transformers aren't supported in flutter.
You may be able to do this with the Build package & tooling introduced in Dart 2, but you'll have to make sure you're using a version of flutter that uses dart 2 (the beta branch/channel probably doesn't yet, the dev may or may not, but master does).

Can I access metadata annotations of a type or parameter in flutter?

Or is that capability lost with the loss of the reflect package?
What I'm curious about is can I use annotations in my own flutter app? Or is that a feature only available in dart, but not flutter?
Annotations can only be used for static analysis in Flutter.
For example the analyzer that generates hints and warnings in your IDE, code generation tools like built_value, built_redux, json_serializable, and other packages that use https://github.com/dart-lang/build make use of this.
There is no way to get metadata information at runtime without dart:mirrors.
There is work in progress to make the reflectable package work with code generation. This might work with Flutter eventually to generate code that allows to access predefined metadata at runtime.
See also https://github.com/dart-lang/reflectable/tree/use_build
Yes, of course you can use metadata annotations in flutter. Flutter has a meta-library, which you can look into to know about available annotations that can be used with flutter.
Hope this helped!

Combining different dart files when executed by JS

I'm building up some Dart code that I would like to use in an app where it is essentially a library to the javascript. I'm wondering how I can specify which Dart files I'd like in the project to be part of the library. For example, theres Foo.dart and Bar.dart. How can I have the created product include both Foo.dart and Bar.dart in one file? I'm also concerned about tree shaking since none of the classes are instantiated in Dart.
There's also a Baz.dart, and I would like to have a different build for compiling Foo.dart and Baz.dart into a single file (though this is less important, as I can accomplish this would separate projects and some symlinking).
Thanks!
This use case (build a JavaScript library with Dart) isn't supported yet.
The reworked js-interop package is supposed to allow to do that but I don't know about it's current state.

ios programming - overriding static library inside a static library at application level

I am very new to the field of ios programming and working with linker is just a whole new world to me. I would try my best to be precise about my question.
Context: Static library linking in an ios project using xcode.
Problem:
Problem members:
3 static libraries.
libTestLibA.a
libTestLibB.a
libTestLibB_mine.a -- same functionality as libTestLibB.a -- same classes/methods everything.
Problem description
I am making an app using libTestLibA.a.
libTestLibA has some classes that depend on some classes from libTestLibB. Hence libTestLibA.a has libTestLibB.a compiled in itself.
Now, I have my own library named libTestLibB_mine. It has the exact same functionality as that of libTestLibB. Same methods / classes for same functionality. I want libTestLibA to use libTestLibB_mine instead of libTestLibB. I just have compiled static libraries (.a) for each of the problem members , ie, libTestLibA, libTestLibB and libTestLibB_mine.
Question:
When I compile my application, can I force a static compiled library (libTestLibA.a) to make use of another library (libTestLibB_mine.a) instead of what it already contains (libTestLibB.a)? If yes, how? If not, is there some work around?
Much thanks.
If A has already been statically complied against B, then I don't think you can replace B with B_mine. But as a workaround, I think what you might be looking for here is "Method Swizzling". What it does is, at runtime, replace the method of a class with another method (intercept the message and direct it somewhere else).
The following links should be useful to you.
CocoaDev Method Swizzling
JRSwizzle - open source library to make swizzling easier
Be sure to read about the dangers of method swizzling too.

Can an iOS static library contain classes/interfaces, that can be used/implemented by iOS code that is using the library?

I apologize if this is a dumb question, or if it does not make sense. I've written some Objective-C code before, but I am not very familiar with writing code for OS X or iOS; I'm pretty much a novice. Currently, I'm trying to port a project from OS X into iOS. The project compiles into a Framework, that other OS X projects can use.
I'm trying to do something similar for iOS. I understand that iOS does not support Frameworks that contain dylibs and that the solution is to create a static library. However, the OS X Framework has several classes (in .m files) that the implementing code uses, extends, or implements. All the examples I've seen for static libraries seem to define a header-file with some functions that can be compiled into a static library.
Is it possible to have classes inside the static library, that iOS code can use? Also, how can I tell if the code is using dynamic libraries?
Yes, static libraries can contain Objective-C classes.
In some cases, you will need to pass options to the linker to force it to include all of the classes and categories defined in a static library. See http://developer.apple.com/library/mac/#qa/qa1490/_index.html

Resources