Skip to content

Commit 357ba8b

Browse files
authoredJan 28, 2023
Merge pull request #13 from QuickWrite/develop
Version `0.2.3-alpha`
2 parents fdca48a + 3dee503 commit 357ba8b

34 files changed

+169
-125
lines changed
 

‎.github/workflows/codeql.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
distribution: adopt
6262

6363
- name: Build with Maven
64-
run: mvn --batch-mode --update-snapshots verify
64+
run: mvn -B package --file pom.xml
6565

6666
- name: Perform CodeQL Analysis
6767
uses: github/codeql-action/analyze@v2

‎.github/workflows/maven-deploy.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ jobs:
1616
server-id: cloudsmith
1717
server-username: MAVEN_USERNAME
1818
server-password: MAVEN_PASSWORD
19+
- name: Build with Maven
20+
run: mvn -B package --file pom.xml
1921
- name: Publish package
20-
run: mvn --batch-mode deploy
22+
run: mvn deploy
2123
env:
2224
MAVEN_USERNAME: ${{ secrets.CLOUDSMITH_USERNAME }}
2325
MAVEN_PASSWORD: ${{ secrets.CLOUDSMITH_TOKEN }}

‎.github/workflows/maven.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
java-version: '16'
2727
distribution: adopt
2828
- name: Build with Maven
29-
run: mvn --batch-mode --update-snapshots verify
29+
run: mvn -B package --file pom.xml
3030
- name: Create necessary directories
3131
run: mkdir staging && cp target/*.jar staging
3232
- name: Upload artifact

‎pom.xml

+1-1
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.2-alpha</version>
9+
<version>0.2.3-alpha</version>
1010
<build>
1111
<plugins>
1212
<plugin>

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ public String getIdentifier() {
8989
}
9090

9191
@Override
92-
public CharSequence getResult(final AccessorBundle bundle) {
92+
public CharSequence getResult(final AccessorBundle bundle, final int recursionDepth) {
9393
if (this.fluentElements.size() == 1) {
94-
return this.fluentElements.get(0).getResult(bundle);
94+
return this.fluentElements.get(0).getResult(bundle, recursionDepth - 1);
9595
}
9696

9797
final StringBuilder builder = new StringBuilder();
9898

9999
for (final FluentElement element : this.fluentElements) {
100-
builder.append(element.getResult(bundle));
100+
builder.append(element.getResult(bundle, recursionDepth - 1));
101101
}
102102

103103
return builder;

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public interface FluentElement {
4242
* it has been called from.
4343
*
4444
* @param bundle The bundle that is getting passed down
45+
* @param recursionDepth The amount of recursive calls that can still be made
4546
* @return The {@link CharSequence} value of the argument with the parameters
4647
*/
47-
CharSequence getResult(final AccessorBundle bundle);
48+
CharSequence getResult(final AccessorBundle bundle, final int recursionDepth);
4849
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public String stringValue() {
8282
}
8383

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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public String stringValue() {
5353
return identifier.stringValue();
5454
}
5555

56-
public CharSequence getResult(AccessorBundle bundle) {
57-
return this.content.getResult(bundle);
56+
public CharSequence getResult(final AccessorBundle bundle, final int recursionDepth) {
57+
return this.content.getResult(bundle, recursionDepth - 1);
5858
}
5959

6060
@Override

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

+6-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.quickwrite.fluent4j.ast.placeable.base.FluentArgumentResult;
77
import net.quickwrite.fluent4j.ast.placeable.base.FluentPlaceable;
88
import net.quickwrite.fluent4j.ast.placeable.base.FluentSelectable;
9+
import net.quickwrite.fluent4j.exception.RecursionDepthReachedException;
910
import net.quickwrite.fluent4j.util.StringSlice;
1011
import net.quickwrite.fluent4j.util.args.FluentArgs;
1112
import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
@@ -42,7 +43,7 @@ public String stringValue() {
4243
}
4344

4445
@Override
45-
public CharSequence getResult(final AccessorBundle bundle) {
46+
public CharSequence getResult(final AccessorBundle bundle, int recursionDepth) {
4647
final FluentMessage fluentMessage = this.getMessage(bundle.getBundle(), reference.stringValue());
4748
if (fluentMessage == null) {
4849
return getErrorString();
@@ -54,11 +55,11 @@ public CharSequence getResult(final AccessorBundle bundle) {
5455
return getErrorString();
5556
}
5657

57-
return attribute.getResult(bundle);
58+
return attribute.getResult(bundle, recursionDepth - 1);
5859
}
5960

6061
@Override
61-
public FluentElement getArgumentResult(final AccessorBundle bundle) {
62+
public FluentElement getArgumentResult(final AccessorBundle bundle, int recursionDepth) {
6263
final FluentMessage fluentMessage = this.getMessage(bundle.getBundle(), reference.stringValue());
6364
if (fluentMessage == null) {
6465
return this;
@@ -70,12 +71,10 @@ public FluentElement getArgumentResult(final AccessorBundle bundle) {
7071
return this;
7172
}
7273

73-
if (bundle.getAccessedStorage().alreadyAccessed(attribute)) {
74-
return this;
74+
if (recursionDepth <= 0) {
75+
throw new RecursionDepthReachedException();
7576
}
7677

77-
bundle.getAccessedStorage().addElement(attribute);
78-
7978
final List<FluentElement> elementList = attribute.getElements();
8079

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

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

+10-5
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ public FunctionReference(final String functionName, final FluentArgs arguments)
2020
}
2121

2222
@Override
23-
public FluentElement getArgumentResult(final AccessorBundle bundle) {
23+
public FluentElement getArgumentResult(final AccessorBundle bundle, int recursionDepth) {
2424
try {
2525
return bundle
2626
.getBundle()
2727
.getFunction(this.functionName)
2828
.orElseThrow()
29-
.getResult(bundle, (FunctionFluentArgs) this.getArguments(bundle));
29+
.getFunctionResult(
30+
bundle,
31+
(FunctionFluentArgs) this.getArguments(bundle, recursionDepth),
32+
recursionDepth - 1
33+
);
3034
} catch (final Exception exception) {
3135
return new StringLiteral("{" + functionName + "()}");
3236
}
@@ -70,11 +74,12 @@ protected boolean check(String string) {
7074
* this function will return <code>{NUMBER()}</code>.
7175
*
7276
*
73-
* @param bundle@return The result of the function with the specific parameters
77+
* @param bundle @return The result of the function with the specific parameters
78+
* @param recursionDepth The amount of recursive calls that can be made
7479
*/
7580
@Override
76-
public CharSequence getResult(AccessorBundle bundle) {
77-
return this.getArgumentResult(bundle).getResult(bundle);
81+
public CharSequence getResult(AccessorBundle bundle, final int recursionDepth) {
82+
return this.getArgumentResult(bundle, recursionDepth - 1).getResult(bundle, recursionDepth - 1);
7883
}
7984

8085
@Override

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public String stringValue() {
3636
}
3737

3838
@Override
39-
public CharSequence getResult(final AccessorBundle bundle) {
39+
public CharSequence getResult(final AccessorBundle bundle, final int recursionDepth) {
4040
return bundle
4141
.getBundle()
42-
.getMessage(this.stringValue(), bundle)
42+
.getMessage(this.stringValue(), bundle, recursionDepth - 1)
4343
.orElse("{" + this.stringValue() + "}");
4444
}
4545

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static NumberLiteral getNumberLiteral(final String value) {
5151
}
5252

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

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ public String stringValue() {
5050
}
5151

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

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

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

6666
@Override

‎src/main/java/net/quickwrite/fluent4j/ast/placeable/StringLiteral.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public StringLiteral(final String content) {
5555
}
5656

5757
@Override
58-
public CharSequence getResult(AccessorBundle bundle) {
58+
public CharSequence getResult(AccessorBundle bundle, final int recursionDepth) {
5959
return this.literal;
6060
}
6161

‎src/main/java/net/quickwrite/fluent4j/ast/placeable/TermReference.java

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package net.quickwrite.fluent4j.ast.placeable;
22

33
import net.quickwrite.fluent4j.ast.FluentElement;
4-
import net.quickwrite.fluent4j.ast.FluentTerm;
54
import net.quickwrite.fluent4j.ast.placeable.base.FluentFunction;
65
import net.quickwrite.fluent4j.util.StringSlice;
76
import net.quickwrite.fluent4j.util.args.FluentArgs;
@@ -40,19 +39,24 @@ protected boolean check(final String string) {
4039
}
4140

4241
@Override
43-
public CharSequence getResult(final AccessorBundle bundle) {
42+
public CharSequence getResult(final AccessorBundle bundle, final int recursionDepth) {
4443
return bundle.getBundle()
45-
.getTerm(this.functionName, new AccessorElementsBundle(bundle.getBundle(), this.getArguments(bundle), bundle.getAccessedStorage()))
44+
.getTerm(this.functionName,
45+
new AccessorElementsBundle(bundle.getBundle(),
46+
this.getArguments(bundle, recursionDepth)),
47+
recursionDepth - 1
48+
)
4649
.orElse("{-" + this.functionName + "}");
4750
}
4851

4952
/**
5053
* @param bundle The bundle that this is being called from
54+
* @param recursionDepth The amount of recursive calls that can still be made
5155
* @return The result of the term that is being called
5256
*/
5357
@Override
54-
public FluentElement getArgumentResult(final AccessorBundle bundle) {
55-
return new StringLiteral(getResult(bundle).toString());
58+
public FluentElement getArgumentResult(final AccessorBundle bundle, final int recursionDepth) {
59+
return new StringLiteral(getResult(bundle, recursionDepth - 1).toString());
5660
}
5761

5862
@Override

‎src/main/java/net/quickwrite/fluent4j/ast/placeable/VariableReference.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public String stringValue() {
5252
}
5353

5454
@Override
55-
public FluentElement getArgumentResult(final AccessorBundle bundle) {
55+
public FluentElement getArgumentResult(final AccessorBundle bundle, final int recursionDepth) {
5656
final FluentArgs arguments = bundle.getArguments();
5757
final FluentElement argument = arguments.getNamed(content);
5858

@@ -64,14 +64,14 @@ public FluentElement getArgumentResult(final AccessorBundle bundle) {
6464
}
6565

6666
@Override
67-
public CharSequence getResult(final AccessorBundle bundle) {
67+
public CharSequence getResult(final AccessorBundle bundle, final int recursionDepth) {
6868
final FluentElement argument = bundle.getArguments().getNamed(content);
6969

7070
if (argument == null) {
7171
return "{$" + content + "}";
7272
}
7373

74-
return argument.getResult(bundle);
74+
return argument.getResult(bundle, recursionDepth - 1);
7575
}
7676

7777
@Override

‎src/main/java/net/quickwrite/fluent4j/ast/placeable/base/FluentArgumentResult.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
55

66
public interface FluentArgumentResult {
7-
FluentElement getArgumentResult(AccessorBundle bundle);
7+
FluentElement getArgumentResult(AccessorBundle bundle, int recursionDepth);
88
}

‎src/main/java/net/quickwrite/fluent4j/ast/placeable/base/FluentFunction.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,24 @@ public FluentFunction(final String functionName, final FluentArgs arguments) {
3535
* has itself in a sanitized form.
3636
*
3737
* @param bundle The arguments that are getting passed down
38+
* @param recursionDepth
3839
* @return The sanitized arguments of the function
3940
*/
40-
protected FluentArgs getArguments(final AccessorBundle bundle) {
41+
protected FluentArgs getArguments(final AccessorBundle bundle, final int recursionDepth) {
4142
if (this.arguments == null)
4243
return null;
4344

44-
return this.arguments.sanitize(bundle);
45+
return this.arguments.sanitize(bundle, recursionDepth);
4546
}
4647

4748
/**
4849
* Returns the {@link FluentElement} that the function is returning.
4950
*
5051
* @param bundle The bundle that this is being called from
52+
* @param recursionDepth
5153
* @return The resulting {@link FluentElement} that has been created
5254
*/
53-
public abstract FluentElement getArgumentResult(final AccessorBundle bundle);
55+
public abstract FluentElement getArgumentResult(final AccessorBundle bundle, int recursionDepth);
5456

5557
/**
5658
* Checks if this FluentFunction and the selector are the same.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package net.quickwrite.fluent4j.exception;
2+
3+
public class RecursionDepthReachedException extends RuntimeException {
4+
}

‎src/main/java/net/quickwrite/fluent4j/functions/AbstractFunction.java

+24-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package net.quickwrite.fluent4j.functions;
22

3-
import net.quickwrite.fluent4j.util.args.FluentArgs;
3+
import net.quickwrite.fluent4j.exception.RecursionDepthReachedException;
44
import net.quickwrite.fluent4j.util.args.FunctionFluentArgs;
5-
import net.quickwrite.fluent4j.util.bundle.DirectFluentBundle;
65
import net.quickwrite.fluent4j.ast.placeable.base.FluentPlaceable;
76
import net.quickwrite.fluent4j.ast.placeable.NumberLiteral;
87
import net.quickwrite.fluent4j.util.bundle.args.AccessorBundle;
@@ -50,6 +49,27 @@ public String getIdentifier() {
5049
return this.identifier;
5150
}
5251

52+
/**
53+
* Returns the result of {@link AbstractFunction#getResult(AccessorBundle, FunctionFluentArgs, int)},
54+
* but also checks the recursion depth.
55+
*
56+
* @param bundle The bundle that this is getting called from
57+
* @param arguments The arguments the function gets
58+
* @param recursionDepth The amount of recursive calls that can still be made
59+
* @return The result
60+
*/
61+
public FluentPlaceable getFunctionResult(
62+
final AccessorBundle bundle,
63+
final FunctionFluentArgs arguments,
64+
final int recursionDepth
65+
) {
66+
if (recursionDepth <= 0) {
67+
throw new RecursionDepthReachedException();
68+
}
69+
70+
return getResult(bundle, arguments, recursionDepth);
71+
}
72+
5373
/**
5474
* Returns the value that should result from the
5575
* specific argument or the bundle itself. <br>
@@ -69,7 +89,8 @@ public String getIdentifier() {
6989
*
7090
* @param bundle The bundle that this is getting called from
7191
* @param arguments The arguments the function gets
92+
* @param recursionDepth The amount of recursive calls that can still be made
7293
* @return The result
7394
*/
74-
public abstract FluentPlaceable getResult(final AccessorBundle bundle, final FunctionFluentArgs arguments);
95+
public abstract FluentPlaceable getResult(final AccessorBundle bundle, final FunctionFluentArgs arguments, final int recursionDepth);
7596
}

‎src/main/java/net/quickwrite/fluent4j/functions/NumberFunction.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ public NumberFunction() {
7171
*
7272
* @param bundle The bundle that this is getting called from
7373
* @param arguments The arguments the function gets
74+
* @param recursionDepth The amount of recursive calls that can still be made
7475
* @return The number as a {@link CustomNumberLiteral} with the parameters
7576
*/
7677
@Override
77-
public FluentPlaceable getResult(final AccessorBundle bundle, final FunctionFluentArgs arguments) {
78+
public FluentPlaceable getResult(final AccessorBundle bundle, final FunctionFluentArgs arguments, int recursionDepth) {
7879
final FluentElement number = arguments.getPositional(0);
7980

8081
CustomNumberLiteral numberLiteral;

‎src/main/java/net/quickwrite/fluent4j/util/args/CustomNumberLiteral.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void setUseGrouping(boolean useGrouping) {
4646
}
4747

4848
@Override
49-
public String getResult(final AccessorBundle bundle) {
49+
public String getResult(final AccessorBundle bundle, int recursionDepth) {
5050
NumberFormat numberFormat = NumberFormat.getInstance(bundle.getBundle().getLocale());
5151
numberFormat.setGroupingUsed(useGrouping);
5252
numberFormat.setMaximumFractionDigits(maximumFractionDigits);

0 commit comments

Comments
 (0)
Please sign in to comment.