1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include "PHPDocVar.h"
#include <wx/regex.h>
#include <wx/tokenzr.h>
PHPDocVar::PHPDocVar(PHPSourceFile& sourceFile, const wxString& doc)
: m_isOk(false)
, m_dbId(wxNOT_FOUND)
, m_lineNumber(wxNOT_FOUND)
{
Parse(sourceFile, doc);
}
PHPDocVar::PHPDocVar()
: m_isOk(false)
, m_dbId(wxNOT_FOUND)
, m_lineNumber(wxNOT_FOUND)
{
}
PHPDocVar::~PHPDocVar() {}
void PHPDocVar::Parse(PHPSourceFile& sourceFile, const wxString& doc)
{
wxString sname;
wxString stype;
m_isOk = false;
wxStringTokenizer tokenizer(doc, " \n\r", wxTOKEN_STRTOK);
// @var Type $name
// @var Type
// @var $Name Type
if(!tokenizer.HasMoreTokens() || tokenizer.GetNextToken() != "@var") {
return;
}
// Next word should be the type
if(!tokenizer.HasMoreTokens()) {
return;
}
stype = tokenizer.GetNextToken();
// Next comes the name
if(tokenizer.HasMoreTokens()) {
sname = tokenizer.GetNextToken();
}
// Handle common developer mistake
if (stype.StartsWith("$")) {
sname.swap(stype);
}
// TODO Support nullable parameters
if (stype.StartsWith("?")) {
stype.Remove(0, 1);
}
// Got the type
m_type = sourceFile.MakeIdentifierAbsolute(stype);
m_isOk = true;
// Found the name
m_name = sname;
}
void PHPDocVar::Store(wxSQLite3Database& db, wxLongLong parentDdId)
{
try {
wxSQLite3Statement statement =
db.PrepareStatement("REPLACE INTO PHPDOC_VAR_TABLE (ID, SCOPE_ID, NAME, TYPE, LINE_NUMBER, FILE_NAME) "
"VALUES (NULL, :SCOPE_ID, :NAME, :TYPE, :LINE_NUMBER, :FILE_NAME)");
statement.Bind(statement.GetParamIndex(":SCOPE_ID"), parentDdId);
statement.Bind(statement.GetParamIndex(":NAME"), GetName());
statement.Bind(statement.GetParamIndex(":TYPE"), GetType());
statement.Bind(statement.GetParamIndex(":LINE_NUMBER"), GetLineNumber());
statement.Bind(statement.GetParamIndex(":FILE_NAME"), GetFilename().GetFullPath());
statement.ExecuteUpdate();
SetDbId(db.GetLastRowId());
} catch(wxSQLite3Exception& exc) {
wxUnusedVar(exc);
}
}
void PHPDocVar::FromResultSet(wxSQLite3ResultSet& res)
{
SetDbId(res.GetInt("ID"));
SetParentDbId(res.GetInt("SCOPE_ID"));
SetName(res.GetString("NAME"));
SetType(res.GetString("TYPE"));
SetLineNumber(res.GetInt("LINE_NUMBER"));
SetFilename(res.GetString("FILE_NAME"));
}
|