/plugins/PHPParser/tags/PHPParser-1.3.2/src/net/sourceforge/phpdt/internal/compiler/ast/InclusionExpression.java

# · Java · 260 lines · 149 code · 50 blank · 61 comment · 5 complexity · 395890d2021bfa35fcc4d6be9cc12c16 MD5 · raw file

  1. /*
  2. * :tabSize=8:indentSize=8:noTabs=false:
  3. * :folding=explicit:collapseFolds=1:
  4. *
  5. * Copyright (C) 2003, 2009 Matthieu Casanova
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or any later version.
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. package net.sourceforge.phpdt.internal.compiler.ast;
  21. import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
  22. import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
  23. import java.util.List;
  24. import gatchan.phpparser.project.itemfinder.PHPItem;
  25. import gatchan.phpparser.parser.PHPParserConstants;
  26. import gatchan.phpparser.parser.PHPParser;
  27. import sidekick.IAsset;
  28. import javax.swing.text.Position;
  29. import javax.swing.*;
  30. /**
  31. * @author Matthieu Casanova
  32. */
  33. public class InclusionExpression extends Expression implements Outlineable, IAsset
  34. {
  35. private boolean silent;
  36. /**
  37. * The kind of include.
  38. */
  39. private final int keyword;
  40. private final Expression expression;
  41. private final transient Outlineable parent;
  42. private transient Position start;
  43. private transient Position end;
  44. private static transient Icon icon;
  45. private String cachedToString;
  46. //{{{ InclusionExpression constructor
  47. public InclusionExpression(Outlineable parent,
  48. int keyword,
  49. Expression expression,
  50. int sourceStart,
  51. int sourceEnd,
  52. int beginLine,
  53. int endLine,
  54. int beginColumn,
  55. int endColumn)
  56. {
  57. super(Type.INTEGER, sourceStart, sourceEnd, beginLine, endLine, beginColumn, endColumn);
  58. this.keyword = keyword;
  59. this.expression = expression;
  60. this.parent = parent;
  61. } //}}}
  62. //{{{ keywordToString() method
  63. private String keywordToString()
  64. {
  65. return PHPParserConstants.tokenImage[keyword];
  66. } //}}}
  67. //{{{ toStringExpression() method
  68. @Override
  69. public String toStringExpression()
  70. {
  71. return toString();
  72. } //}}}
  73. //{{{ toString() method
  74. public String toString()
  75. {
  76. if (cachedToString == null)
  77. {
  78. String keyword = keywordToString();
  79. keyword = keyword.substring(1, keyword.length() - 1);
  80. String expressionString = expression.toStringExpression();
  81. StringBuilder buffer = new StringBuilder(keyword.length() +
  82. expressionString.length() + 2);
  83. if (silent)
  84. {
  85. buffer.append('@');
  86. }
  87. buffer.append(keyword);
  88. buffer.append(' ');
  89. buffer.append(expressionString);
  90. cachedToString = buffer.toString();
  91. }
  92. return cachedToString;
  93. } //}}}
  94. //{{{ getParent() method
  95. public Outlineable getParent()
  96. {
  97. return parent;
  98. } //}}}
  99. //{{{ getOutsideVariable() method
  100. /**
  101. * Get the variables from outside (parameters, globals ...)
  102. *
  103. * @param list the list where we will put variables
  104. */
  105. @Override
  106. public void getOutsideVariable(List<VariableUsage> list)
  107. {
  108. expression.getOutsideVariable(list);
  109. } //}}}
  110. //{{{ getModifiedVariable() method
  111. /**
  112. * get the modified variables.
  113. *
  114. * @param list the list where we will put variables
  115. */
  116. @Override
  117. public void getModifiedVariable(List<VariableUsage> list)
  118. {
  119. expression.getModifiedVariable(list);
  120. } //}}}
  121. //{{{ getUsedVariable() method
  122. /**
  123. * Get the variables used.
  124. *
  125. * @param list the list where we will put variables
  126. */
  127. @Override
  128. public void getUsedVariable(List<VariableUsage> list)
  129. {
  130. expression.getUsedVariable(list);
  131. } //}}}
  132. //{{{ getName() method
  133. public String getName()
  134. {
  135. //todo : change this
  136. return null;
  137. } //}}}
  138. //{{{ getItemType() method
  139. public int getItemType()
  140. {
  141. return PHPItem.INCLUDE;
  142. } //}}}
  143. //{{{ getEnd() method
  144. public Position getEnd()
  145. {
  146. return end;
  147. } //}}}
  148. //{{{ setEnd() method
  149. public void setEnd(Position end)
  150. {
  151. this.end = end;
  152. } //}}}
  153. //{{{ getStart() method
  154. public Position getStart()
  155. {
  156. return start;
  157. } //}}}
  158. //{{{ setStart() method
  159. public void setStart(Position start)
  160. {
  161. this.start = start;
  162. } //}}}
  163. //{{{ getIcon() method
  164. public Icon getIcon()
  165. {
  166. if (icon == null)
  167. {
  168. icon = new ImageIcon(InclusionExpression.class.getResource("/gatchan/phpparser/icons/require.png"));
  169. }
  170. return icon;
  171. } //}}}
  172. //{{{ getShortString() method
  173. public String getShortString()
  174. {
  175. return toString();
  176. } //}}}
  177. //{{{ getLongString() method
  178. public String getLongString()
  179. {
  180. return toString();
  181. } //}}}
  182. //{{{ setName() method
  183. public void setName(String name)
  184. {
  185. } //}}}
  186. //{{{ expressionAt() method
  187. @Override
  188. public Expression expressionAt(int line, int column)
  189. {
  190. return expression.isAt(line, column) ? expression : null;
  191. } //}}}
  192. //{{{ analyzeCode() method
  193. @Override
  194. public void analyzeCode(PHPParser parser)
  195. {
  196. expression.analyzeCode(parser);
  197. } //}}}
  198. public boolean add(Outlineable o)
  199. {
  200. return false;
  201. }
  202. public Outlineable get(int index)
  203. {
  204. return null;
  205. }
  206. public int size()
  207. {
  208. return 0;
  209. }
  210. }