package net.sourceforge.phpdt.internal.compiler.ast;
+
/**
* An argument declaration.
+ *
* @author Matthieu Casanova
*/
-public class ArgumentDeclaration extends VariableDeclaration {
+public final class ArgumentDeclaration extends VariableDeclaration {
- public boolean reference;
/**
* Create an argument.
+ *
+ * @param name the name
+ * @param reference the variable is a reference ?
* @param initialization the initialization
- * @param name the name
+ * @param sourceStart the start point
+ */
+ public ArgumentDeclaration(final Variable name,
+ final boolean reference,
+ final Expression initialization,
+ final int sourceStart) {
+ super(name, initialization, VariableDeclaration.EQUAL, sourceStart);
+ this.reference = reference;
+ }
+
+ /**
+ * Create an argument.
+ *
+ * @param name the name
+ * @param reference the variable is a reference ?
* @param sourceStart the start point
- * @param sourceEnd the end point
*/
- public ArgumentDeclaration(Expression initialization,
- char[] name,
- int sourceStart,
- int sourceEnd,
- boolean reference) {
- super(initialization,name, sourceStart, sourceEnd);
- this.reference = reference;
+ public ArgumentDeclaration(final Variable name,
+ final boolean reference,
+ final int sourceStart) {
+ super(name, sourceStart);
+ this.reference = reference;
+ }
+
+ /**
+ * Return the expression as String.
+ *
+ * @return the expression
+ */
+ public String toStringExpression() {
+ if (initialization == null) {
+ if (reference) {
+ return '&' + variable.toStringExpression();
+ } else {
+ return variable.toStringExpression();
+ }
+ } else {
+ final String variableString = variable.toStringExpression();
+ final String initializationString = initialization.toStringExpression();
+ final StringBuffer buff = new StringBuffer(4 +
+ variableString.length() +
+ initializationString.length());
+ if (reference) {
+ buff.append('&');
+ }
+ buff.append(variableString);
+ buff.append(" = ");
+ buff.append(initializationString);
+ return buff.toString();
+ }
}
}