/* Generated from Java with JSweet 2.3.7 - http://www.jsweet.org */
import { NodeCompat } from '../../compat/NodeCompat';
import { RegexCompat } from '../../compat/RegexCompat';
import { Node } from '../models/Node';
/**
 * A class to help with resolving references.  Handles recursion with loop detection.
 * @author eric.wittmann@gmail.com
 * @class
 */
var LocalReferenceResolver = /** @class */ (function () {
    function LocalReferenceResolver() {
    }
    /**
     * @see io.apicurio.datamodels.core.util.IReferenceResolver#resolveRef(java.lang.String, io.apicurio.datamodels.core.models.Node)
     * @param {string} $ref
     * @param {Node} from
     * @return {Node}
     */
    LocalReferenceResolver.prototype.resolveRef = function ($ref, from) {
        if ($ref == null || $ref.indexOf("#/") !== 0) {
            return null;
        }
        var split = RegexCompat.findMatches($ref, "([^/]+)/?");
        var cnode = null;
        for (var index135 = 0; index135 < split.length; index135++) {
            var mi = split[index135];
            {
                var seg = mi[1];
                if (NodeCompat.equals(seg, "#")) {
                    cnode = from.ownerDocument();
                }
                else if (cnode != null) {
                    if (cnode != null && (cnode["__interfaces"] != null && cnode["__interfaces"].indexOf("io.apicurio.datamodels.core.models.IIndexedNode") >= 0 || cnode.constructor != null && cnode.constructor["__interfaces"] != null && cnode.constructor["__interfaces"].indexOf("io.apicurio.datamodels.core.models.IIndexedNode") >= 0)) {
                        cnode = cnode.getItem(seg);
                    }
                    else {
                        cnode = NodeCompat.getProperty(cnode, seg);
                    }
                }
            }
        }
        if (cnode != null && cnode instanceof Node) {
            return cnode;
        }
        else {
            return null;
        }
    };
    return LocalReferenceResolver;
}());
export { LocalReferenceResolver };
LocalReferenceResolver["__class"] = "io.apicurio.datamodels.core.util.LocalReferenceResolver";
LocalReferenceResolver["__interfaces"] = ["io.apicurio.datamodels.core.util.IReferenceResolver"];
//# sourceMappingURL=LocalReferenceResolver.js.map