org.codehaus.groovy.ast.ClassCodeExpressionTransformer Java Examples

The following examples show how to use org.codehaus.groovy.ast.ClassCodeExpressionTransformer. 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 vote down vote up
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: MapConstructorASTTransformation.java    From groovy with Apache License 2.0 6 votes vote down vote up
private static ClassCodeExpressionTransformer makeMapTypedArgsTransformer() {
    return new ClassCodeExpressionTransformer() {
        @Override
        public Expression transform(Expression exp) {
            if (exp instanceof ClosureExpression) {
                ClosureExpression ce = (ClosureExpression) exp;
                ce.getCode().visit(this);
            } else if (exp instanceof VariableExpression) {
                VariableExpression ve = (VariableExpression) exp;
                if ("args".equals(ve.getName()) && ve.getAccessedVariable() instanceof DynamicVariable) {
                    VariableExpression newVe = varX(param(MAP_TYPE, "args"));
                    newVe.setSourcePosition(ve);
                    return newVe;
                }
            }
            return exp.transformExpression(this);
        }

        @Override
        protected SourceUnit getSourceUnit() {
            return null;
        }
    };
}
 
Example #3
Source File: CalculatedTimeSeriesDslAstTransformation.java    From powsybl-core with Mozilla Public License 2.0 5 votes vote down vote up
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: ContextualClassCodeVisitor.java    From groovy with Apache License 2.0 5 votes vote down vote up
protected TreeContext popContext() {
    final TreeContext treeContext = treeContextStack.pop();
    List<TreeContextAction> actions = treeContext.getOnPopHandlers();
    for (TreeContextAction contextAction : actions) {
        contextAction.call(treeContext);
    }
    lastContext = treeContext;
    ASTNode parentNode = treeContext.parent!=null?treeContext.parent.node:null;
    if (treeContext.node instanceof Expression && parentNode !=null) {
        ClassCodeExpressionTransformer trn = new ClassCodeExpressionTransformer() {
            @Override
            protected SourceUnit getSourceUnit() {
                return null;
            }

            @Override
            public Expression transform(final Expression exp) {
                if (exp==treeContext.node) {
                    Expression replacement = treeContext.getReplacement();
                    if (replacement!=null) {
                        return replacement;
                    }
                }
                return super.transform(exp);
            }
        };
        // todo: reliable way to call the transformer
        //parentNode.visit(trn);
    }
    return treeContext;
}
 
Example #5
Source File: GroovyClassFilterTransformer.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public ClassCodeExpressionTransformer createVisitor(SourceUnit source, ClassNode clazz)
{
	return new Transformer(source, clazz);
}
 
Example #6
Source File: MacroClassTransformation.java    From groovy with Apache License 2.0 4 votes vote down vote up
@Override
protected GroovyCodeVisitor getTransformer(final ASTNode[] nodes, final SourceUnit sourceUnit) {
    ClassCodeExpressionTransformer transformer = new MacroClassTransformer(sourceUnit);

    return new MacroClassTransformingCodeVisitor(transformer, sourceUnit);
}
 
Example #7
Source File: MacroClassTransformation.java    From groovy with Apache License 2.0 4 votes vote down vote up
MacroClassTransformingCodeVisitor(ClassCodeExpressionTransformer transformer, SourceUnit sourceUnit) {
    super(transformer);
    this.sourceUnit = sourceUnit;
}