Skip to content

Commit

Permalink
Merge pull request #77 from IBM/1.0.6
Browse files Browse the repository at this point in the history
Fix issue 76--symbol table is none.
  • Loading branch information
rahlk authored Nov 19, 2024
2 parents 75944f1 + ff079c5 commit 1c07358
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
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

0 comments on commit 1c07358

Please sign in to comment.