Java Code Examples for org.codehaus.groovy.ast.stmt.BlockStatement#visit()
The following examples show how to use
org.codehaus.groovy.ast.stmt.BlockStatement#visit() .
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: UnknownElementsIndexer.java From bonita-studio with GNU General Public License v2.0 | 6 votes |
@Override protected IStatus run(final IProgressMonitor monitor) { monitor.beginTask("Computing unknonwn element...", IProgressMonitor.UNKNOWN); overridenVariables.clear(); unknownVaraibles.clear(); final BlockStatement statementBlock = groovyCompilationUnit.getModuleNode().getStatementBlock(); final VariablesVisitor variablesVisitor = new VariablesVisitor(statementBlock.getVariableScope()); statementBlock.visit(variablesVisitor); final Map<String, Position> declaredExpressions = variablesVisitor.getDeclaredExpressions(); Map<String, ScriptVariable> context = groovyCompilationUnit.getContext(); for (final String variable : variablesVisitor.getVariableExpressions()) { if (!context.containsKey(variable) && !declaredExpressions.keySet().contains(variable)) { addUnknownVaraible(variable); } } for (final Entry<String, Position> declaredVariable : declaredExpressions.entrySet()) { if (context.containsKey(declaredVariable.getKey())) { addOverridenVariable(declaredVariable); } } return Status.OK_STATUS; }
Example 3
Source File: AstUtil.java From powsybl-core with Mozilla Public License 2.0 | 5 votes |
public static String toString(BlockStatement blockStatement) { try (StringWriter writer = new StringWriter()) { blockStatement.visit(new AstNodeToScriptVisitor(writer)); writer.flush(); return writer.toString(); } catch (IOException e) { throw new UncheckedIOException(e); } }
Example 4
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 5
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(); }