Skip to content

Commit

Permalink
Fix inspections.
Browse files Browse the repository at this point in the history
  • Loading branch information
pdvrieze committed Sep 4, 2021
1 parent 7d7a0f0 commit 27b83be
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 52 deletions.
11 changes: 1 addition & 10 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ actual typealias PlatformXmlReader = AndroidXmlReader
* And XMLReader implementation that works on Android
*/
class AndroidXmlReader(val parser: XmlPullParser) : XmlReader {
override var isStarted = false
override var isStarted: Boolean = false

private constructor() : this(XmlPullParserFactory.newInstance().apply { isNamespaceAware = true }.newPullParser())

Expand All @@ -54,7 +54,7 @@ class AndroidXmlReader(val parser: XmlPullParser) : XmlReader {
return parser.getAttributeValue(nsUri, localName)
}

override fun isWhitespace() = parser.isWhitespace
override fun isWhitespace(): Boolean = parser.isWhitespace

@Throws(XmlException::class)
override fun hasNext(): Boolean {
Expand Down Expand Up @@ -138,12 +138,14 @@ class AndroidXmlReader(val parser: XmlPullParser) : XmlReader {
return null
}

override val locationInfo: String?
get() = StringBuilder(Integer.toString(parser.lineNumber)).append(':').append(
Integer.toString(parser.columnNumber)
).toString()
override val locationInfo: String
get() = buildString {
append(parser.lineNumber)
append(':')
append(parser.columnNumber)
}

override val standalone: Boolean?
override val standalone: Boolean
get() = parser.getProperty("xmldecl-standalone") as Boolean

override val encoding: String?
Expand Down
14 changes: 5 additions & 9 deletions core/src/commonMain/kotlin/nl/adaptivity/xmlutil/Namespace.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@

package nl.adaptivity.xmlutil

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.descriptors.buildClassSerialDescriptor
import kotlinx.serialization.descriptors.serialDescriptor
Expand Down Expand Up @@ -61,10 +58,9 @@ interface Namespace {
decoder.decodeStructure(descriptor) {
var index = decodeElementIndex(descriptor)
while (index!=CompositeDecoder.DECODE_DONE) {
val it = index
when (it) {
0 -> prefix = decodeStringElement(descriptor, it)
1 -> namespaceUri = decodeStringElement(descriptor, it)
when (index) {
0 -> prefix = decodeStringElement(descriptor, index)
1 -> namespaceUri = decodeStringElement(descriptor, index)
}

index = decodeElementIndex(descriptor)
Expand All @@ -85,8 +81,8 @@ interface Namespace {

@Suppress("NOTHING_TO_INLINE")
@Deprecated("Use the property version", ReplaceWith("this.prefix"))
inline fun Namespace.getPrefix() = prefix
inline fun Namespace.getPrefix(): String = prefix

@Suppress("NOTHING_TO_INLINE")
@Deprecated("Use the property version", ReplaceWith("this.namespaceURI"))
inline fun Namespace.getNamespaceURI() = namespaceURI
inline fun Namespace.getNamespaceURI(): String = namespaceURI
18 changes: 11 additions & 7 deletions core/src/commonMain/kotlin/nl/adaptivity/xmlutil/XmlReader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ interface XmlReader : Closeable, Iterator<EventType> {

namespace != null &&
namespaceURI != namespace ->
throw XmlException("Namespace ${namespaceURI} does not match expected \"$namespace\"")
throw XmlException("Namespace $namespaceURI does not match expected \"$namespace\"")

name != null &&
localName != name ->
throw XmlException("local name ${localName} does not match expected \"$name\"")
throw XmlException("local name $localName does not match expected \"$name\"")
}
}

Expand Down Expand Up @@ -269,15 +269,19 @@ fun XmlBufferedReader.consecutiveTextContent(): String {

var event: XmlEvent? = null

loop@while ((t.peek().apply { event = this@apply })?.eventType !== EventType.END_ELEMENT) {
loop@ while ((t.peek().apply { event = this@apply })?.eventType !== EventType.END_ELEMENT) {
when (event?.eventType) {
EventType.PROCESSING_INSTRUCTION,
EventType.COMMENT
-> { t.next();Unit } // ignore
-> {
t.next();Unit
} // ignore

// ignore whitespace starting the element.
EventType.IGNORABLE_WHITESPACE
-> { t.next(); whiteSpace.append(t.text) }
-> {
t.next(); whiteSpace.append(t.text)
}

EventType.TEXT,
EventType.ENTITY_REF,
Expand Down Expand Up @@ -420,7 +424,7 @@ fun XmlReader.isElement(
if (r.eventType !== type) {
return false
}
val expNs: CharSequence? = elementNamespace?.let { if (it.isEmpty()) null else it }
val expNs: CharSequence? = elementNamespace?.ifEmpty { null }

if (r.localName != elementName) {
return false
Expand All @@ -436,4 +440,4 @@ fun XmlReader.isElement(
/**
* Write the current event to the writer. This will **not** move the reader.
*/
fun XmlReader.writeCurrent(writer: XmlWriter) = eventType.writeEvent(writer, this)
fun XmlReader.writeCurrent(writer: XmlWriter): Unit = eventType.writeEvent(writer, this)
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ class DefaultSerializationProvider : SerializationProvider {
value.serialize(output)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,15 @@ class StAXStreamingFactory : XmlStreamingFactory {
@Throws(XmlException::class)
override fun newReader(source: Source): XmlReader {
try {
return when {
source !is StreamSource -> {
return when (source) {
is StreamSource -> StAXReader(source)
else -> {
val tf = TransformerFactory.newInstance()
val trans = tf.newTransformer()
val sw = StringWriter()
trans.transform(source, StreamResult(sw))
newReader(sw.toString())
}
else -> StAXReader(source)
}
} catch (e: XMLStreamException) {
throw XmlException(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ data class MyXmlDelegate(val attribute: String) {
@Serializable
@XmlSerialName("MyXml", "urn:OECD:MyXmlFile", "")
private open class BaseSerialDelegate(val attribute: String) {
constructor(origin: MyXmlDelegate): this(origin.attribute)
constructor(origin: MyXmlDelegate) : this(origin.attribute)

fun toMyXml(): MyXmlDelegate = MyXmlDelegate(attribute)
}
Expand All @@ -58,7 +58,7 @@ data class MyXmlDelegate(val attribute: String) {
this.schemalocation = schemalocation
}

constructor(origin: MyXmlDelegate): this(origin.attribute, "urn:OECD:MyXmlFile.xsd")
constructor(origin: MyXmlDelegate) : this(origin.attribute, "urn:OECD:MyXmlFile.xsd")
}

@Suppress("EXPERIMENTAL_API_USAGE")
Expand Down Expand Up @@ -95,9 +95,9 @@ data class MyXmlDelegate(val attribute: String) {
}

override fun deserialize(decoder: Decoder): MyXmlDelegate {
return when {
decoder is XML.XmlInput -> XmlSerialDelegate.serializer().deserialize(decoder).toMyXml()
else -> BaseSerialDelegate.serializer().deserialize(decoder).toMyXml()
return when (decoder) {
is XML.XmlInput -> XmlSerialDelegate.serializer().deserialize(decoder).toMyXml()
else -> BaseSerialDelegate.serializer().deserialize(decoder).toMyXml()
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
*/
@file:JvmName("XmlSerializableExt")

package nl.adaptivity.xmlutil
package nl.adaptivity.xmlutil.xmlserializable

import nl.adaptivity.xmlutil.*
import java.io.*


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
*/
@file:JvmName("XmlSerializableExtJvm")

package nl.adaptivity.xmlutil
package nl.adaptivity.xmlutil.xmlserializable

import java.io.*
import nl.adaptivity.xmlutil.*
import java.io.StringWriter
import java.io.Writer

@Throws(XmlException::class)
fun XmlSerializable.serialize(writer: Writer) {
Expand All @@ -38,4 +40,4 @@ fun XmlSerializable.toString(flags: Int): String {
serialize(writer)
}
}.toString()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
* under the License.
*/

package nl.adaptivity.xmlutil
package nl.adaptivity.xmlutil.xmlserializable

import nl.adaptivity.xmlutil.util.DefaultSerializationProvider
import nl.adaptivity.xmlutil.util.SerializationProvider
import nl.adaptivity.xmlutil.xmlserializable.XmlDeserializer
import nl.adaptivity.xmlutil.XmlDeserializerFactory
import nl.adaptivity.xmlutil.XmlStreaming
import java.io.StringReader
import kotlin.reflect.KClass

/**
* Utility method to deserialize a list of xml containing strings
Expand All @@ -43,4 +41,4 @@ fun <T> Iterable<String>.deSerialize(type: Class<T>): List<T> {
val factory: XmlDeserializerFactory<*> = deserializer.value.java.getConstructor().newInstance() as XmlDeserializerFactory<*>

return this.map { type.cast(factory.deserialize(XmlStreaming.newReader(StringReader(it)))) }
}
}

0 comments on commit 27b83be

Please sign in to comment.