Skip to content

Commit

Permalink
Merge pull request #11 from juanchosaravia/upgrade_processor_dependen…
Browse files Browse the repository at this point in the history
…cies

Upgrade processor dependencies
  • Loading branch information
juanchosaravia authored Jun 8, 2020
2 parents 82c8f01 + 8e2d102 commit c21d032
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 53 deletions.
74 changes: 42 additions & 32 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,54 @@
# Java Gradle CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-java/ for more details
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/openjdk:8-jdk

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4
- image: circleci/openjdk:8-jdk

working_directory: ~/repo

environment:
# Customize the JVM maximum heap limit
JVM_OPTS: -Xmx3200m
TERM: dumb

steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "build.gradle" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: gradle dependencies

- save_cache:
paths:
- ~/.gradle
key: v1-dependencies-{{ checksum "build.gradle" }}

# run tests!
- run: gradle test


- checkout

- restore_cache:
key: v1-gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- restore_cache:
key: v1-gradle-cache-{{ checksum "build.gradle" }}

- run:
name: Run Dependencies
command: |
./gradlew dependencies
- save_cache:
paths:
- ~/.gradle/wrapper
key: v1-gradle-wrapper-{{ checksum "gradle/wrapper/gradle-wrapper.properties" }}
- save_cache:
paths:
- ~/.gradle/caches
key: v1-gradle-cache-{{ checksum "build.gradle" }}

- run:
name: Run Tests
command: |
./gradlew test
- run:
name: Assemble JAR
command: |
# Skip this for other nodes
if [ "$CIRCLE_NODE_INDEX" == 0 ]; then
./gradlew build
fi
- store_artifacts:
path: build/libs

workflows:
version: 2
workflow:
jobs:
- build
3 changes: 2 additions & 1 deletion app/src/main/kotlin/com/autodsl/app/Person.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ internal class Box( // supports internal classes

@AutoDsl
internal class Stamp(
val names: List<String>
val names: List<String>,
val type: StampType?
)
9 changes: 9 additions & 0 deletions app/src/main/kotlin/com/autodsl/app/StampType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.autodsl.app

import com.autodsl.annotation.AutoDsl

internal sealed class StampType
@AutoDsl
internal class GoldStamp(val price: Double): StampType()
internal object MetalStamp : StampType()
internal object BronzeStamp : StampType()
35 changes: 35 additions & 0 deletions app/src/test/kotlin/com/autodsl/app/AutoDslTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.autodsl.app.general.scores
import junit.framework.TestCase.assertEquals
import junit.framework.TestCase.assertTrue
import org.junit.Test
import java.io.InvalidObjectException
import java.util.*

class AutoDslTest {
Expand Down Expand Up @@ -52,6 +53,9 @@ class AutoDslTest {
}
assertEquals(2, me.friends?.size)
assertEquals("Test", me.contact?.name)
assertEquals("Juan", me.name)
assertEquals(34, me.age)
assertEquals(34747, me.address?.zipCode)
}

@Test
Expand Down Expand Up @@ -84,6 +88,28 @@ class AutoDslTest {
assertEquals(usaStamp, box.stamps?.first()?.names?.first())
}

@Test
fun sealedClassTest() {
val box = box {
items {
+"Hello World"
}
+stamp {
names {
+"ARG"
}
type = goldStamp {
price = 15.0
}
}
}

when (val stampType = box.stamps?.first()?.type) {
is GoldStamp -> assertEquals(15.0, stampType.price)
else -> throw InvalidObjectException("incorrect type solved.")
}
}

@Test
fun validStructureFromDifferentPackages() {
scores {
Expand Down Expand Up @@ -142,9 +168,18 @@ class AutoDslTest {
names {
+"ARG"
}
type = MetalStamp
}
+stamp {
names {
+"ARG"
}
type = BronzeStamp
}
}

assertTrue(box.stamps is LinkedList)
assertTrue(box.stamps?.first()?.type == MetalStamp)
assertTrue(box.stamps?.last()?.type == BronzeStamp)
}
}
6 changes: 3 additions & 3 deletions processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ dependencies {
// kotlin metadata
implementation "me.eugeniomarletti.kotlin.metadata:kotlin-metadata:1.4.0"
implementation files("${System.properties['java.home']}/../lib/tools.jar")
implementation 'com.squareup:kotlinpoet:1.0.0-RC2'
implementation "com.google.auto.service:auto-service:1.0-rc4"
kapt "com.google.auto.service:auto-service:1.0-rc4"
implementation 'com.squareup:kotlinpoet:1.4.3'
implementation "com.google.auto.service:auto-service:1.0-rc7"
kapt "com.google.auto.service:auto-service:1.0-rc7"

testImplementation group: 'junit', name: 'junit', version: '4.4'
}
Expand Down
13 changes: 6 additions & 7 deletions processor/src/main/kotlin/com/autodsl/processor/MetadataExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ internal fun ProtoBuf.Type.asTypeName(
}

if (hasFlexibleUpperBound()) {
return WildcardTypeName.subtypeOf(
return WildcardTypeName.consumerOf(
flexibleUpperBound.asTypeName(nameResolver, getTypeParameter, useAbbreviatedType)
)
.asNullableIf(nullable)
} else if (hasOuterType()) {
return WildcardTypeName.supertypeOf(
return WildcardTypeName.consumerOf(
outerType.asTypeName(nameResolver, getTypeParameter, useAbbreviatedType)
)
.asNullableIf(nullable)
Expand Down Expand Up @@ -101,23 +100,23 @@ internal fun ProtoBuf.Type.asTypeName(
.let { argumentTypeName ->
nullableProjection?.let { projection ->
when (projection) {
ProtoBuf.Type.Argument.Projection.IN -> WildcardTypeName.supertypeOf(argumentTypeName)
ProtoBuf.Type.Argument.Projection.IN -> WildcardTypeName.consumerOf(argumentTypeName)
ProtoBuf.Type.Argument.Projection.OUT -> {
if (argumentTypeName == ANY) {
// This becomes a *, which we actually don't want here.
// List<Any> works with List<*>, but List<*> doesn't work with List<Any>
argumentTypeName
} else {
WildcardTypeName.subtypeOf(argumentTypeName)
WildcardTypeName.consumerOf(argumentTypeName)
}
}
ProtoBuf.Type.Argument.Projection.STAR -> WildcardTypeName.subtypeOf(ANY)
ProtoBuf.Type.Argument.Projection.STAR -> WildcardTypeName.consumerOf(ANY)
ProtoBuf.Type.Argument.Projection.INV -> TODO("INV projection is unsupported")
}
} ?: argumentTypeName
}
} else {
WildcardTypeName.subtypeOf(ANY)
WildcardTypeName.consumerOf(ANY)
}
}.toTypedArray()
typeName = (typeName as ClassName).parameterizedBy(*remappedArgs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ internal fun AutoDsl?.getDslNameOrDefault(defaultString: String): String {
}

internal fun TypeName.asNullableIf(condition: Boolean): TypeName {
return if (condition) asNullable() else this
return if (condition) copy(nullable = true) else this
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal class AutoDslParam(
val typeInfo = AutoDslParamType(element as Symbol.VarSymbol)
val typeName = param.proto.type.asTypeName(nameResolver, protoClass::getTypeParameter)

fun isNullable() = typeName.nullable
fun isNullable() = typeName.isNullable
fun getAutoDslCollectionAnnotation(): AutoDslCollection? = element.getAnnotation(AutoDslCollection::class.java)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ private fun createCollectionData(
).build()
)
.returns(builderClassName)
.addStatement("return this.apply { this.$paramName = $collectionClassNameValue().apply { $BLOCK_FUN_NAME() }.$collectionFieldName }")
.addStatement("this.$paramName = $collectionClassNameValue().apply { $BLOCK_FUN_NAME() }.$collectionFieldName")
.addStatement("return this")
.build()

return AutoDslCollectionData(collectionFun, nestedClass)
Expand Down Expand Up @@ -240,7 +241,8 @@ private fun createFunIfAnnotatedWithAutoDsl(
).build()
)
.returns(builderClassName)
.addStatement("return this.apply { this.${param.name} = $paramBuilderName().apply($BLOCK_FUN_NAME).build() }")
.addStatement("this.${param.name} = $paramBuilderName().apply($BLOCK_FUN_NAME).build()")
.addStatement("return this")
.build()

return AutoDslFunctionData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ internal data class TargetType(
return proto.typeParameterList.map {
val possibleBounds = it.upperBoundList
.map { it.asTypeName(nameResolver, proto::getTypeParameter, false) }
val typeVar = if (possibleBounds.isEmpty()) {
return@map if (possibleBounds.isEmpty()) {
TypeVariableName(
name = nameResolver.getString(it.name),
variance = it.varianceModifier
Expand All @@ -118,8 +118,7 @@ internal data class TargetType(
bounds = *possibleBounds.toTypedArray(),
variance = it.varianceModifier
)
}
return@map typeVar.reified(it.reified)
}.copy(reified = it.reified)
}
}

Expand Down
2 changes: 1 addition & 1 deletion release-bintray.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ext {
libraryVersion = '0.0.9'
libraryVersion = '0.0.10'

def groupName = "com.juanchosaravia.autodsl"
bintrayRepo = 'autodsl'
Expand Down
4 changes: 2 additions & 2 deletions samples/android-autodsl/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.0'
ext.autodsl_version = '0.0.9'
ext.kotlin_version = '1.3.72'
ext.autodsl_version = '0.0.10'
repositories {
google()
jcenter()
Expand Down

0 comments on commit c21d032

Please sign in to comment.