From 896f874b9f6dab2ce1485d1caa2aa5ab89d05445 Mon Sep 17 00:00:00 2001 From: Brian Wilkerson Date: Fri, 17 Jul 2020 19:01:17 +0000 Subject: [PATCH] An initial definition of the Target annotation Change-Id: I6980da1e869c57b15a8bd068fef17f33d6a884ab Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/154380 Commit-Queue: Brian Wilkerson Reviewed-by: Nate Bosch Reviewed-by: Phil Quitslund --- pkg/meta/lib/meta_meta.dart | 83 +++++++++++++++++++ .../expectation.txt | 1 + .../loader/valid_packages/expectation.txt | 1 + 3 files changed, 85 insertions(+) create mode 100644 pkg/meta/lib/meta_meta.dart diff --git a/pkg/meta/lib/meta_meta.dart b/pkg/meta/lib/meta_meta.dart new file mode 100644 index 00000000000..5090b051df2 --- /dev/null +++ b/pkg/meta/lib/meta_meta.dart @@ -0,0 +1,83 @@ +// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// Annotations that describe the intended use of other annotations. +library meta_meta; + +/// An annotation used on classes that are intended to be used as annotations +/// to indicate the kinds of declarations and directives for which the +/// annotation is appropriate. +/// +/// The kinds are represented by the constants defined in [TargetKind]. +/// +/// Tools, such as the analyzer, can provide feedback if +/// +/// * the annotation is associated with anything other than a class, where the +/// class must be usable as an annotation (that is, contain at least one +/// `const` constructor). +/// * the annotated annotation is associated with anything other than the kinds +/// of declarations listed as valid targets. +@Target({TargetKind.classType}) +class Target { + /// The kinds of declarations with which the annotated annotation can be + /// associated. + final Set kinds; + + const Target(this.kinds); +} + +/// An enumeration of the kinds of targets to which an annotation can be +/// applied. +enum TargetKind { + /// Indicates that an annotation is valid on any class declaration. + classType, + + /// Indicates that an annotation is valid on any enum declaration. + enumType, + + /// Indicates that an annotation is valid on any extension declaration. + extension, + + /// Indicates that an annotation is valid on any field declaration, both + /// instance and static fields, whether it's in a class, mixin or extension. + field, + + /// Indicates that an annotation is valid on any top-level function + /// declaration. + function, + + /// Indicates that an annotation is valid on the first directive in a library, + /// whether that's a `library`, `import`, `export` or `part` directive. This + /// doesn't include the `part of` directive in a part file. + library, + + /// Indicates that an annotation is valid on any getter declaration, both + /// instance or static getters, whether it's in a class, mixin, extension, or + /// at the top-level of a library. + getter, + + /// Indicates that an annotation is valid on any method declaration, both + /// instance and static methods, whether it's in a class, mixin or extension. + method, + + /// Indicates that an annotation is valid on any mixin declaration. + mixinType, + + /// Indicates that an annotation is valid on any formal parameter declaration, + /// whether it's in a function, method, constructor, or closure. + parameter, + + /// Indicates that an annotation is valid on any setter declaration, both + /// instance or static setters, whether it's in a class, mixin, extension, or + /// at the top-level of a library. + setter, + + /// Indicates that an annotation is valid on any declaration that introduces a + /// type. This includes classes, enums, mixins and typedefs, but does not + /// include extensions because extensions don't introduce a type. + type, + + /// Indicates that an annotation is valid on any typedef declaration. + typedefType, +} diff --git a/pkg/modular_test/test/loader/default_package_dependency_error/expectation.txt b/pkg/modular_test/test/loader/default_package_dependency_error/expectation.txt index 05c60439b04..e00a4e24211 100644 --- a/pkg/modular_test/test/loader/default_package_dependency_error/expectation.txt +++ b/pkg/modular_test/test/loader/default_package_dependency_error/expectation.txt @@ -23,6 +23,7 @@ meta dependencies: sdk lib/dart2js.dart lib/meta.dart + lib/meta_meta.dart sdk is package? no diff --git a/pkg/modular_test/test/loader/valid_packages/expectation.txt b/pkg/modular_test/test/loader/valid_packages/expectation.txt index 680cfc57126..e3bfaeb225b 100644 --- a/pkg/modular_test/test/loader/valid_packages/expectation.txt +++ b/pkg/modular_test/test/loader/valid_packages/expectation.txt @@ -32,6 +32,7 @@ meta dependencies: sdk lib/dart2js.dart lib/meta.dart + lib/meta_meta.dart sdk is package? no