UNPKG

java2ib

Version:

TypeScript library that converts Java code into IB Computer Science pseudocode format

122 lines 4.04 kB
/** * Main converter class for Java to IB Pseudocode conversion * * This class provides the primary interface for converting Java source code * into IB Computer Science pseudocode format according to the official IB specification. * * @example * ```typescript * import { JavaToIBConverter } from 'java-to-ib-pseudocode'; * * const converter = new JavaToIBConverter(); * const result = converter.convert('int x = 5;'); * console.log(result.pseudocode); // Output: X = 5 * ``` * * @example * ```typescript * // Convert a method with options * const options = { preserveComments: true, indentSize: 2 }; * const result = converter.convert(` * public int add(int a, int b) { * return a + b; * } * `, options); * ``` */ import { ConversionOptions, ConversionResult } from './types'; /** * The main converter class that handles Java to IB pseudocode conversion. * * This class orchestrates the entire conversion process through a multi-stage pipeline: * 1. Lexical analysis (tokenization) * 2. Parsing (AST generation) * 3. AST transformation (applying IB rules) * 4. Code generation (producing formatted pseudocode) * * The converter is designed to be stateless and thread-safe, allowing multiple * conversions to be performed concurrently. */ export declare class JavaToIBConverter { private transformer; private ibRules; private generatorCache; private lexerPool; private maxPoolSize; /** * Creates a new JavaToIBConverter instance. * * The constructor initializes the internal components needed for conversion: * - IBRulesEngine for applying IB pseudocode formatting rules * - ASTTransformer for converting Java AST nodes to pseudocode format */ constructor(); /** * Convert Java code to IB pseudocode format. * * This method performs the complete conversion process from Java source code * to IB Computer Science pseudocode format. The conversion follows the official * IB specification for pseudocode syntax and formatting. * * @param javaCode - The Java source code to convert. Must be valid Java syntax. * @param options - Optional conversion settings to customize the output format. * @returns A ConversionResult object containing the converted pseudocode, * success status, any errors or warnings, and conversion metadata. * * @example * ```typescript * // Basic conversion * const result = converter.convert('int x = 10;'); * if (result.success) { * console.log(result.pseudocode); // "X = 10" * } * ``` * * @example * ```typescript * // Conversion with options * const options = { preserveComments: true, indentSize: 2 }; * const result = converter.convert(` * // Calculate area * public int calculateArea(int width, int height) { * return width * height; * } * `, options); * ``` * * @example * ```typescript * // Error handling * const result = converter.convert('invalid java code'); * if (!result.success) { * result.errors.forEach(error => { * console.error(`${error.type}: ${error.message} at line ${error.location.line}`); * }); * } * ``` */ convert(javaCode: string, options?: ConversionOptions): ConversionResult; private createErrorResult; private enhanceErrorMessage; /** * Performance optimization: Efficiently count lines without creating array */ private countLines; /** * Performance optimization: Get a lexer from the pool or create new one */ private getLexer; /** * Performance optimization: Return lexer to pool for reuse */ private returnLexer; /** * Performance optimization: Get cached generator or create new one */ private getGenerator; /** * Count the total number of AST nodes recursively */ private countASTNodes; } //# sourceMappingURL=converter.d.ts.map