6e270c7b058ea1099ebb8cf777d35e4f291e5a60
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / FunctionCall.java
1 package net.sourceforge.phpdt.internal.compiler.ast;
2
3 import java.util.List;
4 import java.util.ArrayList;
5
6 /**
7  * A Function call.
8  * @author Matthieu Casanova
9  */
10 public class FunctionCall extends AbstractSuffixExpression {
11
12   /** the function name. */
13   public Expression functionName;
14
15   /** the arguments. */
16   public Expression[] args;
17
18   public FunctionCall(final Expression prefix,
19                       final Expression[] args,
20                       final int sourceEnd) {
21     super(prefix.sourceStart, sourceEnd);
22     this.functionName = prefix;
23     this.args = args;
24   }
25
26   /**
27    * Return the expression as String.
28    * @return the expression
29    */
30   public String toStringExpression() {
31     final StringBuffer buff = new StringBuffer(functionName.toStringExpression());
32     buff.append('(');
33     if (args != null) {
34       for (int i = 0; i < args.length; i++) {
35         final Expression arg = args[i];
36         if (i != 0) {
37           buff.append(',');
38         }
39         buff.append(arg.toStringExpression());
40       }
41     }
42     buff.append(')');
43     return buff.toString();
44   }
45
46   /**
47    * Get the variables from outside (parameters, globals ...)
48    * @return the variables from outside
49    */
50   public List getOutsideVariable() {
51     return new ArrayList(1);
52   }
53
54   /**
55    * get the modified variables.
56    * @return the variables from we change value
57    */
58   public List getModifiedVariable() {
59     if (args == null) {
60       return new ArrayList(1);
61     }
62     final ArrayList list = new ArrayList();
63     for (int i = 0; i < args.length; i++) {
64       list.addAll(args[i].getModifiedVariable());
65     }
66     return list;
67   }
68
69   /**
70    * Get the variables used.
71    * @return the variables used
72    */
73   public List getUsedVariable() {
74     final List list = functionName.getUsedVariable();
75     if (args != null) {
76       for (int i = 0; i < args.length; i++) {
77         list.addAll(args[i].getUsedVariable());
78       }
79     }
80     return list;
81   }
82 }