Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Jitpack dependency and added memoization to processors #1222

Merged
merged 2 commits into from
Dec 30, 2018
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
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ Add it in your root `build.gradle` at the end of repositories.
allprojects {
repositories {
jcenter()
maven { url 'https://jitpack.io' }
}
}
```
Expand Down
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ buildscript {

repositories {
jcenter()
maven { url 'https://jitpack.io' }
maven { url "http://dl.bintray.com/kotlin/kotlin-dev" }
maven { url "https://dl.bintray.com/jetbrains/markdown/" }
maven { url "https://dl.bintray.com/arrow-kt/arrow-kt/" }
Expand Down Expand Up @@ -73,7 +72,6 @@ allprojects {
maven { url "http://dl.bintray.com/kotlin/kotlin-dev" }
maven { url "http://dl.bintray.com/arrow-kt/arrow-kt" }
maven { url "https://dl.bintray.com/jetbrains/markdown/" }
maven { url 'https://jitpack.io' }
}
}

Expand Down
1 change: 0 additions & 1 deletion modules/core/arrow-annotations-processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies {
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-reflect'
}
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
compile 'com.github.aballano:MnemoniK:1.0.0'
compileOnly 'com.google.auto.service:auto-service:1.0-rc4'
kapt 'com.google.auto.service:auto-service:1.0-rc4'

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package arrow.meta.internal

import java.util.concurrent.ConcurrentHashMap

fun <P1, R> ((P1) -> R).memoize(): (P1) -> R = object : (P1) -> R {
private val m = MemoizedHandler<((P1) -> R), MemoizeKey1<P1, R>, R>(this@memoize)
override fun invoke(p1: P1) = m(MemoizeKey1(p1))
}

private interface MemoizedCall<in F, out R> {
operator fun invoke(f: F): R
}

private data class MemoizeKey1<out P1, R>(val p1: P1) : MemoizedCall<(P1) -> R, R> {
override fun invoke(f: (P1) -> R) = f(p1)
}

private class MemoizedHandler<F, in K : MemoizedCall<F, R>, out R>(val f: F) {
private val m = Platform.newConcurrentMap<K, R>()
operator fun invoke(k: K): R = m[k] ?: run { m.putSafely(k, k(f)) }
}

object Platform {

interface ConcurrentMap<K, V> : MutableMap<K, V> {
fun putSafely(k: K, v: V): V
}

fun <K, V> newConcurrentMap(): ConcurrentMap<K, V> {
val map by lazy { ConcurrentHashMap<K, V>() }
return object : ConcurrentMap<K, V>, MutableMap<K, V> by map {
override fun putSafely(k: K, v: V): V =
map.putIfAbsent(k, v) ?: v
}
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package arrow.meta.processor

import aballano.kotlinmemoization.memoize
import arrow.common.utils.AbstractProcessor
import arrow.common.utils.ClassOrPackageDataWrapper
import arrow.common.utils.ProcessorUtils
import arrow.common.utils.knownError
import arrow.meta.ast.Type
import arrow.meta.ast.TypeName
import arrow.meta.encoder.jvm.JvmMetaApi
import arrow.meta.internal.memoize
import arrow.meta.processor.MetaProcessor.AnnotatedElement
import com.squareup.kotlinpoet.FileSpec
import me.eugeniomarletti.kotlin.metadata.KotlinMetadataUtils
Expand Down
13 changes: 0 additions & 13 deletions modules/docs/arrow-docs/docs/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,6 @@ Add the dependencies that you want to use

## Enabling kapt

Add to your pom.xml file the following repository:
```
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>jitpack</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
```

Enable annotaton processing using kotlin plugin
```
<plugin>
Expand Down