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

# · Java · 111 lines · 65 code · 18 blank · 28 comment · 3 complexity · 336971fd56a6f3bd3fe73d7e6a81a622 MD5 · raw file

  1. package net.sourceforge.phpdt.internal.compiler.ast.declarations;
  2. import net.sourceforge.phpdt.internal.compiler.ast.Type;
  3. /**
  4. * A variable usage. This describe a variable declaration in a php document and his starting offset
  5. *
  6. * @author Matthieu Casanova
  7. */
  8. public final class VariableUsage {
  9. /** the variable name. */
  10. private final String name;
  11. /** where the variable is declared. */
  12. private final int sourceStart;
  13. private final int sourceEnd;
  14. private final int beginLine;
  15. private final int endLine;
  16. private final int beginColumn;
  17. private final int endColumn;
  18. private final Type type;
  19. /**
  20. * create a VariableUsage.
  21. *
  22. * @param name the name of the variable
  23. * @param sourceStart the starting offset
  24. * @param sourceEnd the ending offset
  25. * @param beginLine begin line
  26. * @param endLine end line
  27. * @param beginColumn begin column
  28. * @param endColumn end column
  29. */
  30. public VariableUsage(Type type,
  31. String name,
  32. int sourceStart,
  33. int sourceEnd,
  34. int beginLine,
  35. int endLine,
  36. int beginColumn,
  37. int endColumn) {
  38. this.type = type;
  39. this.name = name;
  40. this.sourceStart = sourceStart;
  41. this.sourceEnd = sourceEnd;
  42. this.beginLine = beginLine;
  43. this.endLine = endLine;
  44. this.beginColumn = beginColumn;
  45. this.endColumn = endColumn;
  46. }
  47. public String toString() {
  48. return name + ' ' + sourceStart;
  49. }
  50. /**
  51. * Get the name of the variable.
  52. *
  53. * @return the name if the variable
  54. */
  55. public String getName() {
  56. return name;
  57. }
  58. /**
  59. * Get the starting offset.
  60. *
  61. * @return the starting offset
  62. */
  63. public int getSourceStart() {
  64. return sourceStart;
  65. }
  66. public int getBeginLine() {
  67. return beginLine;
  68. }
  69. public int getBeginColumn() {
  70. return beginColumn;
  71. }
  72. public int getSourceEnd() {
  73. return sourceEnd;
  74. }
  75. public int getEndLine() {
  76. return endLine;
  77. }
  78. public int getEndColumn() {
  79. return endColumn;
  80. }
  81. public boolean equals(Object object) {
  82. return name.equals(object);
  83. }
  84. public int hashCode() {
  85. return name.hashCode();
  86. }
  87. public Type getType() {
  88. return type;
  89. }
  90. public boolean isDeclaredBefore(VariableUsage variableUsage) {
  91. return (endLine < variableUsage.getEndLine()) || (endLine == variableUsage.getEndLine() && endColumn < variableUsage.getEndColumn());
  92. }
  93. }