final LinkedHashMap<Integer, Integer> blocks = ParserUtils.getBlockLines(fileContent.toString(), validateIdentifier);
if (blocks.size() == 0) {
continue;
}
final FileObject fo = FileManager.getFileObject(filename);
int ptrline = 1;
for (final Integer s : blocks.keySet()) {
final Integer e = blocks.get(s);
final String lines = fo.getLinesAsString(s, e);
// System.out.println("deleteValidateProperties: " + s +
// " -> " + e + "\n" + lines);
int x;
int pos = 0;
int charStart = 0;
int charEnd = 0;
boolean inBlock = false;
int lp = 0, rp = 0;
final StringReader r = new StringReader(lines);
while ((x = r.read()) != -1) {
final char c = (char) x;
if (c == '{') {
if (lp == 0) {
charStart = pos;
inBlock = true;
}
lp++;
} else if (inBlock && c == '}') {
rp++;
}
if (inBlock) {
if (lp == rp) {
charEnd = pos + 1;
break;
}
}
pos++;
}
final String block = lines.substring(charStart, charEnd);
// System.out.println("deleteValidateProperties: " +
// charStart + " -> " + charEnd + "\n" + block);
if (block.length() < replacement.length()) {
System.err.println("WARN - cannot replace " + validateIdentifier + ", not enough space");
continue;
}
contentReplaced.append(fo.getLinesAsString(ptrline, (s - 1)));
contentReplaced.append(lines.substring(0, charStart));
contentReplaced.append(replacement);
contentReplaced.append(lines.substring(charEnd));
ptrline = e + 1;
}
contentReplaced.append(fo.getLinesAsString(ptrline));
FileManager.writeIntoFile(contentReplaced.toString(), filename);
} catch (final IOException e) {
throw new WinkBuildException(e);
}