Skip to content

Commit d308122

Browse files
committed
Additional change to printing if
1 parent 0a4a16f commit d308122

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/main/java/com/github/odiszapc/nginxparser/NgxDumper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ private void writeToStream(NgxBlock config, PrintWriter writer, int level) {
7575
writer
7676
.append(getOffset(level))
7777
.append(ifBlock.toString())
78+
.append(LBRACE)
7879
.append(getLineEnding());
7980
writeToStream(ifBlock, writer, level + 1);
8081
writer

src/main/java/com/github/odiszapc/nginxparser/NgxIfBlock.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,23 @@
1616

1717
package com.github.odiszapc.nginxparser;
1818

19+
import java.util.ArrayList;
20+
1921
public class NgxIfBlock extends NgxBlock {
2022

2123
public String toString() {
22-
return super.toString(); // TODO: add parentheses (looks like "if $a !~ ^1(2)3$ {" currently)
24+
ArrayList<NgxToken> tokens = new ArrayList<>(getTokens());
25+
String ifToken = tokens.remove(0).getToken(); // The "if"
26+
StringBuilder tokenBuilder = new StringBuilder(ifToken)
27+
.append(" ")
28+
.append("(");
29+
30+
for (NgxToken value : tokens) {
31+
tokenBuilder.append(value).append(" ");
32+
}
33+
34+
String result = tokenBuilder.toString();
35+
36+
return result.substring(0, result.length() -1) + ") ";
2337
}
2438
}

0 commit comments

Comments
 (0)