-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c643685
commit 306d1ca
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...ore/src/main/java/software/amazon/smithy/docgen/core/interceptors/XmlNameInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.docgen.core.interceptors; | ||
|
||
import software.amazon.smithy.docgen.core.sections.ProtocolSection; | ||
import software.amazon.smithy.docgen.core.writers.DocWriter; | ||
import software.amazon.smithy.model.shapes.ShapeId; | ||
import software.amazon.smithy.model.traits.XmlNameTrait; | ||
import software.amazon.smithy.utils.SmithyInternalApi; | ||
|
||
/** | ||
* Adds a member's <a href="https://smithy.io/2.0/spec/protocol-traits.html#xmlname-trait"> | ||
* xmlName</a> to the {@link ProtocolSection} if the protocol supports it. | ||
*/ | ||
@SmithyInternalApi | ||
public final class XmlNameInterceptor extends ProtocolTraitInterceptor<XmlNameTrait> { | ||
@Override | ||
protected Class<XmlNameTrait> getTraitClass() { | ||
return XmlNameTrait.class; | ||
} | ||
|
||
@Override | ||
protected ShapeId getTraitId() { | ||
return XmlNameTrait.ID; | ||
} | ||
|
||
@Override | ||
public boolean isIntercepted(ProtocolSection section) { | ||
// The xmlName trait uniquely doesn't inherit values from the target as a member. | ||
return super.isIntercepted(section) && section.shape().hasTrait(XmlNameTrait.class); | ||
} | ||
|
||
@Override | ||
void write(DocWriter writer, String previousText, ProtocolSection section, XmlNameTrait trait) { | ||
writer.putContext("xmlTagName", "XML tag name:"); | ||
writer.write(""" | ||
${xmlTagName:B} $` | ||
$L""", trait.getValue(), previousText); | ||
} | ||
} |