Search in sources :

Example 1 with IVisitor

use of io.apicurio.datamodels.core.visitors.IVisitor in project apicurio-data-models by Apicurio.

the class RenameTagDefinitionCommand method _doTagRename.

/**
 * Does the work of renaming a tag from one name to another.
 * @param document
 * @param from
 * @param to
 * @private
 */
private void _doTagRename(Document document, String from, String to) {
    // If the "to" tag already exists, bail out before doing anything
    Tag existingTag = this._findTag(document, to);
    if (ModelUtils.isDefined(existingTag)) {
        return;
    }
    // Find the tag by name and rename it.
    Tag tagToRename = this._findTag(document, from);
    if (ModelUtils.isDefined(tagToRename)) {
        // Now rename the tag
        tagToRename.name = to;
        // Rename every **usage** of the tag in the document (all operations)
        IVisitor tagRenamer = new TagRenameVisitor(from, to);
        VisitorUtil.visitTree(document, tagRenamer, TraverserDirection.down);
    }
}
Also used : IVisitor(io.apicurio.datamodels.core.visitors.IVisitor) Tag(io.apicurio.datamodels.core.models.common.Tag)

Aggregations

Tag (io.apicurio.datamodels.core.models.common.Tag)1 IVisitor (io.apicurio.datamodels.core.visitors.IVisitor)1