Skip to content

Commit 42f1148

Browse files
hyphzanatolystansler
authored andcommitted
feat: kotlint and some extra language extensions (#227)
* Prevents a null exception error when starting up on Windows caused by the pathname beginning with a drive letter. * Kotlint and some extra language file extensions * Update Logger.kt * Fit in 80 columns * Update CommonExtractor.kt Removed .PRO files for Visual Prolog
1 parent 040517d commit 42f1148

File tree

8 files changed

+133
-123
lines changed

8 files changed

+133
-123
lines changed

src/main/kotlin/app/extractors/CExtractor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import app.model.DiffFile
99

1010
class CExtractor : ExtractorInterface {
1111
companion object {
12-
val LANGUAGE_NAME = "c"
12+
const val LANGUAGE_NAME = "c"
1313
val FILE_EXTS = listOf("c")
1414
val evaluator by lazy {
1515
ExtractorInterface.getLibraryClassifier(LANGUAGE_NAME)

src/main/kotlin/app/extractors/CommonExtractor.kt

Lines changed: 56 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,52 +10,62 @@ class CommonExtractor : ExtractorInterface {
1010
companion object {
1111
val FILE_EXTS_MAP = lazy {
1212
val reversedMap = mutableMapOf<String, List<String>>()
13-
reversedMap.put("actionscript", listOf("as"))
14-
reversedMap.put("arduino", listOf("ino"))
15-
reversedMap.put("assembly", listOf("asm", "s", "S"))
16-
reversedMap.put("clojure", listOf("clj", "cljs", "cljc", "edn"))
17-
reversedMap.put("cobol", listOf("cbl", "cob", "cpy"))
18-
reversedMap.put("coffeescript", listOf("coffee", "litcoffee"))
19-
reversedMap.put("cuda", listOf("cu", "cuh"))
20-
reversedMap.put("d", listOf("d"))
21-
reversedMap.put("emacslisp", listOf("el", "elc"))
22-
reversedMap.put("erlang", listOf("erl", "hrl"))
23-
reversedMap.put("forth", listOf("forth", "4TH"))
24-
reversedMap.put("fortran", listOf("f", "for", "f90", "f95", "f03",
25-
"f08", "f15"))
26-
reversedMap.put("gradle", listOf("gradle"))
27-
reversedMap.put("groovy", listOf("groovy"))
28-
reversedMap.put("haskell", listOf("hs", "lhs"))
29-
reversedMap.put("html", listOf("html", "htm"))
30-
reversedMap.put("j", listOf("ijs"))
31-
reversedMap.put("julia", listOf("jl"))
32-
reversedMap.put("lisp", listOf("lisp", "lsp", "l"))
33-
reversedMap.put("lua", listOf("lua"))
34-
reversedMap.put("makefile", listOf("makefile"))
35-
reversedMap.put("matlab", listOf("m", "mlx"))
36-
reversedMap.put("maven", listOf("pom"))
37-
reversedMap.put("ocaml", listOf("ml", "mli"))
38-
reversedMap.put("pascal", listOf("pas"))
39-
reversedMap.put("perl", listOf("pl", "PL"))
40-
reversedMap.put("powershell", listOf("ps1", "psm1", "psd1"))
41-
reversedMap.put("processing", listOf("pde"))
42-
reversedMap.put("prolog", listOf("pl", "P"))
43-
reversedMap.put("puppet", listOf("pp"))
44-
reversedMap.put("r", listOf("r", "R"))
45-
reversedMap.put("rust", listOf("rs"))
46-
reversedMap.put("sas", listOf("sas"))
47-
reversedMap.put("scala", listOf("scala", "sc"))
48-
reversedMap.put("scheme", listOf("scm", "ss"))
49-
reversedMap.put("shell", listOf("sh"))
50-
reversedMap.put("sql", listOf("sql"))
51-
reversedMap.put("tcl", listOf("tcl"))
52-
reversedMap.put("tex", listOf("tex"))
53-
reversedMap.put("typescript", listOf("ts", "tsx"))
54-
reversedMap.put("verilog", listOf("v"))
55-
reversedMap.put("vhdl", listOf("vhdl"))
56-
reversedMap.put("viml", listOf("vim"))
57-
reversedMap.put("visualbasic", listOf("bas"))
58-
reversedMap.put("vue", listOf("vue"))
13+
reversedMap["actionscript"] = listOf("as")
14+
reversedMap["arduino"] = listOf("ino")
15+
reversedMap["assembly"] = listOf("asm", "s", "S")
16+
reversedMap["clojure"] = listOf("clj", "cljs", "cljc", "edn")
17+
reversedMap["cobol"] = listOf("cbl", "cob", "cpy")
18+
reversedMap["coffeescript"] = listOf("coffee", "litcoffee")
19+
reversedMap["cuda"] = listOf("cu", "cuh")
20+
reversedMap["d"] = listOf("d")
21+
reversedMap["dosbatch"] = listOf("bat")
22+
reversedMap["emacslisp"] = listOf("el", "elc")
23+
reversedMap["erlang"] = listOf("erl", "hrl")
24+
reversedMap["elm"] = listOf("elm")
25+
reversedMap["factor"] = listOf("factor")
26+
reversedMap["forth"] = listOf("forth", "4TH")
27+
reversedMap["fortran"] = listOf("f", "for", "f90", "f95", "f03",
28+
"f08", "f15")
29+
reversedMap["gradle"] = listOf("gradle")
30+
reversedMap["groovy"] = listOf("groovy")
31+
reversedMap["haskell"] = listOf("hs", "lhs")
32+
reversedMap["haxe"] = listOf("hx")
33+
reversedMap["html"] = listOf("html", "htm")
34+
reversedMap["hy"] = listOf("hy")
35+
reversedMap["j"] = listOf("ijs")
36+
reversedMap["julia"] = listOf("jl")
37+
reversedMap["lisp"] = listOf("lisp", "lsp", "l")
38+
reversedMap["lua"] = listOf("lua")
39+
reversedMap["makefile"] = listOf("makefile")
40+
reversedMap["matlab"] = listOf("m", "mlx")
41+
reversedMap["maven"] = listOf("pom")
42+
reversedMap["ocaml"] = listOf("ml", "mli")
43+
reversedMap["oxygene"] = listOf("oxygene")
44+
reversedMap["pascal"] = listOf("pas")
45+
reversedMap["perl"] = listOf("pl", "PL")
46+
reversedMap["powershell"] = listOf("ps1", "psm1", "psd1")
47+
reversedMap["processing"] = listOf("pde")
48+
reversedMap["prolog"] = listOf("pl", "P")
49+
reversedMap["puppet"] = listOf("pp")
50+
reversedMap["r"] = listOf("r", "R")
51+
reversedMap["rust"] = listOf("rs")
52+
reversedMap["sas"] = listOf("sas")
53+
reversedMap["scala"] = listOf("scala", "sc")
54+
reversedMap["scheme"] = listOf("scm", "ss")
55+
reversedMap["shell"] = listOf("sh")
56+
reversedMap["smalltalk"] = listOf("st")
57+
reversedMap["sql"] = listOf("sql")
58+
reversedMap["tcl"] = listOf("tcl")
59+
reversedMap["tex"] = listOf("tex")
60+
reversedMap["typescript"] = listOf("ts", "tsx")
61+
reversedMap["verilog"] = listOf("v")
62+
reversedMap["vhdl"] = listOf("vhdl")
63+
reversedMap["viml"] = listOf("vim")
64+
reversedMap["visualbasic"] = listOf("bas")
65+
reversedMap["visualbasicforapps"] = listOf("vba")
66+
reversedMap["vue"] = listOf("vue")
67+
reversedMap["wolframlanguage"] = listOf("nb","m")
68+
reversedMap["xtend"] = listOf("xtend")
5969

6070
val map = hashMapOf<String, String>()
6171
reversedMap.forEach({ lang, exts ->

src/main/kotlin/app/hashers/CodeLongevity.kt

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class RevCommitLine(val commit: RevCommit, val fileId: AnyObjectId,
3939
val isDeleted: Boolean) {
4040

4141
val id : String
42-
get() = "${fileId.getName()}:$line"
42+
get() = "${fileId.name}:$line"
4343
}
4444

4545
/**
@@ -79,13 +79,12 @@ class CodeLine(val repo: Repository,
7979
}
8080
return field
8181
}
82-
set(v) { field = v }
8382

8483
/**
8584
* The code line text.
8685
*/
8786
val text : String
88-
get() = RawText(repo.open(from.fileId).getBytes()).getString(from.line)
87+
get() = RawText(repo.open(from.fileId).bytes).getString(from.line)
8988

9089
/**
9190
* Email address of the line's author.
@@ -103,7 +102,7 @@ class CodeLine(val repo: Repository,
103102
* A date when the line was changed.
104103
*/
105104
val editDate : Date
106-
get() = Date(to.commit.getCommitTime().toLong() * 1000)
105+
get() = Date(to.commit.commitTime.toLong() * 1000)
107106

108107
/**
109108
* True if the line is deleted.
@@ -116,15 +115,15 @@ class CodeLine(val repo: Repository,
116115
*/
117116
override fun toString() : String {
118117
val df = SimpleDateFormat("yyyy-MM-dd HH:mm z")
119-
val fd = df.format(Date(from.commit.getCommitTime().toLong() * 1000))
120-
val td = df.format(Date(to.commit.getCommitTime().toLong() * 1000))
121-
val fc = "${from.commit.getName()} '${from.commit.getShortMessage()}'"
122-
val tc = "${to.commit.getName()} '${to.commit.getShortMessage()}'"
118+
val fd = df.format(Date(from.commit.commitTime.toLong() * 1000))
119+
val td = df.format(Date(to.commit.commitTime.toLong() * 1000))
120+
val fc = "${from.commit.name} '${from.commit.shortMessage}'"
121+
val tc = "${to.commit.name} '${to.commit.shortMessage}'"
123122
val revState = if (isDeleted) "deleted in" else "last known as"
124123
val state = if (isDeleted) "deleted" else "alive"
125124
return "Line '$text' - '${from.file}:${from.line}' added in $fc $fd\n" +
126-
" ${revState} '${to.file}:${to.line}' in $tc $td,\n" +
127-
" age: ${age} s - $state"
125+
" $revState '${to.file}:${to.line}' in $tc $td,\n" +
126+
" age: $age s - $state"
128127
}
129128
}
130129

@@ -153,7 +152,7 @@ class Colleagues(private val serverRepo: Repo) {
153152
Logger.trace { "collected colleague, age: ${line.age}" }
154153
val vicinity = dates.getOrPut(month, { line.age })
155154
if (vicinity > line.age) {
156-
dates.put(month, line.age)
155+
dates[month] = line.age
157156
}
158157
}
159158

@@ -162,14 +161,14 @@ class Colleagues(private val serverRepo: Repo) {
162161
// colleague2 edited colleauge1 code.
163162
val auxHash = hashSetOf<Pair<String, String>>()
164163
for ((pair, dates) in map) {
165-
val email1 = pair.first;
166-
val email2 = pair.second;
164+
val email1 = pair.first
165+
val email2 = pair.second
167166
if (auxHash.contains(Pair(email2, email1))) {
168-
continue;
167+
continue
169168
}
170169

171170
val min1 = dates.minBy { (_, vicinity) -> vicinity }!!
172-
val dates2 = map.get(Pair(email2, email1));
171+
val dates2 = map[Pair(email2, email1)]
173172
if (dates2 != null) {
174173
auxHash.add(Pair(email1, email2))
175174

@@ -237,7 +236,7 @@ class CodeLineAges : Serializable, Cloneable {
237236
*/
238237
var lastingLines: HashMap<String, LineInfo> = hashMapOf()
239238

240-
override public fun clone(): CodeLineAges {
239+
public override fun clone(): CodeLineAges {
241240
val clone = CodeLineAges()
242241
aggrAges.forEach { (email, age) ->
243242
clone.aggrAges[email] = age.copy() }
@@ -276,7 +275,7 @@ class CodeLongevity(
276275
repoSum += aggrAge.sum
277276
repoTotal += aggrAge.count
278277
if (emails.contains(email)) {
279-
aggrAges.put(email, aggrAge)
278+
aggrAges[email] = aggrAge
280279
}
281280
}
282281

@@ -349,7 +348,7 @@ class CodeLongevity(
349348
// Update ages.
350349
getLinesObservable(storedHead, diffObservable, onError).subscribe({
351350
line ->
352-
Logger.trace { "Scanning: ${line}" }
351+
Logger.trace { "Scanning: $line" }
353352
if (line.isDeleted) {
354353
if (ageData.lastingLines.contains(line.oldId)) {
355354
line.age += ageData.lastingLines.remove(line.oldId)!!.age
@@ -365,15 +364,15 @@ class CodeLongevity(
365364
if (ageData.lastingLines.contains(line.oldId)) {
366365
age += ageData.lastingLines.remove(line.oldId)!!.age
367366
}
368-
ageData.lastingLines.put(line.newId, CodeLineAges.LineInfo(age,
369-
line.authorEmail))
367+
ageData.lastingLines[line.newId] = CodeLineAges.LineInfo(age,
368+
line.authorEmail)
370369
}
371370
}, onError, {
372371
// Store ages for subsequent runs.
373372
try {
374373
val file = dataPath.toFile()
375374
val oStream = ObjectOutputStream(FileOutputStream(file))
376-
oStream.writeUTF(head.getName())
375+
oStream.writeUTF(head.name)
377376
oStream.writeObject(ageData)
378377
}
379378
catch(e: Exception) {
@@ -418,24 +417,24 @@ class CodeLongevity(
418417
Observable.create { subscriber ->
419418

420419
val headWalk = TreeWalk(repo)
421-
headWalk.setRecursive(true)
422-
headWalk.addTree(head.getTree())
420+
headWalk.isRecursive = true
421+
headWalk.addTree(head.tree)
423422

424423
val files: MutableMap<String, ArrayList<RevCommitLine>> = mutableMapOf()
425424

426425
// Build a map of file names and their code lines.
427426
while (headWalk.next()) {
428427
try {
429-
val path = headWalk.getPathString()
428+
val path = headWalk.pathString
430429
val fileId = headWalk.getObjectId(0)
431430
val fileLoader = repo.open(fileId)
432431
if (!RawText.isBinary(fileLoader.openStream())) {
433-
val fileText = RawText(fileLoader.getBytes())
432+
val fileText = RawText(fileLoader.bytes)
434433
val lines = ArrayList<RevCommitLine>(fileText.size())
435-
for (idx in 0..fileText.size() - 1) {
434+
for (idx in 0 until fileText.size()) {
436435
lines.add(RevCommitLine(head, fileId, path, idx, false))
437436
}
438-
files.put(path, lines)
437+
files[path] = lines
439438
}
440439
} catch (e: Exception) {
441440
// TODO(anatoly): better fix of exceptions.
@@ -450,17 +449,17 @@ class CodeLongevity(
450449
// renames properly.
451450
// TODO(alex): cover file renames by tests (see APP-132 issue).
452451
for ((diff, editList) in diffs.asReversed()) {
453-
val oldPath = diff.getOldPath()
454-
val oldId = diff.getOldId().toObjectId()
455-
val newPath = diff.getNewPath()
456-
val newId = diff.getNewId().toObjectId()
452+
val oldPath = diff.oldPath
453+
val oldId = diff.oldId.toObjectId()
454+
val newPath = diff.newPath
455+
val newId = diff.newId.toObjectId()
457456
Logger.trace { "old: '$oldPath', new: '$newPath'" }
458457

459458
// File was deleted, initialize the line array in the files map.
460459
if (diff.changeType == DiffEntry.ChangeType.DELETE) {
461460
val fileLoader = repo.open(oldId)
462-
val fileText = RawText(fileLoader.getBytes())
463-
files.put(oldPath, ArrayList(fileText.size()))
461+
val fileText = RawText(fileLoader.bytes)
462+
files[oldPath] = ArrayList(fileText.size())
464463
}
465464

466465
// If a file was deleted, then the new path is /dev/null.
@@ -469,33 +468,33 @@ class CodeLongevity(
469468
} else {
470469
oldPath
471470
}
472-
val lines = files.get(path)!!
471+
val lines = files[path]!!
473472

474473

475474
// Update the lines array according to diff insertions.
476475
// Traverse the edit list backwards to keep indices of
477476
// the edit list and the lines array in sync.
478477
for (edit in editList.asReversed()) {
479478
// Insertion case: track the lines.
480-
val insCount = edit.getLengthB()
479+
val insCount = edit.lengthB
481480
if (insCount > 0) {
482-
val insStart = edit.getBeginB()
483-
val insEnd = edit.getEndB()
481+
val insStart = edit.beginB
482+
val insEnd = edit.endB
484483
Logger.trace { "ins ($insStart, $insEnd)" }
485484

486-
for (idx in insStart .. insEnd - 1) {
485+
for (idx in insStart until insEnd) {
487486
val from = RevCommitLine(commit, newId,
488487
newPath, idx, false)
489488
try {
490-
val to = lines.get(idx)
489+
val to = lines[idx]
491490
val cl = CodeLine(repo, from, to)
492-
Logger.trace { "Collected: ${cl}" }
491+
Logger.trace { "Collected: $cl" }
493492
subscriber.onNext(cl)
494493
}
495494
catch(e: IndexOutOfBoundsException) {
496-
Logger.error(e, "No line at ${idx}; commit: " +
497-
"${commit.getName()}; " +
498-
"'${commit.getShortMessage()}'")
495+
Logger.error(e, "No line at $idx; commit: " +
496+
"${commit.name}; " +
497+
"'${commit.shortMessage}'")
499498
throw e
500499
}
501500
}
@@ -507,14 +506,14 @@ class CodeLongevity(
507506
for (edit in editList) {
508507
// Deletion case. Chase down the deleted lines through the
509508
// history.
510-
val delCount = edit.getLengthA()
509+
val delCount = edit.lengthA
511510
if (delCount > 0) {
512-
val delStart = edit.getBeginA()
513-
val delEnd = edit.getEndA()
511+
val delStart = edit.beginA
512+
val delEnd = edit.endA
514513
Logger.trace { "del ($delStart, $delEnd)" }
515514

516515
val tmpLines = ArrayList<RevCommitLine>(delCount)
517-
for (idx in delStart .. delEnd - 1) {
516+
for (idx in delStart until delEnd) {
518517
tmpLines.add(RevCommitLine(commit, oldId,
519518
oldPath, idx, true))
520519
}
@@ -524,7 +523,7 @@ class CodeLongevity(
524523

525524
// File was renamed, tweak the files map.
526525
if (diff.changeType == DiffEntry.ChangeType.RENAME) {
527-
files.set(oldPath, files.remove(newPath)!!)
526+
files[oldPath] = files.remove(newPath)!!
528527
}
529528
}
530529
}, onError, {
@@ -534,15 +533,15 @@ class CodeLongevity(
534533
// caller can update their ages properly.
535534
if (tail != null) {
536535
val tailWalk = TreeWalk(repo)
537-
tailWalk.setRecursive(true)
538-
tailWalk.addTree(tail.getTree())
536+
tailWalk.isRecursive = true
537+
tailWalk.addTree(tail.tree)
539538

540539
while (tailWalk.next()) {
541-
val filePath = tailWalk.getPathString()
542-
val lines = files.get(filePath)
540+
val filePath = tailWalk.pathString
541+
val lines = files[filePath]
543542
if (lines != null) {
544543
val fileId = tailWalk.getObjectId(0)
545-
for (idx in 0 .. lines.size - 1) {
544+
for (idx in 0 until lines.size) {
546545
val from = RevCommitLine(tail, fileId,
547546
filePath, idx, false)
548547
val cl = CodeLine(repo, from, lines[idx])

0 commit comments

Comments
 (0)