@abaplint/core
Version:
abaplint - Core API
252 lines • 7.56 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StructureNode = void 0;
const _abstract_node_1 = require("./_abstract_node");
const statement_node_1 = require("./statement_node");
class StructureNode extends _abstract_node_1.AbstractNode {
constructor(structure) {
super();
this.structure = structure;
}
get() {
return this.structure;
}
// todo, remove this method, the logic should never go up in the tree
findParent(node) {
for (const child of this.getChildren()) {
if (child === node) {
return this;
}
else if (child instanceof statement_node_1.StatementNode) {
continue;
}
else {
const res = child.findParent(node);
if (res) {
return res;
}
}
}
return undefined;
}
concatTokens() {
let concat = "";
for (const child of this.getChildren()) {
concat = concat + child.concatTokens();
}
return concat;
}
findDirectStatement(type) {
for (const child of this.getChildren()) {
if (child instanceof statement_node_1.StatementNode && child.get() instanceof type) {
return child;
}
}
return undefined;
}
findDirectStatements(type) {
const ret = [];
for (const child of this.getChildren()) {
if (child instanceof statement_node_1.StatementNode && child.get() instanceof type) {
ret.push(child);
}
}
return ret;
}
findDirectStructures(type) {
const ret = [];
for (const child of this.getChildren()) {
if (child instanceof StructureNode && child.get() instanceof type) {
ret.push(child);
}
}
return ret;
}
findFirstStatement(type) {
for (const child of this.getChildren()) {
if (child.get() instanceof type) {
return child;
}
else if (child instanceof statement_node_1.StatementNode) {
continue;
}
else {
const res = child.findFirstStatement(type);
if (res) {
return res;
}
}
}
return undefined;
}
findFirstExpression(type) {
for (const child of this.getChildren()) {
const res = child.findFirstExpression(type);
if (res) {
return res;
}
}
return undefined;
}
getFirstStatement() {
for (const child of this.getChildren()) {
if (child instanceof statement_node_1.StatementNode) {
return child;
}
return child.getFirstStatement();
}
return undefined;
}
getFirstToken() {
const child = this.getFirstChild();
if (child !== undefined) {
return child.getFirstToken();
}
throw new Error("StructureNode, getFirstToken, unexpected type");
}
getLastToken() {
const child = this.getLastChild();
if (child !== undefined) {
return child.getLastToken();
}
throw new Error("StructureNode, getLastToken, unexpected type");
}
findAllExpressions(type) {
const ret = [];
for (const child of this.getChildren()) {
ret.push(...child.findAllExpressions(type));
}
return ret;
}
findAllExpressionsRecursive(type) {
const ret = [];
for (const child of this.getChildren()) {
if (child instanceof statement_node_1.StatementNode) {
ret.push(...child.findAllExpressionsRecursive(type));
}
else {
ret.push(...child.findAllExpressionsRecursive(type));
}
}
return ret;
}
findAllExpressionsMulti(type) {
const ret = [];
for (const child of this.getChildren()) {
ret.push(...child.findAllExpressionsMulti(type));
}
return ret;
}
findAllStatements(type) {
const ret = [];
for (const child of this.getChildren()) {
if (child instanceof StructureNode) {
ret.push(...child.findAllStatements(type));
}
else if (child.get() instanceof type) {
ret.push(child);
}
}
return ret;
}
findAllStatementNodes() {
const ret = [];
for (const child of this.getChildren()) {
if (child instanceof statement_node_1.StatementNode) {
ret.push(child);
}
else {
ret.push(...child.findAllStatementNodes());
}
}
return ret;
}
findAllStructuresRecursive(type) {
const ret = [];
for (const child of this.getChildren()) {
if (child instanceof statement_node_1.StatementNode) {
continue;
}
else if (child.get() instanceof type) {
ret.push(child);
}
ret.push(...child.findAllStructuresRecursive(type));
}
return ret;
}
findAllStructuresMulti(type) {
const ret = [];
for (const t of type) {
if (this.get() instanceof t) {
return [this];
}
}
for (const child of this.getChildren()) {
if (child instanceof statement_node_1.StatementNode) {
continue;
}
let found = false;
for (const t of type) {
if (this.get() instanceof t) {
ret.push(child);
found = true;
}
}
if (found === false) {
ret.push(...child.findAllStructuresMulti(type));
}
}
return ret;
}
findAllStructures(type) {
const ret = [];
if (this.get() instanceof type) {
return [this];
}
for (const child of this.getChildren()) {
if (child instanceof statement_node_1.StatementNode) {
continue;
}
else if (child.get() instanceof type) {
ret.push(child);
}
else {
ret.push(...child.findAllStructures(type));
}
}
return ret;
}
findDirectStructure(type) {
if (this.get() instanceof type) {
return this;
}
for (const child of this.getChildren()) {
if (child.get() instanceof type) {
return child;
}
}
return undefined;
}
findFirstStructure(type) {
if (this.get() instanceof type) {
return this;
}
for (const child of this.getChildren()) {
if (child instanceof statement_node_1.StatementNode) {
continue;
}
else if (child.get() instanceof type) {
return child;
}
else {
const res = child.findFirstStructure(type);
if (res) {
return res;
}
}
}
return undefined;
}
}
exports.StructureNode = StructureNode;
//# sourceMappingURL=structure_node.js.map