The Java AST library is used by Blueprint engine plugins. Node.js plugins use different methods for code generation as detailed in the Node.js Plugin Events documentation.
The Java AST library provides functionality for generating Java code through an abstract syntax tree in the Amplication platform. It enables the creation of type-safe, well-structured Java code.
The Java AST library is not intended to cover all Java language functionality. Instead, it focuses on the elements needed to create foundation and boilerplate code with Amplication plugins. The library provides building blocks for generating well-structured Java code for common patterns and use cases.When more specialized or custom code is needed, the CodeBlock class can be used as a generic node that can include any code as a string:
Copy
import { CodeBlock } from '@amplication/java-ast';// Create a custom code block for specialized logicconst customLogic = new CodeBlock(` // Custom Java implementation try (BufferedReader reader = new BufferedReader(new FileReader(file))) { String line; while ((line = reader.readLine()) != null) { processLine(line); } } catch (IOException e) { logger.error("Error reading file", e); }`);// Add to your class or method
This flexibility allows you to generate both structured AST-based code and custom code blocks when necessary.