Skip to content
This repository was archived by the owner on Sep 14, 2023. It is now read-only.

Commit 558d68e

Browse files
committed
Deal with simple blocks
1 parent 249af6b commit 558d68e

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

src/main/java/jp/kusumotolab/kgenprog/analysis/DUChainDistanceVisitor.java

+75
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public boolean visit(SimpleName node) {
7575
if (isSwitchStatement(current.getParent())) {
7676
distance += ((SwitchStatement) current.getParent()).statements()
7777
.indexOf(current) + 1;
78+
} else if (isSimpleBlock(current.getParent())) {
79+
final Block parentBlock = (Block) current.getParent();
80+
distance += parentBlock.statements()
81+
.indexOf(current) + 1;
7882
} else if (isBlockStatement(current.getParent())) {
7983
final Block parentBlock = (Block) current.getParent();
8084
distance += parentBlock.statements()
@@ -138,6 +142,10 @@ private boolean isSwitchStatement(ASTNode node) {
138142
return node.getNodeType() == ASTNode.SWITCH_STATEMENT;
139143
}
140144

145+
private boolean isSimpleBlock(final ASTNode node) {
146+
return isBlockStatement(node) && isBlockStatement(node.getParent());
147+
}
148+
141149
private boolean isBlockStatement(ASTNode node) {
142150
return node.getNodeType() == ASTNode.BLOCK;
143151
}
@@ -183,4 +191,71 @@ private boolean isStatement(ASTNode node) {
183191
}
184192
}
185193

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+
// }
186261
}

0 commit comments

Comments
 (0)