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

#
Java | 160 lines | 88 code | 14 blank | 58 comment | 12 complexity | 71cbb84023b40b263b526dffcd6b3305 MD5 | raw file

✨ Summary
  1. /*
  2. * ArrayVariableDeclaration.java
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2003, 2010 Matthieu Casanova
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or any later version.
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. */
  21. package net.sourceforge.phpdt.internal.compiler.ast;
  22. import gatchan.phpparser.parser.PHPParser;
  23. import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
  24. import java.util.List;
  25. /**
  26. * a variable declaration in an array().
  27. * it could take Expression as key.
  28. *
  29. * @author Matthieu Casanova
  30. */
  31. public class ArrayVariableDeclaration extends Expression
  32. {
  33. /**
  34. * the array key.
  35. */
  36. private final Expression key;
  37. /**
  38. * the array value.
  39. */
  40. private Expression value;
  41. public ArrayVariableDeclaration(Expression key,
  42. Expression value,
  43. int sourceStart,
  44. int sourceEnd,
  45. int beginLine,
  46. int endLine,
  47. int beginColumn,
  48. int endColumn)
  49. {
  50. super(Type.UNKNOWN, sourceStart, sourceEnd, beginLine, endLine, beginColumn, endColumn);
  51. this.key = key;
  52. this.value = value;
  53. }
  54. /**
  55. * Create a new array variable declaration.
  56. *
  57. * @param key the key
  58. * @param sourceEnd the end position
  59. */
  60. public ArrayVariableDeclaration(Expression key,
  61. int sourceEnd,
  62. int beginLine,
  63. int endLine,
  64. int beginColumn,
  65. int endColumn)
  66. {
  67. super(Type.UNKNOWN, key.getSourceStart(), sourceEnd, beginLine, endLine, beginColumn, endColumn);
  68. this.key = key;
  69. }
  70. /**
  71. * Return the expression as String.
  72. *
  73. * @return the expression
  74. */
  75. @Override
  76. public String toStringExpression()
  77. {
  78. if (value == null)
  79. {
  80. return key.toStringExpression();
  81. }
  82. else
  83. {
  84. String keyString = key.toStringExpression();
  85. String valueString = value.toStringExpression();
  86. StringBuilder buff = new StringBuilder(keyString.length() + valueString.length() + 3);
  87. buff.append(keyString);
  88. buff.append(" => ");
  89. buff.append(valueString);
  90. return buff.toString();
  91. }
  92. }
  93. /**
  94. * Get the variables from outside (parameters, globals ...)
  95. *
  96. * @param list the list where we will put variables
  97. */
  98. @Override
  99. public void getOutsideVariable(List<VariableUsage> list)
  100. {
  101. }
  102. /**
  103. * get the modified variables.
  104. *
  105. * @param list the list where we will put variables
  106. */
  107. @Override
  108. public void getModifiedVariable(List<VariableUsage> list)
  109. {
  110. key.getModifiedVariable(list);
  111. if (value != null)
  112. {
  113. value.getModifiedVariable(list);
  114. }
  115. }
  116. /**
  117. * Get the variables used.
  118. *
  119. * @param list the list where we will put variables
  120. */
  121. @Override
  122. public void getUsedVariable(List<VariableUsage> list)
  123. {
  124. key.getUsedVariable(list);
  125. if (value != null)
  126. {
  127. value.getUsedVariable(list);
  128. }
  129. }
  130. @Override
  131. public Expression expressionAt(int line, int column)
  132. {
  133. if (key.isAt(line, column)) return key;
  134. if (value != null && value.isAt(line, column)) return value;
  135. return null;
  136. }
  137. @Override
  138. public void analyzeCode(PHPParser parser)
  139. {
  140. key.analyzeCode(parser);
  141. if (value != null)
  142. {
  143. value.analyzeCode(parser);
  144. }
  145. }
  146. }