Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 13355x 13355x 13355x 13355x 13355x 1x 1x 1x 1x 14753x 14753x 14753x 500x 500x 14253x 14253x 14253x 14253x 14253x 14253x 14253x 14253x 14253x 14253x 14253x 14253x 14253x 14253x 14253x 14253x 1x 1x 16206x 16206x 16206x 16206x 16206x 16206x 16206x 1x 1x 130x 73x 73x 130x 130x 1x 1x 99852x 99852x 1x 1x 1190x 1222x 1183x 1183x 1222x 7x 7x 1x 1x 19732x 19732x 19732x 19691x 19632x 19632x 19691x 100x 19732x 14x 14x 14x 14x 14x 86x 86x 1x 1x 16x 16x 16x 16x 16x 1x 1x 57x 57x 57x 57x 57x 10x 10x 57x 57x 1x 1x 57x 57x 57x 57x 57x 1x 1x 75x 75x 75x 48x 48x 27x 75x 70x 70x 1x 1x 69x 70x 1x 1x 68x 70x 70x 70x 70x 41x 41x 70x 70x 27x 1x 1x 57x 57x 57x 57x 52x 52x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x | import {AbstractObject} from "./_abstract_object";
import {xmlToArray, unescape} from "../xml_utils";
import {ABAPParser} from "../abap/abap_parser";
import {ABAPRelease, LanguageVersion} from "../version";
import {ISyntaxResult} from "../abap/5_syntax/_spaghetti_scope";
import {IParseResult} from "./_iobject";
import {ABAPFile} from "../abap/abap_file";
import {IRegistry} from "../_iregistry";
export interface ITextElements {[key: string]: {entry: string, maxLength: number}}
export interface ITranslationTextElements {language: string, textElements: ITextElements}
export abstract class ABAPObject extends AbstractObject {
private parsed: readonly ABAPFile[];
protected texts: {[id: string]: ITextElements} | undefined;
private textsTranslations: ITranslationTextElements[] | undefined;
private rawXMLCache: any | undefined;
private parsing = false;
public syntaxResult: ISyntaxResult | undefined; // do not use this outside of SyntaxLogic class, todo: refactor
public [Symbol.for("debug.description")](){
return `${this.constructor.name} ${this.getName()}`;
}
public abstract getSequencedFiles(): readonly ABAPFile[];
public abstract getDescription(): string | undefined;
public constructor(name: string) {
super(name);
this.parsed = [];
this.texts = undefined;
this.rawXMLCache = undefined;
}
public static is(x: any): x is ABAPObject {
return !!x && x instanceof ABAPObject;
}
public parse(release: ABAPRelease, globalMacros?: readonly string[], reg?: IRegistry,
languageVersion: LanguageVersion = LanguageVersion.Normal): IParseResult {
// an INCLUDE that leads back to this object while it is being parsed is not followed again
if (this.isDirty() === false || this.parsing === true) {
return {updated: false, runtime: 0};
}
const abapFiles = this.getFiles().filter(f => f.getFilename().endsWith(".abap"));
let result;
this.parsing = true;
try {
result = new ABAPParser({release, globalMacros, reg, languageVersion}).parse(abapFiles);
} finally {
this.parsing = false;
}
this.parsed = result.output;
this.old = result.issues;
this.dirty = false;
return {updated: true, runtime: result.runtime, runtimeExtra: result.runtimeExtra};
}
public setDirty(): void {
this.syntaxResult = undefined;
this.texts = undefined;
this.textsTranslations = undefined;
this.rawXMLCache = undefined;
this.parsed = [];
super.setDirty();
}
private getParsedXML(): any | undefined {
if (this.rawXMLCache === undefined) {
this.rawXMLCache = this.parseRaw2() ?? null;
}
return this.rawXMLCache ?? undefined;
}
public getABAPFiles(): readonly ABAPFile[] {
return this.parsed;
}
public getABAPFileByName(filename: string): ABAPFile | undefined {
for (const p of this.parsed) {
if (p.getFilename() === filename) {
return p;
}
}
return undefined;
}
public getMainABAPFile(): ABAPFile | undefined {
const search = this.getName().replace(/\//g, "#").toLowerCase() + "." + this.getType().toLowerCase() + ".abap";
const encodedSearch = search.replace(/#/g, "%23");
for (const file of this.getABAPFiles()) {
if (file.getFilename().endsWith(search) || file.getFilename().endsWith(encodedSearch)) {
return file;
}
}
// uri fallback,
for (const file of this.getABAPFiles()) {
if (file.getFilename().includes(".prog.screen_")) {
continue;
} else if (file.getFilename().endsWith(".abap")) {
return file;
}
}
return undefined;
}
public getTextSymbols(): ITextElements {
if (this.texts === undefined) {
this.findTexts(this.getParsedXML());
}
return this.texts!["I"] ?? {};
}
public getTextElements(): ITextElements {
if (this.texts === undefined) {
this.findTexts(this.getParsedXML());
}
const result: ITextElements = {};
for (const elements of Object.values(this.texts!)) {
Object.assign(result, elements);
}
return result;
}
public getTextElementsTranslations(): ITranslationTextElements[] {
if (this.textsTranslations === undefined) {
this.findTextsTranslations(this.getParsedXML());
}
return this.textsTranslations!;
}
protected findTexts(parsed: any) {
this.texts = {};
if (parsed?.abapGit?.["asx:abap"]?.["asx:values"]?.TPOOL?.item === undefined) {
return;
}
for (const t of xmlToArray(parsed?.abapGit?.["asx:abap"]?.["asx:values"]?.TPOOL?.item)) {
const id = typeof t?.ID === "string" ? t.ID.toUpperCase() : undefined;
if (id === undefined) {
continue;
}
if (id !== "R" && t.KEY === undefined) {
continue;
}
const rawKey = t.KEY ?? t.ID;
const key = typeof rawKey === "string" ? rawKey.toUpperCase() : undefined;
if (key === undefined) {
continue;
}
if (this.texts[id] === undefined) {
this.texts[id] = {};
}
this.texts[id][key] = {entry: t.ENTRY ? unescape(t.ENTRY) : "", maxLength: parseInt(t.LENGTH, 10)};
}
}
private findTextsTranslations(parsed: any): void {
this.textsTranslations = [];
const values = parsed?.abapGit?.["asx:abap"]?.["asx:values"]?.I18N_TPOOL?.item;
if (values === undefined) {
return;
}
for (const langItem of xmlToArray(values)) {
const textElements: ITextElements = {};
for (const item of xmlToArray(langItem.TEXTPOOL?.item)) {
const rawKey = item.KEY ?? item.ID;
const key = typeof rawKey === "string" ? rawKey.toUpperCase() : undefined;
if (key !== undefined) {
textElements[key] = {entry: unescape(item.ENTRY), maxLength: parseInt(item.LENGTH, 10)};
}
}
this.textsTranslations.push({language: langItem.LANGUAGE, textElements});
}
}
}
|