/plugins/PHPParser/tags/PHPParser-1.2.4/src/net/sourceforge/phpdt/internal/compiler/ast/FieldDeclaration.java

#
Java | 248 lines | 154 code | 35 blank | 59 comment | 7 complexity | 53930f47734d5cd2b94906a95e9a8e21 MD5 | raw file

✨ Summary
  1. package net.sourceforge.phpdt.internal.compiler.ast;
  2. import gatchan.phpparser.parser.PHPParser;
  3. import gatchan.phpparser.project.itemfinder.PHPItem;
  4. import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
  5. import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
  6. import org.gjt.sp.jedit.GUIUtilities;
  7. import sidekick.IAsset;
  8. import javax.swing.*;
  9. import javax.swing.text.Position;
  10. import java.util.List;
  11. /**
  12. * A Field declaration. This is a variable declaration for a php class In fact it's an array of VariableUsage, since a
  13. * field could contains several var : var $toto,$tata;
  14. *
  15. * @author Matthieu Casanova
  16. */
  17. public class FieldDeclaration extends Statement implements Outlineable, PHPItem, IAsset
  18. {
  19. private List modifiers;
  20. /** The path of the file containing this field. */
  21. private String path;
  22. /** The variables. */
  23. private final VariableDeclaration variable;
  24. private String nameLowerCase;
  25. /** The parent do not need to be serialized. */
  26. private final transient OutlineableWithChildren parent;
  27. private static transient Icon icon;
  28. private transient Position start;
  29. private transient Position end;
  30. private transient String cachedToString;
  31. private static final long serialVersionUID = 1573325853305553911L;
  32. /**
  33. * Create a field. with public visibility
  34. *
  35. * @param path the path
  36. * @param variable the variable of the field
  37. * @param parent the parent class
  38. * @param sourceStart the sourceStart
  39. * @param sourceEnd source end
  40. * @param beginLine begin line
  41. * @param endLine end line
  42. * @param beginColumn begin column
  43. * @param endColumn end column
  44. */
  45. public FieldDeclaration(String path,
  46. VariableDeclaration variable,
  47. OutlineableWithChildren parent,
  48. int sourceStart,
  49. int sourceEnd,
  50. int beginLine,
  51. int endLine,
  52. int beginColumn,
  53. int endColumn)
  54. {
  55. this(null,
  56. path,
  57. variable,
  58. parent,
  59. sourceStart,
  60. sourceEnd,
  61. beginLine,
  62. endLine,
  63. beginColumn,
  64. endColumn);
  65. }
  66. /**
  67. * Create a field.
  68. *
  69. * @param modifiers a list of {@link Modifier}
  70. * @param path the path
  71. * @param variable the variable of the field
  72. * @param parent the parent class
  73. * @param sourceStart the sourceStart
  74. * @param sourceEnd source end
  75. * @param beginLine begin line
  76. * @param endLine end line
  77. * @param beginColumn begin column
  78. * @param endColumn end column
  79. */
  80. public FieldDeclaration(List modifiers,
  81. String path,
  82. VariableDeclaration variable,
  83. OutlineableWithChildren parent,
  84. int sourceStart,
  85. int sourceEnd,
  86. int beginLine,
  87. int endLine,
  88. int beginColumn,
  89. int endColumn)
  90. {
  91. super(sourceStart, sourceEnd, beginLine, endLine, beginColumn, endColumn);
  92. this.modifiers = modifiers;
  93. this.path = path;
  94. this.variable = variable;
  95. this.parent = parent;
  96. }
  97. /**
  98. * Return the object into String.
  99. *
  100. * @param tab how many tabs (not used here
  101. * @return a String
  102. */
  103. public String toString(int tab)
  104. {
  105. // todo : rewrite tostring method
  106. StringBuffer buff = new StringBuffer(tabString(tab));
  107. buff.append("var ");
  108. buff.append(variable.toStringExpression());
  109. return buff.toString();
  110. }
  111. public String toString()
  112. {
  113. return getName();
  114. }
  115. public OutlineableWithChildren getParent()
  116. {
  117. return parent;
  118. }
  119. /**
  120. * Get the variables from outside (parameters, globals ...)
  121. *
  122. * @param list the list where we will put variables
  123. */
  124. public void getOutsideVariable(List list)
  125. {
  126. }
  127. /**
  128. * get the modified variables.
  129. *
  130. * @param list the list where we will put variables
  131. */
  132. public void getModifiedVariable(List list)
  133. {
  134. }
  135. /**
  136. * Get the variables used.
  137. *
  138. * @param list the list where we will put variables
  139. */
  140. public void getUsedVariable(List list)
  141. {
  142. }
  143. public String getName()
  144. {
  145. if (cachedToString == null)
  146. {
  147. cachedToString = variable.getName();
  148. }
  149. return cachedToString;
  150. }
  151. public String getNameLowerCase()
  152. {
  153. if (nameLowerCase == null)
  154. {
  155. nameLowerCase = variable.getName().toLowerCase();
  156. }
  157. return nameLowerCase;
  158. }
  159. public int getItemType()
  160. {
  161. return FIELD;
  162. }
  163. public String getPath()
  164. {
  165. return path;
  166. }
  167. public Icon getIcon()
  168. {
  169. if (icon == null)
  170. icon = GUIUtilities.loadIcon(ClassHeader.class.getResource("/gatchan/phpparser/icons/field.png").toString());
  171. return icon;
  172. }
  173. public VariableDeclaration getVariable()
  174. {
  175. return variable;
  176. }
  177. public Position getStart()
  178. {
  179. return start;
  180. }
  181. public void setStart(Position start)
  182. {
  183. this.start = start;
  184. }
  185. public Position getEnd()
  186. {
  187. return end;
  188. }
  189. public void setEnd(Position end)
  190. {
  191. this.end = end;
  192. }
  193. public String getShortString()
  194. {
  195. return toString();
  196. }
  197. public String getLongString()
  198. {
  199. return toString();
  200. }
  201. public void setName(String name)
  202. {
  203. }
  204. public Expression expressionAt(int line, int column)
  205. {
  206. if (variable.isAt(line, column)) return variable.expressionAt(line, column);
  207. return null;
  208. }
  209. public void analyzeCode(PHPParser parser)
  210. {
  211. // variable.analyzeCode(parser); no need VariableDeclaration is not used
  212. }
  213. }