Skip to content

Commit

Permalink
Merge pull request #10 from SchwarzIT/bugfix/kotlin1_5_adjustments
Browse files Browse the repository at this point in the history
# FIXED Kokain does not respect class visibility modifier
  • Loading branch information
sbra0902 authored Jun 8, 2021
2 parents adb3e53 + d036b1f commit 21c54af
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 51 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.5.10'
repositories {
google()
jcenter()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.schwarz.kokain.di.observer
package com.schwarz.kokain.api.internal

interface ActivityRefered {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.schwarz.kokain.di.scope
package com.schwarz.kokain.api.internal

import com.schwarz.kokain.api.EBean

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package com.schwarz.kokain.di
import android.app.Activity
import android.app.Application
import android.content.Context
import android.util.Log
import android.view.View
import androidx.activity.ComponentActivity
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import com.schwarz.kokain.api.EBean
import com.schwarz.kokain.di.observer.ActivityRefered
import com.schwarz.kokain.di.scope.BeanScope
import com.schwarz.kokain.api.internal.ActivityRefered
import com.schwarz.kokain.api.internal.BeanScope
import java.lang.ref.WeakReference
import kotlin.reflect.KProperty

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import com.schwarz.kokain.api.EBean
import com.schwarz.kokain.api.KDiFactory
import com.schwarz.kokain.api.internal.BeanScope
import com.schwarz.kokain.di.scope.*
import kotlin.reflect.KClass

Expand Down
16 changes: 9 additions & 7 deletions kokain-processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,21 @@ apply plugin: 'kotlin-kapt'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.squareup:kotlinpoet:1.6.0'
implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.1.0"
implementation "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.3.0"
implementation project(path: ':kokain-core-api', configuration: 'default')
implementation 'org.apache.commons:commons-lang3:3.4'
testImplementation 'com.google.testing.compile:compile-testing:0.11'
testImplementation 'junit:junit:4.12'
testImplementation project(path: ':kokain-core-api', configuration: 'default')
testImplementation 'com.google.truth:truth:1.0'
testImplementation 'com.github.tschuchortdev:kotlin-compile-testing:1.2.7'
testImplementation 'com.github.tschuchortdev:kotlin-compile-testing:1.4.2'
testImplementation 'org.mockito:mockito-core:1.10.19'
kapt "com.google.auto.service:auto-service:1.0-rc6"
implementation "com.google.auto.service:auto-service:1.0-rc6"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

}

targetCompatibility = '1.7'
sourceCompatibility = '1.7'
targetCompatibility = '1.8'
sourceCompatibility = '1.8'

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
Expand All @@ -35,6 +33,10 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
}

jacoco {
toolVersion = "0.8.7"
}

jacocoTestReport {
group 'verification'
dependsOn 'test'
Expand All @@ -51,7 +53,7 @@ artifacts {
archives javadocJar
}
buildscript {
ext.kotlin_version = '1.3.41'
ext.kotlin_version = '1.5.10'
repositories {
mavenCentral()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ import com.schwarz.kokain.api.EBean
import com.squareup.kotlinpoet.ClassName
import com.squareup.kotlinpoet.KModifier
import com.squareup.kotlinpoet.TypeName
import com.sun.org.apache.xpath.internal.operations.Mod
import com.sun.tools.javac.code.Symbol
import kotlinx.metadata.Flag
import kotlinx.metadata.Flags
import kotlinx.metadata.KmClass
import kotlinx.metadata.jvm.KotlinClassHeader
import kotlinx.metadata.jvm.KotlinClassMetadata
import sun.tools.util.ModifierFilter
import javax.lang.model.element.Element
import javax.lang.model.element.Modifier

class EBeanModel(scope: EBean.Scope, sourceElement: Element) {

Expand All @@ -22,7 +18,7 @@ class EBeanModel(scope: EBean.Scope, sourceElement: Element) {
init {
var meta = sourceElement?.getAnnotation(Metadata::class.java)
kotlinClassMetadata = if(meta != null){
(KotlinClassMetadata.read(KotlinClassHeader(meta.kind, meta.metadataVersion, meta.bytecodeVersion, meta.data1, meta.data2, meta.extraString, meta.packageName, meta.extraInt)) as? KotlinClassMetadata.Class)?.toKmClass()
(KotlinClassMetadata.read(KotlinClassHeader(meta.kind, meta.metadataVersion, meta.data1, meta.data2, meta.extraString, meta.packageName, meta.extraInt)) as? KotlinClassMetadata.Class)?.toKmClass()
}else{
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy

object TypeUtil {

const val KOKAIN_DI_BASE_PACKAGE = "com.schwarz.kokain.di"

const val KOKAIN_API_BASE_PACKAGE = "com.schwarz.kokain.api"

fun string(): TypeName {
Expand Down Expand Up @@ -61,11 +59,11 @@ object TypeUtil {
}

fun activityRefered(): TypeName {
return ClassName("$KOKAIN_DI_BASE_PACKAGE.observer", "ActivityRefered")
return ClassName("$KOKAIN_API_BASE_PACKAGE.internal", "ActivityRefered")
}

fun beanScope(): TypeName {
return ClassName("$KOKAIN_DI_BASE_PACKAGE.scope", "BeanScope")
return ClassName("$KOKAIN_API_BASE_PACKAGE.internal", "BeanScope")
}

fun scope(): TypeName {
Expand Down Expand Up @@ -94,28 +92,6 @@ object TypeUtil {
return if (lastIndexOf >= 0) type.toString().substring(0, lastIndexOf) else type.toString()
}

// fun parseMetaType(type: TypeMirror, list: Boolean, subEntity: String?): TypeName {
//
// val simpleName = if (subEntity != null && subEntity.contains(getSimpleName(type))) subEntity else getSimpleName(type)
//
// var baseType: TypeName? = null
//
// if (type.toString().split(".").size == 1) {
// baseType = type.asTypeName()
// } else {
// try {
// baseType = ClassName(getPackage(type), simpleName)
// } catch (e: IllegalArgumentException) {
// baseType = type.asTypeName()
// }
// }
//
// return if (list) {
// list(baseType!!.javaToKotlinType())
// } else baseType!!.javaToKotlinType()
// }


fun classStar(): ParameterizedTypeName {
return ClassName("kotlin.reflect", "KClass").parameterizedBy(star())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class KokainProcessorKotlinTest {


@Test
fun testKotlinAbstractGeneration() {
fun testKotlinBasicGeneration() {

val subEntity = SourceFile.kotlin("FooBean.kt",
HEADER +
Expand All @@ -23,14 +23,28 @@ class KokainProcessorKotlinTest {

val compilation = compileKotlin(subEntity)

Assert.assertEquals(compilation.exitCode, KotlinCompilation.ExitCode.OK)
}

@Test
fun testKotlinInternalBasicGeneration() {

val subEntity = SourceFile.kotlin("FooBean.kt",
HEADER +
"@EBean\n" +
"@EFactory\n" +
"open internal class FooBean {\n" +
"}")


val compilation = compileKotlin(subEntity)

//TODO Fix classpath problem and make this great again
Assert.assertEquals(compilation.exitCode, KotlinCompilation.ExitCode.COMPILATION_ERROR)
Assert.assertEquals(compilation.exitCode, KotlinCompilation.ExitCode.OK)
}

private fun compileKotlin(vararg sourceFiles: SourceFile): KotlinCompilation.Result {
return KotlinCompilation().apply {
sources = sourceFiles.toList()
sources = sourceFiles.toMutableList()

// pass your own instance of an annotation processor
annotationProcessors = listOf(KokainProcessor())
Expand All @@ -44,11 +58,8 @@ class KokainProcessorKotlinTest {
const val HEADER: String =
"package com.kaufland.test\n" +
"\n" +
"import android.content.Context\n" +
"import com.schwarz.kokain.api.EBean\n" +
"import com.schwarz.kokain.api.EFactory\n"
// "import com.schwarz.kokaindi.context\n" +
// "import com.schwarz.kokaindi.inject\n"
}

}

0 comments on commit 21c54af

Please sign in to comment.