Skip to content

Commit e163451

Browse files
author
roman_tcaregorodtcev
committed
Gradle version updated to 3.6.1; kotlin updated to 1.3.71.
Now repository implements methods from parent interfaces.
1 parent 7c710cb commit e163451

File tree

6 files changed

+49
-22
lines changed

6 files changed

+49
-22
lines changed

app/src/main/java/com/omega_r/base/simple/InspectionRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.omega_r.base.data.OmegaRepository.Strategy
55
import kotlinx.coroutines.channels.ReceiveChannel
66

77
@AppOmegaRepository
8-
interface InspectionRepository {
8+
interface InspectionRepository : ParentRepository {
99

1010
val isAuth: Boolean?
1111
get() = true
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.omega_r.base.simple
2+
3+
interface ParentRepository {
4+
5+
suspend fun parentMethod(): String
6+
7+
}

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ ext {
55
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
66

77
buildscript {
8-
ext.kotlin_version = '1.3.61'
8+
ext.kotlin_version = '1.3.71'
99
repositories {
1010
google()
1111
jcenter()
1212

1313
}
1414
dependencies {
15-
classpath 'com.android.tools.build:gradle:3.5.3'
15+
classpath 'com.android.tools.build:gradle:3.6.1'
1616
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1717
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
1818
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Tue Dec 03 09:01:16 MSK 2019
1+
#Fri Mar 27 12:50:10 MSK 2020
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.omega_r.base.processor.extensions
2+
3+
import javax.lang.model.element.TypeElement
4+
import javax.lang.model.type.DeclaredType
5+
import javax.lang.model.type.TypeMirror
6+
7+
fun TypeMirror.asTypeElement(): TypeElement = (this as DeclaredType).asElement() as TypeElement

processor/src/main/java/com/omega_r/base/processor/factories/RepositoryFactory.kt

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import javax.annotation.processing.Messager
1818
import javax.lang.model.element.Element
1919
import javax.lang.model.element.TypeElement
2020
import javax.lang.model.util.Elements
21-
import javax.tools.Diagnostic.Kind.*
21+
import javax.tools.Diagnostic.Kind.ERROR
2222

2323
private const val FUNC_CLEAR_CACHE = "clearCache"
2424

@@ -34,27 +34,36 @@ class RepositoryFactory(private val messager: Messager, private val elements: El
3434
return null
3535
}
3636

37-
val proto = kotlinMetadata.data.classProto
38-
if (proto.classKind != INTERFACE) {
37+
val classData: ClassData = kotlinMetadata.data
38+
if (classData.classProto.classKind != INTERFACE) {
3939
messager.printMessage(ERROR, "@AppOmegaRepository can't be applied to $element: must be a Kotlin interface")
4040
return null
4141
}
4242

43-
val repositoryPackage = elements.packageOf(element)
44-
val repositoryName = element.repositoryName
43+
val functions = classData.getFunctions(element).toMutableList()
44+
element.interfaces.forEach {
45+
functions += create(it.asTypeElement())?.functions ?: return@forEach
46+
}
47+
48+
return Repository(
49+
element.repositoryPackage,
50+
element.repositoryName,
51+
element.superInterfaceClassName,
52+
classData.getParameters(),
53+
functions
54+
)
55+
}
4556

46-
val classProto = kotlinMetadata.data.classProto
47-
val nameResolver = kotlinMetadata.data.nameResolver
48-
val superInterfaceClassName = ClassName.bestGuess("${elements.packageOf(element)}.${element.simpleName}")
57+
private val Element.repositoryPackage
58+
get() = elements.packageOf(this)
4959

50-
val properties = classProto.propertyList.mapNotNull { property ->
60+
private val Element.superInterfaceClassName
61+
get() = ClassName.bestGuess("${elements.packageOf(this)}.${this.simpleName}")
62+
63+
private fun ClassData.getParameters(): List<Parameter> {
64+
return classProto.propertyList.mapNotNull { property ->
5165
property.toParameter(nameResolver)
5266
}
53-
val functions = classProto.functionList.mapNotNull {
54-
it.toFunction(element, nameResolver)
55-
}
56-
57-
return Repository(repositoryPackage, repositoryName, superInterfaceClassName, properties, functions)
5867
}
5968

6069
private fun ProtoBuf.Property.toParameter(nameResolver: NameResolver): Parameter? {
@@ -63,16 +72,20 @@ class RepositoryFactory(private val messager: Messager, private val elements: El
6372
val className = returnType.getClassName(nameResolver)
6473
val parameterizedBy = getParameterTypes(returnType, nameResolver)
6574

66-
messager.printMessage(WARNING, "parameterName $parameterName $parameterizedBy")
67-
6875
return Parameter(parameterName, Type(className, parameterizedBy, returnType.nullable))
6976
}
7077

78+
private fun ClassData.getFunctions(element: Element): List<Function> {
79+
return classProto.functionList.mapNotNull { function ->
80+
function.toFunction(element, nameResolver)
81+
}
82+
}
83+
7184
private fun ProtoBuf.Function.toFunction(element: Element, nameResolver: NameResolver): Function? {
7285
if (modality != ProtoBuf.Modality.ABSTRACT) return null
7386

7487
val functionName = nameResolver.getName(this)
75-
if(functionName == FUNC_CLEAR_CACHE) return null
88+
if (functionName == FUNC_CLEAR_CACHE) return null
7689

7790
val parameters = valueParameterList.map {
7891
it.toParameter(nameResolver)

0 commit comments

Comments
 (0)