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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 9915x 9915x 9915x 9915x 9915x 1x 1x 1x 1x 10770x 10770x 441x 441x 10329x 10329x 10329x 10329x 10329x 10329x 10329x 10329x 10329x 10329x 1x 1x 11661x 11661x 11661x 11661x 11661x 11661x 11661x 1x 1x 94x 55x 55x 94x 94x 1x 1x 60001x 60001x 1x 1x 1030x 1048x 1025x 1025x 1048x 5x 5x 1x 1x 10314x 10314x 10314x 10317x 10264x 10264x 10317x 50x 10314x 13x 13x 13x 13x 13x 37x 37x 1x 1x 16x 16x 16x 16x 16x 1x 1x 39x 39x 39x 39x 39x 10x 10x 39x 39x 1x 1x 39x 39x 39x 39x 39x 1x 1x 57x 57x 57x 31x 31x 26x 57x 69x 69x 69x 69x 1x 1x 68x 69x 69x 69x 41x 41x 69x 69x 26x 1x 1x 39x 39x 39x 39x 35x 35x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 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;
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 {
if (this.isDirty() === false) {
return {updated: false, runtime: 0};
}
const abapFiles = this.getFiles().filter(f => f.getFilename().endsWith(".abap"));
const result = new ABAPParser({release, globalMacros, reg, languageVersion}).parse(abapFiles);
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 = t.ID?.toUpperCase();
if (id === undefined) {
continue;
}
if (id !== "R" && t.KEY === undefined) {
continue;
}
const key = (t.KEY ?? t.ID)?.toUpperCase();
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 key = (item.KEY ?? item.ID)?.toUpperCase();
if (key !== undefined) {
textElements[key] = {entry: unescape(item.ENTRY), maxLength: parseInt(item.LENGTH, 10)};
}
}
this.textsTranslations.push({language: langItem.LANGUAGE, textElements});
}
}
}
|