Java Code Examples for org.codehaus.groovy.ast.ModuleNode#getStatementBlock()
The following examples show how to use
org.codehaus.groovy.ast.ModuleNode#getStatementBlock() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PowsyblDslAstTransformation.java From powsybl-core with Mozilla Public License 2.0 | 6 votes |
protected void visit(SourceUnit sourceUnit, ClassCodeExpressionTransformer transformer) { LOGGER.trace("Apply AST transformation"); ModuleNode ast = sourceUnit.getAST(); BlockStatement blockStatement = ast.getStatementBlock(); if (DEBUG) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(AstUtil.toString(blockStatement)); } } List<MethodNode> methods = ast.getMethods(); for (MethodNode methodNode : methods) { methodNode.getCode().visit(transformer); } blockStatement.visit(transformer); if (DEBUG) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(AstUtil.toString(blockStatement)); } } }
Example 2
Source File: AstUtilTest.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
@Override public void visit(ASTNode[] astNodes, SourceUnit sourceUnit) { ModuleNode ast = sourceUnit.getAST(); BlockStatement blockStatement = ast.getStatementBlock(); String ref = "this.print('hello')\n"; // AstNodeToScriptVisitor has hardcoded \n assertEquals(ref, AstUtil.toString(blockStatement)); }
Example 3
Source File: CalculatedTimeSeriesDslAstTransformation.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
protected void visit(SourceUnit sourceUnit, ClassCodeExpressionTransformer transformer, boolean debug) { LOGGER.trace("Apply AST transformation"); ModuleNode ast = sourceUnit.getAST(); BlockStatement blockStatement = ast.getStatementBlock(); List<MethodNode> methods = ast.getMethods(); for (MethodNode methodNode : methods) { methodNode.getCode().visit(transformer); } blockStatement.visit(transformer); }
Example 4
Source File: GroovyCompilationOnScriptExpressionConstraint.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
private IStatus evaluateExpression(final IValidationContext context, final EObject eObj) { final Expression expression = (Expression) eObj; final String scriptText = expression.getContent(); if (scriptText == null || scriptText.isEmpty()) { return context.createSuccessStatus(); } final IJavaProject javaProject = RepositoryManager.getInstance().getCurrentRepository().getJavaProject(); final GroovySnippetCompiler compiler = new GroovySnippetCompiler((JavaProject) javaProject); final CompilationResult result = compiler.compileForErrors(scriptText, null); final CategorizedProblem[] problems = result.getErrors(); if (problems != null && problems.length > 0) { final StringBuilder sb = new StringBuilder(); for (final CategorizedProblem problem : problems) { sb.append(problem.getMessage()); sb.append(", "); } if (sb.length() > 1) { sb.delete(sb.length() - 2, sb.length()); return context.createFailureStatus(new Object[] { Messages.bind(Messages.groovyCompilationProblem, expression.getName(), sb.toString()) }); } } final ModuleNode moduleNode = compiler.compile(scriptText, null); final BlockStatement statementBlock = moduleNode.getStatementBlock(); final ValidationCodeVisitorSupport validationCodeVisitorSupport = new ValidationCodeVisitorSupport(context, expression, moduleNode); statementBlock.visit(validationCodeVisitorSupport); return validationCodeVisitorSupport.getStatus(); }