Skip to content

Commit fdca48a

Browse files
committed
Merge branch 'develop'
2 parents ad2942b + a439d64 commit fdca48a

32 files changed

+392
-148
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>net.quickwrite</groupId>
88
<artifactId>fluent4j</artifactId>
9-
<version>0.2.1-alpha</version>
9+
<version>0.2.2-alpha</version>
1010
<build>
1111
<plugins>
1212
<plugin>

src/main/java/net/quickwrite/fluent4j/ast/FluentBase.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import net.quickwrite.fluent4j.exception.FluentParseException;
44
import net.quickwrite.fluent4j.util.StringSlice;
55
import net.quickwrite.fluent4j.util.StringSliceUtil;
6-
import net.quickwrite.fluent4j.util.args.FluentArgs;
76
import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
7+
import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
88

99
import java.util.LinkedList;
1010
import java.util.List;
@@ -88,32 +88,16 @@ public String getIdentifier() {
8888
return this.identifier;
8989
}
9090

91-
private StringSlice getVariantIdentifier(final StringSlice content) {
92-
char character = content.getChar();
93-
final int start = content.getPosition();
94-
95-
while (character != ' '
96-
&& character != '\n'
97-
&& character != ']'
98-
&& character != '\0'
99-
) {
100-
content.increment();
101-
character = content.getChar();
102-
}
103-
104-
return content.substring(start, content.getPosition());
105-
}
106-
10791
@Override
108-
public CharSequence getResult(final DirectFluentBundle bundle, final FluentArgs arguments) {
92+
public CharSequence getResult(final AccessorBundle bundle) {
10993
if (this.fluentElements.size() == 1) {
110-
return this.fluentElements.get(0).getResult(bundle, arguments);
94+
return this.fluentElements.get(0).getResult(bundle);
11195
}
11296

11397
final StringBuilder builder = new StringBuilder();
11498

11599
for (final FluentElement element : this.fluentElements) {
116-
builder.append(element.getResult(bundle, arguments));
100+
builder.append(element.getResult(bundle));
117101
}
118102

119103
return builder;

src/main/java/net/quickwrite/fluent4j/ast/FluentElement.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import net.quickwrite.fluent4j.ast.placeable.NumberLiteral;
44
import net.quickwrite.fluent4j.ast.placeable.SelectExpression;
5-
import net.quickwrite.fluent4j.util.args.FluentArgs;
65
import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
6+
import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
77

88
/**
99
* The base interface for the AST.
@@ -41,9 +41,8 @@ public interface FluentElement {
4141
* the different arguments and the base bundle that
4242
* it has been called from.
4343
*
44-
* @param bundle The base bundle
45-
* @param arguments The arguments that are being passed on the scope
44+
* @param bundle The bundle that is getting passed down
4645
* @return The {@link CharSequence} value of the argument with the parameters
4746
*/
48-
CharSequence getResult(final DirectFluentBundle bundle, final FluentArgs arguments);
47+
CharSequence getResult(final AccessorBundle bundle);
4948
}

src/main/java/net/quickwrite/fluent4j/ast/FluentTextElement.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package net.quickwrite.fluent4j.ast;
22

3-
import net.quickwrite.fluent4j.util.args.FluentArgs;
43
import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
54
import net.quickwrite.fluent4j.util.StringSlice;
5+
import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
66

77
/**
88
* The TextElement is just storing a text that does
@@ -82,7 +82,7 @@ public String stringValue() {
8282
}
8383

8484
@Override
85-
public CharSequence getResult(DirectFluentBundle bundle, FluentArgs arguments) {
85+
public CharSequence getResult(AccessorBundle bundle) {
8686
return this.text;
8787
}
8888

src/main/java/net/quickwrite/fluent4j/ast/FluentVariant.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package net.quickwrite.fluent4j.ast;
22

33
import net.quickwrite.fluent4j.exception.FluentParseException;
4-
import net.quickwrite.fluent4j.util.args.FluentArgs;
54
import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
65
import net.quickwrite.fluent4j.ast.placeable.NumberLiteral;
76
import net.quickwrite.fluent4j.ast.placeable.StringLiteral;
87
import net.quickwrite.fluent4j.ast.placeable.base.FluentPlaceable;
8+
import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
99

1010
/**
1111
* A variant stores a single variant of a
@@ -53,8 +53,8 @@ public String stringValue() {
5353
return identifier.stringValue();
5454
}
5555

56-
public CharSequence getResult(final DirectFluentBundle bundle, final FluentArgs arguments) {
57-
return this.content.getResult(bundle, arguments);
56+
public CharSequence getResult(AccessorBundle bundle) {
57+
return this.content.getResult(bundle);
5858
}
5959

6060
@Override

src/main/java/net/quickwrite/fluent4j/ast/placeable/AttributeReference.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.quickwrite.fluent4j.util.StringSlice;
1010
import net.quickwrite.fluent4j.util.args.FluentArgs;
1111
import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
12+
import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
1213

1314
import java.util.List;
1415

@@ -41,8 +42,8 @@ public String stringValue() {
4142
}
4243

4344
@Override
44-
public CharSequence getResult(final DirectFluentBundle bundle, final FluentArgs arguments) {
45-
final FluentMessage fluentMessage = this.getMessage(bundle, reference.stringValue());
45+
public CharSequence getResult(final AccessorBundle bundle) {
46+
final FluentMessage fluentMessage = this.getMessage(bundle.getBundle(), reference.stringValue());
4647
if (fluentMessage == null) {
4748
return getErrorString();
4849
}
@@ -53,12 +54,12 @@ public CharSequence getResult(final DirectFluentBundle bundle, final FluentArgs
5354
return getErrorString();
5455
}
5556

56-
return attribute.getResult(bundle, getArguments(arguments));
57+
return attribute.getResult(bundle);
5758
}
5859

5960
@Override
60-
public FluentElement getArgumentResult(final DirectFluentBundle bundle, final FluentArgs arguments) {
61-
final FluentMessage fluentMessage = this.getMessage(bundle, reference.stringValue());
61+
public FluentElement getArgumentResult(final AccessorBundle bundle) {
62+
final FluentMessage fluentMessage = this.getMessage(bundle.getBundle(), reference.stringValue());
6263
if (fluentMessage == null) {
6364
return this;
6465
}
@@ -69,6 +70,12 @@ public FluentElement getArgumentResult(final DirectFluentBundle bundle, final Fl
6970
return this;
7071
}
7172

73+
if (bundle.getAccessedStorage().alreadyAccessed(attribute)) {
74+
return this;
75+
}
76+
77+
bundle.getAccessedStorage().addElement(attribute);
78+
7279
final List<FluentElement> elementList = attribute.getElements();
7380

7481
if (elementList.size() != 1) {

src/main/java/net/quickwrite/fluent4j/ast/placeable/FunctionReference.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
import net.quickwrite.fluent4j.ast.FluentElement;
44
import net.quickwrite.fluent4j.ast.placeable.base.FluentFunction;
55
import net.quickwrite.fluent4j.ast.placeable.base.FluentSelectable;
6-
import net.quickwrite.fluent4j.util.StringSlice;
76
import net.quickwrite.fluent4j.util.args.FluentArgs;
87
import net.quickwrite.fluent4j.util.args.FunctionFluentArgs;
9-
import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
8+
import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
109

1110
/**
1211
* Functions provide additional functionality available to the localizers.
@@ -21,12 +20,13 @@ public FunctionReference(final String functionName, final FluentArgs arguments)
2120
}
2221

2322
@Override
24-
public FluentElement getArgumentResult(final DirectFluentBundle bundle, final FluentArgs arguments) {
23+
public FluentElement getArgumentResult(final AccessorBundle bundle) {
2524
try {
2625
return bundle
26+
.getBundle()
2727
.getFunction(this.functionName)
2828
.orElseThrow()
29-
.getResult(bundle, (FunctionFluentArgs) this.getArguments(bundle, arguments));
29+
.getResult(bundle, (FunctionFluentArgs) this.getArguments(bundle));
3030
} catch (final Exception exception) {
3131
return new StringLiteral("{" + functionName + "()}");
3232
}
@@ -69,13 +69,12 @@ protected boolean check(String string) {
6969
* This means that the {@code NUMBER}-function gets no arguments
7070
* this function will return <code>{NUMBER()}</code>.
7171
*
72-
* @param bundle The base bundle
73-
* @param arguments The arguments that are being passed on the scope
74-
* @return The result of the function with the specific parameters
72+
*
73+
* @param bundle@return The result of the function with the specific parameters
7574
*/
7675
@Override
77-
public CharSequence getResult(final DirectFluentBundle bundle, final FluentArgs arguments) {
78-
return this.getArgumentResult(bundle, arguments).getResult(bundle, arguments);
76+
public CharSequence getResult(AccessorBundle bundle) {
77+
return this.getArgumentResult(bundle).getResult(bundle);
7978
}
8079

8180
@Override

src/main/java/net/quickwrite/fluent4j/ast/placeable/MessageReference.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import net.quickwrite.fluent4j.ast.FluentElement;
44
import net.quickwrite.fluent4j.ast.placeable.base.FluentPlaceable;
55
import net.quickwrite.fluent4j.util.StringSlice;
6-
import net.quickwrite.fluent4j.util.args.FluentArgs;
76
import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
7+
import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
88

99

1010
/**
@@ -36,9 +36,10 @@ public String stringValue() {
3636
}
3737

3838
@Override
39-
public CharSequence getResult(final DirectFluentBundle bundle, final FluentArgs arguments) {
40-
return bundle
41-
.getMessage(this.stringValue(), arguments)
39+
public CharSequence getResult(final AccessorBundle bundle) {
40+
return bundle
41+
.getBundle()
42+
.getMessage(this.stringValue(), bundle)
4243
.orElse("{" + this.stringValue() + "}");
4344
}
4445

src/main/java/net/quickwrite/fluent4j/ast/placeable/NumberLiteral.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import net.quickwrite.fluent4j.ast.placeable.base.FluentPlaceable;
1111
import net.quickwrite.fluent4j.ast.placeable.base.FluentSelectable;
1212
import net.quickwrite.fluent4j.util.StringSlice;
13-
import net.quickwrite.fluent4j.util.args.FluentArgs;
1413

1514
import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
15+
import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
1616

1717
import java.math.BigDecimal;
1818

@@ -51,8 +51,8 @@ public static NumberLiteral getNumberLiteral(final String value) {
5151
}
5252

5353
@Override
54-
public CharSequence getResult(final DirectFluentBundle bundle, final FluentArgs arguments) {
55-
return NumberFormat.getInstance(bundle.getLocale()).format(number);
54+
public CharSequence getResult(final AccessorBundle bundle) {
55+
return NumberFormat.getInstance(bundle.getBundle().getLocale()).format(number);
5656
}
5757

5858
private static BigDecimal convertToBigDecimal(final Number number) {

src/main/java/net/quickwrite/fluent4j/ast/placeable/SelectExpression.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import net.quickwrite.fluent4j.ast.FluentVariant;
55
import net.quickwrite.fluent4j.ast.placeable.base.FluentArgumentResult;
66
import net.quickwrite.fluent4j.ast.placeable.base.FluentPlaceable;
7-
import net.quickwrite.fluent4j.util.args.FluentArgs;
87
import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
8+
import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
99

1010
import java.util.List;
1111

@@ -50,17 +50,17 @@ public String stringValue() {
5050
}
5151

5252
@Override
53-
public CharSequence getResult(final DirectFluentBundle bundle, final FluentArgs arguments) {
53+
public CharSequence getResult(final AccessorBundle bundle) {
5454
final FluentElement argument = (identifier instanceof FluentArgumentResult) ?
55-
((FluentArgumentResult) identifier).getArgumentResult(bundle, arguments) : identifier;
55+
((FluentArgumentResult) identifier).getArgumentResult(bundle) : identifier;
5656

5757
for (final FluentVariant variant : variants) {
58-
if (argument.matches(bundle, variant.getIdentifier())) {
59-
return variant.getResult(bundle, arguments);
58+
if (argument.matches(bundle.getBundle(), variant.getIdentifier())) {
59+
return variant.getResult(bundle);
6060
}
6161
}
6262

63-
return defaultVariant.getResult(bundle, arguments);
63+
return defaultVariant.getResult(bundle);
6464
}
6565

6666
@Override

0 commit comments

Comments
 (0)