Skip to content
This repository has been archived by the owner on Jan 20, 2018. It is now read-only.

Initial commit #3

Merged
merged 13 commits into from
Jan 15, 2015
Merged

Initial commit #3

merged 13 commits into from
Jan 15, 2015

Conversation

jakemac53
Copy link
Contributor

This deviates from the design doc somewhat, differences are listed below:

  1. Libraries are visited in post-order, but annotations within the libraries are not visited in text-source order. This is because the ClassMirror implementation doesn't implement the location property. The result is that method annotations execute in text-source order but class annotations are mixed in somewhat arbitrarily.
  2. There are two optional arguments to run, typeFilter and customFilter, instead of just filter. The typeFilter is analogous to the filter described in the design doc, and customFilter accepts a function with this signature bool (StaticInitializer annotation).

const _InitMethod();

@override
initialize(_ZeroArg method) => method();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI - if we change later StaticInitializer.initialize to return a future, we'd need to change this to not use =>, but return null instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya, for exactly that reason I think we should leave it as dynamic

@sigmundch
Copy link
Contributor

Super cool!

@jakemac53
Copy link
Contributor Author

ok updated everything and ran the formatter, ready for another look!

…sses, and alphabetical within each category.
// The primary function in this class, invoke it to crawl and call all the
// annotations.
Future run() {
// Parse everything into the two queues.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that the queues are gone, I think we can delete this and the following comment. It's pretty self explanatory now :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

final InitializerFilter customFilter;

// All the libraries we have seen so far.
final Set<LibraryMirror> _librariesSeen = new Set<LibraryMirror>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that we might need to move this down and make it an argument of _readLibraryDeclarations below and not a field anymore. This is for the same reason we do the caching of annotations-found for each initializer: when we process initializers in phases and someone runs init.run a second time, we should revisit all libraries to see if there were other initializers we should add.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya true, this isn't an issue right now because I only ever call run() on one of these crawlers once, but since the class itself doesn't enforce that it could cause bugs later on.

@jakemac53
Copy link
Contributor Author

updated, see note about sorting libraries by uri though, we should talk at some point today about that

} else {
var superMetas = declaration.superclass.metadata
.where((m) => _filterMetadata(declaration.superclass, m))
.toList();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should additionally filter initializers that we have previously found, otherwise we might report the message unnecessarily on an example like this:

import 'a.dart';
@init
class B extends A {}

a.dart:

@init
class A {}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(to clarify - the current check seems to be finding the super initializer, but is not excluding those that don't create a cycle)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does cover this inside _filterMetadata

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah nice, sorry, I totally missed that. Thanks for the clarification

@sigmundch
Copy link
Contributor

ok, I think I just finished the second pass :)

@jakemac53
Copy link
Contributor Author

ok, ready for another look. I also added in the stuff we talked about with regards to ordering file imports by their relative uri to more closely match what the user typed.

///
/// Call [run] from your main and this will print 'Foo says `hello world!`'
///
abstract class StaticInitializer<T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after our discussion earlier, should we rename this to just Initializer? If so, should we rename initialize as run?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I will leave that rename for a followup cl

@sigmundch
Copy link
Contributor

LGTM! Besides the comment about clustering package before file urls, I think we are good!

jakemac53 added a commit that referenced this pull request Jan 15, 2015
@jakemac53 jakemac53 merged commit 2eeb762 into master Jan 15, 2015
@jakemac53 jakemac53 deleted the initial_commit branch January 15, 2015 15:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants