Skip to content

Commit

Permalink
Find methods that have been removed
Browse files Browse the repository at this point in the history
  • Loading branch information
avantgardnerio committed Oct 31, 2018
1 parent d66c04d commit e433694
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/main/kotlin/net/squarelabs/depends/Reporter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package net.squarelabs.depends

import net.squarelabs.depends.models.Artifact

fun fqmns(a: Artifact): HashSet<String> = HashSet(a.classes.values.flatMap { c -> c.methods.values.map { m -> "${c.name}:${m.name}${m.descriptor}" } })

fun allMethods(artifacts: Collection<Artifact>): HashSet<String> {
val reducer = { acc: HashSet<String>, cur: Artifact ->
acc.addAll(fqmns(cur))
acc
}
return artifacts.fold(HashSet(), reducer)
}

fun commonMethods(artifacts: Collection<Artifact>, all: Set<String>): HashSet<String> {
val reducer = { acc: HashSet<String>, cur: Artifact ->
acc.retainAll(fqmns(cur))
acc
}
return artifacts.fold(HashSet(all), reducer)
}

fun removedMethods(artifacts: Collection<Artifact>): Set<String> {
val accumulator: HashSet<String> = allMethods(artifacts)
val common: Set<String> = commonMethods(artifacts, accumulator)
accumulator.removeAll(common)
return accumulator
}
5 changes: 4 additions & 1 deletion src/test/kotlin/net/squarelabs/depends/ResolverTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ class ResolverTest {
println("conflicts:\n\t $conflicts")

// find removals
state.artifactsByGa.keys
val removedMethods = state.artifactsByGa.keys
.filter { key -> state.artifactsByGa[key]!!.size > 1 }
.map { key -> state.artifactsByGa[key]!!.values }
.flatMap { artifacts -> removedMethods(artifacts) }
println("methods removed: ${removedMethods.size}")

// print memory
Runtime.getRuntime().gc()
Expand Down

0 comments on commit e433694

Please sign in to comment.