2020/**
2121 * Statement block. taken from COMPOST and changed to achieve an immutable structure
2222 */
23-
2423public class StatementBlock extends JavaStatement implements StatementContainer ,
2524 TypeDeclarationContainer , VariableScope , TypeScope , ProgramPrefix {
2625
@@ -46,7 +45,6 @@ public StatementBlock() {
4645 *
4746 * @param children an ExtList that contains the children
4847 */
49-
5048 public StatementBlock (ExtList children ) {
5149 super (children );
5250 body = new ImmutableArray <>(children .collect (Statement .class ));
@@ -75,13 +73,32 @@ public StatementBlock(Statement... body) {
7573 }
7674
7775 @ Override
78- public boolean equalsModRenaming (SourceElement se , NameAbstractionTable nat ) {
79- return super .equalsModRenaming (se , nat )
80- && (this .getStartPosition ().equals (Position .UNDEFINED ) || // why do we care here
81- // about position info and
82- // nowhere else?
83- se .getStartPosition ().equals (Position .UNDEFINED )
84- || this .getStartPosition ().line () == se .getStartPosition ().line ());
76+ public boolean equals (Object o ) {
77+ if (o == this ) {
78+ return true ;
79+ }
80+ if (o == null || o .getClass () != this .getClass ()) {
81+ return false ;
82+ }
83+
84+ final JavaNonTerminalProgramElement jnte = (JavaNonTerminalProgramElement ) o ;
85+ if (jnte .getChildCount () != getChildCount ()) {
86+ return false ;
87+ }
88+
89+ for (int i = 0 , cc = getChildCount (); i < cc ; i ++) {
90+ if (!getChildAt (i ).equals (jnte .getChildAt (i ))) {
91+ return false ;
92+ }
93+ }
94+
95+ return (this .getStartPosition ().equals (Position .UNDEFINED ) || // why do we care here
96+ // about position info and
97+ // nowhere else?
98+ // We also care in
99+ // LoopStatement
100+ jnte .getStartPosition ().equals (Position .UNDEFINED )
101+ || this .getStartPosition ().line () == jnte .getStartPosition ().line ());
85102 }
86103
87104 /** computes the prefix elements for the given array of statment block */
@@ -98,14 +115,11 @@ public static ImmutableArray<ProgramPrefix> computePrefixElements(
98115 return new ImmutableArray <>(prefix );
99116 }
100117
101-
102-
103118 /**
104119 * Get body.
105120 *
106121 * @return the statement array wrapper.
107122 */
108-
109123 public ImmutableArray <? extends Statement > getBody () {
110124 return body ;
111125 }
@@ -114,13 +128,11 @@ public final boolean isEmpty() {
114128 return body .isEmpty ();
115129 }
116130
117-
118131 /**
119132 * Returns the number of children of this node.
120133 *
121134 * @return an int giving the number of children of this node
122135 */
123-
124136 public int getChildCount () {
125137 return body .size ();
126138 }
@@ -132,7 +144,6 @@ public int getChildCount() {
132144 * @return the program element at the given position
133145 * @exception ArrayIndexOutOfBoundsException if <tt>index</tt> is out of bounds
134146 */
135-
136147 public ProgramElement getChildAt (int index ) {
137148 if (body != null ) {
138149 return body .get (index );
@@ -145,12 +156,11 @@ public ProgramElement getChildAt(int index) {
145156 *
146157 * @return the number of statements.
147158 */
148-
149159 public int getStatementCount () {
150160 return body .size ();
151161 }
152162
153- /*
163+ /**
154164 * Return the statement at the specified index in this node's "virtual" statement array.
155165 *
156166 * @param index an index for a statement.
@@ -159,7 +169,6 @@ public int getStatementCount() {
159169 *
160170 * @exception ArrayIndexOutOfBoundsException if <tt>index</tt> is out of bounds.
161171 */
162-
163172 public Statement getStatementAt (int index ) {
164173 if (body != null ) {
165174 return body .get (index );
@@ -172,7 +181,6 @@ public Statement getStatementAt(int index) {
172181 *
173182 * @return the number of type declarations.
174183 */
175-
176184 public int getTypeDeclarationCount () {
177185 int count = 0 ;
178186 if (body != null ) {
@@ -185,7 +193,7 @@ public int getTypeDeclarationCount() {
185193 return count ;
186194 }
187195
188- /*
196+ /**
189197 * Return the type declaration at the specified index in this node's "virtual" type declaration
190198 * array.
191199 *
@@ -195,7 +203,6 @@ public int getTypeDeclarationCount() {
195203 *
196204 * @exception ArrayIndexOutOfBoundsException if <tt>index</tt> is out of bounds.
197205 */
198-
199206 public TypeDeclaration getTypeDeclarationAt (int index ) {
200207 if (body != null ) {
201208 int s = body .size ();
@@ -222,7 +229,6 @@ public void visit(Visitor v) {
222229 v .performActionOnStatementBlock (this );
223230 }
224231
225-
226232 public SourceElement getFirstElement () {
227233 if (isEmpty ()) {
228234 return this ;
@@ -240,7 +246,6 @@ public SourceElement getFirstElementIncludingBlocks() {
240246 }
241247 }
242248
243-
244249 @ Override
245250 public boolean hasNextPrefixElement () {
246251 return body .size () != 0 && (body .get (0 ) instanceof ProgramPrefix );
0 commit comments