From ea424f29fb67f5368b9b79606cb80241e21dcdeb Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 23 Jun 2023 22:58:28 +0200 Subject: [PATCH] Fix ktlint issue --- .../realmfieldnameshelper/build.gradle | 4 +- .../realmfieldnames/FieldNameFormatter.kt | 5 +-- .../dk/ilios/realmfieldnames/FileGenerator.kt | 5 --- .../RealmFieldNamesProcessor.kt | 40 ++++++++++++------- .../android/span/style/CustomTypefaceSpan.kt | 2 +- .../span/style/TextDecorationLineSpan.kt | 2 +- 6 files changed, 30 insertions(+), 28 deletions(-) diff --git a/library/external/realmfieldnameshelper/build.gradle b/library/external/realmfieldnameshelper/build.gradle index 13d8de7ca3..e051550210 100644 --- a/library/external/realmfieldnameshelper/build.gradle +++ b/library/external/realmfieldnameshelper/build.gradle @@ -1,8 +1,8 @@ apply plugin: 'kotlin' apply plugin: 'java' -sourceCompatibility = '1.7' -targetCompatibility = '1.7' +sourceCompatibility = versions.sourceCompat +targetCompatibility = versions.sourceCompat dependencies { implementation 'com.squareup:javapoet:1.13.0' diff --git a/library/external/realmfieldnameshelper/src/main/kotlin/dk/ilios/realmfieldnames/FieldNameFormatter.kt b/library/external/realmfieldnameshelper/src/main/kotlin/dk/ilios/realmfieldnames/FieldNameFormatter.kt index fbb44d333b..80ec9f779b 100644 --- a/library/external/realmfieldnameshelper/src/main/kotlin/dk/ilios/realmfieldnames/FieldNameFormatter.kt +++ b/library/external/realmfieldnameshelper/src/main/kotlin/dk/ilios/realmfieldnames/FieldNameFormatter.kt @@ -14,7 +14,7 @@ class FieldNameFormatter { } // Normalize word separator chars - val normalizedFieldName : String = fieldName.replace('-', '_') + val normalizedFieldName: String = fieldName.replace('-', '_') // Iterate field name using the following rules // lowerCase m followed by upperCase anything is considered hungarian notation @@ -39,7 +39,6 @@ class FieldNameFormatter { // Hungarian notation starting with: mX result.delete(0, 1) result.appendCodePoint(currentCodepoint) - } else if (Character.isUpperCase(currentCodepoint) && Character.isUpperCase(previousCodepoint)) { // InvalidCamelCase: XXYx (should have been xxYx) if (offset + Character.charCount(currentCodepoint) < normalizedFieldName.length) { @@ -49,11 +48,9 @@ class FieldNameFormatter { } } result.appendCodePoint(currentCodepoint) - } else if (currentCodepoint === '-'.code as Int? || currentCodepoint === '_'.code as Int?) { // Word-separator: x-x or x_x result.append("_") - } else if (Character.isUpperCase(currentCodepoint) && !Character.isUpperCase(previousCodepoint) && Character.isLetterOrDigit(previousCodepoint)) { // camelCase: xX result.append("_") diff --git a/library/external/realmfieldnameshelper/src/main/kotlin/dk/ilios/realmfieldnames/FileGenerator.kt b/library/external/realmfieldnameshelper/src/main/kotlin/dk/ilios/realmfieldnames/FileGenerator.kt index 02bdc70f44..eeeb5a45b8 100644 --- a/library/external/realmfieldnameshelper/src/main/kotlin/dk/ilios/realmfieldnames/FileGenerator.kt +++ b/library/external/realmfieldnameshelper/src/main/kotlin/dk/ilios/realmfieldnames/FileGenerator.kt @@ -3,9 +3,7 @@ package dk.ilios.realmfieldnames import com.squareup.javapoet.FieldSpec import com.squareup.javapoet.JavaFile import com.squareup.javapoet.TypeSpec - import java.io.IOException - import javax.annotation.processing.Filer import javax.lang.model.element.Modifier @@ -32,13 +30,11 @@ class FileGenerator(private val filer: Filer) { } private fun generateFile(classData: ClassData, classPool: Set): Boolean { - val fileBuilder = TypeSpec.classBuilder(classData.simpleClassName + "Fields") .addModifiers(Modifier.PUBLIC, Modifier.FINAL) .addJavadoc("This class enumerate all queryable fields in {@link \$L.\$L}\n", classData.packageName, classData.simpleClassName) - // Add a static field reference to each queryable field in the Realm model class classData.fields.forEach { fieldName, value -> if (value != null) { @@ -69,7 +65,6 @@ class FileGenerator(private val filer: Filer) { e.printStackTrace() return false } - } private fun addField(fileBuilder: TypeSpec.Builder, fieldName: String, fieldNameValue: String) { diff --git a/library/external/realmfieldnameshelper/src/main/kotlin/dk/ilios/realmfieldnames/RealmFieldNamesProcessor.kt b/library/external/realmfieldnameshelper/src/main/kotlin/dk/ilios/realmfieldnames/RealmFieldNamesProcessor.kt index 6f82882333..29d044c46c 100644 --- a/library/external/realmfieldnameshelper/src/main/kotlin/dk/ilios/realmfieldnames/RealmFieldNamesProcessor.kt +++ b/library/external/realmfieldnameshelper/src/main/kotlin/dk/ilios/realmfieldnames/RealmFieldNamesProcessor.kt @@ -1,14 +1,17 @@ package dk.ilios.realmfieldnames -import java.util.* - import javax.annotation.processing.AbstractProcessor import javax.annotation.processing.Messager import javax.annotation.processing.ProcessingEnvironment import javax.annotation.processing.RoundEnvironment import javax.annotation.processing.SupportedAnnotationTypes import javax.lang.model.SourceVersion -import javax.lang.model.element.* +import javax.lang.model.element.Element +import javax.lang.model.element.ElementKind +import javax.lang.model.element.Modifier +import javax.lang.model.element.PackageElement +import javax.lang.model.element.TypeElement +import javax.lang.model.element.VariableElement import javax.lang.model.type.DeclaredType import javax.lang.model.type.TypeMirror import javax.lang.model.util.Elements @@ -24,9 +27,9 @@ import javax.tools.Diagnostic class RealmFieldNamesProcessor : AbstractProcessor() { private val classes = HashSet() - lateinit private var typeUtils: Types - lateinit private var messager: Messager - lateinit private var elementUtils: Elements + private lateinit var typeUtils: Types + private lateinit var messager: Messager + private lateinit var elementUtils: Elements private var ignoreAnnotation: TypeMirror? = null private var realmClassAnnotation: TypeElement? = null private var realmModelInterface: TypeMirror? = null @@ -35,7 +38,8 @@ class RealmFieldNamesProcessor : AbstractProcessor() { private var fileGenerator: FileGenerator? = null private var done = false - @Synchronized override fun init(processingEnv: ProcessingEnvironment) { + @Synchronized + override fun init(processingEnv: ProcessingEnvironment) { super.init(processingEnv) typeUtils = processingEnv.typeUtils!! messager = processingEnv.messager!! @@ -51,10 +55,14 @@ class RealmFieldNamesProcessor : AbstractProcessor() { ignoreAnnotation = elementUtils.getTypeElement("io.realm.annotations.Ignore")?.asType() realmClassAnnotation = elementUtils.getTypeElement("io.realm.annotations.RealmClass") realmModelInterface = elementUtils.getTypeElement("io.realm.RealmModel")?.asType() - realmListClass = typeUtils.getDeclaredType(elementUtils.getTypeElement("io.realm.RealmList"), - typeUtils.getWildcardType(null, null)) - realmResultsClass = typeUtils.getDeclaredType(elementUtils.getTypeElement("io.realm.RealmResults"), - typeUtils.getWildcardType(null, null)) + realmListClass = typeUtils.getDeclaredType( + elementUtils.getTypeElement("io.realm.RealmList"), + typeUtils.getWildcardType(null, null) + ) + realmResultsClass = typeUtils.getDeclaredType( + elementUtils.getTypeElement("io.realm.RealmResults"), + typeUtils.getWildcardType(null, null) + ) fileGenerator = FileGenerator(processingEnv.filer) } } @@ -83,8 +91,8 @@ class RealmFieldNamesProcessor : AbstractProcessor() { classes.forEach { it.fields.forEach { _, value -> // Analyze the library class file the first time it is encountered. - if (value != null ) { - if (classes.all{ it.qualifiedClassName != value } && !libraryClasses.containsKey(value)) { + if (value != null) { + if (classes.all { it.qualifiedClassName != value } && !libraryClasses.containsKey(value)) { libraryClasses.put(value, processLibraryClass(value)) } } @@ -172,8 +180,10 @@ class RealmFieldNamesProcessor : AbstractProcessor() { val enclosingElement = classElement.enclosingElement if (enclosingElement.kind != ElementKind.PACKAGE) { - messager.printMessage(Diagnostic.Kind.ERROR, - "Could not determine the package name. Enclosing element was: " + enclosingElement.kind) + messager.printMessage( + Diagnostic.Kind.ERROR, + "Could not determine the package name. Enclosing element was: " + enclosingElement.kind + ) return null } diff --git a/library/external/span/src/main/kotlin/me/gujun/android/span/style/CustomTypefaceSpan.kt b/library/external/span/src/main/kotlin/me/gujun/android/span/style/CustomTypefaceSpan.kt index 57ae4548b6..c737c5bf11 100644 --- a/library/external/span/src/main/kotlin/me/gujun/android/span/style/CustomTypefaceSpan.kt +++ b/library/external/span/src/main/kotlin/me/gujun/android/span/style/CustomTypefaceSpan.kt @@ -33,4 +33,4 @@ class CustomTypefaceSpan(private val tf: Typeface) : MetricAffectingSpan() { paint.typeface = tf } -} \ No newline at end of file +} diff --git a/library/external/span/src/main/kotlin/me/gujun/android/span/style/TextDecorationLineSpan.kt b/library/external/span/src/main/kotlin/me/gujun/android/span/style/TextDecorationLineSpan.kt index 662cb82fed..ce37c138f7 100644 --- a/library/external/span/src/main/kotlin/me/gujun/android/span/style/TextDecorationLineSpan.kt +++ b/library/external/span/src/main/kotlin/me/gujun/android/span/style/TextDecorationLineSpan.kt @@ -26,4 +26,4 @@ class TextDecorationLineSpan(private val textDecorationLine: String) : Character else -> throw RuntimeException("Unknown text decoration line") } } -} \ No newline at end of file +}