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 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8096x 8096x 1x 1x 8096x 8096x 8096x 8096x 8096x 8096x 8096x 8096x 632x 632x 7464x 7464x 7464x 7464x 7464x 7464x 7464x 7464x 1x 1x 7464x 7464x 7464x 1104x 1104x 708x 708x 708x 708x 708x 1104x 1104x 1104x 1104x 1104x 1104x 1104x 1104x 7464x 7464x 7464x 1x 1x 7464x 7464x 7464x 332x 332x 332x 332x 332x 332x 332x 332x 332x 7464x 7464x 7464x 1x 1x 7464x 7464x 7464x 307x 307x 307x 307x 307x 307x 307x 307x 307x 307x 307x 307x 307x 307x 307x 307x 307x 307x 307x 307x 307x 7464x 7464x 7464x 1x 1x 7464x 7464x 7464x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1x 1199x 1198x 6x 6x 1199x 1199x 1199x 7x 1199x 1192x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 1199x 7464x 7464x 7464x 1x 1x 1x 1x 1506x 1506x 133x 133x 133x 4x 4x 4x 4x 133x 133x 133x 133x 133x 133x 133x 133x 133x 133x 133x 133x 133x 133x 133x 133x 133x 1506x 1506x 1x 1x 3904x 2628x 2628x 1276x 1276x 3904x 32x 32x 32x 32x 32x 32x 32x 32x 32x 32x 1276x 1276x 1276x 1x 1x 3904x 2628x 2628x 1276x 1276x 3904x 114x 114x 114x 114x 114x 114x 114x 114x 114x 114x 114x 114x 114x 114x 114x 114x 1276x 1276x 1276x 1x 1x 3904x 2628x 2628x 1276x 1276x 3904x 99x 99x 1177x 1177x 3904x 181x 181x 181x 181x 181x 181x 181x 181x 181x 3904x 23x 23x 23x 23x 23x 23x 23x 23x 23x 3904x 107x 107x 107x 107x 107x 107x 107x 107x 107x 1177x 1177x 1177x 1x 1x 3904x 2628x 2628x 1276x 1276x 3904x 848x 848x 848x 848x 848x 848x 848x 848x 848x 848x 848x 848x 848x 848x 848x 848x 848x 848x 1276x 1276x 1x 1x 1x 848x 848x 848x 848x 292x 311x 311x 311x 311x 311x 311x 311x 311x 311x 292x 848x 848x 848x 24x 25x 25x 25x 25x 25x 25x 25x 25x 25x 24x 848x 848x 848x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 14x 848x 848x 848x 135x 135x 135x 135x 135x 135x 135x 135x 135x 848x 848x 848x 1x 1x | import * as Structures from "../3_structures/structures";
import * as Expressions from "../2_statements/expressions";
import * as Statements from "../2_statements/statements";
import {StructureNode, StatementNode} from "../nodes";
import {Identifier} from "./_identifier";
import * as Tokens from "../1_lexer/tokens";
import {Visibility} from "./visibility";
import {ParsedFileInformation} from "./parsed_file_information";
import {InfoClassImplementation, InfoClassDefinition, InfoMethodDefinition, InfoInterfaceDefinition, InfoAttribute, InfoAlias, AttributeLevel, InfoMethodParameter, MethodParameterDirection, InfoFormDefinition, InfoImplementing, InfoConstant, Duration, RiskLevel} from "./_abap_file_information";
export class ABAPFileInformationParser {
private readonly filename: string;
public constructor(filename: string) {
this.filename = filename;
}
public parse(structure: StructureNode | undefined): ParsedFileInformation {
const result: ParsedFileInformation = {
interfaces: [],
classes: [],
forms: [],
implementations: [],
};
if (structure === undefined) {
return result;
}
result.classes = this.parseClasses(structure);
result.interfaces = this.parseInterfaces(structure);
result.implementations = this.parseClassImplementations(structure);
result.forms = this.parseForms(structure);
return result;
}
private parseClassImplementations(structure: StructureNode): InfoClassImplementation[] {
const implementations: InfoClassImplementation[] = [];
for (const found of structure.findAllStructures(Structures.ClassImplementation)) {
const methods = [];
for (const method of found.findAllStructures(Structures.Method)) {
const methodName = method.findFirstExpression(Expressions.MethodName)?.getFirstToken();
if (methodName) {
methods.push(new Identifier(methodName, this.filename));
}
}
const name = found.findFirstStatement(Statements.ClassImplementation)!.findFirstExpression(Expressions.ClassName)!.getFirstToken();
implementations.push({
name: name.getStr(),
identifier: new Identifier(name, this.filename),
methods,
});
}
return implementations;
}
private parseForms(structure: StructureNode): InfoFormDefinition[] {
const forms: InfoFormDefinition[] = [];
for (const statement of structure.findAllStructures(Structures.Form)) {
// FORMs can contain a dash in the name
const pos = statement.findFirstExpression(Expressions.FormName)!.getFirstToken().getStart();
const name = statement.findFirstExpression(Expressions.FormName)!.concatTokens();
const nameToken = new Tokens.Identifier(pos, name);
forms.push({
name: nameToken.getStr(),
identifier: new Identifier(nameToken, this.filename),
});
}
return forms;
}
private parseInterfaces(structure: StructureNode): InfoInterfaceDefinition[] {
const interfaces: InfoInterfaceDefinition[] = [];
for (const found of structure.findDirectStructures(Structures.Interface)) {
const i = found.findFirstStatement(Statements.Interface);
if (i === undefined) {
throw new Error("Interface expected, parseInterfaces");
}
const interfaceName = i.findDirectExpression(Expressions.InterfaceName)!.getFirstToken();
const methods = this.parseMethodDefinition(found, Visibility.Public);
const attributes = this.parseAttributes(found, Visibility.Public);
const aliases = this.parseAliases(found, Visibility.Public);
const constants = this.parseConstants(found, Visibility.Public);
const g = i.findDirectExpression(Expressions.ClassGlobal);
interfaces.push({
name: interfaceName.getStr(),
identifier: new Identifier(interfaceName, this.filename),
isLocal: g === undefined,
isGlobal: g !== undefined,
interfaces: this.getImplementing(found),
aliases,
methods,
constants,
attributes,
});
}
return interfaces;
}
private parseClasses(structure: StructureNode): InfoClassDefinition[] {
const classes: InfoClassDefinition[] = [];
for (const found of structure.findAllStructures(Structures.ClassDefinition)) {
const className = found.findFirstStatement(Statements.ClassDefinition)!.findFirstExpression(Expressions.ClassName)!.getFirstToken();
const methods = this.parseMethodDefinition(found.findFirstStructure(Structures.PublicSection), Visibility.Public);
methods.push(...this.parseMethodDefinition(found.findFirstStructure(Structures.ProtectedSection), Visibility.Protected));
methods.push(...this.parseMethodDefinition(found.findFirstStructure(Structures.PrivateSection), Visibility.Private));
const attributes = this.parseAttributes(found.findFirstStructure(Structures.PublicSection), Visibility.Public);
attributes.push(...this.parseAttributes(found.findFirstStructure(Structures.ProtectedSection), Visibility.Protected));
attributes.push(...this.parseAttributes(found.findFirstStructure(Structures.PrivateSection), Visibility.Private));
const aliases = this.parseAliases(found.findFirstStructure(Structures.PublicSection), Visibility.Public);
aliases.push(...this.parseAliases(found.findFirstStructure(Structures.ProtectedSection), Visibility.Protected));
aliases.push(...this.parseAliases(found.findFirstStructure(Structures.PrivateSection), Visibility.Private));
const constants = this.parseConstants(found.findFirstStructure(Structures.PublicSection), Visibility.Public);
constants.push(...this.parseConstants(found.findFirstStructure(Structures.ProtectedSection), Visibility.Protected));
constants.push(...this.parseConstants(found.findFirstStructure(Structures.PrivateSection), Visibility.Private));
const superClassName = found.findFirstExpression(Expressions.SuperClassName)?.getFirstToken().getStr();
const containsGlobal = found.findFirstExpression(Expressions.ClassGlobal);
const cdef = found.findFirstStatement(Statements.ClassDefinition);
const concat = cdef?.concatTokens().toUpperCase() || "";
let riskLevel: RiskLevel | undefined;
if (concat.includes("RISK LEVEL CRITICAL")) {
riskLevel = RiskLevel.critical;
} else if (concat.includes("RISK LEVEL DANGEROUS")) {
riskLevel = RiskLevel.dangerous;
} else if (concat.includes("RISK LEVEL HARMLESS")) {
riskLevel = RiskLevel.harmless;
}
let duration: Duration | undefined;
if (concat.includes("DURATION SHORT")) {
duration = Duration.short;
} else if (concat.includes("DURATION LONG")) {
duration = Duration.long;
} else if (concat.includes("DURATION MEDIUM")) {
duration = Duration.medium;
}
classes.push({
name: className.getStr(),
identifier: new Identifier(className, this.filename),
isLocal: containsGlobal === undefined,
isGlobal: containsGlobal !== undefined,
methods,
superClassName,
interfaces: this.getImplementing(found),
isForTesting: concat.includes(" FOR TESTING"),
duration,
riskLevel,
isAbstract: cdef?.findDirectTokenByText("ABSTRACT") !== undefined,
isSharedMemory: concat.includes(" SHARED MEMORY ENABLED"),
isFinal: found.findFirstExpression(Expressions.ClassFinal) !== undefined,
aliases,
attributes,
constants,
});
}
return classes;
}
///////////////////
private getImplementing(input: StructureNode): InfoImplementing[] {
const ret: InfoImplementing[] = [];
for (const node of input.findAllStatements(Statements.InterfaceDef)) {
const abstract = node.findDirectExpression(Expressions.AbstractMethods);
const abstractMethods: string[] = [];
if (abstract) {
for (const m of abstract.findDirectExpressions(Expressions.MethodName)) {
abstractMethods.push(m.concatTokens().toUpperCase());
}
}
const final = node.findDirectExpression(Expressions.FinalMethods);
const finalMethods: string[] = [];
if (final) {
for (const m of final.findDirectExpressions(Expressions.MethodName)) {
finalMethods.push(m.concatTokens().toUpperCase());
}
}
const concat = node.concatTokens().toUpperCase();
const allAbstract = concat.includes(" ALL METHODS ABSTRACT");
const partial = concat.includes(" PARTIALLY IMPLEMENTED");
const name = node.findFirstExpression(Expressions.InterfaceName)!.getFirstToken().getStr().toUpperCase();
ret.push({
name,
partial,
allAbstract,
abstractMethods,
finalMethods,
});
}
return ret;
}
private parseAliases(node: StructureNode | undefined, visibility: Visibility): InfoAlias[] {
if (node === undefined) {
return [];
}
const ret: InfoAlias[] = [];
for (const a of node.findAllStatements(Statements.Aliases)) {
const name = a.findFirstExpression(Expressions.SimpleName)!.getFirstToken();
const comp = a.findFirstExpression(Expressions.Field)!.getFirstToken();
ret.push({
name: name.getStr(),
identifier: new Identifier(name, this.filename),
visibility,
component: comp.getStr(),
});
}
return ret;
}
private parseConstants(node: StructureNode | undefined, visibility: Visibility): InfoConstant[] {
if (node === undefined) {
return [];
}
const results: InfoConstant[] = [];
for (const constant of node.findAllStatements(Statements.Constant)) {
const name = constant.findFirstExpression(Expressions.DefinitionName)!.getFirstToken();
const typeName = constant.findFirstExpression(Expressions.TypeName);
// VALUE `const_value` -> `const_value`
const literal = constant.findFirstExpression(Expressions.Value)?.getTokens()[1].getStr() ?? "``";
// `const_value` -> const_value
const value = literal.slice(1, literal?.length - 1);
results.push({
name: name!.getStr(),
typeName: typeName ? typeName.getFirstToken().getStr() : "",
value: value,
identifier: new Identifier(name, this.filename),
visibility,
});
}
return results;
}
private parseAttributes(node: StructureNode | undefined, visibility: Visibility): InfoAttribute[] {
if (node === undefined) {
return [];
}
const contents = node.findFirstStructure(Structures.SectionContents);
if (contents === undefined) {
return [];
}
const ret: InfoAttribute[] = [];
for (const d of contents.findDirectStatements(Statements.Data)) {
const name = d.findFirstExpression(Expressions.DefinitionName)!.getFirstToken();
ret.push({
name: name.getStr(),
identifier: new Identifier(name, this.filename),
level: AttributeLevel.Instance,
readOnly: d.concatTokens().toUpperCase().includes(" READ-ONLY"),
visibility,
});
}
for (const d of contents.findDirectStatements(Statements.ClassData)) {
const name = d.findFirstExpression(Expressions.DefinitionName)!.getFirstToken();
ret.push({
name: name.getStr(),
identifier: new Identifier(name, this.filename),
level: AttributeLevel.Static,
readOnly: d.concatTokens().toUpperCase().includes(" READ-ONLY"),
visibility,
});
}
for (const d of contents.findDirectStatements(Statements.Constant)) {
const name = d.findFirstExpression(Expressions.DefinitionName)!.getFirstToken();
ret.push({
name: name.getStr(),
identifier: new Identifier(name, this.filename),
level: AttributeLevel.Constant,
readOnly: true,
visibility,
});
}
return ret;
}
private parseMethodDefinition(node: StructureNode | undefined, visibility: Visibility): InfoMethodDefinition[] {
if (node === undefined) {
return [];
}
const methods: InfoMethodDefinition[] = [];
for (const def of node.findAllStatements(Statements.MethodDef)) {
const methodName = def.findDirectExpression(Expressions.MethodName)?.getFirstToken();
if (methodName === undefined) {
continue;
}
const parameters = this.parseMethodParameters(def);
methods.push({
name: methodName.getStr(),
identifier: new Identifier(methodName, this.filename),
isRedefinition: def.findDirectExpression(Expressions.Redefinition) !== undefined,
isForTesting: def.concatTokens().toUpperCase().includes(" FOR TESTING"),
isFinal: def.concatTokens().toUpperCase().includes(" FINAL"),
isAbstract: def.findDirectExpression(Expressions.Abstract) !== undefined,
isEventHandler: def.findDirectExpression(Expressions.EventHandler) !== undefined,
visibility,
parameters,
exceptions: [], // todo
});
}
return methods;
}
// todo, refactor this method, it is too long
private parseMethodParameters(node: StatementNode): InfoMethodParameter[] {
const ret: InfoMethodParameter[] = [];
const importing = node.findFirstExpression(Expressions.MethodDefImporting);
if (importing) {
for (const param of importing.findAllExpressions(Expressions.MethodParam)) {
const name = param.findDirectExpression(Expressions.MethodParamName)?.getFirstToken();
if (name) {
ret.push({
name: name.getStr().replace("!", ""),
identifier: new Identifier(name, this.filename),
direction: MethodParameterDirection.Importing,
});
}
}
}
const exporting = node.findFirstExpression(Expressions.MethodDefExporting);
if (exporting) {
for (const param of exporting.findAllExpressions(Expressions.MethodParam)) {
const name = param.findDirectExpression(Expressions.MethodParamName)?.getFirstToken();
if (name) {
ret.push({
name: name.getStr().replace("!", ""),
identifier: new Identifier(name, this.filename),
direction: MethodParameterDirection.Exporting,
});
}
}
}
const changing = node.findFirstExpression(Expressions.MethodDefChanging);
if (changing) {
for (const param of changing.findAllExpressions(Expressions.MethodParam)) {
const name = param.findDirectExpression(Expressions.MethodParamName)?.getFirstToken();
if (name) {
ret.push({
name: name.getStr().replace("!", ""),
identifier: new Identifier(name, this.filename),
direction: MethodParameterDirection.Changing,
});
}
}
}
const returning = node.findFirstExpression(Expressions.MethodDefReturning);
if (returning) {
const name = returning.findDirectExpression(Expressions.MethodParamName)?.getFirstToken();
if (name) {
ret.push({
name: name.getStr().replace("!", ""),
identifier: new Identifier(name, this.filename),
direction: MethodParameterDirection.Returning,
});
}
}
return ret;
}
}
|