/** * Finds a constructor matching the given parameters in this class. * * @return the constructor matching the given parameters or null */ public ConstructorNode getDeclaredConstructor(Parameter[] parameters) { for (ConstructorNode method : getDeclaredConstructors()) { if (parametersEqual(method.getParameters(), parameters)) { return method; } } return null; }
private void doAddConstructor(final ClassNode cNode, final ConstructorNode constructorNode) { cNode.addConstructor(constructorNode); // GROOVY-5814: Immutable is not compatible with @CompileStatic Parameter argsParam = null; for (Parameter p : constructorNode.getParameters()) { if ("args".equals(p.getName())) { argsParam = p; break; } } if (argsParam != null) { final Parameter arg = argsParam; ClassCodeVisitorSupport variableExpressionFix = new ClassCodeVisitorSupport() { @Override protected SourceUnit getSourceUnit() { return cNode.getModule().getContext(); } @Override public void visitVariableExpression(final VariableExpression expression) { super.visitVariableExpression(expression); if ("args".equals(expression.getName())) { expression.setAccessedVariable(arg); } } }; variableExpressionFix.visitConstructor(constructorNode); } }
public void addConstructor(ConstructorNode node) { node.setDeclaringClass(this); final ClassNode r = redirect(); if (r.constructors == null) r.constructors = new ArrayList<ConstructorNode>(); r.constructors.add(node); }