use of org.codehaus.groovy.ast.Parameter in project groovy by apache.
the class AstBuilder method visitStandardLambdaParameters.
@Override
public Parameter[] visitStandardLambdaParameters(final StandardLambdaParametersContext ctx) {
if (asBoolean(ctx.variableDeclaratorId())) {
VariableExpression variable = this.visitVariableDeclaratorId(ctx.variableDeclaratorId());
Parameter parameter = new Parameter(ClassHelper.dynamicType(), variable.getName());
configureAST(parameter, variable);
return new Parameter[] { parameter };
}
Parameter[] parameters = this.visitFormalParameters(ctx.formalParameters());
return (parameters.length > 0 ? parameters : null);
}
use of org.codehaus.groovy.ast.Parameter in project groovy by apache.
the class AstBuilder method visitForStmtAlt.
@Override
public ForStatement visitForStmtAlt(final ForStmtAltContext ctx) {
Tuple2<Parameter, Expression> controlTuple = this.visitForControl(ctx.forControl());
Statement loopBlock = this.unpackStatement((Statement) this.visit(ctx.statement()));
return configureAST(new ForStatement(controlTuple.getV1(), controlTuple.getV2(), asBoolean(loopBlock) ? loopBlock : EmptyStatement.INSTANCE), ctx);
}
use of org.codehaus.groovy.ast.Parameter in project groovy by apache.
the class AstBuilder method visitMethodDeclaration.
@Override
public MethodNode visitMethodDeclaration(final MethodDeclarationContext ctx) {
ModifierManager modifierManager = createModifierManager(ctx);
if (modifierManager.containsAny(VAR)) {
throw createParsingFailedException("var cannot be used for method declarations", ctx);
}
String methodName = this.visitMethodName(ctx.methodName());
ClassNode returnType = this.visitReturnType(ctx.returnType());
Parameter[] parameters = this.visitFormalParameters(ctx.formalParameters());
ClassNode[] exceptions = this.visitQualifiedClassNameList(ctx.qualifiedClassNameList());
anonymousInnerClassesDefinedInMethodStack.push(new LinkedList<>());
Statement code = this.visitMethodBody(ctx.methodBody());
List<InnerClassNode> anonymousInnerClassList = anonymousInnerClassesDefinedInMethodStack.pop();
MethodNode methodNode;
// if classNode is not null, the method declaration is for class declaration
ClassNode classNode = ctx.getNodeMetaData(CLASS_DECLARATION_CLASS_NODE);
if (asBoolean(classNode)) {
validateParametersOfMethodDeclaration(parameters, classNode);
methodNode = createConstructorOrMethodNodeForClass(ctx, modifierManager, methodName, returnType, parameters, exceptions, code, classNode);
} else {
// script method declaration
methodNode = createScriptMethodNode(modifierManager, methodName, returnType, parameters, exceptions, code);
}
anonymousInnerClassList.forEach(e -> e.setEnclosingMethod(methodNode));
methodNode.setGenericsTypes(this.visitTypeParameters(ctx.typeParameters()));
methodNode.setSyntheticPublic(this.isSyntheticPublic(this.isAnnotationDeclaration(classNode), classNode instanceof EnumConstantClassNode, asBoolean(ctx.returnType()), modifierManager));
if (modifierManager.containsAny(STATIC)) {
for (Parameter parameter : methodNode.getParameters()) {
parameter.setInStaticContext(true);
}
methodNode.getVariableScope().setInStaticContext(true);
}
configureAST(methodNode, ctx);
validateMethodDeclaration(ctx, methodNode, modifierManager, classNode);
groovydocManager.handle(methodNode, ctx);
return methodNode;
}
use of org.codehaus.groovy.ast.Parameter in project groovy by apache.
the class AstBuilder method transformRecordHeaderToProperties.
private void transformRecordHeaderToProperties(ClassDeclarationContext ctx, ClassNode classNode) {
Parameter[] parameters = this.visitFormalParameters(ctx.formalParameters());
classNode.putNodeMetaData(RECORD_HEADER, parameters);
final int n = parameters.length;
for (int i = 0; i < n; i += 1) {
Parameter parameter = parameters[i];
FormalParameterContext parameterCtx = parameter.getNodeMetaData(PARAMETER_CONTEXT);
ModifierManager parameterModifierManager = parameter.getNodeMetaData(PARAMETER_MODIFIER_MANAGER);
ClassNode originType = parameter.getOriginType();
PropertyNode propertyNode = declareProperty(parameterCtx, parameterModifierManager, originType, classNode, i, parameter, parameter.getName(), parameter.getModifiers(), parameter.getInitialExpression());
propertyNode.getField().putNodeMetaData(IS_RECORD_GENERATED, Boolean.TRUE);
}
}
use of org.codehaus.groovy.ast.Parameter in project groovy by apache.
the class TryWithResourcesASTTransformation method createCatchBlockForOuterNewTryCatchStatement.
/*
* catch (Throwable #t) {
* #primaryExc = #t;
* throw #t;
* }
*
*/
private CatchStatement createCatchBlockForOuterNewTryCatchStatement(String primaryExcName) {
// { ... }
BlockStatement blockStatement = new BlockStatement();
String tExcName = this.genTExcName();
// #primaryExc = #t;
ExpressionStatement primaryExcAssignStatement = new ExpressionStatement(new BinaryExpression(new VariableExpression(primaryExcName), newSymbol(Types.ASSIGN, -1, -1), new VariableExpression(tExcName)));
astBuilder.appendStatementsToBlockStatement(blockStatement, primaryExcAssignStatement);
// throw #t;
ThrowStatement throwTExcStatement = new ThrowStatement(new VariableExpression(tExcName));
astBuilder.appendStatementsToBlockStatement(blockStatement, throwTExcStatement);
// Throwable #t
Parameter tExcParameter = new Parameter(ClassHelper.THROWABLE_TYPE.getPlainNodeReference(), tExcName);
return new CatchStatement(tExcParameter, blockStatement);
}
Aggregations