aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorAndrey Somov <public.somov@gmail.com>2022-09-09 10:34:56 +0300
committerAndrey Somov <public.somov@gmail.com>2022-09-09 10:34:56 +0300
commitfe5400676b29bdba1aaf9f7477f2f5ef7f46f80c (patch)
tree969a7c085713cd2878d47b5de95cad15c5111375 /src/main/java
parent5e56066540d72a4e2aae7d918f92406686076ceb (diff)
downloadsnakeyaml-fe5400676b29bdba1aaf9f7477f2f5ef7f46f80c.tar.gz
Refactor setting to parse comments to use LoaderOptions
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/yaml/snakeyaml/LoaderOptions.java19
-rw-r--r--src/main/java/org/yaml/snakeyaml/parser/ParserImpl.java2
-rw-r--r--src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java6
3 files changed, 16 insertions, 11 deletions
diff --git a/src/main/java/org/yaml/snakeyaml/LoaderOptions.java b/src/main/java/org/yaml/snakeyaml/LoaderOptions.java
index bcb97135..9625bb2f 100644
--- a/src/main/java/org/yaml/snakeyaml/LoaderOptions.java
+++ b/src/main/java/org/yaml/snakeyaml/LoaderOptions.java
@@ -25,7 +25,7 @@ public class LoaderOptions {
private int nestingDepthLimit = 50;
private int codePointLimit = 100 * 1024;
- public boolean isAllowDuplicateKeys() {
+ public final boolean isAllowDuplicateKeys() {
return allowDuplicateKeys;
}
@@ -47,7 +47,7 @@ public class LoaderOptions {
this.allowDuplicateKeys = allowDuplicateKeys;
}
- public boolean isWrappedToRootException() {
+ public final boolean isWrappedToRootException() {
return wrappedToRootException;
}
@@ -62,7 +62,7 @@ public class LoaderOptions {
this.wrappedToRootException = wrappedToRootException;
}
- public int getMaxAliasesForCollections() {
+ public final int getMaxAliasesForCollections() {
return maxAliasesForCollections;
}
@@ -87,7 +87,7 @@ public class LoaderOptions {
this.allowRecursiveKeys = allowRecursiveKeys;
}
- public boolean getAllowRecursiveKeys() {
+ public final boolean getAllowRecursiveKeys() {
return allowRecursiveKeys;
}
@@ -96,15 +96,16 @@ public class LoaderOptions {
*
* @param processComments <code>true</code> to process; <code>false</code> to ignore
*/
- public void setProcessComments(boolean processComments) {
+ public LoaderOptions setProcessComments(boolean processComments) {
this.processComments = processComments;
+ return this;
}
- public boolean isProcessComments() {
+ public final boolean isProcessComments() {
return processComments;
}
- public boolean isEnumCaseSensitive() {
+ public final boolean isEnumCaseSensitive() {
return enumCaseSensitive;
}
@@ -118,7 +119,7 @@ public class LoaderOptions {
this.enumCaseSensitive = enumCaseSensitive;
}
- public int getNestingDepthLimit() {
+ public final int getNestingDepthLimit() {
return nestingDepthLimit;
}
@@ -132,7 +133,7 @@ public class LoaderOptions {
this.nestingDepthLimit = nestingDepthLimit;
}
- public int getCodePointLimit() {
+ public final int getCodePointLimit() {
return codePointLimit;
}
diff --git a/src/main/java/org/yaml/snakeyaml/parser/ParserImpl.java b/src/main/java/org/yaml/snakeyaml/parser/ParserImpl.java
index 3a8eac28..7c66434f 100644
--- a/src/main/java/org/yaml/snakeyaml/parser/ParserImpl.java
+++ b/src/main/java/org/yaml/snakeyaml/parser/ParserImpl.java
@@ -138,7 +138,7 @@ public class ParserImpl implements Parser {
@Deprecated
public ParserImpl(StreamReader reader, boolean parseComments) {
- this(new ScannerImpl(reader).setParseComments(parseComments));
+ this(new ScannerImpl(reader, new LoaderOptions().setProcessComments(parseComments)));
}
public ParserImpl(StreamReader reader, LoaderOptions options) {
diff --git a/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java b/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java
index 86059f73..e810de85 100644
--- a/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java
+++ b/src/main/java/org/yaml/snakeyaml/scanner/ScannerImpl.java
@@ -179,6 +179,7 @@ public final class ScannerImpl implements Scanner {
// A flag that indicates if comments should be parsed
private boolean parseComments;
+
private final LoaderOptions loaderOptions;
// Variables related to simple keys treatment. See PyYAML.
@@ -220,7 +221,7 @@ public final class ScannerImpl implements Scanner {
}
public ScannerImpl(StreamReader reader, LoaderOptions options) {
- this.parseComments = false;
+ this.parseComments = options.isProcessComments();
this.reader = reader;
this.tokens = new ArrayList<Token>(100);
this.indents = new ArrayStack<Integer>(10);
@@ -231,15 +232,18 @@ public final class ScannerImpl implements Scanner {
}
/**
+ * Please use LoaderOptions instead
* Set the scanner to ignore comments or parse them as a <code>CommentToken</code>.
*
* @param parseComments <code>true</code> to parse; <code>false</code> to ignore
*/
+ @Deprecated
public ScannerImpl setParseComments(boolean parseComments) {
this.parseComments = parseComments;
return this;
}
+ @Deprecated
public boolean isParseComments() {
return parseComments;
}