Skip to content

Commit 1c07358

Browse files
authored
Merge pull request #77 from IBM/1.0.6
Fix issue 76--symbol table is none.
2 parents 75944f1 + ff079c5 commit 1c07358

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/main/java/com/ibm/cldk/utils/AnalysisUtils.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.ibm.wala.ipa.cha.IClassHierarchy;
2525
import com.ibm.wala.ssa.IR;
2626
import com.ibm.wala.ssa.SSAConditionalBranchInstruction;
27+
import com.ibm.wala.ssa.SSASwitchInstruction;
2728
import com.ibm.wala.types.ClassLoaderReference;
2829

2930
import java.util.*;
@@ -86,16 +87,16 @@ public static Pair<String, Callable> createAndPutNewCallableInSymbolTable(IMetho
8687
* @return int Cyclomatic complexity for method/constructor
8788
*/
8889
public static int getCyclomaticComplexity(IR ir) {
89-
90-
try {
91-
int branchCount = (int)Arrays.stream(ir.getInstructions())
92-
.filter(inst -> inst instanceof SSAConditionalBranchInstruction)
93-
.count();
94-
return branchCount + 1;
95-
} catch (NullPointerException nullPointerException) {
96-
Log.error("Null pointer exception in getCyclomaticComplexity");
97-
throw new RuntimeException("Could not get cyclomatic complexity.");
90+
if (ir == null) {
91+
return 0;
9892
}
93+
int conditionalBranchCount = (int) Arrays.stream(ir.getInstructions())
94+
.filter(inst -> inst instanceof SSAConditionalBranchInstruction)
95+
.count();
96+
int switchBranchCount = Arrays.stream(ir.getInstructions())
97+
.filter(inst -> inst instanceof SSASwitchInstruction)
98+
.map(inst -> ((SSASwitchInstruction) inst).getCasesAndLabels().length).reduce(0, Integer::sum);
99+
return conditionalBranchCount + switchBranchCount + 1;
99100
}
100101

101102
public static Pair<String, Callable> getCallableFromSymbolTable(IMethod method) {

src/main/java/com/ibm/cldk/utils/BuildProject.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.nio.file.Files;
1010
import java.nio.file.Path;
1111
import java.nio.file.Paths;
12+
import java.util.ArrayList;
1213
import java.util.Arrays;
1314
import java.util.List;
1415

@@ -158,7 +159,7 @@ private static boolean buildProject(String projectPath, String build) {
158159
* @return true if the streaming was successful, false otherwise.
159160
*/
160161
public static List<Path> buildProjectAndStreamClassFiles(String projectPath, String build) throws IOException {
161-
return buildProject(projectPath, build) ? classFilesStream(projectPath) : null;
162+
return buildProject(projectPath, build) ? classFilesStream(projectPath) : new ArrayList<>();
162163
}
163164

164165
/**

0 commit comments

Comments
 (0)