[CVS snippet] Added support for nested snippets

Aslak Hellesoy <rinkrank-yCVjj/[email protected]> Wed, 25 Feb 2004 16:08:05 -0600
Newsgroups gmane.comp.java.nanocontainer.cvs
Message-ID <[email protected]>
Commit in snippet/src on MAIN

main/snippet/SnippetReader.java +12 -4 1.1.1.1 -> 1.2

test/snippet/SnippetReaderTest.java +3 -1 1.2 -> 1.3

+15 -5

2 modified files

Added support for nested snippets

----------

snippet /src /main /snippet

SnippetReader.java 1.1.1.1 -> 1.2

diff -u -r1.1.1.1 -r1.2
--- SnippetReader.java 25 Feb 2004 20:09:16 -0000 1.1.1.1
+++ SnippetReader.java 25 Feb 2004 22:08:05 -0000 1.2
@@ -23,8 +23,10 @@

StringBuffer result = new StringBuffer();
for (Iterator iterator = lines.iterator(); iterator.hasNext();) {
String line = (String) iterator.next();

- result.append(line.substring(minIndent));
- result.append(EOL);

+ if (!isDemarcator(line)) {
+ result.append(line.substring(minIndent));
+ result.append(EOL);
+ }

}
return result;
}

@@ -76,8 +78,14 @@

protected boolean isDemarcator(String snippetId, String what, String line) {
String upper = line.toUpperCase();

- return upper.indexOf(what.toUpperCase()) != -1 &&
- upper.indexOf("SNIPPET") != -1 && line.indexOf(snippetId) != -1;

+ return isDemarcator(line) &&
+ upper.indexOf(what.toUpperCase()) != -1 &&
+ line.indexOf(snippetId) != -1;
+ }
+
+ protected boolean isDemarcator(String line) {
+ String upper = line.toUpperCase();
+ return upper.indexOf("SNIPPET") != -1;

}

protected boolean isEnd(String snippetId, String line) {

----------

snippet /src /test /snippet

SnippetReaderTest.java 1.2 -> 1.3

diff -u -r1.2 -r1.3
--- SnippetReaderTest.java 25 Feb 2004 21:47:01 -0000 1.2
+++ SnippetReaderTest.java 25 Feb 2004 22:08:05 -0000 1.3
@@ -61,13 +61,15 @@

// START SNIPPET: multilineSnippet
assertEquals(2, 1 + 1);
if(true) {

+ // START SNIPPET: nestedSnippet

assertEquals(6, 2 * 3);

+ // START SNIPPET: nestedSnippet

}
assertEquals(2, 4 / 2);
// END SNIPPET: multilineSnippet
}

- public void testCanReadSnippetsWithSeveralLines() throws IOException {

+ public void testCanReadSnippetsWithSeveralLinesAndNestedSnippet() throws IOException {

SnippetReader snippetReader = new SnippetReader(getResource("SnippetReaderTest.java"));
String snippet = snippetReader.readSnippet("multilineSnippet").toString();
assertEquals(