{NUMBER()}.
*
- * @param bundle The base bundle
- * @param arguments The arguments that are being passed on the scope
- * @return The result of the function with the specific parameters
+ *
+ * @param bundle@return The result of the function with the specific parameters
*/
@Override
- public CharSequence getResult(final DirectFluentBundle bundle, final FluentArgs arguments) {
- return this.getArgumentResult(bundle, arguments).getResult(bundle, arguments);
+ public CharSequence getResult(AccessorBundle bundle) {
+ return this.getArgumentResult(bundle).getResult(bundle);
}
@Override
diff --git a/src/main/java/net/quickwrite/fluent4j/ast/placeable/MessageReference.java b/src/main/java/net/quickwrite/fluent4j/ast/placeable/MessageReference.java
index 5d9c5444..a15e40ba 100644
--- a/src/main/java/net/quickwrite/fluent4j/ast/placeable/MessageReference.java
+++ b/src/main/java/net/quickwrite/fluent4j/ast/placeable/MessageReference.java
@@ -3,8 +3,8 @@
import net.quickwrite.fluent4j.ast.FluentElement;
import net.quickwrite.fluent4j.ast.placeable.base.FluentPlaceable;
import net.quickwrite.fluent4j.util.StringSlice;
-import net.quickwrite.fluent4j.util.args.FluentArgs;
import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
+import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
/**
@@ -36,9 +36,10 @@ public String stringValue() {
}
@Override
- public CharSequence getResult(final DirectFluentBundle bundle, final FluentArgs arguments) {
- return bundle
- .getMessage(this.stringValue(), arguments)
+ public CharSequence getResult(final AccessorBundle bundle) {
+ return bundle
+ .getBundle()
+ .getMessage(this.stringValue(), bundle)
.orElse("{" + this.stringValue() + "}");
}
diff --git a/src/main/java/net/quickwrite/fluent4j/ast/placeable/NumberLiteral.java b/src/main/java/net/quickwrite/fluent4j/ast/placeable/NumberLiteral.java
index 36a7cfae..7f7ba584 100644
--- a/src/main/java/net/quickwrite/fluent4j/ast/placeable/NumberLiteral.java
+++ b/src/main/java/net/quickwrite/fluent4j/ast/placeable/NumberLiteral.java
@@ -10,9 +10,9 @@
import net.quickwrite.fluent4j.ast.placeable.base.FluentPlaceable;
import net.quickwrite.fluent4j.ast.placeable.base.FluentSelectable;
import net.quickwrite.fluent4j.util.StringSlice;
-import net.quickwrite.fluent4j.util.args.FluentArgs;
import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
+import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
import java.math.BigDecimal;
@@ -51,8 +51,8 @@ public static NumberLiteral getNumberLiteral(final String value) {
}
@Override
- public CharSequence getResult(final DirectFluentBundle bundle, final FluentArgs arguments) {
- return NumberFormat.getInstance(bundle.getLocale()).format(number);
+ public CharSequence getResult(final AccessorBundle bundle) {
+ return NumberFormat.getInstance(bundle.getBundle().getLocale()).format(number);
}
private static BigDecimal convertToBigDecimal(final Number number) {
diff --git a/src/main/java/net/quickwrite/fluent4j/ast/placeable/SelectExpression.java b/src/main/java/net/quickwrite/fluent4j/ast/placeable/SelectExpression.java
index 8927e77c..b4c6fc94 100644
--- a/src/main/java/net/quickwrite/fluent4j/ast/placeable/SelectExpression.java
+++ b/src/main/java/net/quickwrite/fluent4j/ast/placeable/SelectExpression.java
@@ -4,8 +4,8 @@
import net.quickwrite.fluent4j.ast.FluentVariant;
import net.quickwrite.fluent4j.ast.placeable.base.FluentArgumentResult;
import net.quickwrite.fluent4j.ast.placeable.base.FluentPlaceable;
-import net.quickwrite.fluent4j.util.args.FluentArgs;
import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
+import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
import java.util.List;
@@ -50,17 +50,17 @@ public String stringValue() {
}
@Override
- public CharSequence getResult(final DirectFluentBundle bundle, final FluentArgs arguments) {
+ public CharSequence getResult(final AccessorBundle bundle) {
final FluentElement argument = (identifier instanceof FluentArgumentResult) ?
- ((FluentArgumentResult) identifier).getArgumentResult(bundle, arguments) : identifier;
+ ((FluentArgumentResult) identifier).getArgumentResult(bundle) : identifier;
for (final FluentVariant variant : variants) {
- if (argument.matches(bundle, variant.getIdentifier())) {
- return variant.getResult(bundle, arguments);
+ if (argument.matches(bundle.getBundle(), variant.getIdentifier())) {
+ return variant.getResult(bundle);
}
}
- return defaultVariant.getResult(bundle, arguments);
+ return defaultVariant.getResult(bundle);
}
@Override
diff --git a/src/main/java/net/quickwrite/fluent4j/ast/placeable/StringLiteral.java b/src/main/java/net/quickwrite/fluent4j/ast/placeable/StringLiteral.java
index 7a957cd8..79f07710 100644
--- a/src/main/java/net/quickwrite/fluent4j/ast/placeable/StringLiteral.java
+++ b/src/main/java/net/quickwrite/fluent4j/ast/placeable/StringLiteral.java
@@ -5,8 +5,8 @@
import net.quickwrite.fluent4j.ast.placeable.base.FluentSelectable;
import net.quickwrite.fluent4j.ast.placeable.base.FluentUnicodeTranslator;
import net.quickwrite.fluent4j.util.StringSlice;
-import net.quickwrite.fluent4j.util.args.FluentArgs;
import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
+import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
import org.apache.commons.text.translate.AggregateTranslator;
import org.apache.commons.text.translate.CharSequenceTranslator;
import org.apache.commons.text.translate.LookupTranslator;
@@ -55,7 +55,7 @@ public StringLiteral(final String content) {
}
@Override
- public CharSequence getResult(final DirectFluentBundle bundle, final FluentArgs arguments) {
+ public CharSequence getResult(AccessorBundle bundle) {
return this.literal;
}
diff --git a/src/main/java/net/quickwrite/fluent4j/ast/placeable/TermReference.java b/src/main/java/net/quickwrite/fluent4j/ast/placeable/TermReference.java
index d3cad0c5..34dd8963 100644
--- a/src/main/java/net/quickwrite/fluent4j/ast/placeable/TermReference.java
+++ b/src/main/java/net/quickwrite/fluent4j/ast/placeable/TermReference.java
@@ -5,7 +5,8 @@
import net.quickwrite.fluent4j.ast.placeable.base.FluentFunction;
import net.quickwrite.fluent4j.util.StringSlice;
import net.quickwrite.fluent4j.util.args.FluentArgs;
-import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
+import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
+import net.quickwrite.fluent4j.util.bundle.args.AccessorElementsBundle;
/**
* Terms are similar to regular messages but they can
@@ -39,24 +40,19 @@ protected boolean check(final String string) {
}
@Override
- public CharSequence getResult(final DirectFluentBundle bundle, final FluentArgs arguments) {
- return this.getArgumentResult(bundle, arguments).getResult(bundle, this.getArguments(bundle, arguments));
+ public CharSequence getResult(final AccessorBundle bundle) {
+ return bundle.getBundle()
+ .getTerm(this.functionName, new AccessorElementsBundle(bundle.getBundle(), this.getArguments(bundle), bundle.getAccessedStorage()))
+ .orElse("{-" + this.functionName + "}");
}
/**
* @param bundle The bundle that this is being called from
- * @param arguments The arguments that are passed into this function
- * @return
+ * @return The result of the term that is being called
*/
@Override
- public FluentElement getArgumentResult(final DirectFluentBundle bundle, final FluentArgs arguments) {
- final FluentTerm term = bundle.getTerm(this.functionName);
-
- if (term == null) {
- return new StringLiteral("{-" + this.functionName + "}");
- }
-
- return term;
+ public FluentElement getArgumentResult(final AccessorBundle bundle) {
+ return new StringLiteral(getResult(bundle).toString());
}
@Override
diff --git a/src/main/java/net/quickwrite/fluent4j/ast/placeable/VariableReference.java b/src/main/java/net/quickwrite/fluent4j/ast/placeable/VariableReference.java
index 9d2db2c2..96f24fad 100644
--- a/src/main/java/net/quickwrite/fluent4j/ast/placeable/VariableReference.java
+++ b/src/main/java/net/quickwrite/fluent4j/ast/placeable/VariableReference.java
@@ -7,6 +7,7 @@
import net.quickwrite.fluent4j.util.StringSlice;
import net.quickwrite.fluent4j.util.args.FluentArgs;
import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
+import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
/**
* Variables are pieces of data received from the app.
@@ -51,25 +52,26 @@ public String stringValue() {
}
@Override
- public FluentElement getArgumentResult(DirectFluentBundle bundle, final FluentArgs arguments) {
+ public FluentElement getArgumentResult(final AccessorBundle bundle) {
+ final FluentArgs arguments = bundle.getArguments();
final FluentElement argument = arguments.getNamed(content);
if (argument == null) {
return new StringLiteral("{$" + content + "}");
}
- return arguments.getNamed(content);
+ return argument;
}
@Override
- public CharSequence getResult(final DirectFluentBundle bundle, final FluentArgs arguments) {
- final FluentElement argument = arguments.getNamed(content);
+ public CharSequence getResult(final AccessorBundle bundle) {
+ final FluentElement argument = bundle.getArguments().getNamed(content);
if (argument == null) {
return "{$" + content + "}";
}
- return argument.getResult(bundle, arguments);
+ return argument.getResult(bundle);
}
@Override
diff --git a/src/main/java/net/quickwrite/fluent4j/ast/placeable/base/FluentArgumentResult.java b/src/main/java/net/quickwrite/fluent4j/ast/placeable/base/FluentArgumentResult.java
index 24be38b8..79827a80 100644
--- a/src/main/java/net/quickwrite/fluent4j/ast/placeable/base/FluentArgumentResult.java
+++ b/src/main/java/net/quickwrite/fluent4j/ast/placeable/base/FluentArgumentResult.java
@@ -1,9 +1,8 @@
package net.quickwrite.fluent4j.ast.placeable.base;
import net.quickwrite.fluent4j.ast.FluentElement;
-import net.quickwrite.fluent4j.util.args.FluentArgs;
-import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
+import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
public interface FluentArgumentResult {
- FluentElement getArgumentResult(final DirectFluentBundle bundle, final FluentArgs arguments);
+ FluentElement getArgumentResult(AccessorBundle bundle);
}
diff --git a/src/main/java/net/quickwrite/fluent4j/ast/placeable/base/FluentFunction.java b/src/main/java/net/quickwrite/fluent4j/ast/placeable/base/FluentFunction.java
index 9b1b15c9..d0b71d18 100644
--- a/src/main/java/net/quickwrite/fluent4j/ast/placeable/base/FluentFunction.java
+++ b/src/main/java/net/quickwrite/fluent4j/ast/placeable/base/FluentFunction.java
@@ -4,8 +4,8 @@
import net.quickwrite.fluent4j.exception.FluentParseException;
import net.quickwrite.fluent4j.util.StringSlice;
import net.quickwrite.fluent4j.util.args.FluentArgs;
-import net.quickwrite.fluent4j.util.args.FunctionFluentArguments;
import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
+import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
/**
* Implements the basis for a value that gets
@@ -34,25 +34,23 @@ public FluentFunction(final String functionName, final FluentArgs arguments) {
* Returns the arguments that the function
* has itself in a sanitized form.
*
- * @param bundle The bundle that this is being called from
- * @param arguments The arguments in this scope
+ * @param bundle The arguments that are getting passed down
* @return The sanitized arguments of the function
*/
- protected FluentArgs getArguments(final DirectFluentBundle bundle, final FluentArgs arguments) {
- if (this.arguments != null)
- this.arguments.sanitize(bundle, arguments);
+ protected FluentArgs getArguments(final AccessorBundle bundle) {
+ if (this.arguments == null)
+ return null;
- return this.arguments;
+ return this.arguments.sanitize(bundle);
}
/**
* Returns the {@link FluentElement} that the function is returning.
*
* @param bundle The bundle that this is being called from
- * @param arguments The arguments that are passed into this function
* @return The resulting {@link FluentElement} that has been created
*/
- public abstract FluentElement getArgumentResult(final DirectFluentBundle bundle, final FluentArgs arguments);
+ public abstract FluentElement getArgumentResult(final AccessorBundle bundle);
/**
* Checks if this FluentFunction and the selector are the same.
diff --git a/src/main/java/net/quickwrite/fluent4j/functions/AbstractFunction.java b/src/main/java/net/quickwrite/fluent4j/functions/AbstractFunction.java
index fd369596..77f72162 100644
--- a/src/main/java/net/quickwrite/fluent4j/functions/AbstractFunction.java
+++ b/src/main/java/net/quickwrite/fluent4j/functions/AbstractFunction.java
@@ -5,6 +5,7 @@
import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
import net.quickwrite.fluent4j.ast.placeable.base.FluentPlaceable;
import net.quickwrite.fluent4j.ast.placeable.NumberLiteral;
+import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
/**
* Functions provide additional functionality available to the localizers.
@@ -70,5 +71,5 @@ public String getIdentifier() {
* @param arguments The arguments the function gets
* @return The result
*/
- public abstract FluentPlaceable getResult(final DirectFluentBundle bundle, final FunctionFluentArgs arguments);
+ public abstract FluentPlaceable getResult(final AccessorBundle bundle, final FunctionFluentArgs arguments);
}
diff --git a/src/main/java/net/quickwrite/fluent4j/functions/NumberFunction.java b/src/main/java/net/quickwrite/fluent4j/functions/NumberFunction.java
index 17d0cf1c..9ae4a0c6 100644
--- a/src/main/java/net/quickwrite/fluent4j/functions/NumberFunction.java
+++ b/src/main/java/net/quickwrite/fluent4j/functions/NumberFunction.java
@@ -3,10 +3,10 @@
import net.quickwrite.fluent4j.ast.FluentElement;
import net.quickwrite.fluent4j.util.args.FluentArgs;
import net.quickwrite.fluent4j.util.args.FunctionFluentArgs;
-import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
import net.quickwrite.fluent4j.ast.placeable.NumberLiteral;
import net.quickwrite.fluent4j.ast.placeable.base.FluentPlaceable;
import net.quickwrite.fluent4j.util.args.CustomNumberLiteral;
+import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
import java.text.ParseException;
@@ -74,7 +74,7 @@ public NumberFunction() {
* @return The number as a {@link CustomNumberLiteral} with the parameters
*/
@Override
- public FluentPlaceable getResult(final DirectFluentBundle bundle, final FunctionFluentArgs arguments) {
+ public FluentPlaceable getResult(final AccessorBundle bundle, final FunctionFluentArgs arguments) {
final FluentElement number = arguments.getPositional(0);
CustomNumberLiteral numberLiteral;
diff --git a/src/main/java/net/quickwrite/fluent4j/util/args/CustomNumberLiteral.java b/src/main/java/net/quickwrite/fluent4j/util/args/CustomNumberLiteral.java
index 78cd80a4..f174fca9 100644
--- a/src/main/java/net/quickwrite/fluent4j/util/args/CustomNumberLiteral.java
+++ b/src/main/java/net/quickwrite/fluent4j/util/args/CustomNumberLiteral.java
@@ -1,8 +1,8 @@
package net.quickwrite.fluent4j.util.args;
import com.ibm.icu.text.NumberFormat;
-import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
import net.quickwrite.fluent4j.ast.placeable.NumberLiteral;
+import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
import java.math.BigDecimal;
import java.text.ParseException;
@@ -46,8 +46,8 @@ public void setUseGrouping(boolean useGrouping) {
}
@Override
- public String getResult(final DirectFluentBundle bundle, final FluentArgs arguments) {
- NumberFormat numberFormat = NumberFormat.getInstance(bundle.getLocale());
+ public String getResult(final AccessorBundle bundle) {
+ NumberFormat numberFormat = NumberFormat.getInstance(bundle.getBundle().getLocale());
numberFormat.setGroupingUsed(useGrouping);
numberFormat.setMaximumFractionDigits(maximumFractionDigits);
numberFormat.setMinimumFractionDigits(minimumFractionDigits);
diff --git a/src/main/java/net/quickwrite/fluent4j/util/args/FluentArgs.java b/src/main/java/net/quickwrite/fluent4j/util/args/FluentArgs.java
index c24ae1ba..e3d22519 100644
--- a/src/main/java/net/quickwrite/fluent4j/util/args/FluentArgs.java
+++ b/src/main/java/net/quickwrite/fluent4j/util/args/FluentArgs.java
@@ -1,7 +1,7 @@
package net.quickwrite.fluent4j.util.args;
import net.quickwrite.fluent4j.ast.FluentElement;
-import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
+import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
import java.util.Set;
@@ -20,11 +20,10 @@ public interface FluentArgs {
*
* This is necessary if the scopes are getting changed as a new scope does not have access
* every variable the previous scope had.
+ * @param bundle The main bundle
*
- * @param bundle The main bundle
- * @param arguments The old arguments
*/
- void sanitize(final DirectFluentBundle bundle, final FluentArgs arguments);
+ FluentArgs sanitize(final AccessorBundle bundle);
/**
* Adds a new named argument to the named arguments.
diff --git a/src/main/java/net/quickwrite/fluent4j/util/args/FluentArguments.java b/src/main/java/net/quickwrite/fluent4j/util/args/FluentArguments.java
index d57af2dd..c3ef71bb 100644
--- a/src/main/java/net/quickwrite/fluent4j/util/args/FluentArguments.java
+++ b/src/main/java/net/quickwrite/fluent4j/util/args/FluentArguments.java
@@ -2,7 +2,7 @@
import net.quickwrite.fluent4j.ast.FluentElement;
import net.quickwrite.fluent4j.ast.placeable.base.FluentArgumentResult;
-import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
+import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
import java.util.HashMap;
import java.util.Map;
@@ -13,7 +13,7 @@
* positional arguments.
*/
public class FluentArguments implements FluentArgs {
- private final Map
+ * So when the {@code .ftl}-files contain:
+ *
+ * So when the {@code .ftl}-files contain:
+ *
+ * it would return the {@link FluentMessage} for the key
+ * {@code test} but {@code null} for anything else.
+ *
+ * @param key The key that the {@link FluentMessage} is stored in.
+ * @param bundle The bundle that is being used as an argument
+ * @return The message itself
+ */
+ Optional
+ * -test = Hello World!
+ *
+ * it would return the {@link FluentTerm} for the key
+ * {@code test} but {@code null} for anything else.
+ *
+ * @param bundle The bundle that is being used as an argument
+ * @param key The key that the {@link FluentTerm} is stored in.
+ * @return The term itself
+ */
+ Optional
+ * test = Hello World!
+ *
+ *