analysis_utils 0.0.7 copy "analysis_utils: ^0.0.7" to clipboard
analysis_utils: ^0.0.7 copied to clipboard

outdated

Utilities for combining static source code analysis with mirrors and so...

example/analysis_utils_example.dart

import 'package:analysis_utils/analysis.dart';

/// The classic documentation
/// comment is supported
class ExampleClass extends ParentClass {
  /** Also
   * this
   * kind
   * of
   * documentation
   * is
   * supported
   */
  int field1;
  String field2;

  void method1() {
    print("method1 executed");
  }

  /// Greet `name`
  String method2(String name) => "Hello $name";

  ExampleClass(String param1, int param2, [this.field1]);

  ExampleClass.withField2(this.field2);
}

//custom annotation, ain't a documentation comment, shouldn't be parsed, so
class annon {
  final int n;
  final String text;
  const annon(this.n, [this.text]);
}

class ParentClass {
  @annon(1, "sorp")
  @annon(2)
  @annon(3, "longa")
  @annon(4)
  List<int> sorp = [];

  double var1 = 2.0, initVal = 723 + 123 / 2;
}

main() {
  ClassAnalysis clazz = new ClassAnalysis.fromType(ExampleClass);
  print("The class name is: ${clazz.name}");
  print("The fields are: " + clazz.fields.keys.join(", "));
  print("The initial value of 'initVal' field is:"
      " ${clazz.fields['initVal'].defaultValue}");
  print("The methods are: " + clazz.methods.keys.join(", "));
  print("The constructors are: " + clazz.constructors.keys.join(", "));
  print(
      "  The default constructor has ${clazz.constructors[""].parameters.length}"
      " parameters:\n${clazz.constructors[""].parameters.all.map((Parameter p) => p.name).join(", ")}");
  print("The documentation for method2 is: " + clazz.methods["method2"].docs);
  print("The inherintance preserves even the annotations from the parent"
      "class! (it has ${clazz.fields["sorp"].metadata.length} annotations)");
}
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Utilities for combining static source code analysis with mirrors and so...

Homepage

License

unknown (LICENSE)

Dependencies

analyzer, path, source_span

More

Packages that depend on analysis_utils