@aurahelper/languages
Version:
Language Libraries to work with XML, Aura, Apex... files. tokenizers, parsers, system classes and much more
894 lines • 100 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApexParser = void 0;
var core_1 = require("@aurahelper/core");
var languageUtils_1 = require("../utils/languageUtils");
var tokenizer_1 = require("./tokenizer");
var Utils = core_1.CoreUtils.Utils;
var Validator = core_1.CoreUtils.Validator;
var StrUtils = core_1.CoreUtils.StrUtils;
var OSUtils = core_1.CoreUtils.OSUtils;
var MathUtils = core_1.CoreUtils.MathUtils;
/**
* Class to parse an Apex Class file, content or tokens to extract the class information like fields, methods, variables, constructors, inner classes... and much more.
*/
var ApexParser = /** @class */ (function () {
/**
* Create Apex Parser instance to parse Apex Files
* @param {string | Token[]} [filePathOrTokens] File path or file tokens (tokenized with ApexTokenizer class)
* @param {ParserData} [systemData] Parser Data object with data from Project and Salesforce to identify tokens with more precission
*/
function ApexParser(filePathOrTokens, systemData) {
this.systemData = systemData;
if (typeof filePathOrTokens !== 'string') {
this.tokens = filePathOrTokens || [];
}
else {
this.tokens = [];
this.filePath = filePathOrTokens;
}
this.tokensLength = this.tokens.length;
this.content = undefined;
this.nodesMap = {};
this.accessModifier;
this.definitionModifier;
this.sharingModifier;
this.staticKeyword;
this.webservice;
this.final;
this.override;
this.transient;
this.testMethod;
this.annotation;
this.comment;
this.nComments = 0;
this.nAnnotations = 0;
this.datatype;
this.cursorPosition;
this.declarationOnly = false;
this.node;
this.tabSize = 4;
}
/**
* Method to set the tab size
* @param {number} tabSize Tab size value
* @returns {ApexParser} Returns the ApexParser instance
*/
ApexParser.prototype.setTabSize = function (tabSize) {
this.tabSize = tabSize;
return this;
};
/**
* Method to set apex file tokens (tokenized with ApexTokenizer class)
* @param {Token[]} tokens Apex file tokens
* @returns {ApexParser} Returns the ApexParser instance
*/
ApexParser.prototype.setTokens = function (tokens) {
this.tokens = tokens;
this.tokensLength = this.tokens.length;
return this;
};
/**
* Method to set Parser Data object with data from Project and Salesforce to identify tokens with more precission
* @param {ParserData} systemData Parser data object
* @returns {ApexParser} Returns the ApexParser instance
*/
ApexParser.prototype.setSystemData = function (systemData) {
this.systemData = systemData;
return this;
};
/**
* Method to set the file path
* @param {string} filePath file path value
* @returns {ApexParser} Returns the ApexParser instance
*/
ApexParser.prototype.setFilePath = function (filePath) {
this.filePath = filePath;
return this;
};
/**
* Method to set apex file content
* @param {string} content file content value
* @returns {ApexParser} Returns the ApexParser instance
*/
ApexParser.prototype.setContent = function (content) {
this.content = content;
return this;
};
/**
* Method to set the cursor position to get PositionData with parsed node
* @param {Position} position Position object with cursor position data
* @returns {ApexParser} Returns the ApexParser instance
*/
ApexParser.prototype.setCursorPosition = function (position) {
this.cursorPosition = position;
return this;
};
/**
* Method to indicate to parser to analize only the next declaration from cursor position
* @param {boolean} declarationOnly True to analize declaration only, false to parse entire file
* @returns {ApexParser} Returns the ApexParser instance
*/
ApexParser.prototype.isDeclarationOnly = function (declarationOnly) {
this.declarationOnly = (declarationOnly !== undefined && Utils.isBoolean(declarationOnly)) ? declarationOnly : false;
return this;
};
/**
* Method to get the file tokens
* @returns {token[]} Return file tokens
*/
ApexParser.prototype.getTokens = function () {
return this.tokens;
};
/**
* Method to parse Apex file and get Node information
* @returns {ApexTrigger | ApexClass | ApexInterface | ApexEnum} Return the Apex Node from the parsed file
*/
ApexParser.prototype.parse = function () {
if (this.node) {
return this.node;
}
if (this.filePath && !this.content && (!this.tokens || this.tokens.length === 0)) {
this.content = core_1.FileReader.readFileSync(Validator.validateFilePath(this.filePath));
this.tokens = tokenizer_1.ApexTokenizer.tokenize(this.content, this.systemData, this.tabSize);
this.tokensLength = this.tokens.length;
}
else if (this.content && (!this.tokens || this.tokens.length === 0)) {
this.tokens = tokenizer_1.ApexTokenizer.tokenize(this.content, this.systemData, this.tabSize);
this.tokensLength = this.tokens.length;
}
else if (!this.tokens) {
this.tokens = [];
}
resetModifiers(this);
var node;
var bracketIndent = 0;
var positionData;
var startLine = (this.cursorPosition && this.declarationOnly) ? this.cursorPosition.line : 0;
for (var index = 0; index < this.tokensLength; index++) {
var lastToken = languageUtils_1.LanguageUtils.getLastToken(this.tokens, index);
var token = new core_1.Token(this.tokens[index]);
var nextToken = languageUtils_1.LanguageUtils.getNextToken(this.tokens, index);
var twoNextToken = languageUtils_1.LanguageUtils.getTwoNextToken(this.tokens, index);
var twoLastToken = languageUtils_1.LanguageUtils.getTwoLastToken(this.tokens, index);
var parentToken = (token.parentToken !== undefined && token.parentToken !== -1) ? new core_1.Token(this.tokens[token.parentToken]) : undefined;
var pairToken = (token.pairToken !== undefined) ? new core_1.Token(this.tokens[token.pairToken]) : undefined;
if (token.range.start.line < startLine) {
continue;
}
if (this.cursorPosition && node && !positionData) {
if (languageUtils_1.LanguageUtils.isOnPosition(token, lastToken, nextToken, this.cursorPosition)) {
var startIndex = this.cursorPosition.character - token.range.start.character;
var startPart = token.text.substring(0, startIndex + 1);
var endPart = token.text.substring(startIndex + 1);
positionData = new core_1.PositionData(startPart, endPart, node.nodeType, node.id, 'Apex');
positionData.onText = token.type === core_1.ApexTokenTypes.PUNCTUATION.QUOTTES_START || token.type === core_1.ApexTokenTypes.PUNCTUATION.QUOTTES_END || token.type === core_1.ApexTokenTypes.LITERAL.STRING;
positionData.signature = node.simplifiedSignature || node.signature;
positionData.parentName = node.parentName;
positionData.token = token;
positionData.nextToken = nextToken;
positionData.twoNextToken = twoNextToken;
positionData.lastToken = lastToken;
positionData.twoLastToken = twoLastToken;
}
}
if (openBracket(token)) {
if (this.declarationOnly && node.nodeType !== core_1.ApexNodeTypes.PROPERTY) {
break;
}
if (!node.startToken) {
node.startToken = token;
}
bracketIndent++;
if (isInitializer(token)) {
var newNode = new core_1.ApexInitializer(((node) ? node.id : 'InitialNode') + '.initializer', 'Initializer', token);
newNode.parentId = (node) ? node.id : undefined;
if (this.annotation) {
this.annotation.parentId = newNode.id;
this.annotation.id = newNode.id + '.' + this.annotation.id;
this.nodesMap[this.annotation.id] = this.annotation;
newNode.annotation = this.annotation;
this.annotation = undefined;
}
if (this.comment) {
this.comment.parentId = newNode.id;
this.comment.id = newNode.id + '.' + this.comment.id;
this.nodesMap[this.comment.id] = this.comment;
newNode.comment = this.comment;
if (!this.declarationOnly && this.systemData && this.systemData.template && Utils.hasKeys(this.systemData.template)) {
newNode.comment.processComment(this.systemData.template);
}
this.comment = undefined;
if (positionData && (positionData.nodeType === core_1.ApexNodeTypes.BLOCK_COMMENT || positionData.nodeType === core_1.ApexNodeTypes.COMMENT)) {
positionData.parentName = newNode.name;
}
}
this.nodesMap[newNode.id] = newNode;
if (node) {
node.addChild(newNode);
}
node = newNode;
resetModifiers(this);
}
}
else if (closeBracket(token)) {
bracketIndent--;
if (this.declarationOnly && bracketIndent === 0) {
break;
}
if (node) {
if (!token.isAux) {
node.endToken = token;
}
if (node.parentId) {
var initializer = false;
if (pairToken && token.pairToken) {
var auxLastPairToken = languageUtils_1.LanguageUtils.getLastToken(this.tokens, token.pairToken);
if (auxLastPairToken && openBracket(auxLastPairToken) && isInitializer(pairToken)) {
initializer = true;
node = this.nodesMap[node.parentId];
}
}
if (!initializer && parentToken && (isMethodDeclaration(parentToken) || isConstructorDeclaration(parentToken) || isProperty(parentToken) || isGetterAccessor(parentToken) || isSetterAccessor(parentToken) || isClass(parentToken) || isEnum(parentToken) || isInterface(parentToken) || isStaticConstructorDeclaration(parentToken))) {
node = this.nodesMap[node.parentId];
}
}
}
}
else if (token.type === core_1.ApexTokenTypes.PUNCTUATION.SEMICOLON) {
if (node && node.parentId) {
if ((node.nodeType === core_1.ApexNodeTypes.GETTER || node.nodeType === core_1.ApexNodeTypes.SETTER) && lastToken && (lastToken.type === core_1.ApexTokenTypes.KEYWORD.DECLARATION.PROPERTY_GETTER || lastToken.type === core_1.ApexTokenTypes.KEYWORD.DECLARATION.PROPERTY_SETTER)) {
if (!node.startToken) {
node.startToken = token;
}
if (!node.endToken) {
node.endToken = token;
}
node = this.nodesMap[node.parentId];
}
else if ((node.nodeType === core_1.ApexNodeTypes.CONSTRUCTOR || node.nodeType === core_1.ApexNodeTypes.METHOD) && lastToken && lastToken.type === core_1.ApexTokenTypes.BRACKET.PARENTHESIS_DECLARATION_PARAM_CLOSE) {
if (!node.startToken) {
node.startToken = token;
}
if (!node.endToken) {
node.endToken = token;
}
node = this.nodesMap[node.parentId];
}
}
}
else if (isAccessModifier(token)) {
this.accessModifier = token;
}
else if (isDefinitionModifier(token)) {
this.definitionModifier = token;
}
else if (isSharingModifier(token)) {
this.sharingModifier = token;
}
else if (isStatic(token)) {
this.staticKeyword = token;
}
else if (isFinal(token)) {
this.final = token;
}
else if (isOverride(token)) {
this.override = token;
}
else if (isTestMethod(token)) {
this.testMethod = token;
}
else if (isTransient(token)) {
this.transient = token;
}
else if (isWebservice(token)) {
this.webservice = token;
}
else if (isCommentLine(token)) {
var newNode = new core_1.ApexComment('comment.' + this.nComments, 'LineComment.' + this.nComments, token);
index = processCommentLine(newNode, this, index, this.cursorPosition);
if (newNode.positionData) {
positionData = newNode.positionData;
newNode.positionData = undefined;
positionData.parentName = (node) ? node.name : undefined;
}
this.comment = newNode;
this.nComments++;
}
else if (openCommentBlock(token)) {
var newNode = new core_1.ApexCommentBlock('comment.' + this.nComments, 'BlockComment.' + this.nComments, token);
index = processCommentBlock(newNode, this, index, this.cursorPosition);
if (newNode.positionData) {
positionData = newNode.positionData;
newNode.positionData = undefined;
positionData.parentName = (node) ? node.name : undefined;
}
this.comment = newNode;
this.nComments++;
}
else if (isAnnotation(token)) {
var newNode = new core_1.ApexAnnotation('annotation.' + this.nAnnotations, token.text, token);
index = processAnnotation(newNode, this, index);
this.annotation = newNode;
this.nAnnotations++;
}
else if (isClass(token)) {
var newNode = new core_1.ApexClass(((node) ? node.id : 'InitialNode') + '.class.' + token.textToLower, token.text);
newNode.accessModifier = this.accessModifier;
newNode.definitionModifier = this.definitionModifier;
newNode.parentId = (node) ? node.id : undefined;
newNode.sharingModifier = this.sharingModifier;
newNode.scope = bracketIndent;
if (this.annotation) {
this.annotation.parentId = newNode.id;
this.annotation.id = newNode.id + '.' + this.annotation.id;
this.nodesMap[this.annotation.id] = this.annotation;
newNode.annotation = this.annotation;
this.annotation = undefined;
}
if (this.comment) {
this.comment.parentId = newNode.id;
this.comment.id = newNode.id + '.' + this.comment.id;
this.nodesMap[this.comment.id] = this.comment;
newNode.comment = this.comment;
if (!this.declarationOnly && this.systemData && this.systemData.template && Utils.hasKeys(this.systemData.template)) {
newNode.comment.processComment(this.systemData.template);
}
this.comment = undefined;
if (positionData && (positionData.nodeType === core_1.ApexNodeTypes.BLOCK_COMMENT || positionData.nodeType === core_1.ApexNodeTypes.COMMENT)) {
positionData.parentName = newNode.name;
}
}
this.nodesMap[newNode.id] = newNode;
if (node) {
node.addChild(newNode);
}
node = newNode;
resetModifiers(this);
}
else if (isInterface(token)) {
var newNode = new core_1.ApexInterface(((node) ? node.id : 'InitialNode') + '.interface.' + token.textToLower, token.text);
newNode.accessModifier = this.accessModifier;
newNode.definitionModifier = this.definitionModifier;
newNode.parentId = (node) ? node.id : undefined;
newNode.sharingModifier = this.sharingModifier;
newNode.scope = bracketIndent;
if (this.annotation) {
this.annotation.parentId = newNode.id;
this.annotation.id = newNode.id + '.' + this.annotation.id;
this.nodesMap[this.annotation.id] = this.annotation;
newNode.annotation = this.annotation;
this.annotation = undefined;
}
if (this.comment) {
this.comment.parentId = newNode.id;
this.comment.id = newNode.id + '.' + this.comment.id;
this.nodesMap[this.comment.id] = this.comment;
newNode.comment = this.comment;
if (!this.declarationOnly && this.systemData && this.systemData.template && Utils.hasKeys(this.systemData.template)) {
newNode.comment.processComment(this.systemData.template);
}
this.comment = undefined;
if (positionData && (positionData.nodeType === core_1.ApexNodeTypes.BLOCK_COMMENT || positionData.nodeType === core_1.ApexNodeTypes.COMMENT)) {
positionData.parentName = newNode.name;
}
}
this.nodesMap[newNode.id] = newNode;
if (node) {
node.addChild(newNode);
}
node = newNode;
resetModifiers(this);
}
else if (isEnum(token)) {
var newNode = new core_1.ApexEnum(((node) ? node.id : 'InitialNode') + '.enum.' + token.textToLower, token.text);
newNode.accessModifier = this.accessModifier;
newNode.definitionModifier = this.definitionModifier;
newNode.parentId = (node) ? node.id : undefined;
newNode.sharingModifier = this.sharingModifier;
newNode.scope = bracketIndent;
if (this.annotation) {
this.annotation.parentId = newNode.id;
this.annotation.id = newNode.id + '.' + this.annotation.id;
this.nodesMap[this.annotation.id] = this.annotation;
newNode.annotation = this.annotation;
this.annotation = undefined;
}
if (this.comment) {
this.comment.parentId = newNode.id;
this.comment.id = newNode.id + '.' + this.comment.id;
this.nodesMap[this.comment.id] = this.comment;
newNode.comment = this.comment;
if (!this.declarationOnly && this.systemData && this.systemData.template && Utils.hasKeys(this.systemData.template)) {
newNode.comment.processComment(this.systemData.template);
}
this.comment = undefined;
if (positionData && (positionData.nodeType === core_1.ApexNodeTypes.BLOCK_COMMENT || positionData.nodeType === core_1.ApexNodeTypes.COMMENT)) {
positionData.parentName = newNode.name;
}
}
this.nodesMap[newNode.id] = newNode;
if (node) {
node.addChild(newNode);
}
node = newNode;
resetModifiers(this);
}
else if (isOnTrigger(token)) {
var newNode = new core_1.ApexTrigger(((node) ? node.id : 'InitialNode') + '.trigger.', nextToken.text);
index = processTrigger(this.tokens, index, newNode);
if (this.comment) {
this.comment.parentId = newNode.id;
this.comment.id = newNode.id + '.' + this.comment.id;
this.nodesMap[this.comment.id] = this.comment;
newNode.comment = this.comment;
if (!this.declarationOnly && this.systemData && this.systemData.template && Utils.hasKeys(this.systemData.template)) {
newNode.comment.processComment(this.systemData.template);
}
this.comment = undefined;
if (positionData && (positionData.nodeType === core_1.ApexNodeTypes.BLOCK_COMMENT || positionData.nodeType === core_1.ApexNodeTypes.COMMENT)) {
positionData.parentName = newNode.name;
}
}
this.nodesMap[newNode.id] = newNode;
if (node) {
node.addChild(newNode);
}
node = newNode;
resetModifiers(this);
}
else if (isOnImplements(token)) {
var data = getInterfaces(this.tokens, index);
index = data.index;
node.implementTypes = data.interfaces;
}
else if (isOnExtends(token)) {
var data = getExtends(this.tokens, index);
index = data.index;
node.extendsType = data.extendsName;
}
else if (isEnumValue(token)) {
if (node) {
node.addChild(token);
}
}
else if (isQuery(token, lastToken)) {
var data = processQuery(this.tokens, index, this.cursorPosition, node);
index = data.index;
if (data.positionData && !positionData) {
positionData = data.positionData;
}
if (node && data.query) {
node.addChild(data.query);
}
}
else if (isProperty(token)) {
var newNode = new core_1.ApexProperty(((node) ? node.id : 'InitialNode') + '.property.' + token.textToLower, token.text);
newNode.accessModifier = this.accessModifier;
newNode.definitionModifier = this.definitionModifier;
newNode.parentId = (node) ? node.id : undefined;
newNode.transient = this.transient;
newNode.static = this.staticKeyword;
newNode.scope = bracketIndent;
if (this.annotation) {
this.annotation.parentId = newNode.id;
this.annotation.id = newNode.id + '.' + this.annotation.id;
this.nodesMap[this.annotation.id] = this.annotation;
newNode.annotation = this.annotation;
this.annotation = undefined;
}
if (this.comment) {
this.comment.parentId = newNode.id;
this.comment.id = newNode.id + '.' + this.comment.id;
this.nodesMap[this.comment.id] = this.comment;
newNode.comment = this.comment;
if (!this.declarationOnly && this.systemData && this.systemData.template && Utils.hasKeys(this.systemData.template)) {
newNode.comment.processComment(this.systemData.template);
}
this.comment = undefined;
if (positionData && (positionData.nodeType === core_1.ApexNodeTypes.BLOCK_COMMENT || positionData.nodeType === core_1.ApexNodeTypes.COMMENT)) {
positionData.parentName = newNode.name;
}
}
if (this.datatype) {
this.datatype.parentId = newNode.id;
this.datatype.id = newNode.id + '.' + this.datatype.id;
this.nodesMap[this.datatype.id] = this.datatype;
newNode.datatype = this.datatype;
this.datatype = undefined;
if (positionData && (positionData.nodeType === core_1.ApexNodeTypes.BLOCK_COMMENT || positionData.nodeType === core_1.ApexNodeTypes.COMMENT)) {
positionData.parentName = newNode.name;
}
}
this.nodesMap[newNode.id] = newNode;
if (node) {
node.addChild(newNode);
}
node = newNode;
resetModifiers(this);
}
else if (isGetterAccessor(token)) {
var newNode = new core_1.ApexGetter(((node) ? node.id : 'InitialNode') + '.getter.' + token.textToLower, token.text);
newNode.parentId = (node) ? node.id : undefined;
if (this.comment) {
this.comment.parentId = newNode.id;
this.comment.id = newNode.id + '.' + this.comment.id;
this.nodesMap[this.comment.id] = this.comment;
newNode.comment = this.comment;
this.comment = undefined;
if (positionData && (positionData.nodeType === core_1.ApexNodeTypes.BLOCK_COMMENT || positionData.nodeType === core_1.ApexNodeTypes.COMMENT)) {
positionData.parentName = newNode.name;
}
}
this.nodesMap[newNode.id] = newNode;
if (node) {
node.addChild(newNode);
}
node = newNode;
resetModifiers(this);
}
else if (isSetterAccessor(token)) {
var newNode = new core_1.ApexSetter(((node) ? node.id : 'InitialNode') + '.setter.' + token.textToLower, token.text);
newNode.parentId = (node) ? node.id : undefined;
if (this.comment) {
this.comment.parentId = newNode.id;
this.comment.id = newNode.id + '.' + this.comment.id;
this.nodesMap[this.comment.id] = this.comment;
newNode.comment = this.comment;
this.comment = undefined;
if (positionData && (positionData.nodeType === core_1.ApexNodeTypes.BLOCK_COMMENT || positionData.nodeType === core_1.ApexNodeTypes.COMMENT)) {
positionData.parentName = newNode.name;
}
}
this.nodesMap[newNode.id] = newNode;
if (node) {
node.addChild(newNode);
}
node = newNode;
resetModifiers(this);
}
else if (isDatatype(token)) {
var newNode = new core_1.ApexDatatype('datatype.', '', token);
index = processDatatype(newNode, this, index);
if (newNode.positionData) {
positionData = newNode.positionData;
newNode.positionData = undefined;
positionData.nodeType = (node) ? node.nodeType : undefined;
positionData.signature = (node) ? node.simplifiedSignature || node.signature : undefined;
positionData.parentName = (node) ? node.name : undefined;
}
this.datatype = newNode;
}
else if (isStaticConstructorDeclaration(token)) {
var newNode = new core_1.ApexStaticConstructor(((node) ? node.id : 'InitialNode') + '.staticConstructor.' + token.textToLower, token.text);
newNode.parentId = (node) ? node.id : undefined;
newNode.scope = bracketIndent;
if (this.annotation) {
this.annotation.parentId = newNode.id;
this.annotation.id = newNode.id + '.' + this.annotation.id;
this.nodesMap[this.annotation.id] = this.annotation;
newNode.annotation = this.annotation;
this.annotation = undefined;
}
if (this.comment) {
this.comment.parentId = newNode.id;
this.comment.id = newNode.id + '.' + this.comment.id;
this.nodesMap[this.comment.id] = this.comment;
newNode.comment = this.comment;
if (!this.declarationOnly && this.systemData && this.systemData.template && Utils.hasKeys(this.systemData.template)) {
newNode.comment.processComment(this.systemData.template);
}
this.comment = undefined;
if (positionData && (positionData.nodeType === core_1.ApexNodeTypes.BLOCK_COMMENT || positionData.nodeType === core_1.ApexNodeTypes.COMMENT)) {
positionData.parentName = newNode.name;
}
}
this.nodesMap[newNode.id] = newNode;
if (node) {
node.addChild(newNode);
}
node = newNode;
resetModifiers(this);
}
else if (isConstructorDeclaration(token)) {
var newNode = new core_1.ApexConstructor(((node) ? node.id : 'InitialNode') + '.constructor.' + token.textToLower, token.text);
newNode.accessModifier = this.accessModifier;
newNode.definitionModifier = this.definitionModifier;
newNode.parentId = (node) ? node.id : undefined;
;
newNode.webservice = this.webservice;
newNode.override = this.override;
newNode.scope = bracketIndent;
index = processMethodSignature(newNode, this, index);
if (newNode.positionData) {
positionData = newNode.positionData;
newNode.positionData = undefined;
positionData.parentName = (node) ? node.name : undefined;
}
if (this.annotation) {
this.annotation.parentId = newNode.id;
this.annotation.id = newNode.id + '.' + this.annotation.id;
this.nodesMap[this.annotation.id] = this.annotation;
newNode.annotation = this.annotation;
this.annotation = undefined;
}
if (this.comment) {
this.comment.parentId = newNode.id;
this.comment.id = newNode.id + '.' + this.comment.id;
this.nodesMap[this.comment.id] = this.comment;
newNode.comment = this.comment;
if (!this.declarationOnly && this.systemData && this.systemData.template && Utils.hasKeys(this.systemData.template)) {
newNode.comment.processComment(this.systemData.template);
}
this.comment = undefined;
if (positionData && (positionData.nodeType === core_1.ApexNodeTypes.BLOCK_COMMENT || positionData.nodeType === core_1.ApexNodeTypes.COMMENT)) {
positionData.parentName = newNode.name;
positionData.signature = newNode.simplifiedSignature;
}
}
this.nodesMap[newNode.id] = newNode;
if (node) {
node.addChild(newNode);
}
node = newNode;
resetModifiers(this);
}
else if (isMethodDeclaration(token)) {
var newNode = new core_1.ApexMethod(((node) ? node.id : 'InitialNode') + '.method.' + token.textToLower, token.text);
newNode.accessModifier = this.accessModifier;
newNode.definitionModifier = this.definitionModifier;
newNode.parentId = (node) ? node.id : undefined;
;
newNode.webservice = this.webservice;
newNode.static = this.staticKeyword;
newNode.final = this.final;
newNode.testMethod = this.testMethod;
newNode.override = this.override;
newNode.scope = bracketIndent;
if (this.datatype) {
this.datatype.parentId = newNode.id;
this.datatype.id = newNode.id + '.' + this.datatype.id;
this.nodesMap[this.datatype.id] = this.datatype;
newNode.datatype = this.datatype;
}
index = processMethodSignature(newNode, this, index);
if (newNode.positionData) {
positionData = newNode.positionData;
newNode.positionData = undefined;
positionData.parentName = (node) ? node.name : undefined;
}
if (this.annotation) {
this.annotation.parentId = newNode.id;
this.annotation.id = newNode.id + '.' + this.annotation.id;
this.nodesMap[this.annotation.id] = this.annotation;
newNode.annotation = this.annotation;
}
if (this.comment) {
this.comment.parentId = newNode.id;
this.comment.id = newNode.id + '.' + this.comment.id;
this.nodesMap[this.comment.id] = this.comment;
newNode.comment = this.comment;
if (!this.declarationOnly && this.systemData && this.systemData.template && Utils.hasKeys(this.systemData.template)) {
newNode.comment.processComment(this.systemData.template);
}
this.comment = undefined;
if (positionData && (positionData.nodeType === core_1.ApexNodeTypes.BLOCK_COMMENT || positionData.nodeType === core_1.ApexNodeTypes.COMMENT)) {
positionData.parentName = newNode.name;
positionData.signature = newNode.simplifiedSignature;
}
}
this.nodesMap[newNode.id] = newNode;
if (node) {
node.addChild(newNode);
}
node = newNode;
resetModifiers(this);
}
else if (isVariableDeclaration(token)) {
var newNode = new core_1.ApexVariable(((node) ? node.id : 'InitialNode') + '.variable.' + token.textToLower, token.text, token);
newNode.accessModifier = this.accessModifier;
newNode.definitionModifier = this.definitionModifier;
newNode.parentId = (node) ? node.id : undefined;
;
newNode.static = this.staticKeyword;
newNode.final = this.final;
newNode.scope = bracketIndent;
newNode.endToken = token;
if (this.annotation) {
this.annotation.parentId = newNode.id;
this.annotation.id = newNode.id + '.' + this.annotation.id;
this.nodesMap[this.annotation.id] = this.annotation;
newNode.annotation = this.annotation;
}
if (this.comment) {
this.comment.parentId = newNode.id;
this.comment.id = newNode.id + '.' + this.comment.id;
this.nodesMap[this.comment.id] = this.comment;
newNode.comment = this.comment;
if (!this.declarationOnly && this.systemData && this.systemData.template && Utils.hasKeys(this.systemData.template)) {
newNode.comment.processComment(this.systemData.template);
}
if (positionData && (positionData.nodeType === core_1.ApexNodeTypes.BLOCK_COMMENT || positionData.nodeType === core_1.ApexNodeTypes.COMMENT)) {
positionData.parentName = newNode.name;
}
}
if (this.datatype) {
this.datatype.parentId = newNode.id;
this.datatype.id = newNode.id + '.' + this.datatype.id;
this.nodesMap[this.datatype.id] = this.datatype;
newNode.datatype = this.datatype;
}
this.nodesMap[newNode.id] = newNode;
if (node) {
node.addChild(newNode);
}
else if (this.declarationOnly) {
node = newNode;
break;
}
if (this.cursorPosition && node && !positionData) {
if (languageUtils_1.LanguageUtils.isOnPosition(token, lastToken, nextToken, this.cursorPosition)) {
var startIndex = this.cursorPosition.character - token.range.start.character;
var startPart = token.text.substring(0, startIndex + 1);
var endPart = token.text.substring(startIndex + 1);
positionData = new core_1.PositionData(startPart, endPart, node.nodeType, node.id, 'Apex');
positionData.onText = token.type === core_1.ApexTokenTypes.PUNCTUATION.QUOTTES_START || token.type === core_1.ApexTokenTypes.PUNCTUATION.QUOTTES_END || token.type === core_1.ApexTokenTypes.LITERAL.STRING;
positionData.signature = node.simplifiedSignature || node.signature;
positionData.parentName = (node) ? node.name : undefined;
positionData.token = token;
positionData.nextToken = nextToken;
positionData.twoNextToken = twoNextToken;
positionData.lastToken = lastToken;
positionData.twoLastToken = twoLastToken;
}
}
if (nextToken && (nextToken.type === core_1.ApexTokenTypes.PUNCTUATION.COMMA || nextToken.type === core_1.ApexTokenTypes.OPERATOR.ASSIGN.ASSIGN)) {
index++;
var paramIndent = 0;
for (; index < this.tokensLength; index++) {
var auxToken = this.tokens[index];
var nextTokenAux = languageUtils_1.LanguageUtils.getNextToken(this.tokens, index);
var lastTokenAux = languageUtils_1.LanguageUtils.getLastToken(this.tokens, index);
var twoNextTokenAux = languageUtils_1.LanguageUtils.getTwoNextToken(this.tokens, index);
var twoLastTokenAux = languageUtils_1.LanguageUtils.getTwoLastToken(this.tokens, index);
if (this.cursorPosition && node && !positionData) {
if (languageUtils_1.LanguageUtils.isOnPosition(token, lastTokenAux, nextTokenAux, this.cursorPosition)) {
var startIndex = this.cursorPosition.character - token.range.start.character;
var startPart = token.text.substring(0, startIndex + 1);
var endPart = token.text.substring(startIndex + 1);
positionData = new core_1.PositionData(startPart, endPart, node.nodeType, node.id, 'Apex');
positionData.onText = token.type === core_1.ApexTokenTypes.PUNCTUATION.QUOTTES_START || token.type === core_1.ApexTokenTypes.PUNCTUATION.QUOTTES_END || token.type === core_1.ApexTokenTypes.LITERAL.STRING;
positionData.signature = node.simplifiedSignature || node.signature;
positionData.parentName = (node) ? node.name : undefined;
positionData.token = token;
positionData.nextToken = nextToken;
positionData.twoNextToken = twoNextTokenAux;
positionData.lastToken = lastToken;
positionData.twoLastToken = twoLastTokenAux;
}
}
if (auxToken.type === core_1.ApexTokenTypes.PUNCTUATION.SEMICOLON) {
break;
}
if (auxToken.type === core_1.ApexTokenTypes.BRACKET.QUERY_START) {
index--;
break;
}
if (auxToken.type === core_1.ApexTokenTypes.BRACKET.PARENTHESIS_PARAM_OPEN) {
paramIndent++;
}
else if (auxToken.type === core_1.ApexTokenTypes.BRACKET.PARENTHESIS_PARAM_CLOSE) {
paramIndent--;
}
if (paramIndent === 0 && (auxToken.type === core_1.ApexTokenTypes.DECLARATION.ENTITY.VARIABLE || auxToken.type === core_1.ApexTokenTypes.ENTITY.VARIABLE)) {
if (lastTokenAux && lastTokenAux.type === core_1.ApexTokenTypes.OPERATOR.ASSIGN.ASSIGN) {
continue;
}
var sameLineVar = new core_1.ApexVariable(((node) ? node.id : 'InitialNode') + '.variable.' + auxToken.textToLower, auxToken.text, auxToken);
sameLineVar.accessModifier = this.accessModifier;
sameLineVar.definitionModifier = this.definitionModifier;
sameLineVar.parentId = (node) ? node.id : undefined;
sameLineVar.static = this.staticKeyword;
sameLineVar.final = this.final;
sameLineVar.scope = bracketIndent;
sameLineVar.endToken = auxToken;
var dataTypeNode = (this.datatype) ? new core_1.ApexDatatype(this.datatype) : new core_1.ApexDatatype('');
dataTypeNode.id = sameLineVar.id + '.datatype.' + dataTypeNode.name;
this.nodesMap[dataTypeNode.id] = dataTypeNode;
sameLineVar.datatype = dataTypeNode;
if (this.annotation) {
this.annotation.parentId = newNode.id;
this.annotation.id = newNode.id + '.' + this.annotation.id;
this.nodesMap[this.annotation.id] = this.annotation;
newNode.annotation = this.annotation;
}
if (this.comment) {
this.comment.parentId = newNode.id;
this.comment.id = newNode.id + '.' + this.comment.id;
this.nodesMap[this.comment.id] = this.comment;
newNode.comment = this.comment;
if (!this.declarationOnly && this.systemData && this.systemData.template && Utils.hasKeys(this.systemData.template)) {
newNode.comment.processComment(this.systemData.template);
}
}
this.nodesMap[sameLineVar.id] = sameLineVar;
if (node) {
node.addChild(sameLineVar);
}
}
}
this.comment = undefined;
this.datatype = undefined;
this.annotation = undefined;
}
else {
this.comment = undefined;
this.datatype = undefined;
this.annotation = undefined;
}
resetModifiers(this);
}
}
if (node) {
node.positionData = positionData;
}
this.node = node;
return node;
};
/**
* Method to resolve resolve extend and implement references from Apex Class or Apex Interface
* @param {ApexClass | ApexInterface} node Node to resolve references
* @returns
*/
ApexParser.prototype.resolveReferences = function (node) {
var nodeToResolve = node || this.node;
if (!nodeToResolve) {
nodeToResolve = this.parse();
}
if (nodeToResolve instanceof core_1.ApexClass || nodeToResolve instanceof core_1.ApexClass) {
if (nodeToResolve && nodeToResolve.extendsType) {
var resolved = resolveDatatypeReference(nodeToResolve.extendsType, this.systemData.userClassesData, this.systemData.namespacesData);
if (resolved instanceof core_1.ApexClass || resolved instanceof core_1.ApexInterface) {
nodeToResolve.extends = resolved;
}
}
if (nodeToResolve && nodeToResolve.implementTypes && nodeToResolve.implementTypes.length > 0) {
var resolved = resolveImplements(nodeToResolve.implementTypes, this.systemData.userClassesData, this.systemData.namespacesData);
var implementTypes = {};
if (resol