-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/1.6.10' into main
- Loading branch information
Showing
359 changed files
with
12,950 additions
and
23,905 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apply plugin: 'kotlin' | ||
apply plugin: 'java' | ||
|
||
sourceCompatibility = versions.sourceCompat | ||
targetCompatibility = versions.sourceCompat | ||
|
||
dependencies { | ||
implementation 'com.squareup:javapoet:1.13.0' | ||
} | ||
|
||
task javadocJar(type: Jar, dependsOn: 'javadoc') { | ||
from javadoc.destinationDir | ||
classifier = 'javadoc' | ||
} | ||
task sourcesJar(type: Jar, dependsOn: 'classes') { | ||
from sourceSets.main.allSource | ||
classifier = 'sources' | ||
} | ||
|
||
sourceSets { | ||
main.java.srcDirs += 'src/main/kotlin' | ||
} | ||
|
24 changes: 24 additions & 0 deletions
24
library/external/realmfieldnameshelper/src/main/kotlin/dk/ilios/realmfieldnames/ClassData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package dk.ilios.realmfieldnames | ||
|
||
import java.util.TreeMap | ||
|
||
/** | ||
* Class responsible for keeping track of the metadata for each Realm model class. | ||
*/ | ||
class ClassData(val packageName: String?, val simpleClassName: String, val libraryClass: Boolean = false) { | ||
|
||
val fields = TreeMap<String, String?>() // <fieldName, linkedType or null> | ||
|
||
fun addField(field: String, linkedType: String?) { | ||
fields.put(field, linkedType) | ||
} | ||
|
||
val qualifiedClassName: String | ||
get() { | ||
if (packageName != null && !packageName.isEmpty()) { | ||
return packageName + "." + simpleClassName | ||
} else { | ||
return simpleClassName | ||
} | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...rnal/realmfieldnameshelper/src/main/kotlin/dk/ilios/realmfieldnames/FieldNameFormatter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package dk.ilios.realmfieldnames | ||
|
||
import java.util.Locale | ||
|
||
/** | ||
* Class for encapsulating the rules for converting between the field name in the Realm model class | ||
* and the matching name in the "<class>Fields" class. | ||
*/ | ||
class FieldNameFormatter { | ||
|
||
@JvmOverloads | ||
fun format(fieldName: String?, locale: Locale = Locale.US): String { | ||
if (fieldName == null || fieldName == "") { | ||
return "" | ||
} | ||
|
||
// Normalize word separator chars | ||
val normalizedFieldName: String = fieldName.replace('-', '_') | ||
|
||
// Iterate field name using the following rules | ||
// lowerCase m followed by upperCase anything is considered hungarian notation | ||
// lowercase char followed by uppercase char is considered camel case | ||
// Two uppercase chars following each other is considered non-standard camelcase | ||
// _ and - are treated as word separators | ||
val result = StringBuilder(normalizedFieldName.length) | ||
|
||
if (normalizedFieldName.codePointCount(0, normalizedFieldName.length) == 1) { | ||
result.append(normalizedFieldName) | ||
} else { | ||
var previousCodepoint: Int? | ||
var currentCodepoint: Int? = null | ||
val length = normalizedFieldName.length | ||
var offset = 0 | ||
while (offset < length) { | ||
previousCodepoint = currentCodepoint | ||
currentCodepoint = normalizedFieldName.codePointAt(offset) | ||
|
||
if (previousCodepoint != null) { | ||
if (Character.isUpperCase(currentCodepoint) && | ||
!Character.isUpperCase(previousCodepoint) && | ||
previousCodepoint === 'm'.code as Int? && | ||
result.length == 1 | ||
) { | ||
// 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) { | ||
val nextCodePoint = normalizedFieldName.codePointAt(offset + Character.charCount(currentCodepoint)) | ||
if (Character.isLowerCase(nextCodePoint)) { | ||
result.append("_") | ||
} | ||
} | ||
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("_") | ||
result.appendCodePoint(currentCodepoint) | ||
} else { | ||
// Unknown type | ||
result.appendCodePoint(currentCodepoint) | ||
} | ||
} else { | ||
// Only triggered for first code point | ||
result.appendCodePoint(currentCodepoint) | ||
} | ||
offset += Character.charCount(currentCodepoint) | ||
} | ||
} | ||
|
||
return result.toString().uppercase(locale) | ||
} | ||
} |
Oops, something went wrong.