-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c9e72ca
commit 0a81c24
Showing
1 changed file
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,15 +160,17 @@ public Set<YamlNode> keys() { | |
//@checkstyle NestedIfDepth (50 lines) | ||
final String key = matcher.group("key"); | ||
if (key != null && !key.isEmpty()) { | ||
keys.add(new PlainStringScalar(key)); | ||
keys.add(new ReadScalarKey(key, this.all, line)); | ||
} else { | ||
final String keyQ = matcher.group("keyQ"); | ||
if (keyQ != null && !keyQ.isEmpty()) { | ||
keys.add(new PlainStringScalar(keyQ)); | ||
keys.add(new ReadScalarKey(keyQ, this.all, line)); | ||
} else { | ||
final String keySQ = matcher.group("keySQ"); | ||
if (keySQ != null && !keySQ.isEmpty()) { | ||
keys.add(new PlainStringScalar(keySQ)); | ||
keys.add(new ReadScalarKey( | ||
keySQ, this.all, line) | ||
); | ||
} | ||
} | ||
} | ||
|
@@ -358,4 +360,84 @@ private YamlLine getPreviousLine(final YamlLine line) { | |
} | ||
return prev; | ||
} | ||
|
||
/** | ||
* A plain scalar mapping key. | ||
* @author Mihai Andronace ([email protected]) | ||
* @version $Id$ | ||
* @since 3.1.3 | ||
*/ | ||
private static class ReadScalarKey extends BaseScalar { | ||
|
||
/** | ||
* String key. | ||
*/ | ||
private final String key; | ||
|
||
/** | ||
* All YAML Lines of the document. | ||
*/ | ||
private final AllYamlLines all; | ||
|
||
/** | ||
* Line where the plain scalar key is found. | ||
*/ | ||
private final YamlLine scalarLine; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param key String key. | ||
* @param all All lines of the document. | ||
* @param scalarLine YamlLine containing the scalar. | ||
*/ | ||
ReadScalarKey( | ||
final String key, final AllYamlLines all, final YamlLine scalarLine | ||
) { | ||
this.key = key; | ||
this.all = all; | ||
this.scalarLine = scalarLine; | ||
} | ||
|
||
/** | ||
* Unescaped String value of this scalar. Pay attention, if the | ||
* scalar's value is the "null" String, then we return null, because | ||
* "null" is a reserved keyword in YAML, indicating a null Scalar. | ||
* | ||
* @return String or null if the Strings value is "null". | ||
* @checkstyle ReturnCount (50 lines) | ||
*/ | ||
@Override | ||
public String value() { | ||
return this.key; | ||
} | ||
|
||
@Override | ||
public Comment comment() { | ||
final Comment comment; | ||
if (this.scalarLine instanceof YamlLine.NullYamlLine) { | ||
comment = new BuiltComment(this, ""); | ||
} else { | ||
final int lineNumber = this.scalarLine.number(); | ||
comment = new ReadComment( | ||
new Backwards( | ||
new FirstCommentFound( | ||
new Backwards( | ||
new Skip( | ||
this.all, | ||
line -> line.number() >= lineNumber, | ||
line -> line.trimmed().startsWith("..."), | ||
line -> line.trimmed().startsWith("%"), | ||
line -> line.trimmed().startsWith("!!") | ||
) | ||
), | ||
false | ||
) | ||
), | ||
this | ||
); | ||
} | ||
return comment; | ||
} | ||
} | ||
} |