@@ -75,6 +75,10 @@ public boolean visit(SimpleName node) {
75
75
if (isSwitchStatement (current .getParent ())) {
76
76
distance += ((SwitchStatement ) current .getParent ()).statements ()
77
77
.indexOf (current ) + 1 ;
78
+ } else if (isSimpleBlock (current .getParent ())) {
79
+ final Block parentBlock = (Block ) current .getParent ();
80
+ distance += parentBlock .statements ()
81
+ .indexOf (current ) + 1 ;
78
82
} else if (isBlockStatement (current .getParent ())) {
79
83
final Block parentBlock = (Block ) current .getParent ();
80
84
distance += parentBlock .statements ()
@@ -138,6 +142,10 @@ private boolean isSwitchStatement(ASTNode node) {
138
142
return node .getNodeType () == ASTNode .SWITCH_STATEMENT ;
139
143
}
140
144
145
+ private boolean isSimpleBlock (final ASTNode node ) {
146
+ return isBlockStatement (node ) && isBlockStatement (node .getParent ());
147
+ }
148
+
141
149
private boolean isBlockStatement (ASTNode node ) {
142
150
return node .getNodeType () == ASTNode .BLOCK ;
143
151
}
@@ -183,4 +191,71 @@ private boolean isStatement(ASTNode node) {
183
191
}
184
192
}
185
193
194
+ // private List<Statement> getStatements(final ASTNode complexStatement) {
195
+ // if (isSwitchStatement(complexStatement)) {
196
+ // return ((SwitchStatement) complexStatement).statements();
197
+ // }
198
+ //
199
+ // if (isDoStatement(complexStatement)) {
200
+ // final Statement body = ((DoStatement) complexStatement).getBody();
201
+ // return getStatementsFromBody(body);
202
+ // }
203
+ //
204
+ // if (isEnhancedForStatement(complexStatement)) {
205
+ // final Statement body = ((EnhancedForStatement) complexStatement).getBody();
206
+ // return getStatementsFromBody(body);
207
+ // }
208
+ //
209
+ // if (isForStatemen(complexStatement)) {
210
+ // final Statement body = ((ForStatement) complexStatement).getBody();
211
+ // return getStatementsFromBody(body);
212
+ // }
213
+ //
214
+ // if (isIfStatement(complexStatement)) {
215
+ // final Statement body = ((IfStatement) complexStatement).getThenStatement();
216
+ // return getStatementsFromBody(body);
217
+ // }
218
+ //
219
+ // if (isTryStatement(complexStatement)) {
220
+ // final Statement body = ((TryStatement) complexStatement).getBody();
221
+ // return getStatementsFromBody(body);
222
+ // }
223
+ //
224
+ // if (isWhileStatement(complexStatement)) {
225
+ // final Statement body = ((WhileStatement) complexStatement).getBody();
226
+ // return getStatementsFromBody(body);
227
+ // }
228
+ //
229
+ // throw new IllegalStateException(
230
+ // "this node does not have statements: " + complexStatement.toString());
231
+ // }
232
+ //
233
+ // private List<Statement> getStatementsFromBody(Statement body) {
234
+ // return isBlockStatement(body) ? ((Block) body).statements()
235
+ // : ImmutableList.of(body);
236
+ // }
237
+ //
238
+ // private boolean isDoStatement(final ASTNode node) {
239
+ // return node.getNodeType() == ASTNode.DO_STATEMENT;
240
+ // }
241
+ //
242
+ // private boolean isEnhancedForStatement(final ASTNode node) {
243
+ // return node.getNodeType() == ASTNode.ENHANCED_FOR_STATEMENT;
244
+ // }
245
+ //
246
+ // private boolean isForStatemen(final ASTNode node) {
247
+ // return node.getNodeType() == ASTNode.FOR_STATEMENT;
248
+ // }
249
+ //
250
+ // private boolean isIfStatement(final ASTNode node) {
251
+ // return node.getNodeType() == ASTNode.IF_STATEMENT;
252
+ // }
253
+ //
254
+ // private boolean isTryStatement(final ASTNode node) {
255
+ // return node.getNodeType() == ASTNode.TRY_STATEMENT;
256
+ // }
257
+ //
258
+ // private boolean isWhileStatement(final ASTNode node) {
259
+ // return node.getNodeType() == ASTNode.WHILE_STATEMENT;
260
+ // }
186
261
}
0 commit comments