|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Objectcomtest.ComTest.ComTestScanner.CommentCodeHandler
public class ComTest.ComTestScanner.CommentCodeHandler
Handles to ComTest-comment and returns the position of last handled line. The main method is readCode and all others are just helper methods to handle the lines. Precondition: inside JavaDoc comment Postcondition: still inside JavaDoc comment
| Field Summary | |
|---|---|
private java.lang.String |
baseIndent
|
private Strings |
endOfLine
|
private boolean |
everyLineInits
|
private java.lang.String |
indent
|
private Strings |
initCmds
|
private int |
initLine
|
private static java.lang.String |
javaShortComment
|
private int |
lineNr
|
private Strings |
methodFooter
|
private Strings |
methodHeader
|
private boolean |
methodHeaderPrinted
|
private int |
methodIndex
|
private java.lang.String |
methodName
|
private java.lang.String |
methodThrows
|
private boolean |
oneTablePrinted
|
private boolean |
rawMode
|
private java.lang.String |
sMethodIndex
|
private Strings |
startOfLine
|
private boolean |
tablePrinted
|
private Strings |
template
|
private Strings |
values
|
private Strings |
vars
|
| Constructor Summary | |
|---|---|
ComTest.ComTestScanner.CommentCodeHandler()
|
|
| Method Summary | |
|---|---|
private void |
addInit(Strings commands,
int realLineNr)
Add sentences to init section. |
private java.lang.String |
checkMethodThrows(java.lang.String s)
Check if line is THROWS line. |
private void |
checkSemiColon(Strings sentences,
int i,
Strings commands)
Check if there is coming a ; then nothing is done. |
private java.lang.String |
checkThrows(java.lang.String s)
Check if line is THROWS line. |
private void |
createHeaderAndFooter(java.lang.String s)
Creates a header and footer for new ComTest test method. |
private void |
deleteLastNewLine(Strings cmds)
Deletes \n from the last line of cmds |
Strings |
getInitCmnds()
This is just for testing purposes to return the initCmds |
java.lang.String |
handleAnnotationInComments(java.lang.String s)
Annotations in comments must be prefixed with something. |
void |
handleSentences(java.lang.String line)
Handles normal lines and table lines from ComTest lines. |
private void |
handleTableLine(java.lang.String line)
Handles lines like " $s | $what | $result" or " "aab" | "a" | "ab" " If there is a $ on the line, it is kept as a header line. |
private java.lang.String |
isPseudoComment(java.lang.String line)
Check if line is pseudo comment /.* or * |
boolean |
isTableLine(java.lang.String s)
Check if the line is a table line, so containing either " | " or | at the beginning or end. |
private boolean |
jUnitAnnotate(java.lang.String s)
Check if s is one of the JUnit annotation. |
private void |
outFooter(int realLineNr)
Copies method footer to outlines if method header is already moved. |
private void |
outLines(Strings commands,
int realLineNr)
Moves commands to outlines. |
void |
outNewHeader()
Moves header lines to outlines. |
private void |
outWithHeader(Strings list,
java.lang.String target,
java.lang.String replacement)
Moves list to outlines. |
int |
readCode(int start)
Reads the code from contents starting from line start and returns the line last handled. |
private java.lang.String |
saveStartAndEndOfLine(java.lang.String s)
Find comments and put possible try catch to start and end of the the current line's start and end lists. |
java.lang.String |
tryToFindMethodName(Strings contents,
int lineNr)
Try to find name for next method. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private static final java.lang.String javaShortComment
private int lineNr
private java.lang.String methodName
private final Strings template
private final Strings initCmds
private final Strings methodHeader
private final Strings methodFooter
private boolean methodHeaderPrinted
private int methodIndex
private java.lang.String sMethodIndex
private Strings vars
private Strings values
private int initLine
private boolean everyLineInits
private boolean tablePrinted
private boolean oneTablePrinted
private boolean rawMode
private java.lang.String baseIndent
private java.lang.String indent
private final Strings startOfLine
private final Strings endOfLine
private java.lang.String methodThrows
| Constructor Detail |
|---|
public ComTest.ComTestScanner.CommentCodeHandler()
| Method Detail |
|---|
public Strings getInitCmnds()
public java.lang.String tryToFindMethodName(Strings contents,
int lineNr)
contents - where to find the namelineNr - where to start
private java.lang.String checkThrows(java.lang.String s)
s - line to look.
private java.lang.String checkMethodThrows(java.lang.String s)
s - line to look.
private java.lang.String saveStartAndEndOfLine(java.lang.String s)
s - line to handle
private void outFooter(int realLineNr)
realLineNr - current line numberpublic void outNewHeader()
private void outWithHeader(Strings list,
java.lang.String target,
java.lang.String replacement)
list - what to movetarget - what is replacedreplacement - by what to replace
private void addInit(Strings commands,
int realLineNr)
commands - sentences to addrealLineNr - real line number for current line
private void outLines(Strings commands,
int realLineNr)
commands - what to moverealLineNr - real line number for current lineprivate boolean jUnitAnnotate(java.lang.String s)
s - line to look
public java.lang.String handleAnnotationInComments(java.lang.String s)
s - where to look annotation
TestHelpper t = new TestHelpper();
t.codeHandler.handleAnnotationInComments("a") === "a";
t.codeHandler.handleAnnotationInComments("* #@Test") === "@Test";
t.codeHandler.handleAnnotationInComments("* #@example") === "* #@example";
private void deleteLastNewLine(Strings cmds)
cmds - where to deletepublic boolean isTableLine(java.lang.String s)
s - line to check
TestHelpper t = new TestHelpper();
t.codeHandler.isTableLine("") === false;
t.codeHandler.isTableLine("a") === false;
t.codeHandler.isTableLine("a|") === true;
t.codeHandler.isTableLine("|a") === true;
t.codeHandler.isTableLine(" a|b ") === false;
t.codeHandler.isTableLine(" a | b ") === true;
private void handleTableLine(java.lang.String line)
line - line to handle.
private void checkSemiColon(Strings sentences,
int i,
Strings commands)
sentences - where to look ;i - from what index to look ;commands - where to add ; if neededprivate java.lang.String isPseudoComment(java.lang.String line)
public void handleSentences(java.lang.String line)
line - line to handle.
TestHelpper t = new TestHelpper();
t.codeHandler.handleSentences("int a = 5;");
t.initCmnds.get(1) === "int a = 5";
t.initCmnds.clear();
t.codeHandler.handleSentences("int a = 5; int b = 7;");
t.initCmnds.get(0) === " ";
t.initCmnds.get(1) === "int a = 5";
t.initCmnds.get(2) === "; ";
t.initCmnds.get(3) === "int b = 7";
t.initCmnds.get(4) === "; ";
t.initCmnds.clear();
t.codeHandler.handleSentences("a === 5;");
t.initCmnds.get(1) === "assertEquals(\"From: test line: 1\", 5, a)";
t.initCmnds.clear();
t.codeHandler.handleSentences("get(request,new String[]{\"str\",\"id\"},13,true) === 123;");
t.initCmnds.get(1) === "assertEquals(\"From: test line: 1\", 123, get(request,new String[]{\"str\",\"id\"},13,true))";
t.initCmnds.clear();
t.codeHandler.handleSentences("\"cat\" =R= \"c.*t\";"); // "cat" =R= "c.*t";
t.initCmnds.get(1) === "{ String l=\"cat\",r=\"c.*t\"; if ( !l.matches(r) ) fail(\"From: test line: 1\" + \" does not match: [\"+ l + \"] != [\" + r + \"]\");}";
t.initCmnds.clear();
t.codeHandler.handleSentences("a ~~~ 6.0;");
t.initCmnds.get(1) === "assertEquals(\"From: test line: 1\", 6.0, a, 0.000001)";
t.initCmnds.clear();
t.codeHandler.handleSentences("\"a$1\""); /// Not a template line
t.initCmnds.get(1) === "\"a$1\"";
t.template.size() === 0;
,
String s="$a"; s === "$b"; $
$a | $b
---------
1 | 1
$a; "a".matches("^a$") === false; // does not generate code
,
String s=null; s === null;
"a".matches("^a$") === true; // generate code
,
String s="$a"; s === "$b"; $;
$a | $b
---------
$ | $
"a".matches("^a$") === true; // this generates
private void createHeaderAndFooter(java.lang.String s)
s - line to start the test.public int readCode(int start)
start - first line index to handle
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||