Fix ktlint issue
This commit is contained in:
parent
dc9e649703
commit
ea424f29fb
|
@ -1,8 +1,8 @@
|
||||||
apply plugin: 'kotlin'
|
apply plugin: 'kotlin'
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
|
|
||||||
sourceCompatibility = '1.7'
|
sourceCompatibility = versions.sourceCompat
|
||||||
targetCompatibility = '1.7'
|
targetCompatibility = versions.sourceCompat
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.squareup:javapoet:1.13.0'
|
implementation 'com.squareup:javapoet:1.13.0'
|
||||||
|
|
|
@ -14,7 +14,7 @@ class FieldNameFormatter {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Normalize word separator chars
|
// Normalize word separator chars
|
||||||
val normalizedFieldName : String = fieldName.replace('-', '_')
|
val normalizedFieldName: String = fieldName.replace('-', '_')
|
||||||
|
|
||||||
// Iterate field name using the following rules
|
// Iterate field name using the following rules
|
||||||
// lowerCase m followed by upperCase anything is considered hungarian notation
|
// lowerCase m followed by upperCase anything is considered hungarian notation
|
||||||
|
@ -39,7 +39,6 @@ class FieldNameFormatter {
|
||||||
// Hungarian notation starting with: mX
|
// Hungarian notation starting with: mX
|
||||||
result.delete(0, 1)
|
result.delete(0, 1)
|
||||||
result.appendCodePoint(currentCodepoint)
|
result.appendCodePoint(currentCodepoint)
|
||||||
|
|
||||||
} else if (Character.isUpperCase(currentCodepoint) && Character.isUpperCase(previousCodepoint)) {
|
} else if (Character.isUpperCase(currentCodepoint) && Character.isUpperCase(previousCodepoint)) {
|
||||||
// InvalidCamelCase: XXYx (should have been xxYx)
|
// InvalidCamelCase: XXYx (should have been xxYx)
|
||||||
if (offset + Character.charCount(currentCodepoint) < normalizedFieldName.length) {
|
if (offset + Character.charCount(currentCodepoint) < normalizedFieldName.length) {
|
||||||
|
@ -49,11 +48,9 @@ class FieldNameFormatter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.appendCodePoint(currentCodepoint)
|
result.appendCodePoint(currentCodepoint)
|
||||||
|
|
||||||
} else if (currentCodepoint === '-'.code as Int? || currentCodepoint === '_'.code as Int?) {
|
} else if (currentCodepoint === '-'.code as Int? || currentCodepoint === '_'.code as Int?) {
|
||||||
// Word-separator: x-x or x_x
|
// Word-separator: x-x or x_x
|
||||||
result.append("_")
|
result.append("_")
|
||||||
|
|
||||||
} else if (Character.isUpperCase(currentCodepoint) && !Character.isUpperCase(previousCodepoint) && Character.isLetterOrDigit(previousCodepoint)) {
|
} else if (Character.isUpperCase(currentCodepoint) && !Character.isUpperCase(previousCodepoint) && Character.isLetterOrDigit(previousCodepoint)) {
|
||||||
// camelCase: xX
|
// camelCase: xX
|
||||||
result.append("_")
|
result.append("_")
|
||||||
|
|
|
@ -3,9 +3,7 @@ package dk.ilios.realmfieldnames
|
||||||
import com.squareup.javapoet.FieldSpec
|
import com.squareup.javapoet.FieldSpec
|
||||||
import com.squareup.javapoet.JavaFile
|
import com.squareup.javapoet.JavaFile
|
||||||
import com.squareup.javapoet.TypeSpec
|
import com.squareup.javapoet.TypeSpec
|
||||||
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
import javax.annotation.processing.Filer
|
import javax.annotation.processing.Filer
|
||||||
import javax.lang.model.element.Modifier
|
import javax.lang.model.element.Modifier
|
||||||
|
|
||||||
|
@ -32,13 +30,11 @@ class FileGenerator(private val filer: Filer) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateFile(classData: ClassData, classPool: Set<ClassData>): Boolean {
|
private fun generateFile(classData: ClassData, classPool: Set<ClassData>): Boolean {
|
||||||
|
|
||||||
val fileBuilder = TypeSpec.classBuilder(classData.simpleClassName + "Fields")
|
val fileBuilder = TypeSpec.classBuilder(classData.simpleClassName + "Fields")
|
||||||
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
|
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
|
||||||
.addJavadoc("This class enumerate all queryable fields in {@link \$L.\$L}\n",
|
.addJavadoc("This class enumerate all queryable fields in {@link \$L.\$L}\n",
|
||||||
classData.packageName, classData.simpleClassName)
|
classData.packageName, classData.simpleClassName)
|
||||||
|
|
||||||
|
|
||||||
// Add a static field reference to each queryable field in the Realm model class
|
// Add a static field reference to each queryable field in the Realm model class
|
||||||
classData.fields.forEach { fieldName, value ->
|
classData.fields.forEach { fieldName, value ->
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
|
@ -69,7 +65,6 @@ class FileGenerator(private val filer: Filer) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addField(fileBuilder: TypeSpec.Builder, fieldName: String, fieldNameValue: String) {
|
private fun addField(fileBuilder: TypeSpec.Builder, fieldName: String, fieldNameValue: String) {
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
package dk.ilios.realmfieldnames
|
package dk.ilios.realmfieldnames
|
||||||
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
import javax.annotation.processing.AbstractProcessor
|
import javax.annotation.processing.AbstractProcessor
|
||||||
import javax.annotation.processing.Messager
|
import javax.annotation.processing.Messager
|
||||||
import javax.annotation.processing.ProcessingEnvironment
|
import javax.annotation.processing.ProcessingEnvironment
|
||||||
import javax.annotation.processing.RoundEnvironment
|
import javax.annotation.processing.RoundEnvironment
|
||||||
import javax.annotation.processing.SupportedAnnotationTypes
|
import javax.annotation.processing.SupportedAnnotationTypes
|
||||||
import javax.lang.model.SourceVersion
|
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.DeclaredType
|
||||||
import javax.lang.model.type.TypeMirror
|
import javax.lang.model.type.TypeMirror
|
||||||
import javax.lang.model.util.Elements
|
import javax.lang.model.util.Elements
|
||||||
|
@ -24,9 +27,9 @@ import javax.tools.Diagnostic
|
||||||
class RealmFieldNamesProcessor : AbstractProcessor() {
|
class RealmFieldNamesProcessor : AbstractProcessor() {
|
||||||
|
|
||||||
private val classes = HashSet<ClassData>()
|
private val classes = HashSet<ClassData>()
|
||||||
lateinit private var typeUtils: Types
|
private lateinit var typeUtils: Types
|
||||||
lateinit private var messager: Messager
|
private lateinit var messager: Messager
|
||||||
lateinit private var elementUtils: Elements
|
private lateinit var elementUtils: Elements
|
||||||
private var ignoreAnnotation: TypeMirror? = null
|
private var ignoreAnnotation: TypeMirror? = null
|
||||||
private var realmClassAnnotation: TypeElement? = null
|
private var realmClassAnnotation: TypeElement? = null
|
||||||
private var realmModelInterface: TypeMirror? = null
|
private var realmModelInterface: TypeMirror? = null
|
||||||
|
@ -35,7 +38,8 @@ class RealmFieldNamesProcessor : AbstractProcessor() {
|
||||||
private var fileGenerator: FileGenerator? = null
|
private var fileGenerator: FileGenerator? = null
|
||||||
private var done = false
|
private var done = false
|
||||||
|
|
||||||
@Synchronized override fun init(processingEnv: ProcessingEnvironment) {
|
@Synchronized
|
||||||
|
override fun init(processingEnv: ProcessingEnvironment) {
|
||||||
super.init(processingEnv)
|
super.init(processingEnv)
|
||||||
typeUtils = processingEnv.typeUtils!!
|
typeUtils = processingEnv.typeUtils!!
|
||||||
messager = processingEnv.messager!!
|
messager = processingEnv.messager!!
|
||||||
|
@ -51,10 +55,14 @@ class RealmFieldNamesProcessor : AbstractProcessor() {
|
||||||
ignoreAnnotation = elementUtils.getTypeElement("io.realm.annotations.Ignore")?.asType()
|
ignoreAnnotation = elementUtils.getTypeElement("io.realm.annotations.Ignore")?.asType()
|
||||||
realmClassAnnotation = elementUtils.getTypeElement("io.realm.annotations.RealmClass")
|
realmClassAnnotation = elementUtils.getTypeElement("io.realm.annotations.RealmClass")
|
||||||
realmModelInterface = elementUtils.getTypeElement("io.realm.RealmModel")?.asType()
|
realmModelInterface = elementUtils.getTypeElement("io.realm.RealmModel")?.asType()
|
||||||
realmListClass = typeUtils.getDeclaredType(elementUtils.getTypeElement("io.realm.RealmList"),
|
realmListClass = typeUtils.getDeclaredType(
|
||||||
typeUtils.getWildcardType(null, null))
|
elementUtils.getTypeElement("io.realm.RealmList"),
|
||||||
realmResultsClass = typeUtils.getDeclaredType(elementUtils.getTypeElement("io.realm.RealmResults"),
|
typeUtils.getWildcardType(null, null)
|
||||||
typeUtils.getWildcardType(null, null))
|
)
|
||||||
|
realmResultsClass = typeUtils.getDeclaredType(
|
||||||
|
elementUtils.getTypeElement("io.realm.RealmResults"),
|
||||||
|
typeUtils.getWildcardType(null, null)
|
||||||
|
)
|
||||||
fileGenerator = FileGenerator(processingEnv.filer)
|
fileGenerator = FileGenerator(processingEnv.filer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,8 +91,8 @@ class RealmFieldNamesProcessor : AbstractProcessor() {
|
||||||
classes.forEach {
|
classes.forEach {
|
||||||
it.fields.forEach { _, value ->
|
it.fields.forEach { _, value ->
|
||||||
// Analyze the library class file the first time it is encountered.
|
// Analyze the library class file the first time it is encountered.
|
||||||
if (value != null ) {
|
if (value != null) {
|
||||||
if (classes.all{ it.qualifiedClassName != value } && !libraryClasses.containsKey(value)) {
|
if (classes.all { it.qualifiedClassName != value } && !libraryClasses.containsKey(value)) {
|
||||||
libraryClasses.put(value, processLibraryClass(value))
|
libraryClasses.put(value, processLibraryClass(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -172,8 +180,10 @@ class RealmFieldNamesProcessor : AbstractProcessor() {
|
||||||
val enclosingElement = classElement.enclosingElement
|
val enclosingElement = classElement.enclosingElement
|
||||||
|
|
||||||
if (enclosingElement.kind != ElementKind.PACKAGE) {
|
if (enclosingElement.kind != ElementKind.PACKAGE) {
|
||||||
messager.printMessage(Diagnostic.Kind.ERROR,
|
messager.printMessage(
|
||||||
"Could not determine the package name. Enclosing element was: " + enclosingElement.kind)
|
Diagnostic.Kind.ERROR,
|
||||||
|
"Could not determine the package name. Enclosing element was: " + enclosingElement.kind
|
||||||
|
)
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,4 +33,4 @@ class CustomTypefaceSpan(private val tf: Typeface) : MetricAffectingSpan() {
|
||||||
|
|
||||||
paint.typeface = tf
|
paint.typeface = tf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,4 +26,4 @@ class TextDecorationLineSpan(private val textDecorationLine: String) : Character
|
||||||
else -> throw RuntimeException("Unknown text decoration line")
|
else -> throw RuntimeException("Unknown text decoration line")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue