Coder Social home page Coder Social logo

Comments (3)

eernstg avatar eernstg commented on July 19, 2024

Hi Dan,

with recent versions of reflectable we have some implications: declarationsCapability is an instance of a subtype of the type of typeCapability, and this means that you cannot have declarationsCapability without typeCapability. The point is that you can never reach any declarations if you cannot reach any types, so declarationsCapability makes no sense without typeCapability.

That was the first step. Second: When you have typeCapability you can also get a mirror of the class of a type annotation for any given declaration mirror (e.g., with a field among the declarations, you can get the class of the type annotation in the declaration of that variable, if any; similarly for method arguments and return types). We even follow that track recursively: If support for a class C causes support for a class D used as a type annotation in C, then you will also get support for class E if it is used in a type annotation in D (all of this: if your capabilities provide support for those members, which might not be the case if you are using ..Meta.. capabilities or using a non-trivial regexp). This is already enough of a reason to make your supported universe larger than you expect---and need, presumably. This also matches the situation as you described it.

If this is the right diagnostic then there is a solution which is just about to be released:

We have introduced the notion of typeAnnotationQuatifyCapability to give you more control. The idea is that the transitive closure of types reachable via type annotations is not any more taken as soon as you have the typeCapability and declarationsCapability, we only take that step if you request it explicitly.

You do that by including typeAnnotationQuatifyCapability or typeAnnotationDeepQuatifyCapability among your capabilities (both instances of a class but providing different arguments for a constructor argument called transitive); the former will cause type annotation classes to be included in one step, and the latter will run a fixed point iteration such that all reachable types (traversing declarations and their types) are included. With deep/transitive quantification we have the old behavior that you are probably using today. If you don't include any of them then you don't get any of the type annotation classes at all (except of course if you have included some of them in some other way).

You can get support for the new quantifiers by switching to commit 195e18b of reflectable or something newer (not yet published, and it only implements the quantifiers for non-transformed code so you can test but you can't really see the space improvement; but it's just about ready for transformed code as well and then we'll publish it in a version '0.3.').

I'm closing the issue now because I think the solution is upcoming. Please create a new issue if it turns out to be a different problem.

from reflectable.dart.

danschultz avatar danschultz commented on July 19, 2024

Thanks, that sounds like what I'm looking for.

from reflectable.dart.

danschultz avatar danschultz commented on July 19, 2024

Hey @eernstg, I tried out the latest release (0.3.2) and I'm having some issues with the new typeAnnotationQuantifyCapability. When reflecting on an instance, it returns null for InstanceMirror.type.

What I'm trying to do is define a class that I can mixin, and be able to inspect the values of the host. For example, something like:

class Person extends Object with Inspectable {
  final String name;
}

var person = new Person("Jim");
print(person.inspect()); // Person {name: "Jim"}

My Reflectable and mixin looks like this:

class ReflectSubtypes extends Reflectable {
  const ReflectSubtypes() : super(typeAnnotationQuantifyCapability, instanceInvokeCapability, subtypeQuantifyCapability);
}

const _inspector = const ReflectSubtypes();

@ReflectSubtypes()
class Inspectable {
  Map<String, dynamic> inspectValues() {
    var mirror = _inspector.reflect(this);
    var valueMirrors = mirror.type.declarations.values.where((value) => value is VariableMirror);
    var valueMap = new Map.fromIterable(valueMirrors,
        key: (value) => value.simpleName,
        value: (value) => mirror.invokeGetter(value.simpleName));
    return valueMap;
  }

  String inspect() {
    return _inspectWithOptions();
  }

  String _inspectWithOptions({String indent: ""}) {
    var mirror = _inspector.reflect(this);
    var buffer = new StringBuffer();
    buffer.writeln("$indent${mirror.type.qualifiedName} {");

    inspectValues().forEach((key, value) {
      if (value is Inspectable) {
        value = value._inspectWithOptions(indent: "$indent  ").trim();
      }

      buffer.writeln("$indent  $key: $value");
    });

    buffer.writeln("$indent}");
    return buffer.toString();
  }
}

Any help on the correct capabilities to use that'll have the smallest JS output would be appreciated.

from reflectable.dart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.