Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/main/java/com/ibm/cldk/utils/AnalysisUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.ibm.wala.ipa.cha.IClassHierarchy;
import com.ibm.wala.ssa.IR;
import com.ibm.wala.ssa.SSAConditionalBranchInstruction;
import com.ibm.wala.ssa.SSASwitchInstruction;
import com.ibm.wala.types.ClassLoaderReference;

import java.util.*;
Expand Down Expand Up @@ -86,16 +87,16 @@ public static Pair<String, Callable> createAndPutNewCallableInSymbolTable(IMetho
* @return int Cyclomatic complexity for method/constructor
*/
public static int getCyclomaticComplexity(IR ir) {

try {
int branchCount = (int)Arrays.stream(ir.getInstructions())
.filter(inst -> inst instanceof SSAConditionalBranchInstruction)
.count();
return branchCount + 1;
} catch (NullPointerException nullPointerException) {
Log.error("Null pointer exception in getCyclomaticComplexity");
throw new RuntimeException("Could not get cyclomatic complexity.");
if (ir == null) {
return 0;
}
int conditionalBranchCount = (int) Arrays.stream(ir.getInstructions())
.filter(inst -> inst instanceof SSAConditionalBranchInstruction)
.count();
int switchBranchCount = Arrays.stream(ir.getInstructions())
.filter(inst -> inst instanceof SSASwitchInstruction)
.map(inst -> ((SSASwitchInstruction) inst).getCasesAndLabels().length).reduce(0, Integer::sum);
return conditionalBranchCount + switchBranchCount + 1;
}

public static Pair<String, Callable> getCallableFromSymbolTable(IMethod method) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/ibm/cldk/utils/BuildProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

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

/**
Expand Down