Skip to content

Conversation

@matanlurey
Copy link
Contributor

Partial support of #178.

Still missing as of this PR:

  • Any sort of sugar for enum, though it should work out of the box anyway.
  • Error recovery: We just return null when something is not resolvable, ideally I'd like to either throw or return a specialized instance (Unrevivable) that explains why not (usually due to a private constructor, or not being able to trace how the object was created

Good starting point though I think.

@matanlurey matanlurey requested a review from kevmoo June 22, 2017 18:14
Copy link
Member

@kevmoo kevmoo left a comment

Choose a reason for hiding this comment

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

We really need to cleanup instantiateAnnotation w/ all of this magic...

mapMap(duration30s.namedArguments,
value: (_, v) => new ConstantReader(v).anyValue),
{
'seconds': 30,
Copy link
Member

Choose a reason for hiding this comment

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

Nice!


/// Returns a revivable instance of [object].
///
/// Optionally specify the [clazz] type that contains the constructor.
Copy link
Member

Choose a reason for hiding this comment

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

Document the behavior if clazz isn't provided?

Are we 99.9% sure we're not going to add more arguments here? Do we really like this to be optional-positional instead of optional-named?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Obsolete.

import 'utils.dart';

/// Base interface for a meta-analyzed [DartObject].
abstract class Revivable {}
Copy link
Member

Choose a reason for hiding this comment

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

Weird to have an empty base class w/ no members – and one implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Obsolete.

});
});

group('Reviable', () {
Copy link
Member

Choose a reason for hiding this comment

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

missing a v

DartObject object,
ClassElement clazz,
) {
final invocation = (object as DartObjectImpl).getInvocation();
Copy link
Member

Choose a reason for hiding this comment

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

getInvocation may return null – need to handle that!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Obsolete.

@matanlurey
Copy link
Contributor Author

@kevmoo PTAL, lots of changes.

Copy link
Member

@kevmoo kevmoo left a comment

Choose a reason for hiding this comment

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

One nit – not related to this CL.

Otherwise, great!

_object.toIntValue() ??
_object.toStringValue() ??
_object.toListValue() ??
_object.toMapValue();
Copy link
Member

Choose a reason for hiding this comment

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

You're missing symbol here – it's supported on DartObject

You'll just want to wrap it in new Symbol if it returns a String.

Copy link
Member

Choose a reason for hiding this comment

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

Also missing double

@kevmoo kevmoo merged commit 6f252d3 into dart-lang:master Jun 22, 2017
@matanlurey matanlurey deleted the constants-reviver branch June 23, 2017 00:28
library ??= object.type.element.library;
var url = Uri.parse(urlOfElement(object.type.element));
final clazz = object?.type?.element as ClassElement;
for (final e in clazz.fields.where(
Copy link
Member

Choose a reason for hiding this comment

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

why does this need to be a for loop if the first line is a return? Is this a typical pattern to handle the 0 or first case?

would this be more readable as

var matchingFields = clazz.fields.where((f) => ...);
if (matchingFields.isNotEmpty) {
return new Revivable._(source: url, accessor: matchinfFields.first.name);
}

Copy link
Member

Choose a reason for hiding this comment

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

Or just firstWhere – or even better – singeWhere – assuming more than one would be a bug

///
/// Optionally specify the [library] type that contains the reference.
///
/// Returns [null] if not revivable.
Copy link
Member

Choose a reason for hiding this comment

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

Do we have known cases we know won't work? Could we expand this?

mosuem pushed a commit to dart-lang/build that referenced this pull request Dec 10, 2024
mosuem pushed a commit to dart-lang/build that referenced this pull request Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants