An initial definition of the Target annotation

Change-Id: I6980da1e869c57b15a8bd068fef17f33d6a884ab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/154380
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
This commit is contained in:
Brian Wilkerson 2020-07-17 19:01:17 +00:00 committed by commit-bot@chromium.org
parent 174759cfbd
commit 896f874b9f
3 changed files with 85 additions and 0 deletions

View file

@ -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<TargetKind> 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,
}

View file

@ -23,6 +23,7 @@ meta
dependencies: sdk
lib/dart2js.dart
lib/meta.dart
lib/meta_meta.dart
sdk
is package? no

View file

@ -32,6 +32,7 @@ meta
dependencies: sdk
lib/dart2js.dart
lib/meta.dart
lib/meta_meta.dart
sdk
is package? no