Skip to content

Commit 5599290

Browse files
committed
Fix quality flaw
1 parent 3e5fd73 commit 5599290

3 files changed

Lines changed: 14 additions & 16 deletions

File tree

java-squid/src/main/java/org/sonar/java/cfg/CFG.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ public class CFG {
9191
private Map<String, Block> labelsBreakTarget = Maps.newHashMap();
9292
private Map<String, Block> labelsContinueTarget = Maps.newHashMap();
9393

94+
private CFG(BlockTree tree, Symbol.MethodSymbol symbol) {
95+
methodSymbol = symbol;
96+
exitBlock = createBlock();
97+
currentBlock = createBlock(exitBlock);
98+
for (StatementTree statementTree : Lists.reverse(tree.body())) {
99+
build(statementTree);
100+
}
101+
prune();
102+
computePredecessors(blocks);
103+
}
104+
94105
public Symbol.MethodSymbol methodSymbol() {
95106
return methodSymbol;
96107
}
@@ -108,13 +119,13 @@ public List<Block> reversedBlocks() {
108119
}
109120

110121
public static class Block {
111-
112122
private int id;
113123
private final List<Tree> elements = new ArrayList<>();
114124
private final Set<Block> successors = new HashSet<>();
115125
private final Set<Block> predecessors = new HashSet<>();
116126
private Block trueBlock;
117127
private Block falseBlock;
128+
118129
private Tree terminator;
119130

120131
public Block(int id) {
@@ -184,7 +195,6 @@ public Tree terminator() {
184195
public boolean isInactive() {
185196
return terminator == null && elements.isEmpty();
186197
}
187-
188198
private void prune(Block inactiveBlock) {
189199
if (inactiveBlock.equals(trueBlock)) {
190200
if (inactiveBlock.successors.size() != 1) {
@@ -202,17 +212,7 @@ private void prune(Block inactiveBlock) {
202212
successors.addAll(inactiveBlock.successors);
203213
}
204214
}
205-
}
206215

207-
private CFG(BlockTree tree, Symbol.MethodSymbol symbol) {
208-
methodSymbol = symbol;
209-
exitBlock = createBlock();
210-
currentBlock = createBlock(exitBlock);
211-
for (StatementTree statementTree : Lists.reverse(tree.body())) {
212-
build(statementTree);
213-
}
214-
prune();
215-
computePredecessors(blocks);
216216
}
217217

218218
private static void computePredecessors(List<Block> blocks) {

java-squid/src/main/java/org/sonar/java/collections/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
@MethodsAreNonnullByDefault
2424
package org.sonar.java.collections;
2525

26-
import org.sonar.plugins.java.api.tree.MethodsAreNonnullByDefault;
26+
import org.sonar.plugins.java.api.tree.MethodsAreNonnullByDefault;

java-squid/src/main/java/org/sonar/java/se/ExplodedGraphWalker.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ private void execute(MethodTree tree) {
137137
// LIFO:
138138
node = workList.removeFirst();
139139
programPosition = node.programPoint;
140-
if (/* last */programPosition.block.successors().isEmpty()) {
141-
// not guaranteed that last block will be reached, e.g. "label: goto label;"
142-
// TODO(Godin): notify clients before continuing with another position
140+
if (programPosition.block.successors().isEmpty()) {
143141
continue;
144142
}
145143
programState = node.programState;

0 commit comments

Comments
 (0)