|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2012-2020 the original author or authors. |
|
|
|
* Copyright 2012-2022 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -42,6 +42,7 @@ import org.springframework.util.Assert; |
|
|
|
* @author Madhura Bhave |
|
|
|
* @author Madhura Bhave |
|
|
|
* @author Phillip Webb |
|
|
|
* @author Phillip Webb |
|
|
|
* @author Thiago Hirata |
|
|
|
* @author Thiago Hirata |
|
|
|
|
|
|
|
* @author Guirong Hu |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class OriginTrackedPropertiesLoader { |
|
|
|
class OriginTrackedPropertiesLoader { |
|
|
|
|
|
|
|
|
|
|
|
@ -78,7 +79,8 @@ class OriginTrackedPropertiesLoader { |
|
|
|
StringBuilder buffer = new StringBuilder(); |
|
|
|
StringBuilder buffer = new StringBuilder(); |
|
|
|
try (CharacterReader reader = new CharacterReader(this.resource)) { |
|
|
|
try (CharacterReader reader = new CharacterReader(this.resource)) { |
|
|
|
while (reader.read()) { |
|
|
|
while (reader.read()) { |
|
|
|
if (reader.isPoundCharacter()) { |
|
|
|
if (reader.isCommentPrefixCharacter()) { |
|
|
|
|
|
|
|
char commentPrefixCharacter = reader.getCharacter(); |
|
|
|
if (isNewDocument(reader)) { |
|
|
|
if (isNewDocument(reader)) { |
|
|
|
if (!document.isEmpty()) { |
|
|
|
if (!document.isEmpty()) { |
|
|
|
documents.add(document); |
|
|
|
documents.add(document); |
|
|
|
@ -89,12 +91,12 @@ class OriginTrackedPropertiesLoader { |
|
|
|
if (document.isEmpty() && !documents.isEmpty()) { |
|
|
|
if (document.isEmpty() && !documents.isEmpty()) { |
|
|
|
document = documents.remove(documents.size() - 1); |
|
|
|
document = documents.remove(documents.size() - 1); |
|
|
|
} |
|
|
|
} |
|
|
|
reader.setLastLineComment(true); |
|
|
|
reader.setLastLineCommentPrefixCharacter(commentPrefixCharacter); |
|
|
|
reader.skipComment(); |
|
|
|
reader.skipComment(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
reader.setLastLineComment(false); |
|
|
|
reader.setLastLineCommentPrefixCharacter(-1); |
|
|
|
loadKeyAndValue(expandLists, document, reader, buffer); |
|
|
|
loadKeyAndValue(expandLists, document, reader, buffer); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -161,10 +163,10 @@ class OriginTrackedPropertiesLoader { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean isNewDocument(CharacterReader reader) throws IOException { |
|
|
|
private boolean isNewDocument(CharacterReader reader) throws IOException { |
|
|
|
if (reader.isLastLineComment()) { |
|
|
|
if (reader.isSameLastLineCommentPrefix()) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
boolean result = reader.getLocation().getColumn() == 0 && reader.isPoundCharacter(); |
|
|
|
boolean result = reader.getLocation().getColumn() == 0; |
|
|
|
result = result && readAndExpect(reader, reader::isHyphenCharacter); |
|
|
|
result = result && readAndExpect(reader, reader::isHyphenCharacter); |
|
|
|
result = result && readAndExpect(reader, reader::isHyphenCharacter); |
|
|
|
result = result && readAndExpect(reader, reader::isHyphenCharacter); |
|
|
|
result = result && readAndExpect(reader, reader::isHyphenCharacter); |
|
|
|
result = result && readAndExpect(reader, reader::isHyphenCharacter); |
|
|
|
@ -196,7 +198,7 @@ class OriginTrackedPropertiesLoader { |
|
|
|
|
|
|
|
|
|
|
|
private int character; |
|
|
|
private int character; |
|
|
|
|
|
|
|
|
|
|
|
private boolean lastLineComment; |
|
|
|
private int lastLineCommentPrefixCharacter; |
|
|
|
|
|
|
|
|
|
|
|
CharacterReader(Resource resource) throws IOException { |
|
|
|
CharacterReader(Resource resource) throws IOException { |
|
|
|
this.reader = new LineNumberReader( |
|
|
|
this.reader = new LineNumberReader( |
|
|
|
@ -209,20 +211,11 @@ class OriginTrackedPropertiesLoader { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
boolean read() throws IOException { |
|
|
|
boolean read() throws IOException { |
|
|
|
return read(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean read(boolean wrappedLine) throws IOException { |
|
|
|
|
|
|
|
this.escaped = false; |
|
|
|
this.escaped = false; |
|
|
|
this.character = this.reader.read(); |
|
|
|
this.character = this.reader.read(); |
|
|
|
this.columnNumber++; |
|
|
|
this.columnNumber++; |
|
|
|
if (this.columnNumber == 0) { |
|
|
|
if (this.columnNumber == 0) { |
|
|
|
skipWhitespace(); |
|
|
|
skipWhitespace(); |
|
|
|
if (!wrappedLine) { |
|
|
|
|
|
|
|
if (this.character == '!') { |
|
|
|
|
|
|
|
skipComment(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
if (this.character == '\\') { |
|
|
|
if (this.character == '\\') { |
|
|
|
this.escaped = true; |
|
|
|
this.escaped = true; |
|
|
|
@ -241,12 +234,8 @@ class OriginTrackedPropertiesLoader { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setLastLineComment(boolean lastLineComment) { |
|
|
|
private void setLastLineCommentPrefixCharacter(int lastLineCommentPrefixCharacter) { |
|
|
|
this.lastLineComment = lastLineComment; |
|
|
|
this.lastLineCommentPrefixCharacter = lastLineCommentPrefixCharacter; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isLastLineComment() { |
|
|
|
|
|
|
|
return this.lastLineComment; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void skipComment() throws IOException { |
|
|
|
private void skipComment() throws IOException { |
|
|
|
@ -264,7 +253,7 @@ class OriginTrackedPropertiesLoader { |
|
|
|
} |
|
|
|
} |
|
|
|
else if (this.character == '\n') { |
|
|
|
else if (this.character == '\n') { |
|
|
|
this.columnNumber = -1; |
|
|
|
this.columnNumber = -1; |
|
|
|
read(true); |
|
|
|
read(); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (this.character == 'u') { |
|
|
|
else if (this.character == 'u') { |
|
|
|
readUnicode(); |
|
|
|
readUnicode(); |
|
|
|
@ -318,8 +307,12 @@ class OriginTrackedPropertiesLoader { |
|
|
|
return new Location(this.reader.getLineNumber(), this.columnNumber); |
|
|
|
return new Location(this.reader.getLineNumber(), this.columnNumber); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
boolean isPoundCharacter() { |
|
|
|
boolean isSameLastLineCommentPrefix() { |
|
|
|
return this.character == '#'; |
|
|
|
return this.lastLineCommentPrefixCharacter == this.character; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean isCommentPrefixCharacter() { |
|
|
|
|
|
|
|
return this.character == '#' || this.character == '!'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
boolean isHyphenCharacter() { |
|
|
|
boolean isHyphenCharacter() { |
|
|
|
|