Skip to content

Instantly share code, notes, and snippets.

@masud-technope
Created July 12, 2022 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masud-technope/4c31119dffbd6ca4075b8c8b31db612f to your computer and use it in GitHub Desktop.
Save masud-technope/4c31119dffbd6ca4075b8c8b31db612f to your computer and use it in GitHub Desktop.
public void collectSourceTermStatsCRCCExt(String itemType) {
ArrayList<String> allTokens = new ArrayList<>();
ArrayList<String> srcFiles = new ArrayList<>();
for (String fileURL : this.results) {
// avoid other files than Java
if (!fileURL.endsWith(".java"))
continue;
String fileName = new File(fileURL).getName();
// String activeURL = this.repoFolder + "/" + fileName;
int index = Integer.parseInt(fileName.split("\\.")[0]);
// System.out.println("Index:"+index);
// direct URL used
String srcFile = this.repoFolder + "/" + index + ".java";
if (itemType.equals("all")) {
ArrayList<String> fileTokens = ContentLoader.getAllTokens(srcFile);
allTokens.addAll(fileTokens);
} else {
try {
CompilationUnit cu = JavaParser.parse(new File(srcFile));
if (cu != null) {
MethodVisitor mv = new MethodVisitor();
cu.accept(mv, null);
switch (itemType) {
case "mpf":
if (!mv.methodSigs.isEmpty()) {
allTokens.addAll(mv.methodSigs);
methodSigs.addAll(mv.methodSigs);
}
for (String key : mv.paramMap.keySet()) {
ArrayList<String> params = mv.paramMap.get(key);
if (!params.isEmpty()) {
allTokens.addAll(params);
methodSigs.addAll(params);
}
}
if (!mv.fieldSigs.isEmpty()) {
allTokens.addAll(mv.fieldSigs);
fieldSigs.addAll(mv.fieldSigs);
}
break;
case "c":
if (!mv.classes.isEmpty()) {
allTokens.addAll(mv.classes);
methodSigs.addAll(mv.classes);
}
break;
default:
break;
}
}
} catch (Exception exc) {
// handle the exception
// exc.printStackTrace();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment