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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 1x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 343x 3845x 3845x 343x 343x 365x 365x 365x 343x 343x 68x 68x 68x 68x 68x 343x 343x 55x 55x 52x 52x 3x 3x 55x 3x 3x 343x 343x 410x 410x 410x 410x 343x 343x 343x 343x 343x 343x 5x 5x 3x 3x 5x 5x 343x 343x 343x 343x 4x 4x 2x 2x 4x 4x 343x 343x 343x 3x 3x 2x 2x 3x 3x 343x 343x 5x 4x 4x 4x 4x 4x 1x 1x 343x 343x 66x 66x 66x 343x 343x 66x 66x 66x 343x 343x 66x 66x 66x 343x 343x 35x 35x 35x 343x 343x 1056x 1056x 1056x 1056x 1056x 1056x 1056x 1056x 707x 707x 349x 349x 349x 140x 24x 24x 116x 116x 116x 116x 116x 116x 116x 116x 140x 140x 349x 349x 1056x 1x 1x 1x 1x 1056x 1x 1x 1x 1x 1x 1x 1x 348x 1x 1x 1x 1x 347x 346x 346x 346x 202x 2x 202x 200x 200x 346x 5x 5x 5x 5x 144x 139x 139x 1056x 349x 1056x 203x 203x 349x 349x 1056x 321x 321x 321x 321x 349x 349x 343x 343x 2069x 1727x 1727x 342x 342x 342x 342x 342x 2069x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 9x 333x 333x 2069x 333x 2069x 2069x 2069x 2069x 2069x 2069x 2069x 2069x 2069x 2069x 2069x 2069x 2069x 2069x 2069x 2069x 2069x 2069x 2069x 2069x 2069x 2069x 2069x 2069x 2069x 5x 5x 5x 5x 5x 5x 5x 5x 5x 333x 333x 333x 333x 343x 343x 345x 345x 343x 343x | import {AbstractObject} from "./_abstract_object";
import {AbstractType} from "../abap/types/basic/_abstract_type";
import {IRegistry} from "../_iregistry";
import {DDIC, ILookupResult} from "../ddic";
import * as Types from "../abap/types/basic";
import {xmlToArray} from "../xml_utils";
import {IObjectAndToken} from "../_iddic_references";
import {Domain} from "./domain";
import {Identifier} from "../abap/4_file_information/_identifier";
import {Identifier as IdentifierToken} from "../abap/1_lexer/tokens/identifier";
import {Position} from "../position";
function toNumber(value: string | undefined): number | undefined {
const parsed = parseInt(value ?? "", 10);
return isNaN(parsed) ? undefined : parsed;
}
export class DataElement extends AbstractObject {
private parsedXML: {
description?: string,
refkind?: string,
domname?: string,
datatype?: string,
leng?: string,
texts?: {
short?: string,
medium?: string,
long?: string,
heading?: string,
}
textMaxLengths?: {
short?: string,
medium?: string,
long?: string,
heading?: string,
}
textsTranslations?: {
language: string,
description?: string,
short?: string,
medium?: string,
long?: string,
heading?: string,
}[]
decimals?: string,
dtelmaster?: string,
affCategory?: string,
} | undefined = undefined;
private parsedType: AbstractType | undefined = undefined;
public getType(): string {
return "DTEL";
}
public getDescription(): string | undefined {
this.parse();
return this.parsedXML?.description;
}
public getAllowedNaming() {
return {
maxLength: 30,
allowNamespace: true,
};
}
public getIdentifier(): Identifier | undefined {
const xmlIdentifier = super.getIdentifier();
if (xmlIdentifier) {
return xmlIdentifier;
}
const file = this.getAFFFile();
if (file === undefined) {
return undefined;
}
return new Identifier(new IdentifierToken(new Position(1, 1), this.getName()), file.getFilename());
}
public setDirty(): void {
this.parsedXML = undefined;
this.parsedType = undefined;
super.setDirty();
}
public getDomainName(): string | undefined {
this.parse();
return this.parsedXML?.domname;
}
/** parseType() cannot distinguish DEC, CURR, and QUAN because they all become PackedType.
* Return the original DDIC datatype instead, resolving domain-backed data elements when possible. */
public getDataType(reg?: IRegistry): string | undefined {
this.parse();
if (this.parsedXML?.datatype) {
return this.parsedXML.datatype;
}
return this.findDomain(reg)?.getDataType();
}
/** DDIC length, eg. number of digits for DEC, which parseType() cannot give.
* Taken from the same place as getDataType(), ie. the data element or its domain. */
public getLength(reg?: IRegistry): number | undefined {
this.parse();
if (this.parsedXML?.datatype) {
return toNumber(this.parsedXML.leng);
}
return this.findDomain(reg)?.getLength();
}
/** DDIC decimals, taken from the same place as getDataType(), ie. the data element or its domain. */
public getDecimals(reg?: IRegistry): number | undefined {
this.parse();
if (this.parsedXML?.datatype) {
return toNumber(this.parsedXML.decimals);
}
return this.findDomain(reg)?.getDecimals();
}
private findDomain(reg?: IRegistry): Domain | undefined {
if (reg && this.parsedXML?.refkind === "D" && this.parsedXML.domname) {
const domain = reg.getObject("DOMA", this.parsedXML.domname);
if (domain instanceof Domain) {
return domain;
}
}
return undefined;
}
public getTexts() {
this.parse();
return this.parsedXML?.texts;
}
public getTextMaxLengths() {
this.parse();
return this.parsedXML?.textMaxLengths;
}
public getTextsTranslations() {
this.parse();
return this.parsedXML?.textsTranslations;
}
public getDtelMaster() {
this.parse();
return this.parsedXML?.dtelmaster;
}
public parseType(reg: IRegistry): AbstractType {
const references: IObjectAndToken[] = [];
let lookup: ILookupResult | undefined;
this.parse();
if (this.parsedXML === undefined) {
lookup = {type: new Types.UnknownType("Data Element " + this.getName() + ", parser error")};
} else {
if (this.parsedType) {
return this.parsedType;
}
const ddic = new DDIC(reg);
const lookupPredefinedType = (): ILookupResult => {
if (this.parsedXML?.datatype === undefined || this.parsedXML.datatype === "") {
return {type: new Types.UnknownType("DATATYPE unexpectely empty in " + this.getName())};
}
return {type: ddic.textToType({
text: this.parsedXML.datatype,
length: this.parsedXML.leng,
decimals: this.parsedXML.decimals,
infoText: this.getName(),
qualifiedName: this.getName(),
conversionExit: undefined,
ddicName: this.getName(),
description: this.parsedXML.texts?.heading,
})};
};
if (this.parsedXML.affCategory === "referenceToPredefinedType") {
const predefined = lookupPredefinedType();
lookup = predefined.type instanceof Types.UnknownType
? predefined
: {type: new Types.DataReference(predefined.type, this.getName())};
} else if (this.parsedXML.affCategory === "referenceDictionaryType") {
if (this.parsedXML.domname === undefined || this.parsedXML.domname === "") {
lookup = {type: new Types.UnknownType("Type name unexpectely empty in " + this.getName())};
} else {
const referenced = ddic.lookup(this.parsedXML.domname);
lookup = referenced.type instanceof Types.UnknownType
? referenced
: {...referenced, type: new Types.DataReference(referenced.type, this.getName())};
}
} else if (this.parsedXML.affCategory === "referenceClasIntType") {
if (this.parsedXML.domname === undefined || this.parsedXML.domname === "") {
lookup = {type: new Types.UnknownType("Type name unexpectely empty in " + this.getName())};
} else {
lookup = ddic.lookupObject(this.parsedXML.domname);
}
} else if (this.parsedXML.affCategory !== undefined
&& this.parsedXML.affCategory !== "domain"
&& this.parsedXML.affCategory !== "predefinedType") {
lookup = {type: new Types.UnknownType(
"Unknown AFF data type category " + this.parsedXML.affCategory + " in " + this.getName())};
} else if (this.parsedXML.refkind === "D") {
if (this.parsedXML.domname === undefined || this.parsedXML.domname === "") {
lookup = {type: new Types.UnknownType("DOMNAME unexpectely empty in " + this.getName())};
} else {
lookup = ddic.lookupDomain(this.parsedXML.domname, this.getName(), this.getDescription());
}
} else if (this.parsedXML.refkind === "R") {
if (this.parsedXML.domname === undefined || this.parsedXML.domname === "") {
lookup = {type: new Types.UnknownType("DOMNAME unexpectely empty in " + this.getName())};
} else {
lookup = ddic.lookupObject(this.parsedXML.domname);
}
} else {
lookup = lookupPredefinedType();
}
}
if (lookup.object) {
references.push({object: lookup.object});
}
reg.getDDICReferences().setUsing(this, references);
if (!(lookup.type instanceof Types.UnknownType)) {
// the referenced type might not exist or contain syntax errors(for CLAS)
// so dont cache it, expect the user to fix it
this.parsedType = lookup.type;
}
return lookup.type;
}
public parse() {
if (this.parsedXML !== undefined) {
return {updated: false, runtime: 0};
}
const start = Date.now();
this.parsedXML = {};
const jsonFile = this.getAFFFile();
if (jsonFile) {
try {
const parsed = JSON.parse(jsonFile.getRaw());
const typeInformation = parsed.dataTypeInformation;
const predefinedType = typeInformation?.predefinedType;
const fieldLabels = parsed.fieldLabels;
this.parsedXML = {
description: parsed.header?.description,
affCategory: typeInformation?.category,
refkind: typeInformation?.category === "domain" ? "D" : undefined,
domname: typeInformation?.typeName,
datatype: predefinedType?.dataType,
leng: predefinedType?.length?.toString(),
decimals: predefinedType?.decimals?.toString(),
texts: {
short: fieldLabels?.short,
medium: fieldLabels?.medium,
long: fieldLabels?.long,
heading: fieldLabels?.heading,
},
textMaxLengths: {
short: fieldLabels?.shortLength?.toString(),
medium: fieldLabels?.mediumLength?.toString(),
long: fieldLabels?.longLength?.toString(),
heading: fieldLabels?.headingLength?.toString(),
},
};
} catch {
// handled by parseType()
}
const end = Date.now();
return {updated: true, runtime: end - start};
}
const parsed = super.parseRaw2();
if (parsed === undefined) {
return {updated: false, runtime: 0};
}
const dd04v = parsed.abapGit?.["asx:abap"]?.["asx:values"]?.DD04V;
this.parsedXML = {
description: dd04v?.DDTEXT,
refkind: dd04v?.REFKIND,
domname: dd04v?.DOMNAME,
datatype: dd04v?.DATATYPE,
leng: dd04v?.LENG,
decimals: dd04v?.DECIMALS,
dtelmaster: dd04v?.DTELMASTER,
texts: {
short: dd04v?.SCRTEXT_S,
medium: dd04v?.SCRTEXT_M,
long: dd04v?.SCRTEXT_L,
heading: dd04v?.REPTEXT,
},
textMaxLengths: {
short: dd04v?.SCRLEN1,
medium: dd04v?.SCRLEN2,
long: dd04v?.SCRLEN3,
heading: dd04v?.HEADLEN,
},
};
this.parsedXML.textsTranslations = [];
for (const item of xmlToArray(parsed.abapGit?.["asx:abap"]?.["asx:values"]?.DD04_TEXTS?.item)) {
this.parsedXML.textsTranslations.push({
language: item.DDLANGUAGE,
description: item.DDTEXT,
short: item.SCRTEXT_S,
medium: item.SCRTEXT_M,
long: item.SCRTEXT_L,
heading: item.REPTEXT,
});
}
const end = Date.now();
return {updated: true, runtime: end - start};
}
private getAFFFile() {
return this.getFiles().find(file => file.getFilename().toLowerCase().endsWith(".dtel.json"));
}
}
|