Get warnings when programmatically parsing Dart file with analyzer_experimental - dart

I am using analyzer_experimental to parse a Dart file into a CompilationUnit:
import 'package:analyzer_experimental/analyzer.dart';
var unit;
try {
unit = parseDartFile(path);
} on AnalyzerErrorGroup catch(e){
print(e);
}
The above code will catch any parsing errors encountered.
I am also interested in seeing any warnings associated with the file (e.g. 'Undefined name "foo"'). I know that the experimental_analyzer library has the capability to generate these warnings when running from the command line but it does not seem to be possible to get the warnings programmatically, without directly referencing classes in the src folder (which seems like a bad idea).
Is there any way to achieve this?

It's likely this package was very incomplete at the time.
There's now an analyzer package on pub and also a (work-in-progress) STDIN/STDOUT Analyzer Service aimed to help making tooling support easier for IDE extension authors.

Related

Error running ParseTree

In the Rascal shell, doing this:
import lang::c90::\syntax::C;
import ParseTree;
parse(#TranslationUnit, |file:///teste.c|);
I get in the stable standalone jar:
|prompt:///|(24,93,<1,24>,<1,117>): ParseError(|file:///home/rafael2k/files/UnB/static_analysis/eclipse-workspace/rascal-C/c-source/teste.c|(47,0,<4,0>,<4,0>))
at parse(|prompt:///|(24,93,<1,24>,<1,117>))
at *** somewhere ***(|prompt:///|(24,93,<1,24>,<1,117>))
at parse(|prompt:///|(24,93,<1,24>,<1,117>))
And in Eclipse I get a giant message error:
(...)
public AbstractStackNode<IConstructor>[] FloatingPointConstant() {
return FloatingPointConstant.EXPECTS;
}
public AbstractStackNode<IConstructor>[] StructDeclarator() {
return StructDeclarator.EXPECTS;
}
}
Advice: |http://tutor.rascal-mpl.org/Errors/Static/JavaCompilation/JavaCompilation.html|null
Any tip?
Btw, running Debian Jessie, Oracle Java 1.8.0_112,x86_64.
I think it can be fixed with this:
parse(#start[TranslationUnit], |file:///teste.c|);
By using a start non-terminal you can parse files which begin and/or end with whitespace or source code comments. See also the answer to this question: Layout in Rascal
By the way, this grammar will parse c programs after the processor has been applied.
The Eclipse error is a seemingly unrelated issue for which we would love to receive a stack trace on the github issue tracker.

Debugging MirrorsUsed

I'm trying to figure out which libraries I need to pass to #MirrorsUsed to get my app compiled and working. Sometimes, it's easy to figure out which library may be missing since a descriptive error is thrown such as Uncaught Unsupported operation: Cannot find class for: NgAttr .
Other times, I get a more obscure message, such as NullError: Cannot call "$gt" on null with no clue as to which library I may be omitting. Is there a better approach to this, besides trial and error?
In case you're wondering, this is an angular app and this is how I currently have it configured:
#MirrorsUsed(targets: const[
'angular',
'angular.core',
'angular.core.dom',
'angular.filter',
'angular.perf',
'angular.directive',
'angular.routing',
'angular.core.parser.dynamic_parser',
'angular.core.parser.lexer',
'todo',
'perf_api',
'List',
'NodeTreeSanitizer',
'PlaybackHttpBackendConfig'
],
override: '*')
import 'dart:mirrors';
Use
pub build --mode=debug
this does tree shaking but retains (mostly) the original Dart names.
Then debugging the generated JavaScript usually lets deduce the source of the exception.
EDIT
IMHO these are not necessary anymore, because they were added to #MirrorsUsed in the Angular libs.
'angular',
'angular.core',
'angular.core.dom',
'angular.filter',
'angular.perf',
'angular.directive',
'angular.routing',
'angular.core.parser.dynamic_parser',
'angular.core.parser.lexer',

Dart Editor: "unused import" errors

For a project, I'm importing a library but I don't use any of the classes in it directly. The goal is to fetch a ClassMirror at runtime to create an instance from it. So I have something like:
import 'controllers.dart';
main() {
ClassMirror controller = getClassFromString(libraryName: 'deck_app', className: 'HomeController');
InstanceMirror instance = controller.newInstance(new Symbol(''), []);
instance.reflectee.sayHey();
}
This gives me an "unused import" error. Idk if this is to be considered a bug. So I'm asking you: do you think this is to be considered as a bug? If not, is there a way I could suppress unused import errors?
What's weird is I thought Dart would tree-shake the source and remove the unused import's code, but it does not. The library is properly imported and available.
The unused import is just a conclusion from the static analyzer. You can ignore it or add a dummy statement to silence the analyzer. This has no effect when you run the application.

Compiling jabber-net in Xamarin Studio

I am trying to compile jabber-net in Xamarin Studio so I can use it in a Xamarin.iOS app.
From other searches I have done I am told I need to recompile the source.
From command line I can build the dll, but I have no idea what version of .NET/Mono this is targeting.
This makes a jabber-net.dll and a jabber-net.dll.mdb.
If I add jabber-net.dll to my project, add the reqiured
using jabber.client;
...
...
...
JabberClient client = new JabberClient ();
and try to compile I am told.
/Users/brad/Projects/XMPPChat/XMPPChat/AppDelegate.cs(37,47): error CS0584: Internal compiler error: Could not import type jabber.client.JabberClient' fromjabber-net, Version=2.1.0.702, Culture=neutral, PublicKeyToken=924c5b18328d6f09'
/Users/brad/Projects/XMPPChat/XMPPChat/AppDelegate.cs(37,38): error CS0584: Internal compiler error: Could not import type jabber.client.JabberClient' fromjabber-net, Version=2.1.0.702, Culture=neutral, PublicKeyToken=924c5b18328d6f09'
/Users/brad/Projects/XMPPChat/XMPPChat/AppDelegate.cs(37,38): error CS0201: Only assignment, call, increment, decrement, and new object expressions can be used as a statement
I got no idea what is going on here...
When I try to open any of the .sln's (or include any of the existing projects, even the mono specific project) that came with jabber-net into my solution it will either hang trying to convert the project, or will tell me
The file '/Users/brad/Projects/XMPPChat/JabberNet-2.1.0.710/mono-jabber-net.csproj' could not be loaded.
and will spit out this error.
Any idea where to go from here? :|
Start a new solution from scratch, and add all of the .cs files except those in the test and examples directories. Also make sure you don't have an old version of the .dll around somewhere.

F# AsyncWaitOne and AsyncReadToEnd

I am working ti old F# code from Expert F#. However, the example doesn't build anymore.
The following two calls don't seem to exist:
semaphore.AsyncWaitOne(?millisecondsTimeout=timeout)
and
reader.ReadToEndAsync()
Does anyone know what these have been replaced with or if I am just missing a reference?
It's now called Async.AwaitWaitHandle.
AsyncReadToEnd is in the F# PowerPack.
By now, FSharp PowerPack project has been broken up into smaller modules for any further development.
Specifically, the AsyncStreamReader class and the extension methods for the reading from a StreamReader, WebClient, etc. the new project is FSharpx.Async.
1) AsyncWaitOne is now called Async.AwaitWaitHandle.
2) AsyncReadToEnd() extension method does not exists anymore in the FSharp.PowerPack.
It has been replaced with the AsyncStreamReader dedicated type that contains proper asynchronous implementation of stream reading (like ReadToEnd, ReadLine, etc.)
It can be used like that:
async {
use asyncReader = new AsyncStreamReader(stream)
return! asyncReader.ReadToEnd() }
Note: Once you have installed FSharp.PowerPack, the AsyncStreamReader type will be 'injected' in the Microsoft.FSharp.Control namespace

Resources