From 770c81ebdee17055a4ab8217309e9f840df807b5 Mon Sep 17 00:00:00 2001 From: Matthew Pope Date: Fri, 6 Sep 2024 11:11:28 -0700 Subject: [PATCH] Little bits of cleanup --- .../impl/_Private_IonTextWriterBuilder_1_1.java | 4 ++-- .../amazon/ion/impl/bin/IonManagedWriter_1_1.kt | 6 +++--- .../ion/impl/bin/ManagedWriterOptions_1_1.kt | 16 ++++++++++------ .../com/amazon/ion/impl/macro/MacroCompiler.kt | 2 +- .../_Private_IonBinaryWriterBuilder_1_1.java | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/amazon/ion/impl/_Private_IonTextWriterBuilder_1_1.java b/src/main/java/com/amazon/ion/impl/_Private_IonTextWriterBuilder_1_1.java index 70b99b999..6ec9ab260 100644 --- a/src/main/java/com/amazon/ion/impl/_Private_IonTextWriterBuilder_1_1.java +++ b/src/main/java/com/amazon/ion/impl/_Private_IonTextWriterBuilder_1_1.java @@ -152,7 +152,7 @@ public IonWriter build(Appendable out) { symbolInliningStrategy, LengthPrefixStrategy.NEVER_PREFIXED, // This could be made configurable. - ManagedWriterOptions_1_1.MacroAddressStrategy.BY_NAME + ManagedWriterOptions_1_1.EExpressionIdentifierStrategy.BY_NAME ); return IonManagedWriter_1_1.textWriter(out, options, b); } @@ -169,7 +169,7 @@ public IonWriter build(OutputStream out) { symbolInliningStrategy, LengthPrefixStrategy.NEVER_PREFIXED, // This could be made configurable. - ManagedWriterOptions_1_1.MacroAddressStrategy.BY_NAME + ManagedWriterOptions_1_1.EExpressionIdentifierStrategy.BY_NAME ); return IonManagedWriter_1_1.textWriter(out, options, b); } diff --git a/src/main/java/com/amazon/ion/impl/bin/IonManagedWriter_1_1.kt b/src/main/java/com/amazon/ion/impl/bin/IonManagedWriter_1_1.kt index e8a5cec6b..711349666 100644 --- a/src/main/java/com/amazon/ion/impl/bin/IonManagedWriter_1_1.kt +++ b/src/main/java/com/amazon/ion/impl/bin/IonManagedWriter_1_1.kt @@ -758,7 +758,7 @@ internal class IonManagedWriter_1_1( override fun addMacro(macro: Macro): MacroRef { val id = internMacro(macro) - return if (options.macroAddressStrategy == ManagedWriterOptions_1_1.MacroAddressStrategy.BY_NAME) { + return if (options.eExpressionIdentifierStrategy == ManagedWriterOptions_1_1.EExpressionIdentifierStrategy.BY_NAME) { macroNames[id] ?.let { MacroRef.ByName(it) } ?: MacroRef.ById(id) @@ -770,7 +770,7 @@ internal class IonManagedWriter_1_1( override fun addMacro(name: String, macro: Macro): MacroRef { val id = internMacro(macro) macroNames[id] = name - return if (options.macroAddressStrategy == ManagedWriterOptions_1_1.MacroAddressStrategy.BY_NAME) { + return if (options.eExpressionIdentifierStrategy == ManagedWriterOptions_1_1.EExpressionIdentifierStrategy.BY_NAME) { MacroRef.ByName(name) } else { MacroRef.ById(id) @@ -778,7 +778,7 @@ internal class IonManagedWriter_1_1( } override fun startMacro(macroRef: MacroRef) { - val useNames = options.macroAddressStrategy == ManagedWriterOptions_1_1.MacroAddressStrategy.BY_NAME + val useNames = options.eExpressionIdentifierStrategy == ManagedWriterOptions_1_1.EExpressionIdentifierStrategy.BY_NAME val ref = when (macroRef) { is MacroRef.ById -> if (useNames) macroRef.intoNamed() else macroRef is MacroRef.ByName -> if (useNames) macroRef else macroRef.intoId() diff --git a/src/main/java/com/amazon/ion/impl/bin/ManagedWriterOptions_1_1.kt b/src/main/java/com/amazon/ion/impl/bin/ManagedWriterOptions_1_1.kt index fa973c739..feac6805f 100644 --- a/src/main/java/com/amazon/ion/impl/bin/ManagedWriterOptions_1_1.kt +++ b/src/main/java/com/amazon/ion/impl/bin/ManagedWriterOptions_1_1.kt @@ -19,7 +19,7 @@ data class ManagedWriterOptions_1_1( val internEncodingDirectiveSymbols: Boolean, val symbolInliningStrategy: SymbolInliningStrategy, val lengthPrefixStrategy: LengthPrefixStrategy, - val macroAddressStrategy: MacroAddressStrategy, + val eExpressionIdentifierStrategy: EExpressionIdentifierStrategy, ) : SymbolInliningStrategy by symbolInliningStrategy, LengthPrefixStrategy by lengthPrefixStrategy { companion object { @JvmField @@ -27,21 +27,25 @@ data class ManagedWriterOptions_1_1( internEncodingDirectiveSymbols = true, symbolInliningStrategy = SymbolInliningStrategy.NEVER_INLINE, lengthPrefixStrategy = LengthPrefixStrategy.ALWAYS_PREFIXED, - macroAddressStrategy = MacroAddressStrategy.BY_ID, + eExpressionIdentifierStrategy = EExpressionIdentifierStrategy.BY_ADDRESS, ) @JvmField val ION_TEXT_DEFAULT = ManagedWriterOptions_1_1( - // It's a little easier to read this way + // Encoding directives are easier to read if we don't intern their keywords. internEncodingDirectiveSymbols = false, symbolInliningStrategy = SymbolInliningStrategy.ALWAYS_INLINE, // This doesn't actually have any effect for Ion Text since there are no length-prefixed containers. lengthPrefixStrategy = LengthPrefixStrategy.NEVER_PREFIXED, - macroAddressStrategy = MacroAddressStrategy.BY_NAME, + eExpressionIdentifierStrategy = EExpressionIdentifierStrategy.BY_NAME, ) } - enum class MacroAddressStrategy { + /** + * Indicates whether e-expressions should be written using macro + * names or macro addresses (when a choice is available). + */ + enum class EExpressionIdentifierStrategy { BY_NAME, - BY_ID, + BY_ADDRESS, } } diff --git a/src/main/java/com/amazon/ion/impl/macro/MacroCompiler.kt b/src/main/java/com/amazon/ion/impl/macro/MacroCompiler.kt index ac8e449dc..4d4b2c2cf 100644 --- a/src/main/java/com/amazon/ion/impl/macro/MacroCompiler.kt +++ b/src/main/java/com/amazon/ion/impl/macro/MacroCompiler.kt @@ -236,7 +236,7 @@ class MacroCompiler(private val reader: IonReaderContinuableCore) { } // TODO: Once we have a macro table, validate that id exists in current macro table. IonType.INT -> MacroRef.ById(reader.intValue()) - else -> throw IonException("macro invocation must start with an id (int) or identifier (symbol); found ${reader.type ?: "nothing"}\"") + else -> throw IonException("macro invocation must start with an id (int) or identifier (symbol); found ${reader.encodingType ?: "nothing"}\"") } val macroStart = expressions.size diff --git a/src/main/java/com/amazon/ion/system/_Private_IonBinaryWriterBuilder_1_1.java b/src/main/java/com/amazon/ion/system/_Private_IonBinaryWriterBuilder_1_1.java index 34ebcb6bd..4eee3e9c9 100644 --- a/src/main/java/com/amazon/ion/system/_Private_IonBinaryWriterBuilder_1_1.java +++ b/src/main/java/com/amazon/ion/system/_Private_IonBinaryWriterBuilder_1_1.java @@ -141,7 +141,7 @@ public IonWriter build(OutputStream out) { true, symbolInliningStrategy, lengthPrefixStrategy, - ManagedWriterOptions_1_1.MacroAddressStrategy.BY_ID + ManagedWriterOptions_1_1.EExpressionIdentifierStrategy.BY_ADDRESS ); return IonManagedWriter_1_1.binaryWriter(out, options, this); }