/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
const RULENAME="oj-js-ojcomp-exist";const DESCRIPTION="The JET component class is either unknown, or is being referenced via the global 'oj' object which was deprecated in JET 6.0.0.<br>"+"It is recommended that you should import the APIs needed and reference them directly. e.g.  'oj.ArrayDataProvider' should be referenced as 'arrayDataProvider'.<br>"+"If the class is unknown, the component class's deprecation period may have expired and has been removed.";const SHORT_DESCRIPTION="Unknown JET component classes should not be instantiated nor accessed via the global 'oj' object.";const DEPMSG="via deprecated (since 6.0.0) global object 'oj'";class Rule{getName(){return RULENAME}getDescription(){return DESCRIPTION}getShortDescription(){return SHORT_DESCRIPTION}register(regCtx){this._metaLib=regCtx.utils.metaLib;let ret={};this._nt=regCtx.jsNodeTypes;ret[this._nt.NEW_EXPR]=this._onNew;return ret}_onNew(ruleCtx,node){var clazz;var me,obj,start;me=node.callee;if(me.type==="MemberExpression"){obj=me.object;if(obj&&obj.type==="Identifier"){if(obj.name==="oj"){if(me.property&&me.property.name){clazz="oj."+me.property.name}start=obj}}}else if(me.type==="Identifier"){clazz=me.name;start=me}if(clazz){let exists;if(!(exists=this._metaLib.isComponent(clazz))){let issue=this._isRenamed(clazz,ruleCtx);if(!issue){issue=this._isDeleted(clazz,ruleCtx)}if(issue){let ft=ruleCtx.filepath.substring(ruleCtx.filepath.lastIndexOf(".")+1);start=ft==="ts"?start.range[0]:start.start;let pos=ruleCtx.utils.utils.getRowColFromIndex(ruleCtx.data,start,ft);issue.setPosition(pos.row,pos.col,start,start+clazz.length);ruleCtx.reporter.addIssue(issue,ruleCtx,start)}}}}_isRenamed(clazz,ruleCtx){var o,issue;if(o=this._metaLib.isClassRenamed(clazz)){issue=new ruleCtx.Issue(`'${o.to}' should be accessed directly rather than '${clazz}' ${DEPMSG}.`);issue.setMsgKey(RULENAME+"_1")}return issue}_isDeleted(clazz,ruleCtx){var ver,issue;if(ver=this._metaLib.isClassDeleted(clazz)){if(clazz==="oj.ojTree"){issue=new ruleCtx.Issue(`Instantiation of '${clazz}' - this class was undocumented in version 6.0.0.`)}else{issue=new ruleCtx.Issue(`Instantiation of removed (in ${ver}) class '${clazz}' ${DEPMSG}`)}issue.setSeverity("critical")}else if(clazz.startsWith("oj.")){issue=new ruleCtx.Issue(`Instantiation of ${clazz.startsWith("oj.ojTree")?"obsolete":"unknown"} class '${clazz}' ${DEPMSG}.`);issue.setSeverity("critical")}return issue}}module.exports=Rule;