/plugins/PHPParser/trunk/src/net/sourceforge/phpdt/internal/compiler/ast/StringLiteral.java

# · Java · 107 lines · 71 code · 11 blank · 25 comment · 6 complexity · 6166f956a683a97842e353cbd2af443a MD5 · raw file

  1. /*
  2. * StringLiteral.java
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2003, 2009 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 java.util.List;
  23. import gatchan.phpparser.parser.Token;
  24. import gatchan.phpparser.parser.PHPParser;
  25. import net.sourceforge.phpdt.internal.compiler.ast.declarations.VariableUsage;
  26. public class StringLiteral extends Literal
  27. {
  28. private String source;
  29. private Expression[] expressions;
  30. public StringLiteral(Token token)
  31. {
  32. this(token.image,
  33. token.sourceStart,
  34. token.sourceEnd,
  35. token.beginLine,
  36. token.endLine,
  37. token.beginColumn,
  38. token.endColumn,
  39. null);
  40. }
  41. public StringLiteral(String source,
  42. int sourceStart,
  43. int sourceEnd,
  44. int beginLine,
  45. int endLine,
  46. int beginColumn,
  47. int endColumn)
  48. {
  49. this(source, sourceStart, sourceEnd, beginLine, endLine, beginColumn, endColumn, null);
  50. }
  51. public StringLiteral(String source,
  52. int sourceStart,
  53. int sourceEnd,
  54. int beginLine,
  55. int endLine,
  56. int beginColumn,
  57. int endColumn,
  58. Expression[] expressions)
  59. {
  60. super(Type.STRING, sourceStart, sourceEnd, beginLine, endLine, beginColumn, endColumn);
  61. this.source = source;
  62. this.expressions = expressions;
  63. }
  64. /**
  65. * Return the expression as String.
  66. *
  67. * @return the expression
  68. */
  69. @Override
  70. public String toStringExpression()
  71. {
  72. return source;
  73. }
  74. @Override
  75. public void getUsedVariable(List<VariableUsage> list)
  76. {
  77. if (expressions != null)
  78. {
  79. for (Expression expression : expressions)
  80. {
  81. expression.getUsedVariable(list);
  82. }
  83. }
  84. }
  85. @Override
  86. public void analyzeCode(PHPParser parser)
  87. {
  88. if (expressions != null)
  89. {
  90. for (Expression expression : expressions)
  91. {
  92. expression.analyzeCode(parser);
  93. }
  94. }
  95. }
  96. }