/plugins/PHPParser/tags/PHPParser-1.2.6/src/net/sourceforge/phpdt/internal/compiler/ast/ArrayVariableDeclaration.java

#
Java | 114 lines | 66 code | 14 blank | 34 comment | 13 complexity | fc9b964b6b8649f3f4114b588e46d15d MD5 | raw file

✨ Summary
  1. package net.sourceforge.phpdt.internal.compiler.ast;
  2. import gatchan.phpparser.parser.PHPParser;
  3. import java.util.List;
  4. /**
  5. * a variable declaration in an array().
  6. * it could take Expression as key.
  7. *
  8. * @author Matthieu Casanova
  9. */
  10. public final class ArrayVariableDeclaration extends Expression {
  11. /** the array key. */
  12. private final Expression key;
  13. /** the array value. */
  14. private Expression value;
  15. public ArrayVariableDeclaration(Expression key,
  16. Expression value,
  17. int sourceStart,
  18. int sourceEnd,
  19. int beginLine,
  20. int endLine,
  21. int beginColumn,
  22. int endColumn) {
  23. super(Type.UNKNOWN, sourceStart, sourceEnd, beginLine, endLine, beginColumn, endColumn);
  24. this.key = key;
  25. this.value = value;
  26. }
  27. /**
  28. * Create a new array variable declaration.
  29. *
  30. * @param key the key
  31. * @param sourceEnd the end position
  32. */
  33. public ArrayVariableDeclaration(Expression key,
  34. int sourceEnd,
  35. int beginLine,
  36. int endLine,
  37. int beginColumn,
  38. int endColumn) {
  39. super(Type.UNKNOWN, key.getSourceStart(), sourceEnd, beginLine, endLine, beginColumn, endColumn);
  40. this.key = key;
  41. }
  42. /**
  43. * Return the expression as String.
  44. *
  45. * @return the expression
  46. */
  47. public String toStringExpression() {
  48. if (value == null) {
  49. return key.toStringExpression();
  50. } else {
  51. String keyString = key.toStringExpression();
  52. String valueString = value.toStringExpression();
  53. StringBuffer buff = new StringBuffer(keyString.length() + valueString.length() + 3);
  54. buff.append(keyString);
  55. buff.append(" => ");
  56. buff.append(valueString);
  57. return buff.toString();
  58. }
  59. }
  60. /**
  61. * Get the variables from outside (parameters, globals ...)
  62. *
  63. * @param list the list where we will put variables
  64. */
  65. public void getOutsideVariable(List list) {
  66. }
  67. /**
  68. * get the modified variables.
  69. *
  70. * @param list the list where we will put variables
  71. */
  72. public void getModifiedVariable(List list) {
  73. key.getModifiedVariable(list);
  74. if (value != null) {
  75. value.getModifiedVariable(list);
  76. }
  77. }
  78. /**
  79. * Get the variables used.
  80. *
  81. * @param list the list where we will put variables
  82. */
  83. public void getUsedVariable(List list) {
  84. key.getUsedVariable(list);
  85. if (value != null) {
  86. value.getUsedVariable(list);
  87. }
  88. }
  89. public Expression expressionAt(int line, int column) {
  90. if (key.isAt(line, column)) return key;
  91. if (value != null && value.isAt(line, column)) return value;
  92. return null;
  93. }
  94. public void analyzeCode(PHPParser parser) {
  95. key.analyzeCode(parser);
  96. if (value != null) {
  97. value.analyzeCode(parser);
  98. }
  99. }
  100. }