| 1 |
#include "PHPDocParam.h" |
| 2 |
#include <wx/wxcrt.h> |
| 3 |
#include <wx/tokenzr.h> |
| 4 |
|
| 5 |
PHPDocParam::PHPDocParam(PHPSourceFile& sourceFile, const wxString& comment) |
| 6 |
: m_sourceFile(sourceFile) |
| 7 |
, m_comment(comment) |
| 8 |
{ |
| 9 |
} |
| 10 |
|
| 11 |
PHPDocParam::~PHPDocParam() {} |
| 12 |
|
| 13 |
const PHPDocParam::Vec_t& PHPDocParam::Parse() |
| 14 |
{ |
| 15 |
wxString sname; |
| 16 |
wxString stype; |
| 17 |
m_params.clear(); |
| 18 |
|
| 19 |
wxStringTokenizer tokenizer(m_comment, " \n\r", wxTOKEN_STRTOK); |
| 20 |
while(tokenizer.HasMoreTokens()) { |
| 21 |
wxString word = tokenizer.GetNextToken(); |
| 22 |
|
| 23 |
if(word == "@param") { |
| 24 |
// Next word should be the type |
| 25 |
if(!tokenizer.HasMoreTokens()) { |
| 26 |
break; |
| 27 |
} |
| 28 |
stype = tokenizer.GetNextToken(); |
| 29 |
|
| 30 |
// Next comes the name |
| 31 |
if(!tokenizer.HasMoreTokens()) { |
| 32 |
break; |
| 33 |
} |
| 34 |
sname = tokenizer.GetNextToken(); |
| 35 |
|
| 36 |
// Handle common developer mistake |
| 37 |
if (stype.StartsWith("$") || stype.StartsWith("&")) { |
| 38 |
sname.swap(stype); |
| 39 |
} |
| 40 |
|
| 41 |
// TODO Support nullable parameters |
| 42 |
if (stype.StartsWith("?")) { |
| 43 |
stype.Remove(0, 1); |
| 44 |
} |
| 45 |
|
| 46 |
// TODO Support by reference parameters |
| 47 |
if (sname.StartsWith("&")) { |
| 48 |
sname.Remove(0, 1); |
| 49 |
} else if (stype.EndsWith("&")) { |
| 50 |
stype.RemoveLast(); |
| 51 |
} |
| 52 |
|
| 53 |
stype = m_sourceFile.MakeIdentifierAbsolute(stype); |
| 54 |
|
| 55 |
m_params.push_back(std::make_pair(sname, stype)); |
| 56 |
} |
| 57 |
} |
| 58 |
return m_params; |
| 59 |
} |