Class Annotations
- All Implemented Interfaces:
software.amazon.jsii.JsiiSerializable
Example:
import software.amazon.awscdk.*; import software.constructs.Construct; import software.constructs.IConstruct; public class MyAspect implements IAspect { public void visit(IConstruct node) { if (node instanceof CfnResource && node.getCfnResourceType() == "Foo::Bar") { this.error(node, "we do not want a Foo::Bar resource"); } } public void error(IConstruct node, String message) { Annotations.of(node).addError(message); } } public class MyStack extends Stack { public MyStack(Construct scope, String id) { super(scope, id); Stack stack = new Stack(); CfnResource.Builder.create(stack, "Foo") .type("Foo::Bar") .properties(Map.of( "Fred", "Thud")) .build(); Aspects.of(stack).add(new MyAspect()); } }
-
Nested Class Summary
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Annotations
(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protected
Annotations
(software.amazon.jsii.JsiiObjectRef objRef) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Acknowledge a warning.void
acknowledgeWarning
(String id, String message) Acknowledge a warning.void
addDeprecation
(String api, String message) Adds a deprecation warning for a specific API.void
Adds an { "error":} metadata entry to this construct. void
Adds an info metadata entry to this construct.void
addWarning
(String message) Adds a warning metadata entry to this construct.void
addWarningV2
(String id, String message) Adds an acknowledgeable warning metadata entry to this construct.static Annotations
of
(software.constructs.IConstruct scope) Returns the annotations API for a construct scope.Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Constructor Details
-
Annotations
protected Annotations(software.amazon.jsii.JsiiObjectRef objRef) -
Annotations
protected Annotations(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
-
-
Method Details
-
of
@Stability(Stable) @NotNull public static Annotations of(@NotNull software.constructs.IConstruct scope) Returns the annotations API for a construct scope.- Parameters:
scope
- The scope. This parameter is required.
-
acknowledgeWarning
Acknowledge a warning. When a warning is acknowledged for a scope all warnings that match the id will be ignored.The acknowledgement will apply to all child scopes
Example:
Construct myConstruct; Annotations.of(myConstruct).acknowledgeWarning("SomeWarningId", "This warning can be ignored because...");
- Parameters:
id
-- the id of the warning message to acknowledge.
message
- optional message to explain the reason for acknowledgement.
-
acknowledgeWarning
Acknowledge a warning. When a warning is acknowledged for a scope all warnings that match the id will be ignored.The acknowledgement will apply to all child scopes
Example:
Construct myConstruct; Annotations.of(myConstruct).acknowledgeWarning("SomeWarningId", "This warning can be ignored because...");
- Parameters:
id
-- the id of the warning message to acknowledge.
-
addDeprecation
Adds a deprecation warning for a specific API.Deprecations will be added only once per construct as a warning and will be deduplicated based on the
api
.If the environment variable
CDK_BLOCK_DEPRECATIONS
is set, this method will throw an error instead with the deprecation message.- Parameters:
api
- The API being deprecated in the formatmodule.Class.property
(e.g.@aws-cdk/core.Construct.node
). This parameter is required.message
- The deprecation message to display, with information about alternatives. This parameter is required.
-
addError
Adds an { "error":} metadata entry to this construct. The toolkit will fail deployment of any stack that has errors reported against it.
- Parameters:
message
- The error message. This parameter is required.
-
addInfo
Adds an info metadata entry to this construct.The CLI will display the info message when apps are synthesized.
- Parameters:
message
- The info message. This parameter is required.
-
addWarning
Adds a warning metadata entry to this construct. Prefer usingaddWarningV2
.The CLI will display the warning when an app is synthesized, or fail if run in
--strict
mode.Warnings added by this call cannot be acknowledged. This will block users from running in
--strict
mode until the deal with the warning, which makes it effectively not very different fromaddError
. Prefer usingaddWarningV2
instead.- Parameters:
message
- The warning message. This parameter is required.
-
addWarningV2
Adds an acknowledgeable warning metadata entry to this construct.The CLI will display the warning when an app is synthesized, or fail if run in
--strict
mode.If the warning is acknowledged using
acknowledgeWarning()
, it will not be shown by the CLI, and will not cause--strict
mode to fail synthesis.Example:
Construct myConstruct; Annotations.of(myConstruct).addWarningV2("my-library:Construct.someWarning", "Some message explaining the warning");
- Parameters:
id
- the unique identifier for the warning. This parameter is required.message
- The warning message. This parameter is required.
-