Martinho0330 / javaparser

Automatically exported from code.google.com/p/javaparser
0 stars 0 forks source link

add a constructor to the MethodDecleration class or any other class that has a List parameter to be passed #26

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

I just found it very annoying when I am constructing a new method that I
have to create a list of parameters and then pass it the constructor 

Here is an example: 
I want to create a setter method so I go like this:
Parameter p = new Parameter(field.getType(), new VariableDeclaratorId("id"));

List<Parameter> ps = new ArrayList<Parameter>();
ps.add(p);

MethodDeclaration setter = new MethodDeclaration(ModifierSet.PUBLIC, 
                                field.getType(), "setId", ps);

Instead I want to be able to do all that one line:
MethodDeclaration setter = new MethodDeclaration(ModifierSet.PUBLIC, 
                                field.getType(), "setId", new
Parameter(field.getType(), new VariableDeclaratorId("id"));

it simplify things a lot ..
So the signature of the constructor I am suggesting is this:
public MethodDeclaration(int modifiers, Type type, String name,
Parameter... parameters);

and the complete implementation would be something like this in the
MethodDeclaration class

public MethodDeclaration(int modifiers, Type type, String name,
Parameter... parameters) {
        this.modifiers = modifiers;
        this.type = type;
        this.name = name;
        this.parameters = Arrays.asList(parameters);
    }

 Thanks

Original issue reported on code.google.com by same%nan...@gtempaccount.com on 10 Oct 2009 at 8:27

GoogleCodeExporter commented 9 years ago

Original comment by jges...@gmail.com on 9 Nov 2009 at 11:27

GoogleCodeExporter commented 9 years ago

Original comment by jges...@gmail.com on 9 Nov 2009 at 11:31