Represents a parameter in a method or constructor declaration. Parameters support optional type information (defaults to java.lang.Object if not specified), default values for optional parameters, and closure variable sharing. Parameters implement the Variable interface to integrate
| 33 | * @see ConstructorNode |
| 34 | */ |
| 35 | public class Parameter extends AnnotatedNode implements Variable { |
| 36 | |
| 37 | public static final Parameter[] EMPTY_ARRAY = {}; |
| 38 | |
| 39 | private ClassNode type; |
| 40 | private final String name; |
| 41 | private ClassNode originType; |
| 42 | private boolean dynamicTyped; |
| 43 | private boolean closureShare; |
| 44 | private Expression defaultValue; |
| 45 | private boolean hasDefaultValue; |
| 46 | private boolean inStaticContext; |
| 47 | private int modifiers; |
| 48 | |
| 49 | /** |
| 50 | * Creates a parameter with the specified type and name. |
| 51 | * |
| 52 | * @param type the {@link ClassNode} representing the parameter's type |
| 53 | * @param name the parameter name (never null) |
| 54 | */ |
| 55 | public Parameter(ClassNode type, String name) { |
| 56 | this.name = name; |
| 57 | this.setType(type); |
| 58 | this.originType = type; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Creates a parameter with a type, name, and default value expression. |
| 63 | * The parameter is marked as having a default value which makes it optional. |
| 64 | * |
| 65 | * @param type the {@link ClassNode} representing the parameter's type |
| 66 | * @param name the parameter name (never null) |
| 67 | * @param defaultValue an {@link Expression} providing the default value for this optional parameter |
| 68 | */ |
| 69 | public Parameter(ClassNode type, String name, Expression defaultValue) { |
| 70 | this(type, name); |
| 71 | this.setInitialExpression(defaultValue); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public String toString() { |
| 76 | return super.toString() + "[name: " + name + (type == null ? "" : ", type: " + type.toString(false)) + ", hasDefaultValue: " + this.hasInitialExpression() + "]"; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Returns the parameter name. |
| 81 | * |
| 82 | * @return the name of this parameter |
| 83 | */ |
| 84 | @Override |
| 85 | public String getName() { |
| 86 | return name; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Returns the type of this parameter. |
| 91 | * If the type has not been set, a dynamic type is returned. |
| 92 | * |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…