/*
 * 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 RULE_NAME="oj-ts-no-ext-final";const LONG_DESCR="Starting in 8.0.0, constructors for classes marked with @final in the JET JS Doc cannot be invoked without use of 'new'";const MSG_PART="' constructor without 'new' will fail in version 8.x or later";const OJ="oj";const OJDOT="oj.";class Rule{getName(){return RULE_NAME}getDescription(){return LONG_DESCR}getShortDescription(){return LONG_DESCR}register(){return{CallExpression:this._onCall,file:this._onNewFile}}_onCall(ruleCtx,node){let callee;if(!node.callee){return}callee=node.callee;if(callee){if(callee.name==="define"||callee.name==="require"){return}if(_specialCase(callee)){return}return this._handleCall(ruleCtx,node,callee)}}_onNewFile(ruleCtx){this._scope=ruleCtx.utils.AstUtils.getScopes()}_handleCall(ruleCtx,node,callee){var clazz,ojclazz,obj,classBase,ojdot,pos,immed=false;if(callee.type==="Identifier"){clazz=callee.name;if(!ruleCtx.utils.metaLib.isClass(clazz)){clazz=this._scope.getVarType(callee);if(!clazz){return}}ojclazz=clazz;pos={start:callee.range[0],end:callee.range[1]};immed=true}else if(callee.type==="MemberExpression"&&callee.object){if(callee.object.type==="NewExpression"){return}if(callee.object.type==="Identifier"){if(callee.object.name===OJ){if(callee.property.type==="Identifier"){clazz=callee.property.name;ojclazz=clazz=OJDOT+clazz;pos={start:callee.object.range[0],end:callee.object.range[0]+ojclazz.length}}}else{clazz=callee.object.name;pos={start:callee.object.range[0],end:callee.object.range[1]}}}else if(callee.object.type==="MemberExpression"){if(callee.object.object&&callee.object.object.type==="Identifier"&&callee.object.object.name===OJ){classBase=callee.object.property.name;clazz=classBase;ojdot=true;pos={start:callee.object.range[0],end:callee.object.range[1]}}}}if(!clazz){return}if(ojclazz){if(_checkFinal(ruleCtx,ojclazz,pos)){return}}if(!immed){ojclazz=clazz;if(!ruleCtx.utils.metaLib.isClass(ojclazz)){if(ojdot){ojclazz=OJDOT+clazz}}if(ruleCtx.utils.metaLib.isClass(ojclazz)){obj=_checkStatic(ruleCtx,ojclazz,callee);if(obj.exists&&!obj.static){_emitIssue("uninstantiated '"+ojclazz+" : use of non-static method '"+obj.fn+"' will fail in JET 8.x or higher",ruleCtx,pos)}else if(!obj.exists){if(callee.property&&callee.property.type==="Identifier"&&callee.property.name){if(clazz.substring(3)===callee.property.name||callee.property.name==="call"||callee.property.name==="apply"){_emitIssue("'"+clazz+MSG_PART,ruleCtx,pos)}}}}}}}function _emitIssue(msg,ruleCtx,pos){var issue=new ruleCtx.Issue(msg);if(pos){issue.setPosition(null,null,pos.start,pos.end)}ruleCtx.reporter.addIssue(issue,ruleCtx)}function _checkFinal(ruleCtx,clazz,pos){var cls,metaLib,ret=false;metaLib=ruleCtx.utils.metaLib;if(clazz.startsWith(OJDOT)){cls=metaLib.isClassRenamed(clazz);if(cls){clazz=cls.to}}if(ruleCtx.utils.metaLib.isClassFinal(clazz)){_emitIssue("'"+clazz+MSG_PART,ruleCtx,pos);ret=true}return ret};function _specialCase(callee){var obj;if(callee){if(callee.object&&callee.object.name){if(callee.object.object){return false}obj=callee.object.name;if(obj==="Object"){return true}}}return false};function _checkStatic(context,ojclazz,callee){var name;var ret={};if(context.utils.metaLib.isClassFinal(ojclazz)){if(callee.property&&callee.property.type==="Identifier"&&callee.property.name){name=callee.property.name;ret.fn=name;if(context.utils.metaLib.isClassMethod(ojclazz,name)){ret.exists=true;ret.static=context.utils.metaLib.isClassMethodStatic(ojclazz,name);return ret}}}ret.fn=null;return ret};module.exports=Rule;