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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
#include "PHPEntityFunction.h"
#include "PHPEntityVariable.h"
#include "PHPLookupTable.h"
#include "commentconfigdata.h"
#include "file_logger.h"
PHPEntityFunction::PHPEntityFunction() {}
PHPEntityFunction::~PHPEntityFunction() {}
void PHPEntityFunction::PrintStdout(int indent) const
{
wxString indentString(' ', indent);
// Print the indentation
wxPrintf("%sFunction: %s%s", indentString, GetShortName(), GetSignature());
wxPrintf(", (%s:%d)\n", GetFilename().GetFullPath(), GetLine());
if(!m_children.empty()) {
wxPrintf("%sLocals:\n", indentString);
PHPEntityBase::List_t::const_iterator iter = m_children.begin();
for(; iter != m_children.end(); ++iter) {
(*iter)->PrintStdout(indent + 4);
}
}
}
wxString PHPEntityFunction::GetSignature() const
{
if(!m_strSignature.IsEmpty()) {
return m_strSignature;
} else {
wxString strSignature = "(";
PHPEntityBase::List_t::const_iterator iter = m_children.begin();
for(; iter != m_children.end(); ++iter) {
PHPEntityVariable* var = (*iter)->Cast<PHPEntityVariable>();
if(var && var->IsFunctionArg()) {
strSignature << var->ToFuncArgString() << ", ";
} else {
break;
}
}
if(strSignature.EndsWith(", ")) { strSignature.RemoveLast(2); }
strSignature << ")";
return strSignature;
}
}
void PHPEntityFunction::Store(PHPLookupTable* lookup)
{
wxString fullname;
fullname << GetScope() << "\\" << GetShortName();
while(fullname.Replace("\\\\", "\\")) {}
try {
wxSQLite3Database& db = lookup->Database();
wxSQLite3Statement statement = db.PrepareStatement(
"INSERT OR REPLACE INTO FUNCTION_TABLE VALUES(NULL, :SCOPE_ID, :NAME, :FULLNAME, :SCOPE, :SIGNATURE, "
":RETURN_VALUE, :FLAGS, :DOC_COMMENT, :LINE_NUMBER, :FILE_NAME)");
statement.Bind(statement.GetParamIndex(":SCOPE_ID"), Parent()->GetDbId());
statement.Bind(statement.GetParamIndex(":NAME"), GetShortName());
statement.Bind(statement.GetParamIndex(":FULLNAME"), fullname);
statement.Bind(statement.GetParamIndex(":SCOPE"), GetScope());
statement.Bind(statement.GetParamIndex(":SIGNATURE"), GetSignature());
statement.Bind(statement.GetParamIndex(":RETURN_VALUE"), GetReturnValue());
statement.Bind(statement.GetParamIndex(":FLAGS"), (int)GetFlags());
statement.Bind(statement.GetParamIndex(":DOC_COMMENT"), GetDocComment());
statement.Bind(statement.GetParamIndex(":LINE_NUMBER"), GetLine());
statement.Bind(statement.GetParamIndex(":FILE_NAME"), GetFilename().GetFullPath());
statement.ExecuteUpdate();
SetDbId(db.GetLastRowId());
} catch(wxSQLite3Exception& exc) {
CL_WARNING("PHPEntityFunction::Store: %s", exc.GetMessage());
}
}
void PHPEntityFunction::FromResultSet(wxSQLite3ResultSet& res)
{
SetDbId(res.GetInt("ID"));
SetFullName(res.GetString("FULLNAME"));
SetShortName(res.GetString("NAME"));
m_strSignature = res.GetString("SIGNATURE");
m_strReturnValue = res.GetString("RETURN_VALUE");
SetFlags(res.GetInt("FLAGS"));
SetDocComment(res.GetString("DOC_COMMENT"));
SetLine(res.GetInt("LINE_NUMBER"));
SetFilename(res.GetString("FILE_NAME"));
}
wxString PHPEntityFunction::GetScope() const
{
if(Parent()) { return Parent()->GetFullName(); }
return "";
}
wxString PHPEntityFunction::Type() const { return GetReturnValue(); }
bool PHPEntityFunction::Is(eEntityType type) const { return type == kEntityTypeFunction; }
wxString PHPEntityFunction::GetDisplayName() const { return wxString() << GetShortName() << GetSignature(); }
wxString PHPEntityFunction::FormatPhpDoc(const CommentConfigData& data) const
{
wxString doc;
doc << data.GetCommentBlockPrefix() << "\n"
<< " * @brief \n";
PHPEntityBase::List_t::const_iterator iter = m_children.begin();
for(; iter != m_children.end(); ++iter) {
const PHPEntityVariable* var = (*iter)->Cast<PHPEntityVariable>();
if(var) {
doc << " * @param " << (var->GetTypeHint().IsEmpty() ? "mixed" : var->GetTypeHint()) << " "
<< var->GetFullName() << " \n";
}
}
doc << " * @return " << GetReturnValue() << " \n";
doc << " */";
return doc;
}
wxString PHPEntityFunction::GetFullPath() const
{
wxString fullpath = GetFullName();
size_t where = fullpath.rfind(GetShortName());
if(where != wxString::npos) {
if(where > 0) {
fullpath = fullpath.Mid(0, where - 1);
if(fullpath.IsEmpty()) {
fullpath << "\\";
} else {
fullpath << "::";
}
}
fullpath << GetShortName();
}
fullpath << GetSignature();
return fullpath;
}
void PHPEntityFunction::FromJSON(const JSONItem& json)
{
BaseFromJSON(json);
m_strReturnValue = json.namedObject("returns").toString();
m_strSignature = json.namedObject("signature").toString();
}
JSONItem PHPEntityFunction::ToJSON() const
{
JSONItem json = BaseToJSON("f");
json.addProperty("returns", m_strReturnValue);
json.addProperty("signature", m_strSignature);
return json;
}
wxString PHPEntityFunction::ToTooltip() const
{
wxString tip;
tip << GetShortName() << GetSignature();
if(!GetReturnValue().IsEmpty()) { tip << " : " << GetReturnValue(); }
return tip;
}
|